📄 teechartgrid.pas
字号:
Options:=[ goHorzLine,
goVertLine,
goRangeSelect,
goDrawFocusSelected,
goRowSizing,
goColSizing,
goEditing,
goTabs,
goThumbTracking
];
RecalcDimensions;
end;
Destructor TCustomChartGrid.Destroy;
begin
Series:=nil; // 5.03
Chart:=nil;
IHasNo:=nil;
inherited;
end;
Procedure TCustomChartGrid.Loaded;
begin
inherited;
RowHeights[0]:=20;
end;
Function TCustomChartGrid.HasPoints:Boolean;
var t: Integer;
begin
result:=False;
if Assigned(FSeries) then { single series }
result:=FSeries.Count>0
else
if Assigned(Chart) then { all series in chart }
With Chart do
for t:=0 to SeriesCount-1 do
if Series[t].Count>0 then
begin
result:=True;
Exit;
end;
end;
Function TCustomChartGrid.FirstRowNum:Integer;
begin
if ShowFields then result:=2 else result:=1;
end;
function TCustomChartGrid.SelectCell(ACol, ARow: Integer): Boolean;
begin
result:=inherited SelectCell(ACol,ARow) and (ACol>0) and (ARow>=FirstRowNum);
// Call event
if result and Assigned(FSelectedChanged) then
FSelectedChanged(Self,ACol,ARow,result);
end;
{$IFNDEF LCL}
function TCustomChartGrid.CanEditModify: Boolean;
begin
result:=inherited CanEditModify;
if result then
if Assigned(INavigator) then INavigator.ActiveChanged(Self);
end;
{$ENDIF}
procedure TCustomChartGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
Procedure SelectColumn;
var tmpCoord : TGridCoord;
tmpSelection : TGridRect;
begin
{$IFNDEF LCL} // MouseCoord not supported
tmpCoord:=MouseCoord(x,y);
if (tmpCoord.X>FixedCols) and (tmpCoord.Y<FixedRows) then
begin
// Select full column
with tmpSelection do
begin
Left:=tmpCoord.X;
Right:=Left;
Top:=FixedRows;
Bottom:=RowCount-1;
end;
// Unselect column if it was previously full selected
if (tmpSelection.Left=Selection.Left) and
(tmpSelection.Top=Selection.Top) and
(tmpSelection.Right=Selection.Right) and
(tmpSelection.Bottom=Selection.Bottom) then
begin
tmpSelection.Top:=Row;
tmpSelection.Bottom:=Row;
end;
Selection:=tmpSelection;
end;
{$ENDIF}
end;
var tmp : TChartSeries;
begin
inherited;
if (FGridState=gsNormal) and (Button=mbLeft) then
if not AtSeriesColor(tmp) then
SelectColumn;
if Assigned(INavigator) then
INavigator.ActiveChanged(Self);
end;
procedure TCustomChartGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
var tmpColor : TColor;
tmpCoord : TGridCoord;
tmpSeries : TChartSeries;
tmpR : TRect;
begin
if goEditing in Options then
begin
tmpCoord:=MouseCoord(x,y);
if ShowColors then
begin
tmpR:=CellRect(tmpCoord.X,tmpCoord.Y);
if (GetSeriesColor(tmpColor,tmpCoord.X,tmpCoord.Y)<>nil) and
PtInRect(tmpR,TeePoint(x,y)) then
Cursor:=crHandPoint
else
Cursor:=crDefault;
end
else
if tmpCoord.Y=0 then
begin
tmpSeries:=GetSeries(tmpCoord.X);
if Assigned(tmpSeries) then
begin
tmpR:=SymbolRect(CellRect(tmpCoord.X,tmpCoord.Y));
if (PtInRect(tmpR,TeePoint(x,y)) and SeriesSymbolClickable) then
Cursor:=crHandPoint
else
Cursor:=crDefault;
end;
end;
end;
inherited;
end;
Procedure TCustomChartGrid.StopEditing(Cancel:Boolean);
begin
if EditorMode then
begin
{$IFNDEF LCL}
if Cancel then InplaceEditor.Text:=''; // 5.02
HideEditor;
{$ENDIF}
if Cancel and (not FWasNull) then SetEditText(Col,Row,FOldValue);
NotifyChange;
end;
end;
{$IFDEF TEEOCX}
procedure TCustomChartGrid.SetFocus; // 6.02
begin
// if GetParentForm(Self)<>nil then inherited
// else
Windows.SetFocus(Handle);
end;
{$ENDIF}
Procedure TCustomChartGrid.StartEditing;
var tmpSeries : TChartSeries;
begin
if (goEditing in Options) and (not EditorMode) then
begin
if Col>0 then
begin
tmpSeries:=GetSeries(Col);
if Assigned(tmpSeries) then
with tmpSeries do
if (DataSource=nil) or Self.AllowChanges then { 5.02 }
begin
if Grid3DMode then
FWasNull:=Row>tmpSeries.MaxZValue
else
FWasNull:=(Row>Count) or (IsNull(Row-1));
if FWasNull then FOldValue:=''
else FOldValue:=GetEditText(Col,Row);
EditorMode:=True;
NotifyChange;
end;
end;
end;
end;
procedure TCustomChartGrid.KeyDown(var Key: Word; Shift: TShiftState);
var tmpSeries : TChartSeries;
tmpCol : Integer;
tmpRow : Integer;
begin
if (not (ssCtrl in Shift)) then
begin
Case Key of
TeeKey_Escape : StopEditing(True);
TeeKey_F2 : if FColors and (Col=ColorsColumn) then
ChangeColor
else
StartEditing;
TeeKey_Up :
if (Row=RowCount-1) then // last row
begin
if FColors and (Col=ColorsColumn) then tmpCol:=Succ(Col)
else tmpCol:=Col;
tmpSeries:=GetSeries(tmpCol);
tmpRow:=Row-FirstRowNum;
if Assigned(tmpSeries) and
(tmpSeries.Count>tmpRow) and { 5.01 }
tmpSeries.IsNull(tmpRow) and
(tmpSeries.Labels[tmpRow]='') then
begin
RowCount:=RowCount-1;
tmpSeries.Delete(Row-FirstRowNum+1);
end
else inherited; { 5.01 }
end
else inherited;
TeeKey_Down :
begin
if Row=RowCount-1 then AppendRow
else inherited;
end;
TeeKey_Insert : Insert;
TeeKey_Delete : if ssCtrl in Shift then Delete
else
begin
if not EditorMode then EditorMode:=True;
inherited;
end;
TeeKey_Return,
TeeKey_Space : if FColors and (Col=ColorsColumn) then
ChangeColor
else
inherited;
TeeKey_Right : if AllowInsertSeries and
(Col=ColCount-1) and
Assigned(Chart) and (Chart.SeriesCount>0) then
begin
Chart.AddSeries(TChartSeriesClass(Chart.SeriesList.Last.ClassType));
inherited;
end
else
inherited;
TeeKey_Left : if AllowInsertSeries and
(Col=ColCount-1) and
Assigned(Chart) and (Chart.SeriesCount>0) and
(Chart.SeriesList.Last.Count=0) then
begin
Chart.AutoRepaint:=False;
Chart.SeriesList.Last.Free;
Chart.AutoRepaint:=True;
Chart.Invalidate;
end
else
inherited;
else inherited;
end;
end
else inherited;
end;
function TCustomChartGrid.GetReadOnly:Boolean;
begin
result:=not (goEditing in Options);
end;
procedure TCustomChartGrid.SetReadOnly(const Value:Boolean);
begin
if Value then Options:=Options-[goEditing]
else Options:=Options+[goEditing];
end;
Procedure TCustomChartGrid.AppendRow;
var tmpCol : Integer;
tmpSeries : TChartSeries;
begin
if (not ReadOnly) and
(AllowInsertSeries or AllowAppend) and
(not Grid3DMode) then
begin
if FColors and (Col=ColorsColumn) then tmpCol:=Succ(Col)
else tmpCol:=Col;
tmpSeries:=GetSeries(tmpCol);
if Assigned(tmpSeries) then
begin
tmpSeries.AddNull;
RowCount:=RowCount+1;
Row:=RowCount-1;
end;
end
end;
Function TCustomChartGrid.FindXYZIndex(ASeries:TChartSeries;
ARow,ACol:Integer):Integer;
var tmpList : TChartValueList;
t : Integer;
begin
result:=-1;
tmpList:=ASeries.GetYValueList('Z'); // Do not localize
for t:=0 to ASeries.Count-1 do
if (tmpList.Value[t]=ARow+1) and
(ASeries.NotMandatoryValueList.Value[t]=ACol) then
begin
result:=t;
break;
end;
end;
function TCustomChartGrid.GetEditText(ACol,ARow: Integer): {$IFDEF CLX}WideString{$ELSE}String{$ENDIF};
Function GetALabel(Index:Integer):String;
var t : Integer;
begin
result:='';
if Assigned(FSeries) then
result:=FSeries.Labels[Index]
else
// return first Label found
for t:=0 to FChart.SeriesCount-1 do
With FChart.Series[t] do
if Labels.Count>Index then { 5.01 }
begin
result:=Labels[Index];
break;
end;
end;
var tmpSeries : TChartSeries;
tmpList : TChartValueList;
Procedure FindHeaderText;
begin
if FLabels and (ACol=LabelsColumn) then { 5.02 }
result:=TeeMsg_Text
else
if FColors and (ACol=ColorsColumn) then
result:=TeeMsg_Colors
else
if ShowFields and (ACol>LabelsColumn) then
begin
tmpSeries:=GetSeries(ACol,tmpList);
if Assigned(tmpSeries) then
if Grid3DMode then
result:=IntToStr(Round(tmpSeries.MinXValue)+ACol-1)
else
if Assigned(tmpList) then
result:=tmpList.Name;
end;
end;
Function GetAValue:String;
var tmpValue : TDateTime;
begin
tmpSeries:=GetSeries(ACol,tmpList);
if Assigned(tmpSeries) and (tmpSeries.Count>ARow) then
if tmpList.DateTime then
begin
tmpValue:=tmpList.Value[ARow];
if tmpValue<1 then result:=TimeToStr(tmpValue)
else result:=DateTimeToStr(tmpValue);
end
else
result:=FormatFloat(tmpSeries.ValueFormat,tmpList.Value[ARow])
else
result:='';
end;
var t : Integer;
begin
result:='';
if ACol=0 then // First column
begin
if ARow>=FirstRowNum then
if Grid3DMode then
begin
tmpSeries:=GetXYZSeries;
result:=IntToStr(Round(tmpSeries.MinZValue)+ARow-FirstRowNum);
end
else
Str(ARow-FirstRowNum,Result)
else
if (not ShowFields) or (ARow=1) then
result:='#'; // Do not localize
end
else
begin
if ((not ShowFields) and (ARow=0)) or
(ShowFields and (ARow=1)) then FindHeaderText // Header
else // Values
if ARow>=FirstRowNum then
begin
Dec(ARow,FirstRowNum);
if Grid3DMode then
begin
tmpSeries:=GetXYZSeries;
t:=FindXYZIndex(tmpSeries,ARow,ACol);
if t<>-1 then
result:=FormatFloat(tmpSeries.ValueFormat,
tmpSeries.MandatoryValueList.Value[t]);
end
else
if FLabels and (ACol=LabelsColumn) then
result:=GetALabel(ARow)
else
if FColors and (ACol=ColorsColumn) then
else
result:=GetAValue;
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -