1. TRxDBGrid - fix error in calc title height procedure on resize column

2. TRxDBGrid - start work on DB independed filter procedure in grid
3. TRxDBGrid - fix calc sum in footer row on Zeos dataset with filter
4. TRxDBGrid - fix calc width of filter combobox after resize filtred column


git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2712 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2013-03-28 15:40:03 +00:00
parent b85c797fd5
commit 94c53ecb53
3 changed files with 181 additions and 20 deletions

View File

@ -27,15 +27,60 @@ type
THackZeosDS = class(TZAbstractRODataset); THackZeosDS = class(TZAbstractRODataset);
THackRxColumnFooter = class(TRxColumnFooter); THackRxColumnFooter = class(TRxColumnFooter);
THackDataLink = class(TDataLink);
THackDataSet = class(TDataSet);
THackRxDBGrid = class(TRxDBGrid);
procedure TZeosDataSetSortEngine.UpdateFooterRows(ADataSet: TDataSet; procedure TZeosDataSetSortEngine.UpdateFooterRows(ADataSet: TDataSet;
AGrid: TRxDBGrid); AGrid: TRxDBGrid);
var var
RS:IZResultSet; RS:IZResultSet;
CurRow, i:integer; CurRow, i:integer;
Col:TRxColumn; Col:TRxColumn;
DHL:THackDataLink;
DHS:THackDataSet;
SaveState:TDataSetState;
SavePos:integer;
SaveActiveRecord:integer;
begin begin
if not Assigned(ADataSet) then exit; if not Assigned(ADataSet) then exit;
RS:=THackZeosDS(ADataSet).ResultSet; DHL:=THackDataLink(THackRxDBGrid(AGrid).Datalink);
DHS:=THackDataSet(ADataSet);
SaveState:=DHS.SetTempState(dsBrowse);
SaveActiveRecord:=DHL.ActiveRecord;
DHL.ActiveRecord:=0;
SavePos:=ADataSet.RecNo;
ADataSet.First;
while not ADataSet.EOF do
begin
for i:=0 to AGrid.Columns.Count-1 do
begin
Col:=TRxColumn(AGrid.Columns[i]);
if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar( ADataSet.FieldByName(Col.Footer.FieldName).Value);
end;
ADataSet.Next;
end;
DHS.RecNo := DHL.RecordCount + SavePos + 1;
while not ADataSet.BOF do
begin
if SavePos = ADataSet.RecNo then
break;
ADataSet.Prior;
end;
DHL.ActiveRecord:=SaveActiveRecord;
DHS.RestoreState(SaveState);
{ RS:=THackZeosDS(ADataSet).ResultSet;
CurRow:=RS.GetRow; CurRow:=RS.GetRow;
RS.First; RS.First;
// while not RS.IsLast do // while not RS.IsLast do
@ -49,7 +94,7 @@ begin
end; end;
RS.Next; RS.Next;
end; end;
RS.MoveAbsolute(CurRow); RS.MoveAbsolute(CurRow);}
end; end;
function TZeosDataSetSortEngine.EnabledFooterRowsCalc: boolean; function TZeosDataSetSortEngine.EnabledFooterRowsCalc: boolean;

View File

@ -110,6 +110,7 @@ type
TRxDSState = (rxdsInactive, rxdsActive); TRxDSState = (rxdsInactive, rxdsActive);
TRxFilterOpCode = (fopEQ, fopNotEQ, fopStartFrom, fopEndTo, fopLike, fopNotLike);
{ TRxDBGridKeyStroke } { TRxDBGridKeyStroke }
TRxDBGridKeyStroke = class(TCollectionItem) TRxDBGridKeyStroke = class(TCollectionItem)
@ -135,11 +136,9 @@ type
TRxDBGridKeyStrokes = class(TOwnedCollection) TRxDBGridKeyStrokes = class(TOwnedCollection)
private private
//FOwn: TPersistent;
function GetItem(Index: integer): TRxDBGridKeyStroke; function GetItem(Index: integer): TRxDBGridKeyStroke;
procedure SetItem(Index: integer; const AValue: TRxDBGridKeyStroke); procedure SetItem(Index: integer; const AValue: TRxDBGridKeyStroke);
protected protected
//function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override; procedure Update(Item: TCollectionItem); override;
public public
constructor Create(AOwner: TPersistent); constructor Create(AOwner: TPersistent);
@ -150,8 +149,7 @@ type
function FindRxCommand(AKey: word; AShift: TShiftState): TRxDBGridCommand; function FindRxCommand(AKey: word; AShift: TShiftState): TRxDBGridCommand;
function FindRxKeyStrokes(ACommand: TRxDBGridCommand): TRxDBGridKeyStroke; function FindRxKeyStrokes(ACommand: TRxDBGridCommand): TRxDBGridKeyStroke;
public public
property Items[Index: integer]: TRxDBGridKeyStroke read GetItem write SetItem; property Items[Index: integer]: TRxDBGridKeyStroke read GetItem write SetItem; default;
default;
end; end;
{ TRxDBGridFooterOptions } { TRxDBGridFooterOptions }
@ -275,6 +273,22 @@ type
read FValueType write SetValueType default fvtNon; read FValueType write SetValueType default fvtNon;
end; end;
{ TRxFilterItem }
TRxFilterItem = class
FVAlue:string;
FCol:TRxColumn;
OpCode:TRxFilterOpCode;
function TestValue:Boolean;
end;
{ TRxFilterItems }
TRxFilterItems = class(TFPList)
function AcceptRecord:boolean;
end;
{ TRxColumnFilter } { TRxColumnFilter }
TRxColumnFilter = class(TPersistent) TRxColumnFilter = class(TPersistent)
@ -390,7 +404,7 @@ type
constructor Create(ACollection: TCollection); override; constructor Create(ACollection: TCollection); override;
destructor Destroy; override; destructor Destroy; override;
procedure OptimizeWidth; procedure OptimizeWidth;
property SortOrder: TSortMarker read FSortOrder; property SortOrder: TSortMarker read FSortOrder write FSortOrder;
property SortPosition: integer read FSortPosition; property SortPosition: integer read FSortPosition;
published published
property Footer: TRxColumnFooter read GetFooter write SetFooter; property Footer: TRxColumnFooter read GetFooter write SetFooter;
@ -551,9 +565,7 @@ type
procedure OnIniLoad(Sender: TObject); procedure OnIniLoad(Sender: TObject);
procedure CleanDSEvent; procedure CleanDSEvent;
procedure CollumnSortListUpdate;
procedure CollumnSortListClear;
procedure CollumnSortListApply;
procedure UpdateRowsHeight; procedure UpdateRowsHeight;
procedure ResetRowHeght; procedure ResetRowHeght;
@ -561,6 +573,10 @@ type
procedure DoClearInvalidTitle; procedure DoClearInvalidTitle;
procedure DoDrawInvalidTitle; procedure DoDrawInvalidTitle;
protected protected
procedure CollumnSortListUpdate;
procedure CollumnSortListClear;
procedure CollumnSortListApply;
function DatalinkActive: boolean; function DatalinkActive: boolean;
procedure LinkActive(Value: Boolean); override; procedure LinkActive(Value: Boolean); override;
@ -603,8 +619,9 @@ type
procedure InternalOptimizeColumnsWidth(AColList: TList); procedure InternalOptimizeColumnsWidth(AColList: TList);
function IsDefaultRowHeightStored: boolean; function IsDefaultRowHeightStored: boolean;
procedure VisualChange; override; procedure VisualChange; override;
procedure SetQuickUTF8Search(AValue: string); procedure EditorWidthChanged(aCol,aWidth: Integer); override;
procedure SetQuickUTF8Search(AValue: string);
procedure BeforeDel(DataSet: TDataSet); procedure BeforeDel(DataSet: TDataSet);
procedure BeforePo(DataSet: TDataSet); procedure BeforePo(DataSet: TDataSet);
procedure ErrorDel(DataSet: TDataSet; E: EDatabaseError; procedure ErrorDel(DataSet: TDataSet; E: EDatabaseError;
@ -631,9 +648,11 @@ type
procedure FilterRec(DataSet: TDataSet; var Accept: boolean); procedure FilterRec(DataSet: TDataSet; var Accept: boolean);
function EditorByStyle(Style: TColumnButtonStyle): TWinControl; override; function EditorByStyle(Style: TColumnButtonStyle): TWinControl; override;
procedure LayoutChanged; override; procedure LayoutChanged; override;
procedure SetFocus; override;
procedure ShowFindDialog; procedure ShowFindDialog;
procedure ShowColumnsDialog; procedure ShowColumnsDialog;
procedure ShowSortDialog; procedure ShowSortDialog;
procedure ShowFilterDialog;
function ColumnByFieldName(AFieldName: string): TRxColumn; function ColumnByFieldName(AFieldName: string): TRxColumn;
function ColumnByCaption(ACaption: string): TRxColumn; function ColumnByCaption(ACaption: string): TRxColumn;
procedure CalcStatTotals; procedure CalcStatTotals;
@ -870,6 +889,42 @@ type
procedure EditingDone; override; procedure EditingDone; override;
end; end;
{ TRxFilterItems }
function TRxFilterItems.AcceptRecord: boolean;
var
i:integer;
begin
Result:=true;
for i:=0 to Count-1 do
begin
if not TRxFilterItem(Items[i]).TestValue then
begin
Result:=false;
exit;
end;
end;
end;
{ TRxFilterItem }
function TRxFilterItem.TestValue: Boolean;
var
ATestValue: string;
begin
ATestValue:=FCol.Field.DisplayText;
case OpCode of
fopEQ:Result:=ATestValue = FVAlue;
fopNotEQ:Result:=ATestValue <> FVAlue;
fopStartFrom:Result:=UTF8Copy(ATestValue, 1, UTF8Length(FVAlue)) = FVAlue;
fopEndTo:Result:=Copy(ATestValue, UTF8Length(ATestValue) - UTF8Length(FVAlue), UTF8Length(FVAlue)) = FVAlue;
fopLike:Result:=UTF8Pos(FVAlue, ATestValue) > 0;
fopNotLike:Result:=UTF8Pos(FVAlue, ATestValue) = 0;
else
Result:=false;
end;
end;
{ TRxDbGridColumnsSortList } { TRxDbGridColumnsSortList }
function TRxDbGridColumnsSortList.GetCollumn(Index: Integer): TRxColumn; function TRxDbGridColumnsSortList.GetCollumn(Index: Integer): TRxColumn;
@ -1886,16 +1941,16 @@ begin
S := MLRec1.Caption; S := MLRec1.Caption;
if not Assigned(MLRec1.Prior) then if not Assigned(MLRec1.Prior) then
begin begin
W := rxCol.Width;//MLRec1.Width; W := rxCol.Width;
P := MLRec1.Next; P := MLRec1.Next;
while Assigned(P) do while Assigned(P) do
begin begin
Inc(W, P.Col.Width);//P.Width); Inc(W, P.Col.Width);
P := P.Next; P := P.Next;
end; end;
W1 := tmpCanvas.TextWidth(MLRec1.Caption) + 2; W1 := tmpCanvas.TextWidth(MLRec1.Caption) + 2;
if W1 > W then if W1 > W then
MLRec1.Hegth := W1 div Max(W, 1) + 1 MLRec1.Hegth := Min(W1 div Max(W, 1) + 1, UTF8Length(MLRec1.Caption))
else else
MLRec1.Hegth := 1; MLRec1.Hegth := 1;
@ -2307,6 +2362,7 @@ var
S:string; S:string;
Asc:array of boolean; Asc:array of boolean;
begin begin
if (FSortColumns.Count = 0) then exit;
FSortingNow:=true; FSortingNow:=true;
if FSortColumns.Count>1 then if FSortColumns.Count>1 then
begin begin
@ -3465,6 +3521,7 @@ end;
procedure TRxDBGrid.Paint; procedure TRxDBGrid.Paint;
begin begin
Inc(FInProcessCalc);
if rdgWordWrap in FOptionsRx then if rdgWordWrap in FOptionsRx then
UpdateRowsHeight; UpdateRowsHeight;
@ -3476,14 +3533,15 @@ begin
if FFooterOptions.Active and (FFooterOptions.RowCount > 0) then if FFooterOptions.Active and (FFooterOptions.RowCount > 0) then
DrawFooterRows; DrawFooterRows;
Dec(FInProcessCalc);
end; end;
procedure TRxDBGrid.UpdateActive; procedure TRxDBGrid.UpdateActive;
begin begin
if FInProcessCalc > 0 then { if FInProcessCalc > 0 then
exit; exit;}
inherited UpdateActive; inherited UpdateActive;
if FInProcessCalc < 0 then { if FInProcessCalc < 0 then
begin begin
FInProcessCalc := 0; FInProcessCalc := 0;
UpdateFooterRowOnUpdateActive; UpdateFooterRowOnUpdateActive;
@ -3491,7 +3549,7 @@ begin
else else
if FFooterOptions.Active and (FFooterOptions.RowCount > 0) then if FFooterOptions.Active and (FFooterOptions.RowCount > 0) then
UpdateFooterRowOnUpdateActive; UpdateFooterRowOnUpdateActive;
}
// UpdateRowsHeight; // UpdateRowsHeight;
end; end;
@ -3638,6 +3696,19 @@ begin
UpdateRowsHeight;} UpdateRowsHeight;}
end; end;
procedure TRxDBGrid.EditorWidthChanged(aCol, aWidth: Integer);
var
R:TRect;
begin
inherited EditorWidthChanged(aCol, aWidth);
if FFilterListEditor.Visible then
begin
R:=CellRect(FFilterListEditor.Col+1,0);
FFilterListEditor.Width:=Columns[FFilterListEditor.Col].Width;
FFilterListEditor.Left:=R.Left;
end;
end;
function TRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl; function TRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
var var
F: TField; F: TField;
@ -4308,6 +4379,13 @@ begin
CalcStatTotals; CalcStatTotals;
end; end;
procedure TRxDBGrid.SetFocus;
begin
inherited SetFocus;
if FFilterListEditor.Visible then
FFilterListEditor.Hide;
end;
procedure TRxDBGrid.ShowFindDialog; procedure TRxDBGrid.ShowFindDialog;
begin begin
ShowRxDBGridFindForm(Self); ShowRxDBGridFindForm(Self);
@ -4323,6 +4401,11 @@ begin
OnSortBy(nil); OnSortBy(nil);
end; end;
procedure TRxDBGrid.ShowFilterDialog;
begin
OnFilterBy(nil);
end;
function TRxDBGrid.ColumnByFieldName(AFieldName: string): TRxColumn; function TRxDBGrid.ColumnByFieldName(AFieldName: string): TRxColumn;
var var
i: integer; i: integer;

View File

@ -57,25 +57,58 @@ uses rxmemds;
type type
THackRxMemoryData = class(TRxMemoryData); THackRxMemoryData = class(TRxMemoryData);
THackRxColumnFooter = class(TRxColumnFooter); THackRxColumnFooter = class(TRxColumnFooter);
THackDataLink = class(TDataLink);
THackDataSet = class(TDataSet);
THackRxDBGrid = class(TRxDBGrid);
procedure TRxMemoryDataSortEngine.UpdateFooterRows(ADataSet: TDataSet; procedure TRxMemoryDataSortEngine.UpdateFooterRows(ADataSet: TDataSet;
AGrid: TRxDBGrid); AGrid: TRxDBGrid);
var var
i, j:integer; i, j:integer;
Col:TRxColumn; Col:TRxColumn;
DHL:THackDataLink;
DHS:THackDataSet;
SaveState:TDataSetState;
SavePos:integer;
SaveActiveRecord:integer;
begin begin
if not Assigned(ADataSet) then exit; if not Assigned(ADataSet) then exit;
for j:=0 to ADataSet.RecordCount-1 do DHL:=THackDataLink(THackRxDBGrid(AGrid).Datalink);
DHS:=THackDataSet(ADataSet);
SaveState:=DHS.SetTempState(dsBrowse);
SaveActiveRecord:=DHL.ActiveRecord;
DHL.ActiveRecord:=0;
SavePos:=ADataSet.RecNo;
ADataSet.First;
while not ADataSet.EOF do
begin begin
for i:=0 to AGrid.Columns.Count-1 do for i:=0 to AGrid.Columns.Count-1 do
begin begin
Col:=TRxColumn(AGrid.Columns[i]); Col:=TRxColumn(AGrid.Columns[i]);
if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar( THackRxMemoryData(ADataSet).GetAnyRecField(j, ADataSet.FieldByName(Col.Footer.FieldName))); THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar( ADataSet.FieldByName(Col.Footer.FieldName).Value);
end; end;
ADataSet.Next;
end; end;
DHS.RecNo := DHL.RecordCount + SavePos + 1;
while not ADataSet.BOF do
begin
if SavePos = ADataSet.RecNo then
break;
ADataSet.Prior;
end;
DHL.ActiveRecord:=SaveActiveRecord;
DHS.RestoreState(SaveState);
end; end;
function TRxMemoryDataSortEngine.EnabledFooterRowsCalc: boolean; function TRxMemoryDataSortEngine.EnabledFooterRowsCalc: boolean;