mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 09:16:13 +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
@ -113,14 +113,25 @@ type
|
||||
|
||||
{ TIndexedComponent }
|
||||
|
||||
TIndexedComponent = class (TComponent)
|
||||
TIndexedComponent = class(TComponent)
|
||||
protected
|
||||
function GetIndex: Integer; virtual; abstract;
|
||||
procedure SetIndex(AValue: Integer); virtual; abstract;
|
||||
public
|
||||
procedure ChangeNamePrefix(const AOld, ANew: String; var AFailed: String);
|
||||
|
||||
property Index: Integer read GetIndex write SetIndex;
|
||||
end;
|
||||
|
||||
TShowMessageProc = procedure (const AMsg: String);
|
||||
|
||||
{ TIndexedComponentList }
|
||||
|
||||
TIndexedComponentList = class(TFPList)
|
||||
public
|
||||
procedure ChangeNamePrefix(const AOld, ANew: String);
|
||||
end;
|
||||
|
||||
TBroadcaster = class;
|
||||
|
||||
{ TListener }
|
||||
@ -291,9 +302,16 @@ operator :=(const ASize: TSize): TPoint; inline;
|
||||
|
||||
var
|
||||
DrawData: TDrawDataRegistry;
|
||||
ShowMessageProc: TShowMessageProc;
|
||||
|
||||
resourcestring
|
||||
tasFailedSubcomponentRename = 'Failed to rename components: %s';
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
StrUtils;
|
||||
|
||||
const
|
||||
ORIENTATION_UNITS_PER_DEG = 10;
|
||||
|
||||
@ -929,6 +947,34 @@ begin
|
||||
Result.Y := ASize.cy;
|
||||
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 }
|
||||
|
||||
procedure TIntervalList.AddPoint(APoint: Double); inline;
|
||||
|
@ -29,7 +29,7 @@ interface
|
||||
|
||||
uses
|
||||
LCLType, LResources,
|
||||
SysUtils, Classes, Controls, Graphics, Dialogs,
|
||||
SysUtils, Classes, Controls, Graphics,
|
||||
TAChartUtils, TATypes, TALegend, TAChartAxis;
|
||||
|
||||
type
|
||||
@ -119,7 +119,7 @@ type
|
||||
|
||||
TChartSeriesList = class(TPersistent)
|
||||
private
|
||||
FList: TFPList;
|
||||
FList: TIndexedComponentList;
|
||||
function GetItem(AIndex: Integer): TBasicChartSeries;
|
||||
public
|
||||
constructor Create;
|
||||
@ -129,7 +129,7 @@ type
|
||||
function Count: Integer;
|
||||
public
|
||||
property Items[AIndex: Integer]: TBasicChartSeries read GetItem; default;
|
||||
property List: TFPList read FList;
|
||||
property List: TIndexedComponentList read FList;
|
||||
end;
|
||||
|
||||
TChartAfterDrawEvent = procedure (
|
||||
@ -229,6 +229,7 @@ type
|
||||
procedure PrepareLegend(
|
||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
|
||||
var AClipRect: TRect; out ALegendRect: TRect);
|
||||
procedure SetName(const AValue: TComponentName); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -351,7 +352,7 @@ var
|
||||
implementation
|
||||
|
||||
uses
|
||||
Clipbrd, GraphMath, LCLProc, Math, Types, TADrawUtils;
|
||||
Clipbrd, Dialogs, GraphMath, LCLProc, Math, Types, TADrawUtils;
|
||||
|
||||
function CompareZPosition(AItem1, AItem2: Pointer): Integer;
|
||||
begin
|
||||
@ -949,6 +950,17 @@ begin
|
||||
Invalidate;
|
||||
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);
|
||||
begin
|
||||
if FOnAfterDrawBackground = AValue then exit;
|
||||
@ -1245,7 +1257,7 @@ end;
|
||||
|
||||
constructor TChartSeriesList.Create;
|
||||
begin
|
||||
FList := TFPList.Create;
|
||||
FList := TIndexedComponentList.Create;
|
||||
end;
|
||||
|
||||
destructor TChartSeriesList.Destroy;
|
||||
@ -1299,6 +1311,7 @@ initialization
|
||||
{$I tagraph.lrs}
|
||||
SkipObsoleteChartProperties;
|
||||
SeriesClassRegistry := TStringList.Create;
|
||||
ShowMessageProc := @ShowMessage;
|
||||
|
||||
finalization
|
||||
FreeAndNil(SeriesClassRegistry);
|
||||
|
@ -70,15 +70,17 @@ type
|
||||
|
||||
TAxisTransformClass = class of TAxisTransform;
|
||||
|
||||
TAxisTransformList = class(TFPList)
|
||||
TAxisTransformList = class(TIndexedComponentList)
|
||||
end;
|
||||
|
||||
{ TChartAxisTransformations }
|
||||
|
||||
TChartAxisTransformations = class (TComponent)
|
||||
TChartAxisTransformations = class(TComponent)
|
||||
private
|
||||
FBroadcaster: TBroadcaster;
|
||||
FList: TAxisTransformList;
|
||||
protected
|
||||
procedure SetName(const AValue: TComponentName); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -524,6 +526,17 @@ begin
|
||||
List.Move(i, Order);
|
||||
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);
|
||||
var
|
||||
i: Integer;
|
||||
|
Loading…
Reference in New Issue
Block a user