TAChart: Add design-time editor for TListChartSource.DataPoints property

git-svn-id: trunk@32080 -
This commit is contained in:
ask 2011-08-28 10:06:13 +00:00
parent d03bd83f01
commit 2e38d51e90
5 changed files with 212 additions and 2 deletions

2
.gitattributes vendored
View File

@ -2495,6 +2495,8 @@ components/tachart/tachartwmf.lpk svneol=native#text/plain
components/tachart/tachartwmf.pas svneol=native#text/pascal
components/tachart/tacustomseries.pas svneol=native#text/plain
components/tachart/tacustomsource.pas svneol=native#text/pascal
components/tachart/tadatapointseditor.lfm svneol=native#text/plain
components/tachart/tadatapointseditor.pas svneol=native#text/pascal
components/tachart/tadbsource.pas svneol=native#text/pascal
components/tachart/tadraweraggpas.pas svneol=native#text/pascal
components/tachart/tadrawerbgra.pas svneol=native#text/pascal

View File

@ -30,7 +30,7 @@
for details about the copyright.
"/>
<Version Major="1"/>
<Files Count="30">
<Files Count="31">
<Item1>
<Filename Value="tagraph.pas"/>
<HasRegisterProc Value="True"/>
@ -164,6 +164,11 @@
<Filename Value="taenumerators.pas"/>
<UnitName Value="TAEnumerators"/>
</Item30>
<Item31>
<Filename Value="tadatapointseditor.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="TADataPointsEditor"/>
</Item31>
</Files>
<LazDoc Paths="$(LazarusDir)\components\tachart\fpdoc"/>
<Type Value="RunAndDesignTime"/>

View File

@ -12,7 +12,7 @@ uses
TATypes, TADrawUtils, TAMultiSeries, TALegend, TAStyles, TAFuncSeries,
TALegendPanel, TARadialSeries, TACustomSource, TAGeometry, TANavigation,
TADrawerCanvas, TADrawerSVG, TAIntervalSources, TAChartAxisUtils,
TAChartListbox, TAEnumerators, LazarusPackageIntf;
TAChartListbox, TAEnumerators, TADataPointsEditor, LazarusPackageIntf;
implementation
@ -29,6 +29,7 @@ begin
RegisterUnit('TANavigation', @TANavigation.Register);
RegisterUnit('TAIntervalSources', @TAIntervalSources.Register);
RegisterUnit('TAChartListbox', @TAChartListbox.Register);
RegisterUnit('TADataPointsEditor', @TADataPointsEditor.Register);
end;
initialization

View File

@ -0,0 +1,49 @@
object DataPointsEditorForm: TDataPointsEditorForm
Left = 418
Height = 303
Top = 235
Width = 357
Caption = 'DataPoints editor'
ClientHeight = 303
ClientWidth = 357
LCLVersion = '0.9.31'
object sgData: TStringGrid
Left = 0
Height = 257
Top = 0
Width = 357
Align = alClient
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goRowMoving, goEditing, goAutoAddRows, goRowSelect, goAlwaysShowEditor, goSmoothScroll, goFixedRowNumbering]
PopupMenu = pmRows
TabOrder = 0
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 34
Top = 263
Width = 345
OKButton.Name = 'OKButton'
OKButton.Caption = '&OK'
HelpButton.Name = 'HelpButton'
HelpButton.Caption = '&Help'
CloseButton.Name = 'CloseButton'
CloseButton.Caption = '&Close'
CancelButton.Name = 'CancelButton'
CancelButton.Caption = 'Cancel'
TabOrder = 1
ShowButtons = [pbOK, pbCancel]
end
object pmRows: TPopupMenu
OnPopup = pmRowsPopup
left = 193
top = 124
object miInsertRow: TMenuItem
Caption = 'Insert row'
OnClick = miInsertRowClick
end
object miDeleteRow: TMenuItem
Caption = 'Delete row'
OnClick = miDeleteRowClick
end
end
end

View File

@ -0,0 +1,153 @@
unit TADataPointsEditor;
{$H+}
interface
uses
ButtonPanel, Classes, ExtCtrls, Grids, Menus, SysUtils, FileUtil, Forms,
Controls, Graphics, Dialogs;
type
TDataPointsEditorForm = class(TForm)
ButtonPanel1: TButtonPanel;
miInsertRow: TMenuItem;
miDeleteRow: TMenuItem;
pmRows: TPopupMenu;
sgData: TStringGrid;
procedure miDeleteRowClick(Sender: TObject);
procedure miInsertRowClick(Sender: TObject);
procedure pmRowsPopup(Sender: TObject);
strict private
FCurrentRow: Integer;
FDataPoints: TStrings;
FYCount: Integer;
public
procedure InitData(AYCount: Integer; ADataPoints: TStrings);
procedure ExtractData;
end;
procedure Register;
implementation
uses
Math, PropEdits, TASources;
{$R *.lfm}
type
TDataPointsPropertyEditor = class(TPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: AnsiString; override;
end;
procedure Register;
begin
RegisterPropertyEditor(
TypeInfo(TStrings), TListChartSource, 'DataPoints',
TDataPointsPropertyEditor);
end;
{ TDataPointsEditorForm }
procedure TDataPointsEditorForm.ExtractData;
var
i: Integer;
s: String;
begin
FDataPoints.BeginUpdate;
try
FDataPoints.Clear;
for i := 1 to sgData.RowCount - 1 do begin
with sgData.Rows[i] do begin
Delimiter := '|';
StrictDelimiter := true;
s := DelimitedText;
end;
if Length(s) >= sgData.ColCount then
FDataPoints.Add(Copy(s, 2, MaxInt));
end;
finally
FDataPoints.EndUpdate;
end;
end;
procedure TDataPointsEditorForm.InitData(
AYCount: Integer; ADataPoints: TStrings);
var
i: Integer;
begin
FYCount := AYCount;
FDataPoints := ADataPoints;
sgData.ColCount := AYCount + 4;
sgData.RowCount := Max(ADataPoints.Count + 1, 2);
sgData.Cells[0, 0] := 'No.';
sgData.Cells[1, 0] := 'X';
sgData.Cells[2, 0] := 'Y';
for i := 2 to AYCount do
sgData.Cells[i + 1, 0] := 'Y' + IntToStr(i);
sgData.Cells[AYCount + 2, 0] := 'Color';
sgData.Cells[AYCount + 3, 0] := 'Text';
for i := 0 to ADataPoints.Count - 1 do
with sgData.Rows[i + 1] do begin
Delimiter := '|';
StrictDelimiter := true;
DelimitedText := '|' + ADataPoints[i];
end;
end;
procedure TDataPointsEditorForm.miDeleteRowClick(Sender: TObject);
begin
if sgData.RowCount <= 2 then begin
sgData.Rows[1].Clear;
exit;
end;
if InRange(FCurrentRow, 1, sgData.RowCount - 1) then begin
sgData.DeleteRow(FCurrentRow);
end;
end;
procedure TDataPointsEditorForm.miInsertRowClick(Sender: TObject);
begin
sgData.InsertColRow(false, FCurrentRow);
end;
procedure TDataPointsEditorForm.pmRowsPopup(Sender: TObject);
begin
FCurrentRow := sgData.MouseToCell(sgData.ScreenToClient(Mouse.CursorPos)).Y;
if not InRange(FCurrentRow, 1, sgData.RowCount - 1) then
Abort;
sgData.Row := FCurrentRow;
end;
{ TDataPointsPropertyEditor }
procedure TDataPointsPropertyEditor.Edit;
begin
with TDataPointsEditorForm.Create(nil) do
try
InitData(
(GetComponent(0) as TListChartSource).YCount,
GetObjectValue as TStrings);
if ShowModal = mrOK then
ExtractData;
finally
Free;
end;
end;
function TDataPointsPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paMultiSelect, paReadOnly, paRevertable];
end;
function TDataPointsPropertyEditor.GetValue: AnsiString;
begin
Result := (GetObjectValue as TStrings).Text;
end;
end.