mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:19:22 +02:00
TValueListEditor: implement sort. Based on a patch by Jesus Reyes. Issue #0034141.
git-svn-id: trunk@58773 -
This commit is contained in:
parent
a39a12bac0
commit
828f4e74ef
@ -1379,7 +1379,7 @@ type
|
||||
procedure DeleteColRow(IsColumn: Boolean; index: Integer);
|
||||
procedure DeleteCol(Index: Integer); virtual;
|
||||
procedure DeleteRow(Index: Integer); virtual;
|
||||
procedure ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer);
|
||||
procedure ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer); virtual;
|
||||
procedure InsertColRow(IsColumn: boolean; index: integer);
|
||||
procedure MoveColRow(IsColumn: Boolean; FromIndex, ToIndex: Integer);
|
||||
procedure SortColRow(IsColumn: Boolean; index:Integer); overload;
|
||||
@ -3691,6 +3691,7 @@ procedure TCustomGrid.ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer)
|
||||
begin
|
||||
end;
|
||||
|
||||
{Use in derived grids to exchange the actual data}
|
||||
procedure TCustomGrid.ColRowExchanged(IsColumn: Boolean; index, WithIndex: Integer);
|
||||
begin
|
||||
end;
|
||||
@ -6282,9 +6283,9 @@ begin
|
||||
exit;
|
||||
end;
|
||||
if IsColumn then
|
||||
FCols.Exchange(index, WithIndex)
|
||||
FCols.Exchange(index, WithIndex) //exchanges the dimensions (width/height) of the resp. columns
|
||||
else
|
||||
FRows.Exchange(index, WithIndex);
|
||||
FRows.Exchange(index, WithIndex); //exchanges the dimensions (width/height) of the resp. rows
|
||||
ColRowExchanged(IsColumn, index, WithIndex);
|
||||
VisualChange;
|
||||
|
||||
|
@ -14,6 +14,7 @@ type
|
||||
TValueListStrings = class;
|
||||
|
||||
TEditStyle = (esSimple, esEllipsis, esPickList);
|
||||
TVleSortCol = (colKey, colValue);
|
||||
|
||||
{ TItemProp }
|
||||
|
||||
@ -149,6 +150,7 @@ type
|
||||
procedure SetFixedCols(const AValue: Integer); override;
|
||||
procedure ShowColumnTitles;
|
||||
procedure AdjustRowCount; virtual;
|
||||
procedure ColRowExchanged(IsColumn: Boolean; index, WithIndex: Integer); override;
|
||||
procedure DefineCellsProperty(Filer: TFiler); override;
|
||||
procedure InvalidateCachedRow;
|
||||
procedure GetAutoFillColumnInfo(const Index: Integer; var aMin,aMax,aPriority: Integer); override;
|
||||
@ -162,6 +164,7 @@ type
|
||||
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
|
||||
procedure SetFixedRows(const AValue: Integer); override;
|
||||
procedure SetRowCount(AValue: Integer);
|
||||
procedure Sort(ColSorting: Boolean; index,IndxFrom,IndxTo:Integer); override;
|
||||
procedure TitlesChanged(Sender: TObject);
|
||||
function ValidateEntry(const ACol,ARow:Integer; const OldValue:string; var NewValue:string): boolean; override;
|
||||
public
|
||||
@ -176,11 +179,13 @@ type
|
||||
procedure InsertColRow(IsColumn: boolean; index: integer);
|
||||
function InsertRow(const KeyName, Value: string; Append: Boolean): Integer;
|
||||
procedure InsertRowWithValues(Index: Integer; Values: array of String);
|
||||
procedure ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer);
|
||||
procedure ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer); override;
|
||||
function IsEmptyRow: Boolean; {Delphi compatible function}
|
||||
function IsEmptyRow(aRow: Integer): Boolean; {This for makes more sense to me}
|
||||
procedure MoveColRow(IsColumn: Boolean; FromIndex, ToIndex: Integer);
|
||||
function RestoreCurrentRow: Boolean;
|
||||
procedure Sort(Index, IndxFrom, IndxTo: Integer);
|
||||
procedure Sort(ACol: TVleSortCol = colKey);
|
||||
|
||||
property Modified;
|
||||
property Keys[Index: Integer]: string read GetKey write SetKey;
|
||||
@ -536,6 +541,7 @@ end;
|
||||
procedure TValueListStrings.Assign(Source: TPersistent);
|
||||
begin
|
||||
FGrid.InvalidateCachedRow;
|
||||
Clear; //if this is not done, and a TValueListEditor.Sort() is done and then later a Strings.Assign, an exception will occur.
|
||||
inherited Assign(Source);
|
||||
if (Source is TValueListStrings) then
|
||||
FItemProps.Assign(TValueListStrings(Source).FItemProps);
|
||||
@ -848,7 +854,7 @@ end;
|
||||
procedure TValueListEditor.ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer);
|
||||
begin
|
||||
if not IsColumn then
|
||||
Strings.Exchange(Index - FixedRows, WithIndex - FixedRows)
|
||||
inherited ExchangeColRow(IsColumn, index, WithIndex)
|
||||
else
|
||||
Raise EGridException.CreateFmt(rsVLEInvalidRowColOperation,['ExchangeColRow',' on columns']);
|
||||
end;
|
||||
@ -910,9 +916,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.Sort(ACol: TVleSortCol = colKey);
|
||||
begin
|
||||
SortColRow(True, Ord(ACol));
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.Sort(Index, IndxFrom, IndxTo: Integer);
|
||||
begin
|
||||
Sort(True, Index, IndxFrom, IndxTo);
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.StringsChange(Sender: TObject);
|
||||
begin
|
||||
//Since we never call inherited SetCell, this seems the logical place to do it
|
||||
Modified := True;
|
||||
AdjustRowCount;
|
||||
Invalidate;
|
||||
@ -1100,6 +1115,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.ColRowExchanged(IsColumn: Boolean; index,
|
||||
WithIndex: Integer);
|
||||
begin
|
||||
Strings.Exchange(Index - FixedRows, WithIndex - FixedRows);
|
||||
inherited ColRowExchanged(IsColumn, index, WithIndex);
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.DefineCellsProperty(Filer: TFiler);
|
||||
begin
|
||||
end;
|
||||
@ -1336,6 +1358,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.Sort(ColSorting: Boolean; index, IndxFrom,
|
||||
IndxTo: Integer);
|
||||
var
|
||||
HideEditor: Boolean;
|
||||
begin
|
||||
HideEditor := goAlwaysShowEditor in Options;
|
||||
if HideEditor then Options := Options - [goAlwaysShowEditor];
|
||||
Strings.BeginUpdate;
|
||||
try
|
||||
inherited Sort(True, index, IndxFrom, IndxTo);
|
||||
finally
|
||||
Strings.EndUpdate;
|
||||
end;
|
||||
if HideEditor then Options := Options + [goAlwaysShowEditor];
|
||||
end;
|
||||
|
||||
procedure TValueListEditor.TitlesChanged(Sender: TObject);
|
||||
begin
|
||||
// Refresh the display.
|
||||
|
Loading…
Reference in New Issue
Block a user