mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 18:39:20 +02:00
TAChart: Auto-rename subcomponents when parent component name changes
git-svn-id: trunk@29331 -
This commit is contained in:
parent
9f1e2fbd9c
commit
c25cf46ae6
@ -118,9 +118,20 @@ type
|
|||||||
function GetIndex: Integer; virtual; abstract;
|
function GetIndex: Integer; virtual; abstract;
|
||||||
procedure SetIndex(AValue: Integer); virtual; abstract;
|
procedure SetIndex(AValue: Integer); virtual; abstract;
|
||||||
public
|
public
|
||||||
|
procedure ChangeNamePrefix(const AOld, ANew: String; var AFailed: String);
|
||||||
|
|
||||||
property Index: Integer read GetIndex write SetIndex;
|
property Index: Integer read GetIndex write SetIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TShowMessageProc = procedure (const AMsg: String);
|
||||||
|
|
||||||
|
{ TIndexedComponentList }
|
||||||
|
|
||||||
|
TIndexedComponentList = class(TFPList)
|
||||||
|
public
|
||||||
|
procedure ChangeNamePrefix(const AOld, ANew: String);
|
||||||
|
end;
|
||||||
|
|
||||||
TBroadcaster = class;
|
TBroadcaster = class;
|
||||||
|
|
||||||
{ TListener }
|
{ TListener }
|
||||||
@ -291,9 +302,16 @@ operator :=(const ASize: TSize): TPoint; inline;
|
|||||||
|
|
||||||
var
|
var
|
||||||
DrawData: TDrawDataRegistry;
|
DrawData: TDrawDataRegistry;
|
||||||
|
ShowMessageProc: TShowMessageProc;
|
||||||
|
|
||||||
|
resourcestring
|
||||||
|
tasFailedSubcomponentRename = 'Failed to rename components: %s';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
StrUtils;
|
||||||
|
|
||||||
const
|
const
|
||||||
ORIENTATION_UNITS_PER_DEG = 10;
|
ORIENTATION_UNITS_PER_DEG = 10;
|
||||||
|
|
||||||
@ -929,6 +947,34 @@ begin
|
|||||||
Result.Y := ASize.cy;
|
Result.Y := ASize.cy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TIndexedComponentList }
|
||||||
|
|
||||||
|
procedure TIndexedComponentList.ChangeNamePrefix(
|
||||||
|
const AOld, ANew: String);
|
||||||
|
var
|
||||||
|
failed: String;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
failed := '';
|
||||||
|
for i := 0 to Count - 1 do
|
||||||
|
TIndexedComponent(Items[i]).ChangeNamePrefix(AOld, ANew, failed);
|
||||||
|
if (failed <> '') and Assigned(ShowMessageProc) then
|
||||||
|
ShowMessageProc(Format(tasFailedSubcomponentRename, [failed]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TIndexedComponent }
|
||||||
|
|
||||||
|
procedure TIndexedComponent.ChangeNamePrefix(
|
||||||
|
const AOld, ANew: String; var AFailed: String);
|
||||||
|
begin
|
||||||
|
if AnsiStartsStr(AOld, Name) then
|
||||||
|
try
|
||||||
|
Name := ANew + Copy(Name, Length(AOld) + 1, Length(Name));
|
||||||
|
except on EComponentError do
|
||||||
|
AFailed += IfThen(AFailed = '', '', ', ') + Name;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TIntervalList }
|
{ TIntervalList }
|
||||||
|
|
||||||
procedure TIntervalList.AddPoint(APoint: Double); inline;
|
procedure TIntervalList.AddPoint(APoint: Double); inline;
|
||||||
|
@ -29,7 +29,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
LCLType, LResources,
|
LCLType, LResources,
|
||||||
SysUtils, Classes, Controls, Graphics, Dialogs,
|
SysUtils, Classes, Controls, Graphics,
|
||||||
TAChartUtils, TATypes, TALegend, TAChartAxis;
|
TAChartUtils, TATypes, TALegend, TAChartAxis;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -119,7 +119,7 @@ type
|
|||||||
|
|
||||||
TChartSeriesList = class(TPersistent)
|
TChartSeriesList = class(TPersistent)
|
||||||
private
|
private
|
||||||
FList: TFPList;
|
FList: TIndexedComponentList;
|
||||||
function GetItem(AIndex: Integer): TBasicChartSeries;
|
function GetItem(AIndex: Integer): TBasicChartSeries;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
@ -129,7 +129,7 @@ type
|
|||||||
function Count: Integer;
|
function Count: Integer;
|
||||||
public
|
public
|
||||||
property Items[AIndex: Integer]: TBasicChartSeries read GetItem; default;
|
property Items[AIndex: Integer]: TBasicChartSeries read GetItem; default;
|
||||||
property List: TFPList read FList;
|
property List: TIndexedComponentList read FList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TChartAfterDrawEvent = procedure (
|
TChartAfterDrawEvent = procedure (
|
||||||
@ -229,6 +229,7 @@ type
|
|||||||
procedure PrepareLegend(
|
procedure PrepareLegend(
|
||||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
|
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
|
||||||
var AClipRect: TRect; out ALegendRect: TRect);
|
var AClipRect: TRect; out ALegendRect: TRect);
|
||||||
|
procedure SetName(const AValue: TComponentName); override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -351,7 +352,7 @@ var
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Clipbrd, GraphMath, LCLProc, Math, Types, TADrawUtils;
|
Clipbrd, Dialogs, GraphMath, LCLProc, Math, Types, TADrawUtils;
|
||||||
|
|
||||||
function CompareZPosition(AItem1, AItem2: Pointer): Integer;
|
function CompareZPosition(AItem1, AItem2: Pointer): Integer;
|
||||||
begin
|
begin
|
||||||
@ -949,6 +950,17 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChart.SetName(const AValue: TComponentName);
|
||||||
|
var
|
||||||
|
oldName: String;
|
||||||
|
begin
|
||||||
|
if Name = AValue then exit;
|
||||||
|
oldName := Name;
|
||||||
|
inherited SetName(AValue);
|
||||||
|
if csDesigning in ComponentState then
|
||||||
|
Series.List.ChangeNamePrefix(oldName, AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChart.SetOnAfterDrawBackground(AValue: TChartAfterDrawEvent);
|
procedure TChart.SetOnAfterDrawBackground(AValue: TChartAfterDrawEvent);
|
||||||
begin
|
begin
|
||||||
if FOnAfterDrawBackground = AValue then exit;
|
if FOnAfterDrawBackground = AValue then exit;
|
||||||
@ -1245,7 +1257,7 @@ end;
|
|||||||
|
|
||||||
constructor TChartSeriesList.Create;
|
constructor TChartSeriesList.Create;
|
||||||
begin
|
begin
|
||||||
FList := TFPList.Create;
|
FList := TIndexedComponentList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TChartSeriesList.Destroy;
|
destructor TChartSeriesList.Destroy;
|
||||||
@ -1299,6 +1311,7 @@ initialization
|
|||||||
{$I tagraph.lrs}
|
{$I tagraph.lrs}
|
||||||
SkipObsoleteChartProperties;
|
SkipObsoleteChartProperties;
|
||||||
SeriesClassRegistry := TStringList.Create;
|
SeriesClassRegistry := TStringList.Create;
|
||||||
|
ShowMessageProc := @ShowMessage;
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeAndNil(SeriesClassRegistry);
|
FreeAndNil(SeriesClassRegistry);
|
||||||
|
@ -70,7 +70,7 @@ type
|
|||||||
|
|
||||||
TAxisTransformClass = class of TAxisTransform;
|
TAxisTransformClass = class of TAxisTransform;
|
||||||
|
|
||||||
TAxisTransformList = class(TFPList)
|
TAxisTransformList = class(TIndexedComponentList)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartAxisTransformations }
|
{ TChartAxisTransformations }
|
||||||
@ -79,6 +79,8 @@ type
|
|||||||
private
|
private
|
||||||
FBroadcaster: TBroadcaster;
|
FBroadcaster: TBroadcaster;
|
||||||
FList: TAxisTransformList;
|
FList: TAxisTransformList;
|
||||||
|
protected
|
||||||
|
procedure SetName(const AValue: TComponentName); override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -524,6 +526,17 @@ begin
|
|||||||
List.Move(i, Order);
|
List.Move(i, Order);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartAxisTransformations.SetName(const AValue: TComponentName);
|
||||||
|
var
|
||||||
|
oldName: String;
|
||||||
|
begin
|
||||||
|
if Name = AValue then exit;
|
||||||
|
oldName := Name;
|
||||||
|
inherited SetName(AValue);
|
||||||
|
if csDesigning in ComponentState then
|
||||||
|
List.ChangeNamePrefix(oldName, AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChartAxisTransformations.UpdateBounds(var AMin, AMax: Double);
|
procedure TChartAxisTransformations.UpdateBounds(var AMin, AMax: Double);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user