Main Page · Class Overview · Hierarchy · All Classes
layoutelement-axisrect.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
25 
26 #ifndef QCP_LAYOUTELEMENT_AXISRECT_H
27 #define QCP_LAYOUTELEMENT_AXISRECT_H
28 
29 #include "../global.h"
30 #include "../axis.h"
31 #include "../layout.h"
32 
33 class QCPPainter;
34 class QCustomPlot;
35 class QCPAxis;
37 class QCPGraph;
38 class QCPAbstractItem;
39 
40 class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
41 {
42  Q_OBJECT
44  Q_PROPERTY(QPixmap background READ background WRITE setBackground)
45  Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
46  Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
47  Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
48  Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
50 public:
51  explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
52  virtual ~QCPAxisRect();
53 
54  // getters:
55  QPixmap background() const { return mBackgroundPixmap; }
56  bool backgroundScaled() const { return mBackgroundScaled; }
57  Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
58  Qt::Orientations rangeDrag() const { return mRangeDrag; }
59  Qt::Orientations rangeZoom() const { return mRangeZoom; }
60  QCPAxis *rangeDragAxis(Qt::Orientation orientation);
61  QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
62  double rangeZoomFactor(Qt::Orientation orientation);
63 
64  // setters:
65  void setBackground(const QPixmap &pm);
66  void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
67  void setBackground(const QBrush &brush);
68  void setBackgroundScaled(bool scaled);
69  void setBackgroundScaledMode(Qt::AspectRatioMode mode);
70  void setRangeDrag(Qt::Orientations orientations);
71  void setRangeZoom(Qt::Orientations orientations);
72  void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
73  void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
74  void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
75  void setRangeZoomFactor(double factor);
76 
77  // non-property methods:
78  int axisCount(QCPAxis::AxisType type) const;
79  QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
80  QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
81  QList<QCPAxis*> axes() const;
82  QCPAxis *addAxis(QCPAxis::AxisType type);
83  QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
84  bool removeAxis(QCPAxis *axis);
85  QCPLayoutInset *insetLayout() const { return mInsetLayout; }
86 
87  void setupFullAxesBox(bool connectRanges=false);
88  QList<QCPAbstractPlottable*> plottables() const;
89  QList<QCPGraph*> graphs() const;
90  QList<QCPAbstractItem*> items() const;
91 
92  // read-only interface imitating a QRect:
93  int left() const { return mRect.left(); }
94  int right() const { return mRect.right(); }
95  int top() const { return mRect.top(); }
96  int bottom() const { return mRect.bottom(); }
97  int width() const { return mRect.width(); }
98  int height() const { return mRect.height(); }
99  QSize size() const { return mRect.size(); }
100  QPoint topLeft() const { return mRect.topLeft(); }
101  QPoint topRight() const { return mRect.topRight(); }
102  QPoint bottomLeft() const { return mRect.bottomLeft(); }
103  QPoint bottomRight() const { return mRect.bottomRight(); }
104  QPoint center() const { return mRect.center(); }
105 
106  // reimplemented virtual methods:
107  virtual void update(UpdatePhase phase);
108  virtual QList<QCPLayoutElement*> elements(bool recursive) const;
109 
110 protected:
111  // property members:
112  QBrush mBackgroundBrush;
113  QPixmap mBackgroundPixmap;
114  QPixmap mScaledBackgroundPixmap;
115  bool mBackgroundScaled;
116  Qt::AspectRatioMode mBackgroundScaledMode;
117  QCPLayoutInset *mInsetLayout;
118  Qt::Orientations mRangeDrag, mRangeZoom;
119  QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
120  double mRangeZoomFactorHorz, mRangeZoomFactorVert;
121  // non-property members:
122  QCPRange mDragStartHorzRange, mDragStartVertRange;
123  QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
124  QPoint mDragStart;
125  bool mDragging;
126  QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
127 
128  // reimplemented virtual methods:
129  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
130  virtual void draw(QCPPainter *painter);
131  virtual int calculateAutoMargin(QCP::MarginSide side);
132  // events:
133  virtual void mousePressEvent(QMouseEvent *event);
134  virtual void mouseMoveEvent(QMouseEvent *event);
135  virtual void mouseReleaseEvent(QMouseEvent *event);
136  virtual void wheelEvent(QWheelEvent *event);
137 
138  // non-property methods:
139  void drawBackground(QCPPainter *painter);
140  void updateAxesOffset(QCPAxis::AxisType type);
141 
142 private:
143  Q_DISABLE_COPY(QCPAxisRect)
144 
145  friend class QCustomPlot;
146 };
147 
148 
149 #endif // QCP_LAYOUTELEMENT_AXISRECT_H