TAChart: Implement typed Items property in TChartLegendItems

git-svn-id: trunk@31389 -
This commit is contained in:
ask 2011-06-26 05:46:17 +00:00
parent 06a81a23bd
commit a6c1d7e971
2 changed files with 25 additions and 4 deletions

View File

@ -28,7 +28,7 @@ unit TAGraph;
interface
uses
Graphics, Classes, Contnrs, Controls, LCLType, SysUtils,
Graphics, Classes, Controls, LCLType, SysUtils,
TAChartAxis, TAChartUtils, TADrawUtils, TALegend, TATypes;
type

View File

@ -97,7 +97,16 @@ type
procedure Draw(ADrawer: IChartDrawer; const ARect: TRect); override;
end;
TChartLegendItems = TObjectList;
{ TChartLegendItems }
TChartLegendItems = class(TObjectList)
private
function GetItem(AIndex: Integer): TLegendItem;
procedure SetItem(AIndex: Integer; AValue: TLegendItem);
public
property Items[AIndex: Integer]: TLegendItem
read GetItem write SetItem; default;
end;
TChartLegendBrush = class(TBrush)
published
@ -204,6 +213,18 @@ uses
const
SYMBOL_TEXT_SPACING = 4;
{ TChartLegendItems }
function TChartLegendItems.GetItem(AIndex: Integer): TLegendItem;
begin
Result := TLegendItem(inherited GetItem(AIndex));
end;
procedure TChartLegendItems.SetItem(AIndex: Integer; AValue: TLegendItem);
begin
inherited;
end;
{ TLegendItem }
constructor TLegendItem.Create(const AText: String; AColor: TColor);
@ -387,7 +408,7 @@ begin
ADrawer.Pen := SymbolFrame
else
ADrawer.SetPenParams(psClear, clTAColor);
(AItems[i] as TLegendItem).Draw(ADrawer, r);
AItems[i].Draw(ADrawer, r);
OffsetRect(r, 0, itemHeight + Spacing);
end;
finally
@ -403,7 +424,7 @@ begin
ADrawer.Font := Font;
Result := Point(0, 0);
for i := 0 to AItems.Count - 1 do
with ADrawer.TextExtent((AItems[i] as TLegendItem).FText) do begin
with ADrawer.TextExtent(AItems[i].FText) do begin
Result.X := Max(X, Result.X);
Result.Y := Max(Y, Result.Y);
end;