Main Page · Class Overview · Hierarchy · All Classes
layer.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013 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: 04.11.13 **
23 ** Version: 1.1.0 **
24 ****************************************************************************/
25 
26 #ifndef QCP_LAYER_H
27 #define QCP_LAYER_H
28 
29 #include "global.h"
30 
31 class QCPPainter;
32 class QCustomPlot;
33 class QCPLayerable;
34 class QCPLayoutElement;
35 class QCPLayout;
36 
37 class QCP_LIB_DECL QCPLayer : public QObject
38 {
39  Q_OBJECT
41  Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
42  Q_PROPERTY(QString name READ name)
43  Q_PROPERTY(int index READ index)
44  Q_PROPERTY(QList<QCPLayerable*> children READ children)
46 public:
47  QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
48  ~QCPLayer();
49 
50  // getters:
51  QCustomPlot *parentPlot() const { return mParentPlot; }
52  QString name() const { return mName; }
53  int index() const { return mIndex; }
54  QList<QCPLayerable*> children() const { return mChildren; }
55 
56 protected:
57  // property members:
58  QCustomPlot *mParentPlot;
59  QString mName;
60  int mIndex;
61  QList<QCPLayerable*> mChildren;
62 
63  // non-virtual methods:
64  void addChild(QCPLayerable *layerable, bool prepend);
65  void removeChild(QCPLayerable *layerable);
66 
67 private:
68  Q_DISABLE_COPY(QCPLayer)
69 
70  friend class QCustomPlot;
71  friend class QCPLayerable;
72 };
73 
74 class QCP_LIB_DECL QCPLayerable : public QObject
75 {
76  Q_OBJECT
78  Q_PROPERTY(bool visible READ visible WRITE setVisible)
79  Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
80  Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
81  Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer)
82  Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
84 public:
85  QCPLayerable(QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0);
86  ~QCPLayerable();
87 
88  // getters:
89  bool visible() const { return mVisible; }
90  QCustomPlot *parentPlot() const { return mParentPlot; }
91  QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
92  QCPLayer *layer() const { return mLayer; }
93  bool antialiased() const { return mAntialiased; }
94 
95  // setters:
96  void setVisible(bool on);
97  bool setLayer(QCPLayer *layer);
98  bool setLayer(const QString &layerName);
99  void setAntialiased(bool enabled);
100 
101  // introduced virtual methods:
102  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
103 
104  // non-property methods:
105  bool realVisibility() const;
106 
107 protected:
108  // property members:
109  bool mVisible;
110  QCustomPlot *mParentPlot;
111  QPointer<QCPLayerable> mParentLayerable;
112  QCPLayer *mLayer;
113  bool mAntialiased;
114 
115  // introduced virtual methods:
116  virtual void parentPlotInitialized(QCustomPlot *parentPlot);
117  virtual QCP::Interaction selectionCategory() const;
118  virtual QRect clipRect() const;
119  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
120  virtual void draw(QCPPainter *painter) = 0;
121  // events:
122  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
123  virtual void deselectEvent(bool *selectionStateChanged);
124 
125  // non-property methods:
126  void initializeParentPlot(QCustomPlot *parentPlot);
127  void setParentLayerable(QCPLayerable* parentLayerable);
128  bool moveToLayer(QCPLayer *layer, bool prepend);
129  void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
130 
131 private:
132  Q_DISABLE_COPY(QCPLayerable)
133 
134  friend class QCustomPlot;
135  friend class QCPAxisRect;
136 };
137 
138 #endif // QCP_LAYER_H