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, 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_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)
45  Q_PROPERTY(bool visible READ visible WRITE setVisible)
47 public:
48  QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
49  ~QCPLayer();
50 
51  // getters:
52  QCustomPlot *parentPlot() const { return mParentPlot; }
53  QString name() const { return mName; }
54  int index() const { return mIndex; }
55  QList<QCPLayerable*> children() const { return mChildren; }
56  bool visible() const { return mVisible; }
57 
58  // setters:
59  void setVisible(bool visible);
60 
61 protected:
62  // property members:
63  QCustomPlot *mParentPlot;
64  QString mName;
65  int mIndex;
66  QList<QCPLayerable*> mChildren;
67  bool mVisible;
68 
69  // non-virtual methods:
70  void addChild(QCPLayerable *layerable, bool prepend);
71  void removeChild(QCPLayerable *layerable);
72 
73 private:
74  Q_DISABLE_COPY(QCPLayer)
75 
76  friend class QCustomPlot;
77  friend class QCPLayerable;
78 };
79 
80 class QCP_LIB_DECL QCPLayerable : public QObject
81 {
82  Q_OBJECT
84  Q_PROPERTY(bool visible READ visible WRITE setVisible)
85  Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
86  Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
87  Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
88  Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
90 public:
91  QCPLayerable(QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0);
92  ~QCPLayerable();
93 
94  // getters:
95  bool visible() const { return mVisible; }
96  QCustomPlot *parentPlot() const { return mParentPlot; }
97  QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
98  QCPLayer *layer() const { return mLayer; }
99  bool antialiased() const { return mAntialiased; }
100 
101  // setters:
102  void setVisible(bool on);
103  Q_SLOT bool setLayer(QCPLayer *layer);
104  bool setLayer(const QString &layerName);
105  void setAntialiased(bool enabled);
106 
107  // introduced virtual methods:
108  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
109 
110  // non-property methods:
111  bool realVisibility() const;
112 
113 signals:
114  void layerChanged(QCPLayer *newLayer);
115 
116 protected:
117  // property members:
118  bool mVisible;
119  QCustomPlot *mParentPlot;
120  QPointer<QCPLayerable> mParentLayerable;
121  QCPLayer *mLayer;
122  bool mAntialiased;
123 
124  // introduced virtual methods:
125  virtual void parentPlotInitialized(QCustomPlot *parentPlot);
126  virtual QCP::Interaction selectionCategory() const;
127  virtual QRect clipRect() const;
128  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
129  virtual void draw(QCPPainter *painter) = 0;
130  // events:
131  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
132  virtual void deselectEvent(bool *selectionStateChanged);
133 
134  // non-property methods:
135  void initializeParentPlot(QCustomPlot *parentPlot);
136  void setParentLayerable(QCPLayerable* parentLayerable);
137  bool moveToLayer(QCPLayer *layer, bool prepend);
138  void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
139 
140 private:
141  Q_DISABLE_COPY(QCPLayerable)
142 
143  friend class QCustomPlot;
144  friend class QCPAxisRect;
145 };
146 
147 #endif // QCP_LAYER_H