mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 17:52:59 +02:00
TAChart: Convert chart tools from collection items into subcomponents, similar to series
git-svn-id: trunk@24310 -
This commit is contained in:
parent
9857d352e0
commit
82c421e69c
@ -103,10 +103,11 @@ type
|
|||||||
|
|
||||||
{ TBasicСhartTool }
|
{ TBasicСhartTool }
|
||||||
|
|
||||||
TBasicChartTool = class(TCollectionItem)
|
TBasicChartTool = class(TComponent)
|
||||||
protected
|
strict protected
|
||||||
FChart: TChart;
|
FChart: TChart;
|
||||||
|
|
||||||
|
function Index: Integer; virtual; abstract;
|
||||||
procedure Activate;
|
procedure Activate;
|
||||||
procedure Deactivate;
|
procedure Deactivate;
|
||||||
end;
|
end;
|
||||||
|
@ -27,21 +27,36 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
TChartToolset = class;
|
||||||
|
|
||||||
{ TChartTool }
|
{ TChartTool }
|
||||||
|
|
||||||
TChartTool = class(TBasicChartTool)
|
TChartTool = class(TBasicChartTool)
|
||||||
private
|
private
|
||||||
FEnabled: Boolean;
|
FEnabled: Boolean;
|
||||||
FShift: TShiftState;
|
FShift: TShiftState;
|
||||||
|
FToolset: TChartToolset;
|
||||||
|
procedure SetToolset(const AValue: TChartToolset);
|
||||||
|
protected
|
||||||
|
procedure ReadState(Reader: TReader); override;
|
||||||
|
procedure SetParentComponent(AParent: TComponent); override;
|
||||||
protected
|
protected
|
||||||
procedure Dispatch(
|
procedure Dispatch(
|
||||||
AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint);
|
AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint);
|
||||||
|
function Index: Integer; override;
|
||||||
function IsActive: Boolean;
|
function IsActive: Boolean;
|
||||||
procedure MouseDown(APoint: TPoint); virtual;
|
procedure MouseDown(APoint: TPoint); virtual;
|
||||||
procedure MouseMove(APoint: TPoint); virtual;
|
procedure MouseMove(APoint: TPoint); virtual;
|
||||||
procedure MouseUp(APoint: TPoint); virtual;
|
procedure MouseUp(APoint: TPoint); virtual;
|
||||||
public
|
public
|
||||||
constructor Create(ACollection: TCollection); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
|
public
|
||||||
|
procedure Assign(Source: TPersistent); override;
|
||||||
|
function GetParentComponent: TComponent; override;
|
||||||
|
function HasParent: Boolean; override;
|
||||||
|
|
||||||
|
property Toolset: TChartToolset read FToolset write SetToolset;
|
||||||
published
|
published
|
||||||
property Enabled: Boolean read FEnabled write FEnabled default true;
|
property Enabled: Boolean read FEnabled write FEnabled default true;
|
||||||
property Shift: TShiftState read FShift write FShift;
|
property Shift: TShiftState read FShift write FShift;
|
||||||
@ -49,22 +64,28 @@ type
|
|||||||
|
|
||||||
TChartToolClass = class of TChartTool;
|
TChartToolClass = class of TChartTool;
|
||||||
|
|
||||||
|
TChartTools = class(TFPList)
|
||||||
|
end;
|
||||||
|
|
||||||
{ TChartToolset }
|
{ TChartToolset }
|
||||||
|
|
||||||
TChartToolset = class(TBasicChartToolset)
|
TChartToolset = class(TBasicChartToolset)
|
||||||
private
|
private
|
||||||
FTools: TCollection;
|
FTools: TChartTools;
|
||||||
function GetItem(AIndex: Integer): TChartTool;
|
function GetItem(AIndex: Integer): TChartTool;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
public
|
||||||
|
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
|
||||||
|
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
|
||||||
|
public
|
||||||
function Dispatch(
|
function Dispatch(
|
||||||
AChart: TChart; AEventId: TChartToolEventId;
|
AChart: TChart; AEventId: TChartToolEventId;
|
||||||
AShift: TShiftState; APoint: TPoint): Boolean; override;
|
AShift: TShiftState; APoint: TPoint): Boolean; override;
|
||||||
property Item[AIndex: Integer]: TChartTool read GetItem; default;
|
property Item[AIndex: Integer]: TChartTool read GetItem; default;
|
||||||
published
|
published
|
||||||
property Tools: TCollection read FTools;
|
property Tools: TChartTools read FTools;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartZoomDragTool }
|
{ TChartZoomDragTool }
|
||||||
@ -92,30 +113,11 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
CollectionPropEditForm, Forms, GraphMath, Math, Menus, PropEdits, Types,
|
GraphMath, Math, Types,
|
||||||
TAChartUtils;
|
TAChartUtils;
|
||||||
|
|
||||||
type
|
|
||||||
|
|
||||||
{ TChartToolsEditor }
|
|
||||||
|
|
||||||
TChartToolsEditor = class(TCollectionPropertyEditor)
|
|
||||||
public
|
|
||||||
class function ShowCollectionEditor(
|
|
||||||
ACollection: TCollection; OwnerPersistent: TPersistent;
|
|
||||||
const PropName: String): TCustomForm; override;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TChartToolsEditorForm }
|
|
||||||
|
|
||||||
TChartToolsEditorForm = class(TCollectionPropertyEditorForm)
|
|
||||||
private
|
|
||||||
procedure OnAddToolClick(ASender: TObject);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
ToolsClassRegistry: TStringList;
|
ToolsClassRegistry: TStringList;
|
||||||
ChartToolsForm: TChartToolsEditorForm;
|
|
||||||
|
|
||||||
function InitBuitlinTools(AChart: TChart): TBasicChartToolset;
|
function InitBuitlinTools(AChart: TChart): TBasicChartToolset;
|
||||||
var
|
var
|
||||||
@ -123,35 +125,16 @@ var
|
|||||||
begin
|
begin
|
||||||
ts := TChartToolset.Create(AChart);
|
ts := TChartToolset.Create(AChart);
|
||||||
Result := ts;
|
Result := ts;
|
||||||
TChartZoomDragTool.Create(ts.Tools).Shift := [ssLeft];
|
with TChartZoomDragTool.Create(AChart) do begin
|
||||||
TChartReticuleTool.Create(ts.Tools);
|
Shift := [ssLeft];
|
||||||
end;
|
Toolset := ts;
|
||||||
|
|
||||||
procedure InitChartToolsForm;
|
|
||||||
var
|
|
||||||
m: TPopupMenu;
|
|
||||||
mi: TMenuItem;
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
if ChartToolsForm <> nil then exit;
|
|
||||||
ChartToolsForm := TChartToolsEditorForm.Create(Application);
|
|
||||||
m := TPopupMenu.Create(ChartToolsForm);
|
|
||||||
for i := 0 to ToolsClassRegistry.Count - 1 do begin
|
|
||||||
mi := TMenuItem.Create(ChartToolsForm);
|
|
||||||
mi.Caption := ToolsClassRegistry[i];
|
|
||||||
mi.Tag := i;
|
|
||||||
mi.OnClick := @ChartToolsForm.OnAddToolClick;
|
|
||||||
m.Items.Add(mi);
|
|
||||||
end;
|
end;
|
||||||
ChartToolsForm.AddButton.DropdownMenu := m;
|
TChartReticuleTool.Create(AChart).Toolset := ts;
|
||||||
ChartToolsForm.AddButton.OnClick := nil;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
RegisterComponents(CHART_COMPONENT_IDE_PAGE, [TChartToolset]);
|
RegisterComponents(CHART_COMPONENT_IDE_PAGE, [TChartToolset]);
|
||||||
RegisterPropertyEditor(
|
|
||||||
TypeInfo(TCollection), TChartToolset, 'Tools', TChartToolsEditor);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure RegisterChartToolClass(
|
procedure RegisterChartToolClass(
|
||||||
@ -160,44 +143,31 @@ begin
|
|||||||
ToolsClassRegistry.AddObject(ACaption, TObject(AToolClass));
|
ToolsClassRegistry.AddObject(ACaption, TObject(AToolClass));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartToolsEditor }
|
procedure TChartTool.Assign(Source: TPersistent);
|
||||||
|
|
||||||
class function TChartToolsEditor.ShowCollectionEditor(
|
|
||||||
ACollection: TCollection; OwnerPersistent: TPersistent;
|
|
||||||
const PropName: String): TCustomForm;
|
|
||||||
begin
|
begin
|
||||||
InitChartToolsForm;
|
if Source is TChartTool then
|
||||||
ChartToolsForm.SetCollection(ACollection, OwnerPersistent, PropName);
|
with TChartTool(Source) do begin
|
||||||
ChartToolsForm.EnsureVisible;
|
Self.FEnabled := Enabled;
|
||||||
Result := ChartToolsForm;
|
Self.FShift := Shift;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
inherited Assign(Source);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartToolsEditorForm }
|
|
||||||
|
|
||||||
procedure TChartToolsEditorForm.OnAddToolClick(ASender: TObject);
|
|
||||||
begin
|
|
||||||
if Collection = nil then exit;
|
|
||||||
with ASender as TMenuItem do
|
|
||||||
TChartToolClass(ToolsClassRegistry.Objects[Tag]).Create(Collection);
|
|
||||||
|
|
||||||
FillCollectionListBox;
|
|
||||||
if CollectionListBox.Items.Count > 0 then
|
|
||||||
CollectionListBox.ItemIndex := CollectionListBox.Items.Count - 1;
|
|
||||||
SelectInObjectInspector(True, False);
|
|
||||||
UpdateButtons;
|
|
||||||
UpdateCaption;
|
|
||||||
Modified;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TChartTool }
|
{ TChartTool }
|
||||||
|
|
||||||
constructor TChartTool.Create(ACollection: TCollection);
|
constructor TChartTool.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(ACollection);
|
inherited Create(AOwner);
|
||||||
FEnabled := true;
|
FEnabled := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
destructor TChartTool.Destroy;
|
||||||
|
begin
|
||||||
|
Toolset := nil;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChartTool.Dispatch(
|
procedure TChartTool.Dispatch(
|
||||||
AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint);
|
AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint);
|
||||||
begin
|
begin
|
||||||
@ -215,6 +185,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TChartTool.GetParentComponent: TComponent;
|
||||||
|
begin
|
||||||
|
Result := FToolset;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TChartTool.HasParent: Boolean;
|
||||||
|
begin
|
||||||
|
Result := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TChartTool.Index: Integer;
|
||||||
|
begin
|
||||||
|
if FToolset = nil then
|
||||||
|
Result := -1
|
||||||
|
else
|
||||||
|
Result := FToolset.Tools.IndexOf(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
function TChartTool.IsActive: Boolean;
|
function TChartTool.IsActive: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FChart.ActiveToolIndex = Index;
|
Result := FChart.ActiveToolIndex = Index;
|
||||||
@ -235,16 +223,41 @@ begin
|
|||||||
Unused(APoint);
|
Unused(APoint);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartTool.ReadState(Reader: TReader);
|
||||||
|
begin
|
||||||
|
inherited ReadState(Reader);
|
||||||
|
if Reader.Parent is TChartToolset then
|
||||||
|
Toolset := Reader.Parent as TChartToolset;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TChartTool.SetParentComponent(AParent: TComponent);
|
||||||
|
begin
|
||||||
|
if not (csLoading in ComponentState) then
|
||||||
|
Toolset := AParent as TChartToolset;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TChartTool.SetToolset(const AValue: TChartToolset);
|
||||||
|
begin
|
||||||
|
if FToolset = AValue then exit;
|
||||||
|
if FToolset <> nil then
|
||||||
|
FToolset.FTools.Remove(Self);
|
||||||
|
FToolset := AValue;
|
||||||
|
if FToolset <> nil then
|
||||||
|
FToolset.FTools.Add(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TChartToolset }
|
{ TChartToolset }
|
||||||
|
|
||||||
constructor TChartToolset.Create(AOwner: TComponent);
|
constructor TChartToolset.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FTools := TCollection.Create(TChartTool);
|
FTools := TChartTools.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TChartToolset.Destroy;
|
destructor TChartToolset.Destroy;
|
||||||
begin
|
begin
|
||||||
|
while Tools.Count > 0 do
|
||||||
|
Item[Tools.Count - 1].Free;
|
||||||
FTools.Free;
|
FTools.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
@ -269,9 +282,30 @@ begin
|
|||||||
Result := false;
|
Result := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartToolset.GetChildren(Proc: TGetChildProc; Root: TComponent);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
t: TChartTool;
|
||||||
|
begin
|
||||||
|
for i := 0 to Tools.Count - 1 do begin
|
||||||
|
t := Item[i];
|
||||||
|
if t.Owner = Root then
|
||||||
|
Proc(t);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TChartToolset.GetItem(AIndex: Integer): TChartTool;
|
function TChartToolset.GetItem(AIndex: Integer): TChartTool;
|
||||||
begin
|
begin
|
||||||
Result := Tools.Items[AIndex] as TChartTool;
|
Result := TChartTool(Tools.Items[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TChartToolset.SetChildOrder(Child: TComponent; Order: Integer);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
i := Tools.IndexOf(Child);
|
||||||
|
if i >= 0 then
|
||||||
|
Tools.Move(i, Order);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartZoomDragTool }
|
{ TChartZoomDragTool }
|
||||||
|
Loading…
Reference in New Issue
Block a user