mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-20 22:39:17 +02:00
TAChart: Add and use TLegendItemsEnumerator
git-svn-id: trunk@31674 -
This commit is contained in:
parent
9ddaa28a8f
commit
267a457efe
@ -115,13 +115,13 @@ end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
li: TLegendItem;
|
||||
begin
|
||||
// Workaround for issue #19632
|
||||
Chart1FuncSeries1.Legend.OnCreate := @Chart1FuncSeries1LegendCreate;
|
||||
FItems := Chart1.GetLegendItems;
|
||||
Chart1.Legend.SortItemsByOrder(FItems);
|
||||
for i := 1 to FItems.Count do
|
||||
for li in FItems do
|
||||
cbSeries.AddItem('', nil);
|
||||
end;
|
||||
|
||||
|
@ -460,7 +460,7 @@ procedure TChartListbox.Populate;
|
||||
{ populates the listbox with all series contained in the chart. Use the event
|
||||
OnPopulate if you don't omit special series from the listbox (RemoveSeries) }
|
||||
var
|
||||
i: Integer;
|
||||
li: TLegendItem;
|
||||
begin
|
||||
Items.BeginUpdate;
|
||||
try
|
||||
@ -469,9 +469,9 @@ begin
|
||||
FreeAndNil(FLegendItems);
|
||||
FLegendItems := CreateLegendItems;
|
||||
Chart.Legend.SortItemsByOrder(FLegendItems);
|
||||
for i := 0 to FLegendItems.Count - 1 do
|
||||
for li in FLegendItems do
|
||||
// The caption is owner-drawn, but add it anyway for user convenience.
|
||||
Items.AddObject(FLegendItems[i].Text, FLegendItems[i]);
|
||||
Items.AddObject(li.Text, li);
|
||||
if Assigned(OnPopulate) then
|
||||
OnPopulate(Self);
|
||||
finally
|
||||
|
@ -111,6 +111,12 @@ type
|
||||
procedure Draw(ADrawer: IChartDrawer; const ARect: TRect); override;
|
||||
end;
|
||||
|
||||
TLegendItemsEnumerator = class(TListEnumerator)
|
||||
public
|
||||
function GetCurrent: TLegendItem;
|
||||
property Current: TLegendItem read GetCurrent;
|
||||
end;
|
||||
|
||||
{ TChartLegendItems }
|
||||
|
||||
TChartLegendItems = class(TObjectList)
|
||||
@ -118,6 +124,7 @@ type
|
||||
function GetItem(AIndex: Integer): TLegendItem;
|
||||
procedure SetItem(AIndex: Integer; AValue: TLegendItem);
|
||||
public
|
||||
function GetEnumerator: TLegendItemsEnumerator;
|
||||
property Items[AIndex: Integer]: TLegendItem
|
||||
read GetItem write SetItem; default;
|
||||
end;
|
||||
@ -275,8 +282,20 @@ begin
|
||||
Result := Sign(li1.Order - li2.Order);
|
||||
end;
|
||||
|
||||
{ TLegendItemsEnumerator }
|
||||
|
||||
function TLegendItemsEnumerator.GetCurrent: TLegendItem;
|
||||
begin
|
||||
Result := TLegendItem(inherited GetCurrent);
|
||||
end;
|
||||
|
||||
{ TChartLegendItems }
|
||||
|
||||
function TChartLegendItems.GetEnumerator: TLegendItemsEnumerator;
|
||||
begin
|
||||
Result := TLegendItemsEnumerator.Create(Self);
|
||||
end;
|
||||
|
||||
function TChartLegendItems.GetItem(AIndex: Integer): TLegendItem;
|
||||
begin
|
||||
Result := TLegendItem(inherited GetItem(AIndex));
|
||||
@ -517,19 +536,18 @@ end;
|
||||
function TChartLegend.MeasureItem(
|
||||
ADrawer: IChartDrawer; AItems: TChartLegendItems): TPoint;
|
||||
var
|
||||
i: Integer;
|
||||
p: TPoint;
|
||||
prevFont: TFont = nil;
|
||||
li: TLegendItem;
|
||||
begin
|
||||
Result := Point(0, 0);
|
||||
for i := 0 to AItems.Count - 1 do
|
||||
with AItems[i] do begin
|
||||
AItems[i].UpdateFont(ADrawer, prevFont);
|
||||
p := ADrawer.TextExtent(Text);
|
||||
if HasSymbol then
|
||||
p.X += SYMBOL_TEXT_SPACING + SymbolWidth;
|
||||
Result := MaxPoint(p, Result);
|
||||
end;
|
||||
for li in AItems do begin
|
||||
li.UpdateFont(ADrawer, prevFont);
|
||||
p := ADrawer.TextExtent(li.Text);
|
||||
if li.HasSymbol then
|
||||
p.X += SYMBOL_TEXT_SPACING + SymbolWidth;
|
||||
Result := MaxPoint(p, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TChartLegend.Prepare(
|
||||
|
Loading…
Reference in New Issue
Block a user