src/plottable.h Source File

· · ·
plottable.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_PLOTTABLE_H
27 #define QCP_PLOTTABLE_H
28
29 #include "global.h"
30 #include "range.h"
31 #include "layer.h"
32 #include "axis.h"
33
34 class QCPPainter;
35
36 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
37 {
38 Q_OBJECT
40 Q_PROPERTY(QString name READ name WRITE setName)
41 Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
42 Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
43 Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
44 Q_PROPERTY(QPen pen READ pen WRITE setPen)
45 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
46 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
47 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
48 Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
49 Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
50 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
51 Q_PROPERTY(bool selected READ selected WRITE setSelected)
53 public:
54 QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
55
56 // getters:
57 QString name() const { return mName; }
58 bool antialiasedFill() const { return mAntialiasedFill; }
59 bool antialiasedScatters() const { return mAntialiasedScatters; }
60 bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
61 QPen pen() const { return mPen; }
62 QPen selectedPen() const { return mSelectedPen; }
63 QBrush brush() const { return mBrush; }
64 QBrush selectedBrush() const { return mSelectedBrush; }
65 QCPAxis *keyAxis() const { return mKeyAxis.data(); }
66 QCPAxis *valueAxis() const { return mValueAxis.data(); }
67 bool selectable() const { return mSelectable; }
68 bool selected() const { return mSelected; }
69
70 // setters:
71 void setName(const QString &name);
72 void setAntialiasedFill(bool enabled);
73 void setAntialiasedScatters(bool enabled);
74 void setAntialiasedErrorBars(bool enabled);
75 void setPen(const QPen &pen);
76 void setSelectedPen(const QPen &pen);
77 void setBrush(const QBrush &brush);
78 void setSelectedBrush(const QBrush &brush);
79 void setKeyAxis(QCPAxis *axis);
80 void setValueAxis(QCPAxis *axis);
81 Q_SLOT void setSelectable(bool selectable);
82 Q_SLOT void setSelected(bool selected);
83
84 // introduced virtual methods:
85 virtual void clearData() = 0;
86 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
87 virtual bool addToLegend();
88 virtual bool removeFromLegend() const;
89
90 // non-property methods:
91 void rescaleAxes(bool onlyEnlarge=false) const;
92 void rescaleKeyAxis(bool onlyEnlarge=false) const;
93 void rescaleValueAxis(bool onlyEnlarge=false) const;
94
95 signals:
96 void selectionChanged(bool selected);
97
98 protected:
102 enum SignDomain { sdNegative
103 ,sdBoth
104 ,sdPositive
105 };
106
107 // property members:
108 QString mName;
109 bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
110 QPen mPen, mSelectedPen;
111 QBrush mBrush, mSelectedBrush;
112 QPointer<QCPAxis> mKeyAxis, mValueAxis;
113 bool mSelectable, mSelected;
114
115 // reimplemented virtual methods:
116 virtual QRect clipRect() const;
117 virtual void draw(QCPPainter *painter) = 0;
118 virtual QCP::Interaction selectionCategory() const;
119 void applyDefaultAntialiasingHint(QCPPainter *painter) const;
120 // events:
121 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
122 virtual void deselectEvent(bool *selectionStateChanged);
123
124 // introduced virtual methods:
125 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
126 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
127 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
128
129 // non-virtual methods:
130 void coordsToPixels(double key, double value, double &x, double &y) const;
131 const QPointF coordsToPixels(double key, double value) const;
132 void pixelsToCoords(double x, double y, double &key, double &value) const;
133 void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
134 QPen mainPen() const;
135 QBrush mainBrush() const;
136 void applyFillAntialiasingHint(QCPPainter *painter) const;
137 void applyScattersAntialiasingHint(QCPPainter *painter) const;
138 void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
139 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
140
141 private:
142 Q_DISABLE_COPY(QCPAbstractPlottable)
143
144 friend class QCustomPlot;
145 friend class QCPAxis;
146 friend class QCPPlottableLegendItem;
147 };
148
149 #endif // QCP_PLOTTABLE_H
Generated with Doxygen 1.8.1.2