mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-09 23:37:12 +01:00
TAChart: Correctly refresh db-aware chart after dataset changes.
* Add BeforeDraw/AfterDraw procedures to series and sources * Preserve dataset cursor position while drawing db-aware Series * Update chart after deleting a record git-svn-id: trunk@20216 -
This commit is contained in:
parent
ed14f938e7
commit
421cb0e7aa
@ -29,12 +29,14 @@ type
|
||||
|
||||
TDbChartSource = class(TCustomChartSource)
|
||||
private
|
||||
FBookmark: TBookmark;
|
||||
FCurItem: TChartDataItem;
|
||||
FDataLink: TDataLink;
|
||||
FFieldColor: String;
|
||||
FFieldText: String;
|
||||
FFieldX: String;
|
||||
FFieldY: String;
|
||||
FCurItem: TChartDataItem;
|
||||
|
||||
function GetDataSource: TDataSource;
|
||||
procedure SetDataSource(AValue: TDataSource);
|
||||
procedure SetFieldColor(const AValue: String);
|
||||
@ -47,6 +49,9 @@ type
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
public
|
||||
procedure AfterDraw; override;
|
||||
procedure BeforeDraw; override;
|
||||
procedure Reset;
|
||||
published
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
@ -86,19 +91,21 @@ end;
|
||||
procedure TDbChartSourceDataLink.DataSetChanged;
|
||||
begin
|
||||
inherited DataSetChanged;
|
||||
//FChartSrc.Reset;
|
||||
if (FChartSrc.FBookmark = nil) and (DataSet.State = dsBrowse) then
|
||||
FChartSrc.Reset;
|
||||
end;
|
||||
|
||||
procedure TDbChartSourceDataLink.DataSetScrolled(Distance: Integer);
|
||||
begin
|
||||
inherited DataSetChanged;
|
||||
Unused(Distance);
|
||||
// No need to react on scrolling
|
||||
end;
|
||||
|
||||
procedure TDbChartSourceDataLink.UpdateData;
|
||||
begin
|
||||
inherited UpdateData;
|
||||
FChartSrc.Reset;
|
||||
if FChartSrc.FBookmark = nil then
|
||||
FChartSrc.Reset;
|
||||
end;
|
||||
|
||||
|
||||
@ -109,6 +116,23 @@ end;
|
||||
|
||||
{ TDbChartSource }
|
||||
|
||||
procedure TDbChartSource.AfterDraw;
|
||||
begin
|
||||
if not FDataLink.Active or (FBookmark = nil) then exit;
|
||||
try
|
||||
FDataLink.DataSet.GotoBookmark(FBookmark);
|
||||
FDataLink.DataSet.FreeBookmark(FBookmark);
|
||||
finally
|
||||
FBookmark := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDbChartSource.BeforeDraw;
|
||||
begin
|
||||
if FDataLink.Active then
|
||||
FBookmark := FDataLink.DataSet.GetBookmark;
|
||||
end;
|
||||
|
||||
constructor TDbChartSource.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
@ -58,6 +58,8 @@ type
|
||||
FZPosition: TChartZPosition;
|
||||
|
||||
procedure AfterAdd; virtual;
|
||||
procedure AfterDraw; virtual;
|
||||
procedure BeforeDraw; virtual;
|
||||
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); virtual; abstract;
|
||||
function GetLegendCount: Integer; virtual; abstract;
|
||||
function GetLegendWidth(ACanvas: TCanvas): Integer; virtual; abstract;
|
||||
@ -417,18 +419,26 @@ begin
|
||||
end;
|
||||
|
||||
procedure TChart.PaintOnCanvas(ACanvas: TCanvas; ARect: TRect);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Clean(ACanvas, ARect);
|
||||
|
||||
FClipRect := ARect;
|
||||
InflateRect(FClipRect, -2, -2);
|
||||
|
||||
for i := 0 to SeriesCount - 1 do
|
||||
Series[i].BeforeDraw;
|
||||
|
||||
UpdateExtent;
|
||||
DrawTitleFoot(ACanvas);
|
||||
DrawLegend(ACanvas);
|
||||
DrawAxis(ACanvas, ARect);
|
||||
DisplaySeries(ACanvas);
|
||||
DrawReticule(ACanvas);
|
||||
|
||||
for i := 0 to SeriesCount - 1 do
|
||||
Series[i].AfterDraw;
|
||||
end;
|
||||
|
||||
procedure TChart.PrepareXorPen;
|
||||
@ -1085,7 +1095,6 @@ begin
|
||||
finally
|
||||
seriesInZOrder.Free;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TChart.DrawReticule(ACanvas: TCanvas);
|
||||
@ -1374,6 +1383,16 @@ begin
|
||||
// nothing
|
||||
end;
|
||||
|
||||
procedure TBasicChartSeries.AfterDraw;
|
||||
begin
|
||||
// empty
|
||||
end;
|
||||
|
||||
procedure TBasicChartSeries.BeforeDraw;
|
||||
begin
|
||||
// empty
|
||||
end;
|
||||
|
||||
destructor TBasicChartSeries.Destroy;
|
||||
begin
|
||||
if FChart <> nil then
|
||||
|
||||
@ -51,6 +51,8 @@ type
|
||||
procedure SetSource(AValue: TCustomChartSource);
|
||||
protected
|
||||
procedure AfterAdd; override;
|
||||
procedure AfterDraw; override;
|
||||
procedure BeforeDraw; override;
|
||||
function ColorOrDefault(AColor: TColor; ADefault: TColor = clTAColor): TColor;
|
||||
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override;
|
||||
procedure GetCoords(AIndex: Integer; out AG: TDoublePoint; out AI: TPoint);
|
||||
@ -397,6 +399,16 @@ begin
|
||||
FMarks.SetOwner(FChart);
|
||||
end;
|
||||
|
||||
procedure TChartSeries.AfterDraw;
|
||||
begin
|
||||
Source.AfterDraw;
|
||||
end;
|
||||
|
||||
procedure TChartSeries.BeforeDraw;
|
||||
begin
|
||||
Source.BeforeDraw;
|
||||
end;
|
||||
|
||||
procedure TChartSeries.Clear;
|
||||
begin
|
||||
ListSource.Clear;
|
||||
|
||||
@ -65,6 +65,8 @@ type
|
||||
public
|
||||
destructor Destroy; override;
|
||||
public
|
||||
procedure AfterDraw; virtual;
|
||||
procedure BeforeDraw; virtual;
|
||||
procedure BeginUpdate;
|
||||
procedure EndUpdate;
|
||||
function IsUpdating: Boolean; inline;
|
||||
@ -229,6 +231,16 @@ end;
|
||||
|
||||
{ TCustomChartSource }
|
||||
|
||||
procedure TCustomChartSource.AfterDraw;
|
||||
begin
|
||||
// empty
|
||||
end;
|
||||
|
||||
procedure TCustomChartSource.BeforeDraw;
|
||||
begin
|
||||
// empty
|
||||
end;
|
||||
|
||||
procedure TCustomChartSource.BeginUpdate;
|
||||
begin
|
||||
Inc(FUpdateCount);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user