TAChart: Introduce TIndexedComponent as a base class for tools and series

git-svn-id: trunk@24426 -
This commit is contained in:
ask 2010-04-05 08:18:40 +00:00
parent 79f2391096
commit 221162d126
4 changed files with 39 additions and 2 deletions

View File

@ -129,6 +129,16 @@ type
TCaseOfTwo = (cotNone, cotFirst, cotSecond, cotBoth); TCaseOfTwo = (cotNone, cotFirst, cotSecond, cotBoth);
{ TIndexedComponent }
TIndexedComponent = class (TComponent)
protected
function GetIndex: Integer; virtual; abstract;
procedure SetIndex(AValue: Integer); virtual; abstract;
public
property Index: Integer read GetIndex write SetIndex;
end;
const const
// 0-value, 1-percent, 2-label, 3-total, 4-xvalue // 0-value, 1-percent, 2-label, 3-total, 4-xvalue
SERIES_MARK_FORMATS: array [TSeriesMarksStyle] of String = ( SERIES_MARK_FORMATS: array [TSeriesMarksStyle] of String = (

View File

@ -52,6 +52,10 @@ type
procedure ReadState(Reader: TReader); override; procedure ReadState(Reader: TReader); override;
procedure SetParentComponent(AParent: TComponent); override; procedure SetParentComponent(AParent: TComponent); override;
protected
function GetIndex: Integer; override;
procedure SetIndex(AValue: Integer); override;
protected protected
function AxisToGraphX(AX: Double): Double; override; function AxisToGraphX(AX: Double): Double; override;
function AxisToGraphY(AY: Double): Double; override; function AxisToGraphY(AY: Double): Double; override;
@ -224,6 +228,11 @@ begin
end; end;
end; end;
function TCustomChartSeries.GetIndex: Integer;
begin
Result := FChart.Series.List.IndexOf(Self);
end;
function TCustomChartSeries.GetParentComponent: TComponent; function TCustomChartSeries.GetParentComponent: TComponent;
begin begin
Result := FChart; Result := FChart;
@ -286,6 +295,12 @@ begin
UpdateParentChart; UpdateParentChart;
end; end;
procedure TCustomChartSeries.SetIndex(AValue: Integer);
begin
with FChart.Series.List do
Move(Index, EnsureRange(AValue, 0, Count - 1));
end;
procedure TCustomChartSeries.SetParentComponent(AParent: TComponent); procedure TCustomChartSeries.SetParentComponent(AParent: TComponent);
begin begin
if not (csLoading in ComponentState) then if not (csLoading in ComponentState) then

View File

@ -43,7 +43,7 @@ type
{ TBasicChartSeries } { TBasicChartSeries }
TBasicChartSeries = class(TComponent) TBasicChartSeries = class(TIndexedComponent)
protected protected
FActive: Boolean; FActive: Boolean;
FChart: TChart; FChart: TChart;
@ -96,7 +96,7 @@ type
{ TBasicСhartTool } { TBasicСhartTool }
TBasicChartTool = class(TComponent) TBasicChartTool = class(TIndexedComponent)
strict protected strict protected
FChart: TChart; FChart: TChart;

View File

@ -51,11 +51,13 @@ type
procedure Deactivate; override; procedure Deactivate; override;
procedure Dispatch( procedure Dispatch(
AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint); AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint);
function GetIndex: Integer; override;
function Index: Integer; override; function Index: Integer; override;
function IsActive: Boolean; function IsActive: Boolean;
procedure MouseDown(APoint: TPoint); virtual; procedure MouseDown(APoint: TPoint); virtual;
procedure MouseMove(APoint: TPoint); virtual; procedure MouseMove(APoint: TPoint); virtual;
procedure MouseUp(APoint: TPoint); virtual; procedure MouseUp(APoint: TPoint); virtual;
procedure SetIndex(AValue: Integer); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -352,6 +354,11 @@ begin
end; end;
end; end;
function TChartTool.GetIndex: Integer;
begin
Result := Toolset.Tools.IndexOf(Self);
end;
function TChartTool.GetParentComponent: TComponent; function TChartTool.GetParentComponent: TComponent;
begin begin
Result := FToolset; Result := FToolset;
@ -420,6 +427,11 @@ begin
FChart.Cursor := ActiveCursor; FChart.Cursor := ActiveCursor;
end; end;
procedure TChartTool.SetIndex(AValue: Integer);
begin
Toolset.Tools.Move(Index, EnsureRange(AValue, 0, Toolset.Tools.Count - 1));
end;
procedure TChartTool.SetParentComponent(AParent: TComponent); procedure TChartTool.SetParentComponent(AParent: TComponent);
begin begin
if not (csLoading in ComponentState) then if not (csLoading in ComponentState) then