📄 teechartgrid.pas
字号:
begin
tmpCoord:=MouseCoord(x,y);
{$IFNDEF LCL}
if (GetSeriesColor(tmpColor,tmpCoord.X,tmpCoord.Y)<>nil) and
PtInRect(CellRect(tmpCoord.X,tmpCoord.Y),TeePoint(x,y)) then
Cursor:=crHandPoint
else
Cursor:=crDefault;
{$ENDIF}
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 tmpList : TChartValueList;
tmpSeries : TChartSeries;
begin
if (goEditing in Options) and (not EditorMode) then
begin
if Col>0 then
begin
tmpSeries:=GetSeries(Col,tmpList);
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 tmpList : TChartValueList;
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,tmpList);
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;
else inherited;
end;
end
else inherited;
end;
Procedure TCustomChartGrid.AppendRow;
var tmpCol : Integer;
tmpSeries : TChartSeries;
tmpList : TChartValueList;
begin
if (goEditing in Options) and (not Grid3DMode) then // 7.0
begin
if FColors and (Col=ColorsColumn) then tmpCol:=Succ(Col)
else tmpCol:=Col;
tmpSeries:=GetSeries(tmpCol,tmpList);
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');
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:='#';
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;
Procedure TCustomChartGrid.SetGrid3DMode(Value:Boolean);
begin
FGrid3DMode:=Value;
Regenerate;
Repaint;
end;
type TSeriesAccess=class(TChartSeries);
Procedure TCustomChartGrid.SetManualData(ASeries:TChartSeries);
begin
TSeriesAccess(ASeries).ManualData:=True;
end;
procedure TCustomChartGrid.SetEditText(ACol, ARow: Integer;
const Value: {$IFDEF CLX}WideString{$ELSE}string{$ENDIF});
Procedure SetALabel(Index:Integer; Const AValue:String);
Procedure SetLabelSeries(ASeries:TChartSeries);
begin
While Index>=ASeries.Count do ASeries.AddNull('');
ASeries.Labels[Index]:=AValue;
end;
var t : Integer;
begin
if Assigned(Series) then SetLabelSeries(Series)
else
for t:=0 to Chart.SeriesCount-1 do SetLabelSeries(Chart[t]);
end;
Procedure SetAllManualData;
var t : Integer;
begin
if Assigned(Series) then SetManualData(Series)
else
for t:=0 to Chart.SeriesCount-1 do SetManualData(Chart[t]);
end;
var tmpSeries : TChartSeries;
tmpList : TChartValueList;
tmpRow : Integer;
begin
inherited;
if Assigned(FSeries) or (Assigned(FChart) and (FChart.SeriesCount>0)) then
try
SetAllManualData;
Dec(ARow,FirstRowNum);
if FLabels and (ACol=LabelsColumn) then // Labels
SetALabel(ARow,Value)
else
if FColors and (ACol=ColorsColumn) then // Colors
else
begin // Values
tmpSeries:=GetSeries(ACol,tmpList);
if Assigned(tmpSeries) then
begin
if Grid3DMode then
begin
tmpRow:=FindXYZIndex(tmpSeries,ARow,ACol);
tmpList:=tmpSeries.MandatoryValueList;
end
else
begin
While ARow>=tmpSeries.Count do tmpSeries.AddNull;
tmpRow:=ARow;
end;
if Trim(Value)='' then // 5.03
begin
if not EditorMode then
begin
tmpSeries.ValueColor[tmpRow]:=clNone;
Invalidate;
end;
end
else
begin
if tmpList.DateTime then
tmpList.Value[tmpRow]:=StrToDateTime(Value)
else
tmpList.Value[tmpRow]:=StrToFloat(Value);
tmpList.Modified:=True;
if tmpSeries.IsNull(tmpRow) then
begin
tmpSeries.ValueColor[tmpRow]:=clTeeColor;
if FColors then Self.Repaint; // 5.02
end;
end;
tmpSeries.RefreshSeries;
end;
{ Repaint Series and / or Chart }
if Assigned(FSeries) then FSeries.Repaint
else FChart.Repaint;
end;
{ call event }
if Assigned(FOnSetCell) then
FOnSetCell(Self,ACol,ARow+FirstRowNum,Value);
except { hide exception }
on EConvertError do ;
end;
end;
Function TCustomChartGrid.GetXYZSeries:TChartSeries;
var t : Integer;
begin
result:=nil;
if Assigned(FChart) then
begin
for t:=0 to FChart.SeriesCount-1 do
if FChart[t].HasZValues then
begin
result:=FChart[t];
break;
end;
end
else
if Assigned(FSeries) and FSeries.HasZValues then
result:=FSeries;
end;
// Returns series and series valuelist for the ACol column parameter
Function TCustomChartGrid.GetSeries(ACol:Integer; Var AList:TChartValueList):TChartSeries;
procedure GetAList(Index:Integer);
begin
if IHasNo[Index] then
AList:=result.ValuesList[ACol-1]
else
if result.YMandatory or (ACol=0) then
AList:=result.ValuesList[ACol]
else
AList:=result.ValuesList[ACol-1];
end;
var tmp : Integer;
t : Integer;
begin
AList:=nil;
if Grid3DMode then result:=GetXYZSeries
else
begin
if FLabels then Dec(ACol);
{$IFNDEF TEEOCX}
if FColors then Dec(ACol);
{$ENDIF}
if ACol>=0 then
begin
if Assigned(FSeries) then
begin
tmp:=FSeries.ValuesList.Count;
if not IHasNo[0] then Dec(tmp);
if (tmp>=ACol) then
begin
result:=FSeries;
GetAList(0);
Exit;
end;
end
else
if Assigned(FChart) then
for t:=0 to FChart.SeriesCount-1 do
begin
tmp:=FChart.Series[t].ValuesList.Count;
if not IHasNo[t] then Dec(tmp);
if (tmp>=ACol) then
begin
result:=FChart.Series[t];
GetAList(t);
Exit;
end;
Dec(ACol,tmp);
end;
end;
result:=nil;
end;
end;
procedure TCustomChartGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
Function GetSeriesCol(ACol:Integer):TChartSeries;
var tmp : Integer;
t : Integer;
begin
if FLabels then tmp:=LabelsColumn else
if FColors then tmp:=ColorsColumn else tmp:=0;
if Assigned(FSeries) then
begin
result:=FSeries;
exit;
end
else
for t:=0 to FChart.SeriesCount-1 do
begin
Inc(tmp);
if tmp=ACol then
begin
result:=FChart.Series[t];
exit;
end;
Inc(tmp,FChart.Series[t].ValuesList.Count-2);
if IHasNo[t] then Inc(tmp);
end;
result:=nil;
end;
Procedure FillWithColor(AColor:TColor);
begin
Canvas.Brush.Color:=AColor;
Canvas.Brush.Style:=bsSolid;
Canvas.FillRect(ARect);
end;
var tmp : Integer;
tmpSeries : TChartSeries;
AList : TChartValueList;
tmpSt : String;
tmpColor : TColor;
begin
if Assigned(FChart) or Assigned(FSeries) then
begin
tmp:=0;
if FLabels then Inc(tmp);
if FColors then Inc(tmp);
if (ARow=0) and (ACol>tmp) then // Series first Header
begin
tmpSeries:=GetSeriesCol(ACol);
if Assigned(FSeries) and (not ShowFields) then // 5.03
begin
GetSeries(ACol,AList);
Canvas.TextRect(ARect, ARect.Left+18, ARect.Top+4,AList.Name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -