mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 20:59:06 +02:00
TAChart: Make TCustomSortedChartSource.Sort safer and more versatile. Part of patch by Marcin Wiazowski.
git-svn-id: trunk@60981 -
This commit is contained in:
parent
f308975433
commit
2d7a2cb821
@ -29,9 +29,11 @@ type
|
|||||||
procedure SetSorted(AValue: Boolean);
|
procedure SetSorted(AValue: Boolean);
|
||||||
procedure SetOnCompare(AValue: TChartSortCompare);
|
procedure SetOnCompare(AValue: TChartSortCompare);
|
||||||
protected
|
protected
|
||||||
|
FCompareProc: TChartSortCompare;
|
||||||
FData: TFPList;
|
FData: TFPList;
|
||||||
FSorted: Boolean;
|
FSorted: Boolean;
|
||||||
function DefaultCompare(AItem1, AItem2: Pointer): Integer; virtual; abstract;
|
function DefaultCompare(AItem1, AItem2: Pointer): Integer; virtual; abstract;
|
||||||
|
function DoCompare(AItem1, AItem2: Pointer): Integer; virtual;
|
||||||
procedure ExecSort(ACompare: TChartSortCompare); virtual;
|
procedure ExecSort(ACompare: TChartSortCompare); virtual;
|
||||||
procedure SetSortBy(AValue: TChartSortBy); override;
|
procedure SetSortBy(AValue: TChartSortBy); override;
|
||||||
procedure SetSortDir(AValue: TChartSortDir); override;
|
procedure SetSortDir(AValue: TChartSortDir); override;
|
||||||
@ -523,6 +525,11 @@ end;
|
|||||||
|
|
||||||
{ TCustomSortedChartSource }
|
{ TCustomSortedChartSource }
|
||||||
|
|
||||||
|
function TCustomSortedChartSource.DoCompare(AItem1, AItem2: Pointer): Integer;
|
||||||
|
begin
|
||||||
|
Result := FCompareProc(AItem1, AItem2);
|
||||||
|
end;
|
||||||
|
|
||||||
{ Built-in sorting algorithm of the ChartSource, a standard QuickSort.
|
{ Built-in sorting algorithm of the ChartSource, a standard QuickSort.
|
||||||
Copied from the classes unit because the compare function must be a method. }
|
Copied from the classes unit because the compare function must be a method. }
|
||||||
procedure TCustomSortedChartSource.ExecSort(ACompare: TChartSortCompare);
|
procedure TCustomSortedChartSource.ExecSort(ACompare: TChartSortCompare);
|
||||||
@ -614,9 +621,14 @@ procedure TCustomSortedChartSource.Sort;
|
|||||||
begin
|
begin
|
||||||
if csLoading in ComponentState then exit;
|
if csLoading in ComponentState then exit;
|
||||||
if (FSortBy = sbCustom) then begin
|
if (FSortBy = sbCustom) then begin
|
||||||
if Assigned(FOnCompare) then ExecSort(FOnCompare);
|
if not Assigned(FOnCompare) then exit;
|
||||||
end else
|
FCompareProc := FOnCompare;
|
||||||
ExecSort(@DefaultCompare);
|
end else begin
|
||||||
|
if (FSortBy = sbX) and (FSortIndex <> 0) and (FSortIndex >= FXCount) then exit;
|
||||||
|
if (FSortBy = sbY) and (FSortIndex <> 0) and (FSortIndex >= FYCount) then exit;
|
||||||
|
FCompareProc := @DefaultCompare;
|
||||||
|
end;
|
||||||
|
ExecSort(@DoCompare);
|
||||||
Notify;
|
Notify;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user