From b4612a8bc78fc20b4d402308e18843c2f425c36f Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 23 Apr 2018 11:25:30 +0000 Subject: [PATCH] * Allow use of custom elements registered in reporting engine (barcode en QRCode are standard) git-svn-id: trunk@57686 - --- .../design/frmfpreportdesignermain.pp | 76 +++++++++++++++++++ components/fpreport/design/reportdesign.lpr | 2 + components/fpreport/fpreportlclexport.pas | 13 ++-- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/components/fpreport/design/frmfpreportdesignermain.pp b/components/fpreport/design/frmfpreportdesignermain.pp index 7d56f22774..cb281dd6c9 100644 --- a/components/fpreport/design/frmfpreportdesignermain.pp +++ b/components/fpreport/design/frmfpreportdesignermain.pp @@ -313,6 +313,7 @@ type procedure VAlignExecute(Sender: TObject); procedure VResizeExecute(Sender: TObject); private + FCustomStartIndex : Integer; FInitialFileName: String; FLoadModified : Boolean; FStopDesigning: Boolean; @@ -339,6 +340,8 @@ type procedure GetReportDataNames(Sender: TObject; List: TStrings); procedure InitialiseData; {$ENDIF} + procedure AddCustomElementExecute(Sender: TObject); + procedure AddCustomElements; procedure CheckLoadInitialFile; function CreateDesignPopupMenu(aOWner: TComponent): TPopupMenu; function CreateNewPage: TFPReportCustomPage; @@ -535,6 +538,8 @@ begin FreeAndNil(TSDesign); // Remove design-time added page FReportDesignData:=TDesignReportDataManager.Create(Self); SetBandActionTags; + FCustomStartIndex:=Madd.Count; + AddCustomElements; // DEMO {$IFDEF USEDEMOREPORT} CreateDemoReport; @@ -558,6 +563,77 @@ begin end; end; +Type + { TAddElementAction } + + TAddElementAction = Class(TAction) + private + FClass: TFPReportElementClass; + published + Property AClass : TFPReportElementClass Read FClass Write FClass; + end; + +procedure TFPReportDesignerForm.AddCustomElements; + + Function AllowClass(M : TFPReportClassMapping) : Boolean; + + begin + Result:= not M.ReportElementClass.InheritsFrom(TFPReportCustomBand) + and not M.ReportElementClass.InheritsFrom(TFPReportCustomPage); + if Result then + Result:=Not M.Standard; + end; + +Var + I : Integer; + M : TFPReportClassMapping; + MI : TMenuItem; + A : TAddElementAction; + Img : TPortableNetworkGraphic; + S : TMemoryStream; + +begin + for I:=0 to gElementFactory.MappingCount-1 do + begin + M:=gElementFactory.Mappings[i]; + if AllowClass(M) then + begin + A:=TAddElementAction.Create(Self); + A.Caption:=M.MappingName; + A.AClass:=M.ReportElementClass; + A.OnUpdate:=@AAddElementUpdate; + A.OnExecute:=@AddCustomElementExecute; + A.Category:='Add'; + A.ActionList:=ALReport; + if (Length(M.IconData)>0) then + begin + Img:=Nil; + S:=TMemoryStream.Create; + try + S.WriteBuffer(M.IconData[0],Length(M.IConData)); + S.Position:=0; + Img:=TPortableNetworkGraphic.Create; + Img.LoadFromStream(S); + A.ImageIndex:=ILReport.Add(Img,Nil); + Finally + S.Free; + Img.Free; + end; + end; + MI:=TMenuItem.Create(Self); + MI.Action:=A; + MAdd.Add(MI); + end; + end; +end; + +procedure TFPReportDesignerForm.AddCustomElementExecute(Sender: TObject); + +begin + if (Sender is TAddElementAction) then + CurrentDesigner.AddElement((Sender as TAddElementAction).AClass); +end; + procedure TFPReportDesignerForm.FormCloseQuery(Sender: TObject; var CanClose: boolean); begin diff --git a/components/fpreport/design/reportdesign.lpr b/components/fpreport/design/reportdesign.lpr index 60253c483b..c23248947a 100644 --- a/components/fpreport/design/reportdesign.lpr +++ b/components/fpreport/design/reportdesign.lpr @@ -12,6 +12,8 @@ uses reportconns, fpreport, fpreportdb, + fpreportbarcode, + fpreportqrcode, // Exports fpreportpdfexport, fpreporthtmlexport, diff --git a/components/fpreport/fpreportlclexport.pas b/components/fpreport/fpreportlclexport.pas index 980ecca253..d3f7630454 100644 --- a/components/fpreport/fpreportlclexport.pas +++ b/components/fpreport/fpreportlclexport.pas @@ -892,6 +892,7 @@ procedure TFPReportExportCanvas.RenderElement(ABand : TFPReportCustomBand; Eleme Var C : TFPReportPoint; + LB,LE : TFPReportLayout; begin {$IFDEF DEBUGRD} @@ -909,11 +910,13 @@ begin RenderCheckbox(ABand,TFPReportCustomCheckbox(Element)) else if not (Element is TFPReportCustomBand) then begin - C.Left := ABand.RTLayout.Left + Element.RTLayout.Left; - C.Top := ABand.RTLayout.Top + Element.RTLayout.Top ; // + Element.RTLayout.Height; - RenderFrame(ABand, Element.Frame, C, Element.RTLayout.Width, Element.RTLayout.Height); - C.Left:=aband.RTLayout.Left; - C.Top:=aband.RTLayout.Top; + LB:=GetLayout(ABand); + LE:=GetLayout(Element); + C.Left := LB.Left + LE.Left; + C.Top := LB.Top + LE.Top ; // + Element.RTLayout.Height; + RenderFrame(ABand, Element.Frame, C, LE.Width, LE.Height); + C.Left:=LB.Left; + C.Top:=LB.Top; RenderUnknownElement(C,Element,Self.VDPI); end; end;