mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 20:59:17 +02:00
TAChart: Extend TListChartSource.DataPoints to support separator ('|') as well as line breaks in the Text field.
git-svn-id: trunk@60501 -
This commit is contained in:
parent
bfaf53d166
commit
2361649666
@ -33,6 +33,7 @@ object DataPointsEditorForm: TDataPointsEditorForm
|
|||||||
Width = 63
|
Width = 63
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
|
ButtonStyle = cbsEllipsis
|
||||||
Title.Alignment = taCenter
|
Title.Alignment = taCenter
|
||||||
Title.Font.Style = [fsBold]
|
Title.Font.Style = [fsBold]
|
||||||
Title.Caption = 'Text'
|
Title.Caption = 'Text'
|
||||||
|
@ -59,11 +59,41 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LCLIntf, LCLType, Math,
|
LCLIntf, LCLType, Math, StdCtrls,
|
||||||
TAChartStrConsts, TAChartUtils, TASources;
|
TAChartStrConsts, TAChartUtils, TASources;
|
||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
|
function EditText(var AText: String): Boolean;
|
||||||
|
var
|
||||||
|
F: TForm;
|
||||||
|
memo: TMemo;
|
||||||
|
begin
|
||||||
|
F := TForm.CreateNew(Application);
|
||||||
|
try
|
||||||
|
F.Caption := 'Data point text';
|
||||||
|
F.Position := poScreenCenter;
|
||||||
|
memo := TMemo.Create(F);
|
||||||
|
with memo do begin
|
||||||
|
Parent := F;
|
||||||
|
Align := alClient;
|
||||||
|
BorderSpacing.Around := 6;
|
||||||
|
Lines.Text := AText;
|
||||||
|
end;
|
||||||
|
with TButtonPanel.Create(F) do begin
|
||||||
|
Parent := F;
|
||||||
|
Align := alBottom;
|
||||||
|
BorderSpacing.Around := 6;
|
||||||
|
ShowButtons := [pbOK, pbCancel];
|
||||||
|
end;
|
||||||
|
Result := F.ShowModal = mrOK;
|
||||||
|
if Result then AText := memo.Lines.Text;
|
||||||
|
finally
|
||||||
|
F.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TDataPointsEditorForm }
|
{ TDataPointsEditorForm }
|
||||||
|
|
||||||
procedure TDataPointsEditorForm.ExtractData(out AModified: Boolean);
|
procedure TDataPointsEditorForm.ExtractData(out AModified: Boolean);
|
||||||
@ -200,12 +230,21 @@ end;
|
|||||||
|
|
||||||
procedure TDataPointsEditorForm.sgDataButtonClick(
|
procedure TDataPointsEditorForm.sgDataButtonClick(
|
||||||
ASender: TObject; ACol, ARow: Integer);
|
ASender: TObject; ACol, ARow: Integer);
|
||||||
|
var
|
||||||
|
s: String;
|
||||||
begin
|
begin
|
||||||
Unused(ASender);
|
Unused(ASender);
|
||||||
if (ARow < 1) or (ACol <> FXCount + FYCount + 1) then exit;
|
if (ARow < 1) then exit;
|
||||||
cdItemColor.Color := StrToIntDef(sgData.Cells[ACol, ARow], clRed);
|
|
||||||
if not cdItemColor.Execute then exit;
|
if (ACol = FXCount + FYCount + 1) then begin
|
||||||
sgData.Cells[ACol, ARow] := IntToColorHex(cdItemColor.Color);
|
cdItemColor.Color := StrToIntDef(sgData.Cells[ACol, ARow], clRed);
|
||||||
|
if cdItemColor.Execute then
|
||||||
|
sgData.Cells[ACol, ARow] := IntToColorHex(cdItemColor.Color);
|
||||||
|
end else
|
||||||
|
if (ACol = FXCount + FYCount + 2) then begin
|
||||||
|
s := sgData.Cells[ACol, ARow];
|
||||||
|
if EditText(s) then sgData.Cells[ACol, ARow] := s;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDataPointsEditorForm.sgDataDrawCell(
|
procedure TDataPointsEditorForm.sgDataDrawCell(
|
||||||
|
@ -313,6 +313,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TListChartSourceStrings.Get(Index: Integer): String;
|
function TListChartSourceStrings.Get(Index: Integer): String;
|
||||||
|
const
|
||||||
|
COLOR_TEXT_MASK: array[boolean] of string = ('%s|%s', '%s|"%s"');
|
||||||
|
|
||||||
function NumberStr(AValue: Double): String;
|
function NumberStr(AValue: Double): String;
|
||||||
begin
|
begin
|
||||||
@ -335,7 +337,7 @@ begin
|
|||||||
Result += NumberStr(Y);
|
Result += NumberStr(Y);
|
||||||
for i := 0 to High(YList) do
|
for i := 0 to High(YList) do
|
||||||
Result += NumberStr(YList[i]);
|
Result += NumberStr(YList[i]);
|
||||||
Result += Format('%s|%s', [IntToColorHex(Color), Text]);
|
Result += Format(COLOR_TEXT_MASK[pos('|', Text) > 0], [IntToColorHex(Color), Text]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -423,6 +425,7 @@ begin
|
|||||||
parts := Split(AString);
|
parts := Split(AString);
|
||||||
try
|
try
|
||||||
// There must be XCount + YCount + 2 parts of the string (+2 for Color and Text)
|
// There must be XCount + YCount + 2 parts of the string (+2 for Color and Text)
|
||||||
|
// Text must be quoted if it contains '|'.
|
||||||
if (Cardinal(parts.Count) <> FSource.XCount + FSource.YCount + 2) then
|
if (Cardinal(parts.Count) <> FSource.XCount + FSource.YCount + 2) then
|
||||||
raise EListSourceStringError.CreateFmt(
|
raise EListSourceStringError.CreateFmt(
|
||||||
rsListSourceStringFormatError, [SourceClassString, ChopString(AString, 20)]);
|
rsListSourceStringFormatError, [SourceClassString, ChopString(AString, 20)]);
|
||||||
|
@ -563,7 +563,15 @@ begin
|
|||||||
FSource.DataPoints.Add('1|2|3||t');
|
FSource.DataPoints.Add('1|2|3||t');
|
||||||
AssertEquals(clTAColor, FSource[6]^.Color);
|
AssertEquals(clTAColor, FSource[6]^.Color);
|
||||||
|
|
||||||
// check multiple x and y values
|
// Check Text part containing '|' character(s)
|
||||||
|
FSource.DataPoints.Add('1|2|3|?|"a|b|c"');
|
||||||
|
AssertEquals('a|b|c', FSource[7]^.Text);
|
||||||
|
|
||||||
|
// Check Text part containing line ending
|
||||||
|
FSource.DataPoints.Add('1|2|3|?|"a'+LineEnding+'b"');
|
||||||
|
AssertEquals('a'+LineEnding+'b', FSource[8]^.Text);
|
||||||
|
|
||||||
|
// Check multiple x and y values
|
||||||
FSource.Clear;
|
FSource.Clear;
|
||||||
FSource.XCount := 2;
|
FSource.XCount := 2;
|
||||||
FSource.YCount := 3;
|
FSource.YCount := 3;
|
||||||
|
Loading…
Reference in New Issue
Block a user