TValueListEditor: implement sort. Based on a patch by Jesus Reyes. Issue #0034141.

git-svn-id: trunk@58773 -
This commit is contained in:
bart 2018-08-24 16:06:59 +00:00
parent a39a12bac0
commit 828f4e74ef
2 changed files with 45 additions and 6 deletions

View File

@ -1379,7 +1379,7 @@ type
procedure DeleteColRow(IsColumn: Boolean; index: Integer); procedure DeleteColRow(IsColumn: Boolean; index: Integer);
procedure DeleteCol(Index: Integer); virtual; procedure DeleteCol(Index: Integer); virtual;
procedure DeleteRow(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 InsertColRow(IsColumn: boolean; index: integer);
procedure MoveColRow(IsColumn: Boolean; FromIndex, ToIndex: Integer); procedure MoveColRow(IsColumn: Boolean; FromIndex, ToIndex: Integer);
procedure SortColRow(IsColumn: Boolean; index:Integer); overload; procedure SortColRow(IsColumn: Boolean; index:Integer); overload;
@ -3691,6 +3691,7 @@ procedure TCustomGrid.ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer)
begin begin
end; end;
{Use in derived grids to exchange the actual data}
procedure TCustomGrid.ColRowExchanged(IsColumn: Boolean; index, WithIndex: Integer); procedure TCustomGrid.ColRowExchanged(IsColumn: Boolean; index, WithIndex: Integer);
begin begin
end; end;
@ -6282,9 +6283,9 @@ begin
exit; exit;
end; end;
if IsColumn then if IsColumn then
FCols.Exchange(index, WithIndex) FCols.Exchange(index, WithIndex) //exchanges the dimensions (width/height) of the resp. columns
else else
FRows.Exchange(index, WithIndex); FRows.Exchange(index, WithIndex); //exchanges the dimensions (width/height) of the resp. rows
ColRowExchanged(IsColumn, index, WithIndex); ColRowExchanged(IsColumn, index, WithIndex);
VisualChange; VisualChange;

View File

@ -14,6 +14,7 @@ type
TValueListStrings = class; TValueListStrings = class;
TEditStyle = (esSimple, esEllipsis, esPickList); TEditStyle = (esSimple, esEllipsis, esPickList);
TVleSortCol = (colKey, colValue);
{ TItemProp } { TItemProp }
@ -149,6 +150,7 @@ type
procedure SetFixedCols(const AValue: Integer); override; procedure SetFixedCols(const AValue: Integer); override;
procedure ShowColumnTitles; procedure ShowColumnTitles;
procedure AdjustRowCount; virtual; procedure AdjustRowCount; virtual;
procedure ColRowExchanged(IsColumn: Boolean; index, WithIndex: Integer); override;
procedure DefineCellsProperty(Filer: TFiler); override; procedure DefineCellsProperty(Filer: TFiler); override;
procedure InvalidateCachedRow; procedure InvalidateCachedRow;
procedure GetAutoFillColumnInfo(const Index: Integer; var aMin,aMax,aPriority: Integer); override; 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 SetEditText(ACol, ARow: Longint; const Value: string); override;
procedure SetFixedRows(const AValue: Integer); override; procedure SetFixedRows(const AValue: Integer); override;
procedure SetRowCount(AValue: Integer); procedure SetRowCount(AValue: Integer);
procedure Sort(ColSorting: Boolean; index,IndxFrom,IndxTo:Integer); override;
procedure TitlesChanged(Sender: TObject); procedure TitlesChanged(Sender: TObject);
function ValidateEntry(const ACol,ARow:Integer; const OldValue:string; var NewValue:string): boolean; override; function ValidateEntry(const ACol,ARow:Integer; const OldValue:string; var NewValue:string): boolean; override;
public public
@ -176,11 +179,13 @@ type
procedure InsertColRow(IsColumn: boolean; index: integer); procedure InsertColRow(IsColumn: boolean; index: integer);
function InsertRow(const KeyName, Value: string; Append: Boolean): Integer; function InsertRow(const KeyName, Value: string; Append: Boolean): Integer;
procedure InsertRowWithValues(Index: Integer; Values: array of String); 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: Boolean; {Delphi compatible function}
function IsEmptyRow(aRow: Integer): Boolean; {This for makes more sense to me} function IsEmptyRow(aRow: Integer): Boolean; {This for makes more sense to me}
procedure MoveColRow(IsColumn: Boolean; FromIndex, ToIndex: Integer); procedure MoveColRow(IsColumn: Boolean; FromIndex, ToIndex: Integer);
function RestoreCurrentRow: Boolean; function RestoreCurrentRow: Boolean;
procedure Sort(Index, IndxFrom, IndxTo: Integer);
procedure Sort(ACol: TVleSortCol = colKey);
property Modified; property Modified;
property Keys[Index: Integer]: string read GetKey write SetKey; property Keys[Index: Integer]: string read GetKey write SetKey;
@ -536,6 +541,7 @@ end;
procedure TValueListStrings.Assign(Source: TPersistent); procedure TValueListStrings.Assign(Source: TPersistent);
begin begin
FGrid.InvalidateCachedRow; 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); inherited Assign(Source);
if (Source is TValueListStrings) then if (Source is TValueListStrings) then
FItemProps.Assign(TValueListStrings(Source).FItemProps); FItemProps.Assign(TValueListStrings(Source).FItemProps);
@ -848,7 +854,7 @@ end;
procedure TValueListEditor.ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer); procedure TValueListEditor.ExchangeColRow(IsColumn: Boolean; index, WithIndex: Integer);
begin begin
if not IsColumn then if not IsColumn then
Strings.Exchange(Index - FixedRows, WithIndex - FixedRows) inherited ExchangeColRow(IsColumn, index, WithIndex)
else else
Raise EGridException.CreateFmt(rsVLEInvalidRowColOperation,['ExchangeColRow',' on columns']); Raise EGridException.CreateFmt(rsVLEInvalidRowColOperation,['ExchangeColRow',' on columns']);
end; end;
@ -910,9 +916,18 @@ begin
end; end;
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); procedure TValueListEditor.StringsChange(Sender: TObject);
begin begin
//Since we never call inherited SetCell, this seems the logical place to do it
Modified := True; Modified := True;
AdjustRowCount; AdjustRowCount;
Invalidate; Invalidate;
@ -1100,6 +1115,13 @@ begin
end; end;
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); procedure TValueListEditor.DefineCellsProperty(Filer: TFiler);
begin begin
end; end;
@ -1336,6 +1358,22 @@ begin
end; end;
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); procedure TValueListEditor.TitlesChanged(Sender: TObject);
begin begin
// Refresh the display. // Refresh the display.