From ce83bb5a9157adfb0e65601e5700e3e4ebb98ed1 Mon Sep 17 00:00:00 2001 From: ask Date: Tue, 6 Apr 2010 15:35:21 +0000 Subject: [PATCH] TAChart: Use broadacster/listener to update chart after changes in axis transformation git-svn-id: trunk@24473 - --- components/tachart/tachartaxis.pas | 8 +++++++- components/tachart/tatransformations.pas | 21 +++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/tachart/tachartaxis.pas b/components/tachart/tachartaxis.pas index 888d5108e7..002c123656 100644 --- a/components/tachart/tachartaxis.pas +++ b/components/tachart/tachartaxis.pas @@ -104,6 +104,7 @@ type TChartAxis = class(TCollectionItem) private + FListener: TListener; FMarkTexts: TStringDynArray; FMarkValues: TDoubleDynArray; FSize: Integer; @@ -323,6 +324,7 @@ end; constructor TChartAxis.Create(ACollection: TCollection); begin inherited Create(ACollection); + FListener := TListener.Create(@FTransformations, @StyleChanged); FGrid := TChartAxisPen.Create; FGrid.OnChange := @StyleChanged; FGrid.Style := psDot; @@ -330,7 +332,6 @@ begin FTickColor := clBlack; FTickLength := DEF_TICK_LENGTH; FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart); - //FTransformation.OnChanged := @StyleChanged; FVisible := true; end; @@ -338,6 +339,7 @@ destructor TChartAxis.Destroy; begin FTitle.Free; FMarks.Free; + FListener.Free; FGrid.Free; inherited; end; @@ -644,7 +646,11 @@ end; procedure TChartAxis.SetTransformations(AValue: TChartAxisTransformations); begin if FTransformations = AValue then exit; + if FListener.IsListening then + Transformations.Broadcaster.Unsubscribe(FListener); FTransformations := AValue; + if FTransformations <> nil then + Transformations.Broadcaster.Subscribe(FListener); StyleChanged(Self); end; diff --git a/components/tachart/tatransformations.pas b/components/tachart/tatransformations.pas index 707448b65f..a4c3858f32 100644 --- a/components/tachart/tatransformations.pas +++ b/components/tachart/tatransformations.pas @@ -35,9 +35,7 @@ type TAxisTransform = class(TIndexedComponent) private FEnabled: Boolean; - FOnChanged: TNotifyEvent; FTransformations: TChartAxisTransformations; - procedure SetOnChanged(const AValue: TNotifyEvent); procedure SetTransformations(AValue: TChartAxisTransformations); protected procedure ReadState(Reader: TReader); override; @@ -57,8 +55,8 @@ type function AxisToGraph(AX: Double): Double; virtual; function GraphToAxis(AX: Double): Double; virtual; - property OnChanged: TNotifyEvent read FOnChanged write SetOnChanged; - property Transformations: TChartAxisTransformations read FTransformations write SetTransformations; + property Transformations: TChartAxisTransformations + read FTransformations write SetTransformations; published property Enabled: Boolean read FEnabled write FEnabled default true; end; @@ -72,6 +70,7 @@ type TChartAxisTransformations = class (TComponent) private + FBroadcaster: TBroadcaster; FList: TAxisTransformList; public constructor Create(AOwner: TComponent); override; @@ -82,6 +81,8 @@ type public function AxisToGraph(AX: Double): Double; function GraphToAxis(AX: Double): Double; + + property Broadcaster: TBroadcaster read FBroadcaster; published property List: TAxisTransformList read FList; end; @@ -278,8 +279,8 @@ end; procedure TAxisTransform.Changed; begin - if Assigned(FOnChanged) then - FOnChanged(Self); + if Transformations <> nil then + Transformations.Broadcaster.Broadcast; end; constructor TAxisTransform.Create(AOwner: TComponent); @@ -330,12 +331,6 @@ begin Move(Index, EnsureRange(AValue, 0, Count - 1)); end; -procedure TAxisTransform.SetOnChanged(const AValue: TNotifyEvent); -begin - if TMethod(FOnChanged) = TMethod(AValue) then exit; - FOnChanged := AValue; -end; - procedure TAxisTransform.SetParentComponent(AParent: TComponent); begin if not (csLoading in ComponentState) then @@ -366,6 +361,7 @@ end; constructor TChartAxisTransformations.Create(AOwner: TComponent); begin inherited Create(AOwner); + FBroadcaster := TBroadcaster.Create; FList := TAxisTransformList.Create; end; @@ -374,6 +370,7 @@ begin while List.Count > 0 do TAxisTransform(List[List.Count - 1]).Free; FList.Free; + FBroadcaster.Free; inherited; end;