KD Chart 2  [rev.2.6]
KDChartCartesianCoordinatePlane.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2019 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 );
52 
53  void addDiagram ( AbstractDiagram* diagram );
54 
60  void setIsometricScaling ( bool onOff );
61 
62  bool doesIsometricScaling() const;
63 
64  const QPointF translate ( const QPointF& diagramPoint ) const;
65 
69  virtual qreal zoomFactorX() const;
73  virtual qreal zoomFactorY() const;
74 
78  virtual void setZoomFactors( qreal factorX, qreal factorY );
82  virtual void setZoomFactorX( qreal factor );
86  virtual void setZoomFactorY( qreal factor );
87 
91  virtual QPointF zoomCenter() const;
92 
96  virtual void setZoomCenter( const QPointF& center );
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  virtual void paint( QPainter* );
379 
381  AbstractCoordinatePlane* sharedAxisMasterPlane( QPainter* p = 0 );
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 );
441 
442  // reimplemented
443  Qt::Orientations expandingDirections() const;
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  virtual DataDimensionsList getDataDimensionsList() const;
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();
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;
492  int heightForWidth( int w ) const;
493  QSize sizeHint() const;
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)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/