mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-07 04:18:19 +02:00
TAChart: Allow design-time tools editing
git-svn-id: trunk@24326 -
This commit is contained in:
parent
4ad6beba14
commit
02e6a3fe48
@ -35,7 +35,7 @@ resourcestring
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, ComponentEditors, Forms,Menus, PropEdits, SysUtils,
|
Classes, ComponentEditors, Forms, Menus, PropEdits, SysUtils,
|
||||||
TAGraph, TASubcomponentsEditor;
|
TAGraph, TASubcomponentsEditor;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -70,17 +70,17 @@ type
|
|||||||
FPropertyEditor: TComponentListPropertyEditor;
|
FPropertyEditor: TComponentListPropertyEditor;
|
||||||
function FindChild(ACandidate: TPersistent; out AIndex: Integer): Boolean;
|
function FindChild(ACandidate: TPersistent; out AIndex: Integer): Boolean;
|
||||||
procedure OnComponentRenamed(AComponent: TComponent);
|
procedure OnComponentRenamed(AComponent: TComponent);
|
||||||
procedure OnPersistentDeleting(APersistent: TPersistent);
|
|
||||||
procedure OnGetSelection(const ASelection: TPersistentSelectionList);
|
procedure OnGetSelection(const ASelection: TPersistentSelectionList);
|
||||||
procedure OnSetSelection(const ASelection: TPersistentSelectionList);
|
|
||||||
procedure OnPersistentAdded(APersistent: TPersistent; ASelect: Boolean);
|
procedure OnPersistentAdded(APersistent: TPersistent; ASelect: Boolean);
|
||||||
|
procedure OnPersistentDeleting(APersistent: TPersistent);
|
||||||
|
procedure OnSetSelection(const ASelection: TPersistentSelectionList);
|
||||||
procedure SelectionChanged;
|
procedure SelectionChanged;
|
||||||
protected
|
protected
|
||||||
procedure AddSubcomponentClass(const ACaption: String; ATag: Integer);
|
|
||||||
procedure AddSubcomponent(AParent, AChild: TComponent); virtual; abstract;
|
procedure AddSubcomponent(AParent, AChild: TComponent); virtual; abstract;
|
||||||
|
procedure AddSubcomponentClass(const ACaption: String; ATag: Integer);
|
||||||
procedure BuildCaption; virtual; abstract;
|
procedure BuildCaption; virtual; abstract;
|
||||||
procedure EnumerateSubcomponentClasses; virtual; abstract;
|
|
||||||
function ChildClass: TComponentClass; virtual; abstract;
|
function ChildClass: TComponentClass; virtual; abstract;
|
||||||
|
procedure EnumerateSubcomponentClasses; virtual; abstract;
|
||||||
function MakeSubcomponent(
|
function MakeSubcomponent(
|
||||||
AOwner: TComponent; ATag: Integer): TComponent; virtual; abstract;
|
AOwner: TComponent; ATag: Integer): TComponent; virtual; abstract;
|
||||||
procedure RefreshList; virtual; abstract;
|
procedure RefreshList; virtual; abstract;
|
||||||
|
@ -110,11 +110,46 @@ type
|
|||||||
procedure RegisterChartToolClass(
|
procedure RegisterChartToolClass(
|
||||||
AToolClass: TChartToolClass; const ACaption: String);
|
AToolClass: TChartToolClass; const ACaption: String);
|
||||||
|
|
||||||
|
resourcestring
|
||||||
|
tasToolsEditorTitle = 'Edit tools';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
GraphMath, Math, Types,
|
ComponentEditors, Forms, GraphMath, Math, PropEdits, Types,
|
||||||
TAChartUtils;
|
TAChartUtils, TASubcomponentsEditor;
|
||||||
|
|
||||||
|
type
|
||||||
|
{ TToolsComponentEditor }
|
||||||
|
|
||||||
|
TToolsComponentEditor = class(TSubComponentListEditor)
|
||||||
|
protected
|
||||||
|
function MakeEditorForm: TForm; override;
|
||||||
|
public
|
||||||
|
function GetVerbCount: Integer; override;
|
||||||
|
function GetVerb(Index: Integer): string; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TToolsPropertyEditor }
|
||||||
|
|
||||||
|
TToolsPropertyEditor = class(TComponentListPropertyEditor)
|
||||||
|
protected
|
||||||
|
function MakeEditorForm: TForm; override;
|
||||||
|
function GetChildrenCount: Integer; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TToolsEditorForm }
|
||||||
|
|
||||||
|
TToolsEditorForm = class(TComponentListEditorForm)
|
||||||
|
protected
|
||||||
|
procedure AddSubcomponent(AParent, AChild: TComponent); override;
|
||||||
|
procedure BuildCaption; override;
|
||||||
|
function ChildClass: TComponentClass; override;
|
||||||
|
procedure EnumerateSubcomponentClasses; override;
|
||||||
|
function MakeSubcomponent(
|
||||||
|
AOwner: TComponent; ATag: Integer): TComponent; override;
|
||||||
|
procedure RefreshList; override;
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
ToolsClassRegistry: TStringList;
|
ToolsClassRegistry: TStringList;
|
||||||
@ -135,14 +170,95 @@ end;
|
|||||||
procedure Register;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
RegisterComponents(CHART_COMPONENT_IDE_PAGE, [TChartToolset]);
|
RegisterComponents(CHART_COMPONENT_IDE_PAGE, [TChartToolset]);
|
||||||
|
RegisterPropertyEditor(
|
||||||
|
TypeInfo(TChartTools), TChartToolset, 'Tools', TToolsPropertyEditor);
|
||||||
|
RegisterComponentEditor(TChartToolset, TToolsComponentEditor);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure RegisterChartToolClass(
|
procedure RegisterChartToolClass(
|
||||||
AToolClass: TChartToolClass; const ACaption: String);
|
AToolClass: TChartToolClass; const ACaption: String);
|
||||||
begin
|
begin
|
||||||
ToolsClassRegistry.AddObject(ACaption, TObject(AToolClass));
|
ToolsClassRegistry.AddObject(ACaption, TObject(AToolClass));
|
||||||
|
RegisterClass(AToolClass);
|
||||||
|
RegisterNoIcon([AToolClass]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TToolsComponentEditor }
|
||||||
|
|
||||||
|
function TToolsComponentEditor.GetVerb(Index: Integer): string;
|
||||||
|
begin
|
||||||
|
if Index = 0 then
|
||||||
|
Result := tasToolsEditorTitle
|
||||||
|
else
|
||||||
|
Result := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TToolsComponentEditor.GetVerbCount: Integer;
|
||||||
|
begin
|
||||||
|
Result := 1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TToolsComponentEditor.MakeEditorForm: TForm;
|
||||||
|
begin
|
||||||
|
Result := TToolsEditorForm.Create(Application, GetComponent, Self, nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TToolsPropertyEditor }
|
||||||
|
|
||||||
|
function TToolsPropertyEditor.GetChildrenCount: Integer;
|
||||||
|
begin
|
||||||
|
Result := (GetObjectValue as TChartTools).Count;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TToolsPropertyEditor.MakeEditorForm: TForm;
|
||||||
|
begin
|
||||||
|
with TToolsEditorForm do
|
||||||
|
Result := Create(Application, GetComponent(0) as TComponent, nil, Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TToolsEditorForm }
|
||||||
|
|
||||||
|
procedure TToolsEditorForm.AddSubcomponent(AParent, AChild: TComponent);
|
||||||
|
begin
|
||||||
|
(AChild as TChartTool).Toolset := (AParent as TChartToolset);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TToolsEditorForm.BuildCaption;
|
||||||
|
begin
|
||||||
|
Caption := tasToolsEditorTitle + ' - ' + Parent.Name;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TToolsEditorForm.ChildClass: TComponentClass;
|
||||||
|
begin
|
||||||
|
Result := TChartTool;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TToolsEditorForm.EnumerateSubcomponentClasses;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to ToolsClassRegistry.Count - 1 do
|
||||||
|
AddSubcomponentClass(ToolsClassRegistry[i], i);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TToolsEditorForm.MakeSubcomponent(
|
||||||
|
AOwner: TComponent; ATag: Integer): TComponent;
|
||||||
|
begin
|
||||||
|
Result := TChartToolClass(ToolsClassRegistry.Objects[ATag]).Create(AOwner);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TToolsEditorForm.RefreshList;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
ChildrenListBox.Clear;
|
||||||
|
with Parent as TChartToolset do
|
||||||
|
for i := 0 to Tools.Count - 1 do
|
||||||
|
ChildrenListBox.Items.AddObject(Item[i].Name, Item[i]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TChartTool }
|
||||||
|
|
||||||
procedure TChartTool.Assign(Source: TPersistent);
|
procedure TChartTool.Assign(Source: TPersistent);
|
||||||
begin
|
begin
|
||||||
if Source is TChartTool then
|
if Source is TChartTool then
|
||||||
@ -154,8 +270,6 @@ begin
|
|||||||
inherited Assign(Source);
|
inherited Assign(Source);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartTool }
|
|
||||||
|
|
||||||
constructor TChartTool.Create(AOwner: TComponent);
|
constructor TChartTool.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
|
Loading…
Reference in New Issue
Block a user