KD Chart 2  [rev.2.7]
KDChartCartesianCoordinatePlane.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDCHARTCARTESIANCOORDINATEPLANE_H
24 #define KDCHARTCARTESIANCOORDINATEPLANE_H
25 
27 
28 namespace KDChart {
29 
30  class Chart;
31  class PaintContext;
32  class AbstractDiagram;
33  class CartesianAxis;
34  class CartesianGrid;
35 
39  class KDCHART_EXPORT CartesianCoordinatePlane : public AbstractCoordinatePlane
40  {
41  Q_OBJECT
42 
43  Q_DISABLE_COPY( CartesianCoordinatePlane )
45 
46  friend class CartesianAxis;
47  friend class CartesianGrid;
48 
49  public:
50  explicit CartesianCoordinatePlane ( Chart* parent = 0 );
51  ~CartesianCoordinatePlane() override;
52 
53  void addDiagram ( AbstractDiagram* diagram ) override;
54 
60  void setIsometricScaling ( bool onOff );
61 
62  bool doesIsometricScaling() const;
63 
64  const QPointF translate ( const QPointF& diagramPoint ) const override;
65 
69  qreal zoomFactorX() const override;
73  qreal zoomFactorY() const override;
74 
78  void setZoomFactors( qreal factorX, qreal factorY ) override;
82  void setZoomFactorX( qreal factor ) override;
86  void setZoomFactorY( qreal factor ) override;
87 
91  QPointF zoomCenter() const override;
92 
96  void setZoomCenter( const QPointF& center ) override;
97 
107  void setFixedDataCoordinateSpaceRelation( bool fixed );
108  bool hasFixedDataCoordinateSpaceRelation() const;
109 
117  void setXAxisStartAtZero(bool fixedStart);
118  bool xAxisStartAtZero() const;
119 
155  void setHorizontalRange( const QPair<qreal, qreal> & range );
156 
192  void setVerticalRange( const QPair<qreal, qreal> & range );
193 
201  QPair<qreal, qreal> horizontalRange() const;
202 
210  QPair<qreal, qreal> verticalRange() const;
211 
232  void setAutoAdjustHorizontalRangeToData( unsigned int percentEmpty = 67 );
233 
254  void setAutoAdjustVerticalRangeToData( unsigned int percentEmpty = 67 );
255 
266  unsigned int autoAdjustHorizontalRangeToData() const;
267 
278  unsigned int autoAdjustVerticalRangeToData() const;
279 
280 
302  void setGridAttributes( Qt::Orientation orientation, const GridAttributes & );
303 
315  void resetGridAttributes( Qt::Orientation orientation );
316 
331  const GridAttributes gridAttributes( Qt::Orientation orientation ) const;
332 
345  bool hasOwnGridAttributes( Qt::Orientation orientation ) const;
346 
354  void setAutoAdjustGridToZoom( bool autoAdjust );
355 
361 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
362  const bool autoAdjustGridToZoom() const;
363 #else
364  bool autoAdjustGridToZoom() const;
365 #endif
366 
367  AxesCalcMode axesCalcModeY() const;
368  AxesCalcMode axesCalcModeX() const;
369 
371  void setAxesCalcModes( AxesCalcMode mode );
373  void setAxesCalcModeY( AxesCalcMode mode );
375  void setAxesCalcModeX( AxesCalcMode mode );
376 
378  void paint( QPainter* ) override;
379 
381  AbstractCoordinatePlane* sharedAxisMasterPlane( QPainter* p = 0 ) override;
382 
387  QRectF visibleDataRange() const;
388 
393  QRectF logicalArea() const;
394 
402  QRectF diagramArea() const;
403 
409  QRectF visibleDiagramArea() const;
410 
417  void setHorizontalRangeReversed( bool reverse );
418 
422  bool isHorizontalRangeReversed() const;
423 
430  void setVerticalRangeReversed( bool reverse );
431 
435  bool isVerticalRangeReversed() const;
436 
440  void setGeometry( const QRect& r ) override;
441 
442  // reimplemented
443  Qt::Orientations expandingDirections() const override;
444 
445 
446  public Q_SLOTS:
455  void adjustRangesToData();
456 
461  void adjustHorizontalRangeToData();
462 
467  void adjustVerticalRangeToData();
468 
469  protected:
470  QRectF getRawDataBoundingRectFromDiagrams() const;
471  QRectF adjustedToMaxEmptyInnerPercentage(
472  const QRectF& r, unsigned int percentX, unsigned int percentY ) const;
473  virtual QRectF calculateRawDataBoundingRect() const;
474  DataDimensionsList getDataDimensionsList() const override;
475  // the whole drawing area, includes diagrams and axes, but maybe smaller
476  // than (width, height):
477  virtual QRectF drawingArea() const;
478  public:
479  const QPointF translateBack( const QPointF& screenPoint ) const;
480  protected:
481  void paintEvent ( QPaintEvent* );
482  void layoutDiagrams() override;
483  // the following three return true if the new value is different from the old
484  bool doneSetZoomFactorX( qreal factor );
485  bool doneSetZoomFactorY( qreal factor );
486  bool doneSetZoomCenter( const QPointF& center );
487 
488  void handleFixedDataCoordinateSpaceRelation( const QRectF& geometry );
489 
490  // reimplemented from QLayoutItem, via AbstractLayoutItem, AbstractArea, AbstractCoordinatePlane
491  bool hasHeightForWidth() const override;
492  int heightForWidth( int w ) const override;
493  QSize sizeHint() const override;
494 
495  protected Q_SLOTS:
496  void slotLayoutChanged( AbstractDiagram* );
497 
498  private:
499  void setHasOwnGridAttributes(
500  Qt::Orientation orientation, bool on );
501  };
502 
503 }
504 
505 #endif
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
A chart with one or more diagrams.
Definition: KDChartChart.h:98
AbstractDiagram defines the interface for diagram classes.
The class for cartesian axes.
QPointF translate(const TernaryPoint &point)
A set of attributes controlling the appearance of grids.
#define KDCHART_DECLARE_PRIVATE_DERIVED_PARENT(X, ParentType)
Definition: KDChartGlobal.h:58

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/