fpspreadsheet: Fix severe speed issue in WorksheetGrid (unnecessarily seeking last sheet column in DrawRow, needed for cell text overflow).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4039 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-03-16 17:40:16 +00:00
parent 99276082a3
commit d1a80fc98f
5 changed files with 27 additions and 50 deletions

View File

@ -59,6 +59,13 @@
<OtherUnitFiles Value="..\..\.."/>
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, Grids, Buttons, Menus, ActnList, StdActns,
fpstypes, fpspreadsheet, fpspreadsheetctrls, fpSpreadsheetGrid, fpsActions;
fpsTypes, fpSpreadsheet, fpSpreadsheetCtrls, fpSpreadsheetGrid, fpsActions;
type

View File

@ -98,9 +98,9 @@ type
FLeftPaneWidth: Integer;
FTopPaneHeight: Integer;
FOptions: TsSheetOptions;
FLastFoundCell: PCell;
FLastFoundRow: Cardinal;
FLastFoundCol: Cardinal;
// FLastFoundCell: PCell;
// FLastFoundRow: Cardinal;
// FLastFoundCol: Cardinal;
FFirstRowIndex: Cardinal;
FFirstColIndex: Cardinal;
FLastRowIndex: Cardinal;
@ -1108,9 +1108,9 @@ begin
FActiveCellRow := Cardinal(-1);
FActiveCellCol := Cardinal(-1);
FLastFoundCell := nil;
{ FLastFoundCell := nil;
FLastFoundRow := Cardinal(-1);
FLastFoundCol := Cardinal(-1);
FLastFoundCol := Cardinal(-1);}
FOptions := [soShowGridLines, soShowHeaders];
end;

View File

@ -816,30 +816,22 @@ end;
-------------------------------------------------------------------------------}
procedure TsWorkbookSource.InternalLoadFromFile(AFileName: string;
AAutoDetect: Boolean; AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = 0);
var
t: TTime;
begin
// Create a new empty workbook
t := now;
InternalCreateNewWorkbook;
DebugLn(Format('[Timer] Create workbook: %.3f sec', [(now-t)*24*3600]));
DisableControls;
try
t := Now;
// Read workbook from file and get worksheet
if AAutoDetect then
FWorkbook.ReadFromFile(AFileName)
else
FWorkbook.ReadFromFile(AFileName, AFormat);
DebugLn(Format('[Timer] Read file: %.3f sec', [(now-t)*24*3600]))
finally
EnableControls;
end;
t := now;
SelectWorksheet(FWorkbook.GetWorkSheetByIndex(AWorksheetIndex));
DebugLn(Format('[Timer] Select worksheet: %.3f sec', [(now-t)*24*3600]));
// If required, display loading error message
if FWorkbook.ErrorMsg <> '' then

View File

@ -1454,7 +1454,6 @@ var
tmp: Integer = 0;
begin
inherited;
Canvas.SaveHandleState;
try
// Avoid painting into the header cells
@ -1463,15 +1462,12 @@ begin
ColRowToOffset(True, True, FixedCols-1, tmp, cliprect.Left);
if FixedRows > 0 then
ColRowToOffset(False, True, FixedRows-1, tmp, cliprect.Top);
DrawFrozenPaneBorders(clipRect);
rgn := CreateRectRgn(cliprect.Left, cliprect.top, cliprect.Right, cliprect.Bottom);
SelectClipRgn(Canvas.Handle, Rgn);
DrawCellBorders;
DrawSelection;
DeleteObject(rgn);
finally
Canvas.RestoreHandleState;
@ -1770,7 +1766,7 @@ end;
procedure TsCustomWorksheetGrid.DrawRow(ARow: Integer);
var
gds: TGridDrawState;
sr, sr1,sc1,sr2,sc2: Cardinal; // sheet row/column
sr, sr1,sc1,sr2,sc2, scLastUsed: Cardinal; // sheet row/column
gr, gc, gcNext, gcLast, gc1, gc2, gcLastUsed: Integer; // grid row/column
i: Integer;
rct, saved_rct, temp_rct, commentcell_rct: TRect;
@ -1835,11 +1831,13 @@ begin
exit;
end;
scLastused := Worksheet.GetLastColIndex;
sr := GetWorksheetRow(ARow);
// Draw columns in this row
with GCache.VisibleGrid do
begin
gcLast := Right;
gc := Left;
// Because of possible cell overflow from cells left of the visible range
@ -1873,7 +1871,7 @@ begin
gcLast := Right;
if FTextOverflow and (sr <> Cardinal(-1)) and Assigned(Worksheet) then
begin
gcLastUsed := GetGridCol(Worksheet.GetLastOccupiedColIndex);
gcLastUsed := GetGridCol(scLastUsed);
while (gcLast < ColCount-1) and (gcLast < gcLastUsed) do begin
inc(gcLast);
cell := Worksheet.FindCell(sr, GetWorksheetCol(gcLast));
@ -3338,8 +3336,6 @@ end;
-------------------------------------------------------------------------------}
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer);
var
t: TTime;
begin
if FOwnsWorkbook then
FreeAndNil(FOwnedWorkbook);
@ -3350,17 +3346,9 @@ begin
begin
BeginUpdate;
try
t := now;
CreateNewWorkbook;
DebugLn(Format('[Timer] Create workbook: %.3f sec', [(now - t)*24*3600]));
t := now;
Workbook.ReadFromFile(AFileName, AFormat);
DebugLn(Format('[Timer] Read file: %.3f sec', [(now - t)*24*3600]));
t := now;
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
DebugLn(Format('[Timer] Load into grid: %.3f sec', [(now - t)*24*3600]));
finally
EndUpdate;
end;
@ -3376,8 +3364,6 @@ end;
-------------------------------------------------------------------------------}
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
AWorksheetIndex: Integer);
var
t: TTime;
begin
if FOwnsWorkbook then
FreeAndNil(FOwnedWorkbook);
@ -3388,17 +3374,9 @@ begin
begin
BeginUpdate;
try
t := now;
CreateNewWorkbook;
DebugLn(Format('[Timer] Create workbook: %.3f sec', [(now - t)*24*3600]));
t := now;
Workbook.ReadFromFile(AFilename);
DebugLn(Format('[Timer] Read file: %.3f sec', [(now - t)*24*3600]));
t := now;
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
DebugLn(Format('[Timer] Load into grid: %.3f sec', [(now - t)*24*3600]));
finally
EndUpdate;
end;
@ -3678,12 +3656,12 @@ end;
@param AFileName Name of the file to which the workbook is to be
saved
If the file format is not known is is written
If the file format is not known it is written
as BIFF8/XLS.
@param AOverwriteExisting If this file already exists it is overwritten if
AOverwriteExisting = true, or an exception is
raised if AOverwriteExisting = false.
}
-------------------------------------------------------------------------------}
procedure TsCustomWorksheetGrid.SaveToSpreadsheetFile(AFileName: String;
AOverwriteExisting: Boolean = true);
begin