mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 18:09:32 +02:00
TAChart: Use enumerators in utils, tools and transformations
git-svn-id: trunk@31700 -
This commit is contained in:
parent
d73181cc5c
commit
14fabdf99b
components/tachart
@ -130,6 +130,15 @@ type
|
||||
|
||||
TShowMessageProc = procedure (const AMsg: String);
|
||||
|
||||
{$IFNDEF fpdoc} // Workaround for issue #18549.
|
||||
generic TTypedFPListEnumerator<T> = class(TFPListEnumerator)
|
||||
{$ELSE}
|
||||
TTypedFPListEnumerator = class(TFPListEnumerator)
|
||||
{$ENDIF}
|
||||
function GetCurrent: T;
|
||||
property Current: T read GetCurrent;
|
||||
end;
|
||||
|
||||
{ TIndexedComponentList }
|
||||
|
||||
TIndexedComponentList = class(TFPList)
|
||||
@ -427,6 +436,13 @@ begin
|
||||
Result := (A.Code = B.Code) and (A.Data = B.Data);
|
||||
end;
|
||||
|
||||
{ TTypedFPListEnumerator }
|
||||
|
||||
function TTypedFPListEnumerator.GetCurrent: T;
|
||||
begin
|
||||
Result := T(inherited GetCurrent);
|
||||
end;
|
||||
|
||||
{ TIndexedComponentList }
|
||||
|
||||
procedure TIndexedComponentList.ChangeNamePrefix(
|
||||
@ -607,19 +623,19 @@ end;
|
||||
|
||||
procedure TBroadcaster.Broadcast(ASender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
p: Pointer;
|
||||
begin
|
||||
if Locked then exit;
|
||||
for i := 0 to Count - 1 do
|
||||
TListener(Items[i]).Notify(ASender);
|
||||
for p in Self do
|
||||
TListener(p).Notify(ASender);
|
||||
end;
|
||||
|
||||
destructor TBroadcaster.Destroy;
|
||||
var
|
||||
i: Integer;
|
||||
p: Pointer;
|
||||
begin
|
||||
for i := 0 to Count - 1 do
|
||||
TListener(Items[i]).Forget;
|
||||
for p in Self do
|
||||
TListener(p).Forget;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
@ -1180,25 +1180,24 @@ end;
|
||||
|
||||
function TDataPointTool.ParseAffectedSeries: TBooleanDynArray;
|
||||
var
|
||||
s: TStringList;
|
||||
i, p: Integer;
|
||||
sl: TStringList;
|
||||
p: Integer;
|
||||
s: String;
|
||||
begin
|
||||
SetLength(Result, FChart.SeriesCount);
|
||||
if AffectedSeries = '' then begin
|
||||
FillChar(Result[0], Length(Result), true);
|
||||
exit;
|
||||
end;
|
||||
s := TStringList.Create;
|
||||
sl := TStringList.Create;
|
||||
try
|
||||
s.CommaText := AffectedSeries;
|
||||
sl.CommaText := AffectedSeries;
|
||||
FillChar(Result[0], Length(Result), false);
|
||||
for i := 0 to s.Count - 1 do begin
|
||||
p := StrToIntDef(s[i], -1);
|
||||
if InRange(p, 0, High(Result)) then
|
||||
for s in sl do
|
||||
if TryStrToInt(s, p) and InRange(p, 0, High(Result)) then
|
||||
Result[p] := true;
|
||||
end;
|
||||
finally
|
||||
s.Free;
|
||||
sl.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -70,7 +70,13 @@ type
|
||||
|
||||
TAxisTransformClass = class of TAxisTransform;
|
||||
|
||||
{$IFNDEF fpdoc} // Workaround for issue #18549.
|
||||
TAxisTransformEnumerator = specialize TTypedFPListEnumerator<TAxisTransform>;
|
||||
{$ENDIF}
|
||||
|
||||
TAxisTransformList = class(TIndexedComponentList)
|
||||
public
|
||||
function GetEnumerator: TAxisTransformEnumerator;
|
||||
end;
|
||||
|
||||
{ TChartAxisTransformations }
|
||||
@ -258,6 +264,13 @@ begin
|
||||
AxisTransformsClassRegistry.AddObject(ACaption, TObject(AAxisTransformClass));
|
||||
end;
|
||||
|
||||
{ TAxisTransformList }
|
||||
|
||||
function TAxisTransformList.GetEnumerator: TAxisTransformEnumerator;
|
||||
begin
|
||||
Result := TAxisTransformEnumerator.Create(Self);
|
||||
end;
|
||||
|
||||
{ TAxisTransformsComponentEditor }
|
||||
|
||||
function TAxisTransformsComponentEditor.GetVerb(Index: Integer): string;
|
||||
@ -450,23 +463,21 @@ end;
|
||||
|
||||
function TChartAxisTransformations.AxisToGraph(AX: Double): Double;
|
||||
var
|
||||
i: Integer;
|
||||
t: TAxisTransform;
|
||||
begin
|
||||
Result := AX;
|
||||
for i := 0 to List.Count - 1 do
|
||||
with TAxisTransform(List[i]) do
|
||||
if Enabled then
|
||||
Result := AxisToGraph(Result);
|
||||
for t in List do
|
||||
if t.Enabled then
|
||||
Result := t.AxisToGraph(Result);
|
||||
end;
|
||||
|
||||
procedure TChartAxisTransformations.ClearBounds;
|
||||
var
|
||||
i: Integer;
|
||||
t: TAxisTransform;
|
||||
begin
|
||||
for i := List.Count - 1 downto 0 do
|
||||
with TAxisTransform(List[i]) do
|
||||
if Enabled then
|
||||
ClearBounds;
|
||||
for t in List do
|
||||
if t.Enabled then
|
||||
t.ClearBounds;
|
||||
end;
|
||||
|
||||
constructor TChartAxisTransformations.Create(AOwner: TComponent);
|
||||
@ -488,11 +499,11 @@ end;
|
||||
procedure TChartAxisTransformations.GetChildren(
|
||||
Proc: TGetChildProc; Root: TComponent);
|
||||
var
|
||||
i: Integer;
|
||||
t: TAxisTransform;
|
||||
begin
|
||||
for i := 0 to List.Count - 1 do
|
||||
if TAxisTransform(List[i]).Owner = Root then
|
||||
Proc(TAxisTransform(List[i]));
|
||||
for t in List do
|
||||
if t.Owner = Root then
|
||||
Proc(t);
|
||||
end;
|
||||
|
||||
function TChartAxisTransformations.GraphToAxis(AX: Double): Double;
|
||||
@ -508,12 +519,11 @@ end;
|
||||
|
||||
procedure TChartAxisTransformations.SetChart(AChart: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
t: TAxisTransform;
|
||||
begin
|
||||
for i := 0 to List.Count - 1 do
|
||||
with TAxisTransform(List[i]) do
|
||||
if Enabled then
|
||||
TAxisTransform(List[i]).SetChart(AChart);
|
||||
for t in List do
|
||||
if t.Enabled then
|
||||
t.SetChart(AChart);
|
||||
end;
|
||||
|
||||
procedure TChartAxisTransformations.SetChildOrder(
|
||||
@ -539,12 +549,11 @@ end;
|
||||
|
||||
procedure TChartAxisTransformations.UpdateBounds(var AMin, AMax: Double);
|
||||
var
|
||||
i: Integer;
|
||||
t: TAxisTransform;
|
||||
begin
|
||||
for i := 0 to List.Count - 1 do
|
||||
with TAxisTransform(List[i]) do
|
||||
if Enabled then
|
||||
UpdateBounds(AMin, AMax);
|
||||
for t in List do
|
||||
if t.Enabled then
|
||||
t.UpdateBounds(AMin, AMax);
|
||||
end;
|
||||
|
||||
{ TLinearAxisTransform }
|
||||
|
Loading…
Reference in New Issue
Block a user