📄 teechartgrid.pas
字号:
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) then
begin
if (not Assigned(FSeries)) and
((FChart.SeriesCount=0) and AllowInsertSeries) then
begin
Chart.AddSeries(TBarSeries);
end;
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;
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;
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;
Function TCustomChartGrid.GetSeries(ACol:Integer):TChartSeries;
var tmp : TChartValueList;
begin
result:=GetSeries(ACol,tmp);
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
if ACol>0 then
AList:=result.ValuesList[ACol-1]
else
AList:=result.ValuesList[ACol]
else
if result.YMandatory or (ACol=0) then
AList:=result.ValuesList[ACol]
else
if ACol>0 then
AList:=result.ValuesList[ACol-1]
else
AList:=result.ValuesList[ACol]
end;
var tmp : Integer;
t : Integer;
begin
AList:=nil;
if Grid3DMode then
result:=GetXYZSeries
else
begin
if FLabels then
Dec(ACol);
if FColors then
Dec(ACol);
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;
function TCustomChartGrid.SymbolRect(const Rect:TRect):TRect;
begin
with Rect do
result:=TeeRect(Left+4,Top+4,Left+16,Top+16);
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;
procedure DrawValueText(TopOffset:Integer); // Values and # symbol
var tmpSt : String;
begin
{$IFNDEF CLX}
{$IFNDEF CLR}Windows.{$ENDIF}SetTextAlign(Canvas.Handle,TA_RIGHT);
{$ENDIF}
{$IFDEF CLX}
QPainter_setBackgroundMode(Canvas.Handle,BGMode_TransparentMode);
{$ENDIF}
tmpSt:=GetEditText(ACol, ARow);
{$IFDEF CLX}
Dec(ARect.Right,3);
{$ENDIF}
Canvas.TextRect(ARect,
{$IFDEF CLX}ARect.Left{$ELSE}ARect.Right-2{$ENDIF},
ARect.Top+TopOffset, tmpSt
{$IFDEF CLX},Integer(AlignmentFlags_AlignRight){$ENDIF});
{$IFNDEF CLX}
{$IFNDEF CLR}Windows.{$ENDIF}SetTextAlign(Canvas.Handle,TA_LEFT);
{$ENDIF}
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);
end
else
if Assigned(tmpSeries) then
if (not Grid3DMode) or ((ACol-tmp)=1) then // only once for 3D mode
begin
PaintSeriesLegend(tmpSeries,Canvas,SymbolRect(ARect));
{$IFDEF CLX}
QPainter_setBackgroundMode(Canvas.Handle,BGMode_TransparentMode);
{$ENDIF}
Canvas.Brush.Style:=bsClear;
Canvas.Pen.Style:=psSolid;
Canvas.Font.Color:=Self.Font.Color;
tmpSt:=ReplaceChar(SeriesTitleOrName(tmpSeries),TeeLineSeparator,' ');
tmpSt:=ReplaceChar(tmpSt,TeeColumnSeparator,' ');
Canvas.TextRect(ARect, ARect.Left+18, ARect.Top+4,tmpSt);
end;
end
else
begin
if (ACol=0) or (ShowFields and (ARow=1)) then // Point number (#) column
FillWithColor(FixedColor);
if FColors and (ACol=ColorsColumn) then // Colors
begin
if ARow=FirstRowNum-1 then
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+4,TeeMsg_Colors)
else
if ARow>=FirstRowNum then
begin
tmpSeries:=GetSeries(ACol+1);
if Assigned(tmpSeries) and (tmpSeries.Count>(ARow-FirstRowNum)) then
begin
tmpColor:=tmpSeries.ValueColor[ARow-FirstRowNum];
if tmpColor=clNone then tmpColor:=Self.Color;
end
else tmpColor:=Self.Color;
FillWithColor(tmpColor);
end;
end
else
if FLabels and (ACol=LabelsColumn) then // Labels
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+3, GetEditText(ACol, ARow))
else
if (ARow=0) and (ACol=0) then // # symbol
DrawValueText(4)
else
DrawValueText(2);
end;
end;
end;
procedure TCustomChartGrid.Notification( AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if Operation=opRemove then
begin
if Assigned(FChart) and (AComponent=FChart) then
Chart:=nil
else
if Assigned(INavigator) and (AComponent=INavigator) then
INavigator:=nil
else
if Assigned(FSeries) and (AComponent=FSeries) then
Series:=nil
end;
end;
// Deletes current row, also deletes series points
Procedure TCustomChartGrid.Delete;
Procedure TryDelete(ASeries:TChartSeries; AIndex:Integer);
begin
With ASeries do
if (Row-FirstRowNum)<Count then
begin
Delete(Row-FirstRowNum);
if not IHasNo[AIndex] then
NotMandatoryValueList.FillSequence;
end;
end;
var t : Integer;
begin
if goEditing in Options then // 7.0
begin
if Assigned(FSeries) then
TryDelete(FSeries,0)
else
With FChart do
for t:=0 to SeriesCount-1 do
TryDelete(Series[t],t);
if RowCount>(1+FirstRowNum) then RowCount:=RowCount-1
else
begin
Repaint;
NotifyChange;
end;
end;
end;
// Inserts a new row to the end (appends),
// also inserts (appends) new series points
Procedure TCustomChartGrid.Insert;
var tmpInc : Boolean;
Procedure TryInsert(ASeries:TChartSeries);
begin
With ASeries do
begin
tmpInc:=Count>0;
AddNullXY(Count,0);
end;
end;
Var t : Integer;
begin
if goEditing in Options then // 7.0
begin
tmpInc:=False;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -