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);
{ 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
// 0-value, 1-percent, 2-label, 3-total, 4-xvalue
SERIES_MARK_FORMATS: array [TSeriesMarksStyle] of String = (

View File

@ -52,6 +52,10 @@ type
procedure ReadState(Reader: TReader); override;
procedure SetParentComponent(AParent: TComponent); override;
protected
function GetIndex: Integer; override;
procedure SetIndex(AValue: Integer); override;
protected
function AxisToGraphX(AX: Double): Double; override;
function AxisToGraphY(AY: Double): Double; override;
@ -224,6 +228,11 @@ begin
end;
end;
function TCustomChartSeries.GetIndex: Integer;
begin
Result := FChart.Series.List.IndexOf(Self);
end;
function TCustomChartSeries.GetParentComponent: TComponent;
begin
Result := FChart;
@ -286,6 +295,12 @@ begin
UpdateParentChart;
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);
begin
if not (csLoading in ComponentState) then

View File

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

View File

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