LazStats: LazStats: Prepare more generalized layout by add form ancestors TBasicStatsReportForm and TBasicStatsReportAndChartForm

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7727 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-01 15:08:49 +00:00
parent 349f9b039b
commit 3e4d68478c
12 changed files with 284 additions and 56 deletions

View File

@ -9,6 +9,7 @@
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<Scaled Value="True"/> <Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
<XPManifest> <XPManifest>
<DpiAware Value="True"/> <DpiAware Value="True"/>
@ -121,7 +122,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item7> </Item7>
</RequiredPackages> </RequiredPackages>
<Units Count="178"> <Units Count="180">
<Unit0> <Unit0>
<Filename Value="LazStats.lpr"/> <Filename Value="LazStats.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -1517,6 +1518,22 @@
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="GroupFreqUnit"/> <UnitName Value="GroupFreqUnit"/>
</Unit177> </Unit177>
<Unit178>
<Filename Value="forms\misc\basicstatsreportfromunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="BasicStatsReportForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="BasicStatsReportFromUnit"/>
</Unit178>
<Unit179>
<Filename Value="forms\misc\basicstatsreportandchartformunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="BasicStatsReportAndChartForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="BasicStatsReportAndChartFormUnit"/>
</Unit179>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -7,8 +7,9 @@ uses
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset Interfaces, // this includes the LCL widgetset
Forms, tachartlazaruspkg, tachartprint, lhelpcontrolpkg, Forms, tachartlazaruspkg, tachartprint, lhelpcontrolpkg, Globals, LicenseUnit,
Globals, LicenseUnit, OptionsUnit, MainDM, MainUnit; OptionsUnit, MainDM, MainUnit, BasicStatsReportFromUnit,
BasicStatsReportAndChartFormUnit;
{$R LazStats.res} {$R LazStats.res}
@ -28,6 +29,8 @@ begin
end; end;
Application.CreateForm(TMainDataModule, MainDataModule); Application.CreateForm(TMainDataModule, MainDataModule);
Application.CreateForm(TOS3MainFrm, OS3MainFrm); Application.CreateForm(TOS3MainFrm, OS3MainFrm);
Application.CreateForm(TBasicStatsReportAndChartForm,
BasicStatsReportAndChartForm);
Application.Run; Application.Run;
end. end.

View File

@ -1,25 +1,27 @@
inherited GroupFreqForm: TGroupFreqForm inherited GroupFreqForm: TGroupFreqForm
Height = 212 Height = 279
Width = 673
Caption = 'Group Frequency Analysis' Caption = 'Group Frequency Analysis'
ClientHeight = 212 ClientHeight = 279
ClientWidth = 673
inherited ParamsPanel: TPanel inherited ParamsPanel: TPanel
Height = 196 Height = 263
ClientHeight = 196 ClientHeight = 263
inherited CloseBtn: TButton inherited CloseBtn: TButton
Top = 171 Top = 238
end end
inherited ComputeBtn: TButton inherited ComputeBtn: TButton
Top = 171 Top = 238
end end
inherited ResetBtn: TButton inherited ResetBtn: TButton
Top = 171 Top = 238
end end
inherited HelpBtn: TButton inherited HelpBtn: TButton
Tag = 162 Tag = 162
Top = 171 Top = 238
end end
inherited ButtonBevel: TBevel inherited ButtonBevel: TBevel
Top = 155 Top = 222
end end
object Label1: TLabel[5] object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
@ -38,7 +40,7 @@ inherited GroupFreqForm: TGroupFreqForm
AnchorSideRight.Control = GrpInBtn AnchorSideRight.Control = GrpInBtn
AnchorSideBottom.Control = ButtonBevel AnchorSideBottom.Control = ButtonBevel
Left = 0 Left = 0
Height = 138 Height = 205
Top = 17 Top = 17
Width = 126 Width = 126
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
@ -184,6 +186,6 @@ inherited GroupFreqForm: TGroupFreqForm
end end
end end
inherited ParamsSplitter: TSplitter inherited ParamsSplitter: TSplitter
Height = 212 Height = 279
end end
end end

View File

@ -32,12 +32,12 @@ type
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListSelectionChange(Sender: TObject; User: boolean);
private private
FLabelsSource: TListChartSource; FLabelsSource: TListChartSource;
procedure UpdateBtnStates;
protected protected
procedure AdjustConstraints; override; procedure AdjustConstraints; override;
procedure Compute; override; procedure Compute; override;
procedure Plot(XLabels: StrDyneVec; FreqValues: DblDyneVec; XTitle: String); procedure Plot(XLabels: StrDyneVec; FreqValues: DblDyneVec; XTitle: String);
procedure UpdateBtnStates; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -83,8 +83,8 @@ end;
procedure TGroupFreqForm.Compute; procedure TGroupFreqForm.Compute;
VAR var
nogroups, mingrp, maxgrp, grpcol, minfreq, maxfreq: integer; grpcol: integer;
cellStr: string; cellStr: string;
i, numValues, valueIdx: integer; i, numValues, valueIdx: integer;
freq: DblDyneVec = nil; // Could be IntDyneVec, but easier plotting with Dbl freq: DblDyneVec = nil; // Could be IntDyneVec, but easier plotting with Dbl
@ -97,7 +97,7 @@ begin
begin begin
grpcol := i; grpcol := i;
break; break;
end; end;
if grpcol = 0 then if grpcol = 0 then
begin begin
MessageDlg('No variable selected.', mtError, [mbOK], 0); MessageDlg('No variable selected.', mtError, [mbOK], 0);
@ -243,21 +243,21 @@ procedure TGroupFreqForm.Reset;
var var
i: integer; i: integer;
begin begin
inherited;
VarList.Clear; VarList.Clear;
for i := 1 to NoVariables do for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
GrpVarEdit.Text := ''; GrpVarEdit.Text := '';
UpdateBtnStates; UpdateBtnStates;
FChartFrame.Clear;
end; end;
procedure TGroupFreqForm.UpdateBtnStates; procedure TGroupFreqForm.UpdateBtnStates;
begin begin
GrpInBtn.Enabled := VarList.ItemIndex > -1; inherited;
GrpInBtn.Enabled := (VarList.ItemIndex > -1);
GrpOutBtn.Enabled := (GrpVarEdit.Text <> ''); GrpOutBtn.Enabled := (GrpVarEdit.Text <> '');
FChartFrame.UpdateBtnStates;
end; end;

View File

@ -1,6 +1,5 @@
inherited BasicStatsChartForm: TBasicStatsChartForm inherited BasicStatsChartForm: TBasicStatsChartForm
OnActivate = nil OnActivate = nil
OnCreate = FormCreate
inherited ParamsPanel: TPanel inherited ParamsPanel: TPanel
inherited CloseBtn: TButton inherited CloseBtn: TButton
OnClick = CloseBtnClick OnClick = CloseBtnClick

View File

@ -20,9 +20,11 @@ type
protected protected
FChartFrame: TChartFrame; FChartFrame: TChartFrame;
procedure UpdateBtnStates; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end; end;
@ -58,5 +60,21 @@ begin
Reset; Reset;
end; end;
procedure TBasicStatsChartForm.Reset;
begin
inherited;
if Assigned(FChartFrame) then
FChartFrame.Clear;
end;
procedure TBasicStatsChartForm.UpdateBtnStates;
begin
inherited;
if Assigned(FChartFrame) then
FChartFrame.UpdateBtnStates;
end;
end. end.

View File

@ -1,7 +1,5 @@
inherited BasicStatsParamsForm: TBasicStatsParamsForm inherited BasicStatsParamsForm: TBasicStatsParamsForm
Caption = 'BasicStatsParamsForm' Caption = 'BasicStatsParamsForm'
OnActivate = FormActivate
OnCreate = FormCreate
Position = poMainFormCenter Position = poMainFormCenter
object ParamsPanel: TPanel[0] object ParamsPanel: TPanel[0]
Left = 8 Left = 8

View File

@ -22,16 +22,17 @@ type
ParamsSplitter: TSplitter; ParamsSplitter: TSplitter;
procedure CloseBtnClick(Sender: TObject); procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject); procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure HelpBtnClick(Sender: TObject); procedure HelpBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
private private
protected protected
FAutoSized: Boolean; FAutoSized: Boolean;
procedure Activate; override;
procedure AdjustConstraints; virtual; procedure AdjustConstraints; virtual;
procedure Compute; virtual; procedure Compute; virtual;
procedure InitForm;
procedure UpdateBtnStates; virtual;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; virtual; function Validate(out AMsg: String; out AControl: TWinControl): Boolean; virtual;
public public
@ -49,7 +50,7 @@ implementation
uses uses
Math, Math,
Utils; Globals, Utils;
{ TBasicStatsParamsForm } { TBasicStatsParamsForm }
@ -57,6 +58,10 @@ uses
constructor TBasicStatsParamsForm.Create(AOwner: TComponent); constructor TBasicStatsParamsForm.Create(AOwner: TComponent);
begin begin
inherited; inherited;
InitForm;
Reset;
CloseBtn.OnClick := @CloseBtnClick; CloseBtn.OnClick := @CloseBtnClick;
ComputeBtn.OnClick := @ComputeBtnClick; ComputeBtn.OnClick := @ComputeBtnClick;
ResetBtn.OnClick := @ResetBtnClick; ResetBtn.OnClick := @ResetBtnClick;
@ -64,6 +69,29 @@ begin
end; end;
procedure TBasicStatsParamsForm.Activate;
var
w: Integer;
begin
if FAutoSized then
exit;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
HelpBtn.Constraints.MinWidth := 2;
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
AdjustConstraints;
if Width < Constraints.MinWidth then Width := 1; // enforce constraints
if Height < Constraints.MinHeight then Height := 1;
Position := poDesigned;
FAutoSized := true;
end;
procedure TBasicStatsParamsForm.AdjustConstraints; procedure TBasicStatsParamsForm.AdjustConstraints;
begin begin
// be be overridden // be be overridden
@ -98,34 +126,6 @@ begin
Compute; Compute;
end; end;
procedure TBasicStatsParamsForm.FormActivate(Sender: TObject);
var
w: Integer;
begin
if FAutoSized then
exit;
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
AdjustConstraints;
if Width < Constraints.MinWidth then Width := 1; // enforce constraints
if Height < Constraints.MinHeight then Height := 1;
Position := poDesigned;
FAutoSized := true;
end;
procedure TBasicStatsParamsForm.FormCreate(Sender: TObject);
begin
InitForm(self);
Reset;
end;
procedure TBasicStatsParamsForm.HelpBtnClick(Sender: TObject); procedure TBasicStatsParamsForm.HelpBtnClick(Sender: TObject);
begin begin
@ -135,12 +135,26 @@ begin
end; end;
procedure TBasicStatsParamsForm.InitForm;
begin
Width := Scale96ToFont(DEFAULT_WIDTH);
Height := Scale96ToFont(DEFAULT_HEIGHT);
Position := poMainFormCenter;
end;
procedure TBasicStatsParamsForm.ResetBtnClick(Sender: TObject); procedure TBasicStatsParamsForm.ResetBtnClick(Sender: TObject);
begin begin
Reset; Reset;
end; end;
procedure TBasicStatsParamsForm.UpdateBtnStates;
begin
// to be overridden
end;
function TBasicStatsParamsForm.Validate(out AMsg: String; function TBasicStatsParamsForm.Validate(out AMsg: String;
out AControl: TWinControl): Boolean; out AControl: TWinControl): Boolean;
begin begin

View File

@ -0,0 +1,22 @@
inherited BasicStatsReportAndChartForm: TBasicStatsReportAndChartForm
object PageControl: TPageControl[2]
Left = 312
Height = 443
Top = 8
Width = 397
ActivePage = ReportPage
Align = alClient
BorderSpacing.Left = 4
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
TabIndex = 0
TabOrder = 2
object ReportPage: TTabSheet
Caption = 'Report'
end
object ChartPage: TTabSheet
Caption = 'Chart'
end
end
end

View File

@ -0,0 +1,78 @@
unit BasicStatsReportAndChartFormUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
StdCtrls, ReportFrameUnit, ChartFrameUnit, BasicStatsParamsFormUnit;
type
{ TBasicStatsReportAndChartForm }
TBasicStatsReportAndChartForm = class(TBasicStatsParamsForm)
PageControl: TPageControl;
ReportPage: TTabSheet;
ChartPage: TTabSheet;
private
protected
FReportFrame: TReportFrame;
FChartFrame: TChartFrame;
procedure UpdateBtnStates; override;
public
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
var
BasicStatsReportAndChartForm: TBasicStatsReportAndChartForm;
implementation
{$R *.lfm}
constructor TBasicStatsReportAndChartForm.Create(AOwner: TComponent);
begin
inherited;
FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage;
FReportFrame.Align := alClient;
FChartFrame := TChartFrame.Create(self);
FChartFrame.Parent := ChartPage;
FChartFrame.Align := alClient;
FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
FChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
Reset;
end;
procedure TBasicStatsReportAndChartForm.Reset;
begin
inherited;
if Assigned(FReportFrame) then
FReportFrame.Clear;
if Assigned(FChartFrame) then
FChartFrame.Clear;
end;
procedure TBasicStatsReportAndChartForm.UpdateBtnStates;
begin
inherited;
if Assigned(FReportFrame) then
FReportFrame.UpdateBtnStates;
if Assigned(FChartFrame) then
FChartFrame.UpdateBtnStates;
end;
end.

View File

@ -0,0 +1,4 @@
inherited BasicStatsReportForm: TBasicStatsReportForm
Caption = 'BasicStatsReportForm'
OnCreate = FormCreate
end

View File

@ -0,0 +1,73 @@
unit BasicStatsReportFromUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
ReportFrameUnit, BasicStatsParamsFormUnit;
type
{ TBasicStatsReportForm }
TBasicStatsReportForm = class(TBasicStatsParamsForm)
private
protected
FReportFrame: TReportFrame;
procedure UpdateBtnStates; override;
public
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
var
BasicStatsReportForm: TBasicStatsReportForm;
implementation
{$R *.lfm}
uses
Utils;
constructor TBasicStatsReportForm.Create(AOwner: TComponent);
begin
inherited;
FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := Self;
FReportFrame.Align := alClient;
FReportFrame.BorderSpacing.Left := 4;
FReportFrame.BorderSpacing.Top := 8;
FReportFrame.BorderSpacing.Bottom := 8;
FReportFrame.BorderSpacing.Right := 8;
InitToolbar(FReportFrame.ReportToolbar, tpRight);
Reset;
end;
procedure TBasicStatsReportForm.Reset;
begin
inherited;
if Assigned(FReportFrame) then
FReportFrame.Clear;
end;
procedure TBasicStatsReportForm.UpdateBtnStates;
begin
inherited;
if Assigned(FReportFrame) then
FReportFrame.UpdateBtnStates;
end;
end.