teechartgrid.pas
来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 1,341 行 · 第 1/3 页
PAS
1,341 行
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
With ARect do
PaintSeriesLegend(tmpSeries,Canvas,TeeRect(Left+4,Top+4,Left+16,Top+16));
{$IFDEF CLX}
QPainter_setBackgroundMode(Canvas.Handle,BGMode_TransparentMode);
{$ENDIF}
Canvas.Brush.Style:=bsClear;
Canvas.Pen.Style:=psSolid;
Canvas.Font.Color:=Self.Font.Color;
Canvas.TextRect(ARect, ARect.Left+18, ARect.Top+4,
SeriesTitleOrName(tmpSeries));
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+2,
TeeMsg_Colors)
else
if ARow>=FirstRowNum then
begin
tmpSeries:=GetSeries(ACol+1,AList);
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+2, GetEditText(ACol, ARow))
else
begin
// Values
{$IFNDEF CLX}
Windows.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+2, tmpSt
{$IFDEF CLX},Integer(AlignmentFlags_AlignRight){$ENDIF});
{$IFNDEF CLX}
Windows.SetTextAlign(Canvas.Handle,TA_LEFT);
{$ENDIF}
end;
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 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;
// 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
tmpInc:=False;
if Assigned(FSeries) then
TryInsert(FSeries)
else
With FChart do
for t:=0 to SeriesCount-1 do
TryInsert(Series[t]);
if tmpInc then RowCount:=RowCount+1;
Row:=RowCount-1; // Go to last row
end;
type TTeePanelAccess=class(TCustomTeePanel);
Procedure TCustomChartGrid.AddListener(AChart:TCustomAxisPanel); // 5.03
begin
if Assigned(AChart) then
begin
AChart.FreeNotification(Self);
TTeePanelAccess(AChart).Listeners.Add(Self);
end;
end;
Procedure TCustomChartGrid.RemoveListener(AChart:TCustomAxisPanel); // 5.03
begin
if Assigned(AChart) and (not (csDestroying in AChart.ComponentState)) then
begin
{$IFDEF D5}
AChart.RemoveFreeNotification(Self);
{$ENDIF}
TTeePanelAccess(AChart).RemoveListener(Self);
end;
end;
Procedure TCustomChartGrid.SetChart(AChart:TCustomChart);
begin
if FChart<>AChart then
begin
RemoveListener(FChart);
FChart:=AChart;
AddListener(FChart);
end;
Regenerate;
Repaint; { 5.01 }
end;
Procedure TCustomChartGrid.SetNavigator(ANavigator:TChartGridNavigator);
begin
INavigator:=ANavigator;
if Assigned(INavigator) then INavigator.FreeNotification(Self);
end;
// Main procedure to calculate how many rows and columns should the grid have
Procedure TCustomChartGrid.RecalcDimensions;
Function MaxNumPoints:Integer;
var t : Integer;
begin
result:=0;
if Assigned(FSeries) then result:=FSeries.Count
else
for t:=0 to FChart.SeriesCount-1 do
With FChart.Series[t] do
if (t=0) or (Count>result) then result:=Count;
end;
var tmpCol : Integer;
Procedure CalcParams(ASeries:TChartSeries; AIndex:Integer);
begin
if not (csDestroying in ASeries.ComponentState) then
begin
Inc(tmpCol);
if FXValues=cgsAuto then
IHasNo[AIndex]:=HasNoMandatoryValues(ASeries)
else
IHasNo[AIndex]:=FXValues=cgsYes;
if IHasNo[AIndex] then Inc(tmpCol);
Inc(tmpCol,ASeries.ValuesList.Count-2);
end;
end;
Procedure SetXYZDimensions;
var tmpSeries : TChartSeries;
begin
tmpSeries:=GetXYZSeries;
if Assigned(tmpSeries) then
begin
// problem with Surface: One less colum... (works fine with ColorGrid)
ColCount:={1+}Round(tmpSeries.MaxZValue-tmpSeries.MinZValue+1);
with tmpSeries.NotMandatoryValueList do
RowCount:=2+Round(MaxValue-MinValue+1);
end;
FLabels:=False;
FColors:=False;
FixedRows:=2;
end;
var t : Integer;
begin
if Grid3DMode then SetXYZDimensions
else
begin
tmpCol:=1;
if Assigned(FChart) or Assigned(FSeries) then
begin
if Assigned(FSeries) then CalcParams(FSeries,0)
else
for t:=0 to FChart.SeriesCount-1 do CalcParams(FChart[t],t);
if FLabels then Inc(tmpCol);
if FColors then Inc(tmpCol);
RowCount:=Math.Max(1+FirstRowNum,MaxNumPoints+FirstRowNum);
end
else RowCount:=1+FirstRowNum;
ColCount:=tmpCol;
ColWidths[0]:=30;
if FColors and (ColCount>1) then
ColWidths[1]:=40; { 5.02 }
if ShowFields then FixedRows:=2
else FixedRows:=1;
end;
if (Col=0) and (ColCount>1) then Col:=1; // 5.02
NotifyChange;
end;
procedure TCustomChartGrid.NotifyChange;
begin
if Assigned(FActiveChanged) then FActiveChanged(Self);
end;
Procedure TCustomChartGrid.SetBooleanProperty(Var Variable:Boolean; Value:Boolean);
begin
if Variable<>Value then
begin
Variable:=Value;
RecalcDimensions;
Repaint;
end;
end;
Procedure TCustomChartGrid.SetShowFields(Value:Boolean);
begin
SetBooleanProperty(FShowFields,Value);
if Row<FirstRowNum then Row:=FirstRowNum;
end;
procedure TCustomChartGrid.SetShowLabels(Value: Boolean);
begin
SetBooleanProperty(FLabels,Value);
end;
Procedure TCustomChartGrid.SetShowColors(Value:Boolean);
begin
SetBooleanProperty(FColors,Value);
end;
Procedure TCustomChartGrid.SetShowXValues(Value:TChartGridShow);
begin
FXValues:=Value;
RecalcDimensions;
Repaint;
end;
procedure TCustomChartGrid.TeeEvent(Event: TTeeEvent);
begin
if not (csDestroying in ComponentState) then
if Event is TTeeSeriesEvent then
Case TTeeSeriesEvent(Event).Event of
seChangeTitle,
seChangeColor,
seChangeActive: Repaint
else RecalcDimensions;
end;
end;
Procedure TCustomChartGrid.ChangeColor;
var tmpSeries : TChartSeries;
tmpList : TChartValueList;
tmpColor : TColor;
begin
if FColors and (Col=ColorsColumn) and (Row>=FirstRowNum) then
begin
tmpSeries:=GetSeries(Col+1,tmpList);
if Assigned(tmpSeries) then
with tmpSeries do
begin
if Count>(Row-FirstRowNum) then
begin
tmpColor:=ValueColor[Row-FirstRowNum];
if EditColorDialog(Self,tmpColor) then
begin
ValueColor[Row-FirstRowNum]:=tmpColor;
SetManualData(tmpSeries);
Self.DrawCell(Col,Row,Self.CellRect(Col,Row),[gdSelected,gdFocused]);
if Assigned(Self.FOnChangeColor) then Self.FOnChangeColor(Self);
end;
end;
end;
end;
end;
// Use double-click mouse event to show the color editor dialog
// to change a series point color
procedure TCustomChartGrid.DblClick;
begin
if FColors and (Col=ColorsColumn) and (goEditing in Options) then
ChangeColor
else
inherited;
end;
function TCustomChartGrid.CanEditShow: Boolean;
begin
if FColors and (Col=ColorsColumn) then
result:=False
else
begin
result:=inherited CanEditShow;
if result then FOldValue:=GetEditText(Col,Row);
end;
end;
procedure TCustomChartGrid.Regenerate;
begin
if not (csDestroying in ComponentState) then
begin
RecalcDimensions;
MoveColRow(Math.Min(ColCount-1,1), FirstRowNum, True, True);
end;
end;
procedure TCustomChartGrid.SetSeries(const Value: TChartSeries);
begin
if FSeries<>Value then
begin
if Assigned(FSeries) then
begin
{$IFDEF D5}
FSeries.RemoveFreeNotification(Self);
{$ENDIF}
RemoveListener(FSeries.ParentChart);
end;
FSeries:=Value;
if Assigned(FSeries) then
begin
FSeries.FreeNotification(Self);
Chart:=nil;
AddListener(FSeries.ParentChart);
end;
end;
Regenerate;
Repaint;
end;
// Returns column number for series "Labels"
Function TCustomChartGrid.LabelsColumn:Integer;
begin
if FLabels then
begin
if FColors then result:=2
else result:=1;
end
else result:=-1;
end;
// Returns column number for series "Colors"
Function TCustomChartGrid.ColorsColumn:Integer;
begin
if FColors then result:=1 else result:=-1;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?