mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-23 20:50:40 +02:00
TAChart: Keep selected items when populating a multiselect TChartListbox (http://forum.lazarus.freepascal.org/index.php/topic,28314.0.html)
git-svn-id: trunk@48942 -
This commit is contained in:
parent
ae10af0c87
commit
4204fd910e
@ -470,20 +470,42 @@ procedure TChartListbox.Populate;
|
|||||||
OnPopulate if you don't omit special series from the listbox (RemoveSeries) }
|
OnPopulate if you don't omit special series from the listbox (RemoveSeries) }
|
||||||
var
|
var
|
||||||
li: TLegendItem;
|
li: TLegendItem;
|
||||||
|
list: TFPList;
|
||||||
|
ser: TCustomChartSeries;
|
||||||
|
i, idx: Integer;
|
||||||
begin
|
begin
|
||||||
Items.BeginUpdate;
|
Items.BeginUpdate;
|
||||||
|
list := TFPList.Create;
|
||||||
try
|
try
|
||||||
|
// In case of multiselect, the selected items would get lost here.
|
||||||
|
// Store series belonging to selected items in temporary list
|
||||||
|
for i:=0 to Items.Count-1 do
|
||||||
|
if Selected[i] then begin
|
||||||
|
li := TLegendItem(Items.Objects[i]);
|
||||||
|
if (li <> nil) and (li.Owner is TCustomChartSeries) then begin
|
||||||
|
ser := TCustomChartSeries(li.Owner);
|
||||||
|
list.Add(ser);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Items.Clear;
|
Items.Clear;
|
||||||
if (FChart = nil) or (FChart.Series = nil) then exit;
|
if (FChart = nil) or (FChart.Series = nil) then exit;
|
||||||
FreeAndNil(FLegendItems);
|
FreeAndNil(FLegendItems);
|
||||||
FLegendItems := CreateLegendItems;
|
FLegendItems := CreateLegendItems;
|
||||||
Chart.Legend.SortItemsByOrder(FLegendItems);
|
Chart.Legend.SortItemsByOrder(FLegendItems);
|
||||||
for li in FLegendItems do
|
for li in FLegendItems do begin
|
||||||
// The caption is owner-drawn, but add it anyway for user convenience.
|
// The caption is owner-drawn, but add it anyway for user convenience.
|
||||||
Items.AddObject(li.Text, li);
|
idx := Items.AddObject(li.Text, li);
|
||||||
|
// Restore selected state from temporary list
|
||||||
|
if (li.Owner is TCustomChartSeries) then begin
|
||||||
|
ser := TCustomChartSeries(li.Owner);
|
||||||
|
if list.IndexOf(ser) <> -1 then Selected[idx] := true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
if Assigned(OnPopulate) then
|
if Assigned(OnPopulate) then
|
||||||
OnPopulate(Self);
|
OnPopulate(Self);
|
||||||
finally
|
finally
|
||||||
|
list.Free;
|
||||||
Items.EndUpdate;
|
Items.EndUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user