mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 00:59:38 +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) }
|
||||
var
|
||||
li: TLegendItem;
|
||||
list: TFPList;
|
||||
ser: TCustomChartSeries;
|
||||
i, idx: Integer;
|
||||
begin
|
||||
Items.BeginUpdate;
|
||||
list := TFPList.Create;
|
||||
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;
|
||||
if (FChart = nil) or (FChart.Series = nil) then exit;
|
||||
FreeAndNil(FLegendItems);
|
||||
FLegendItems := CreateLegendItems;
|
||||
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.
|
||||
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
|
||||
OnPopulate(Self);
|
||||
finally
|
||||
list.Free;
|
||||
Items.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user