]> Creatis software - FrontAlgorithms.git/blob - appli/CTArteries/QCustomPlot.h
...
[FrontAlgorithms.git] / appli / CTArteries / QCustomPlot.h
1 /***************************************************************************
2 **                                                                        **
3 **  QCustomPlot, an easy to use, modern plotting widget for Qt            **
4 **  Copyright (C) 2011-2015 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: 22.12.15                                             **
23 **          Version: 1.3.2                                                **
24 ****************************************************************************/
25
26 #ifndef QCUSTOMPLOT_H
27 #define QCUSTOMPLOT_H
28
29 #include <QObject>
30 #include <QPointer>
31 #include <QWidget>
32 #include <QPainter>
33 #include <QPaintEvent>
34 #include <QMouseEvent>
35 #include <QPixmap>
36 #include <QVector>
37 #include <QString>
38 #include <QDateTime>
39 #include <QMultiMap>
40 #include <QFlags>
41 #include <QDebug>
42 #include <QVector2D>
43 #include <QStack>
44 #include <QCache>
45 #include <QMargins>
46 #include <qmath.h>
47 #include <limits>
48 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
49 #  include <qnumeric.h>
50 #  include <QPrinter>
51 #  include <QPrintEngine>
52 #else
53 #  include <QtNumeric>
54 #  include <QtPrintSupport/QtPrintSupport>
55 #endif
56
57 class QCPPainter;
58 class QCustomPlot;
59 class QCPLayerable;
60 class QCPLayoutElement;
61 class QCPLayout;
62 class QCPAxis;
63 class QCPAxisRect;
64 class QCPAxisPainterPrivate;
65 class QCPAbstractPlottable;
66 class QCPGraph;
67 class QCPAbstractItem;
68 class QCPItemPosition;
69 class QCPLayer;
70 class QCPPlotTitle;
71 class QCPLegend;
72 class QCPAbstractLegendItem;
73 class QCPColorMap;
74 class QCPColorScale;
75 class QCPBars;
76
77
78 /*! \file */
79
80
81 // decl definitions for shared library compilation/usage:
82 /* LFV
83    #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
84    #  define QCP_LIB_DECL Q_DECL_EXPORT
85    #elif defined(QCUSTOMPLOT_USE_LIBRARY)
86    #  define QCP_LIB_DECL Q_DECL_IMPORT
87    #else
88    #  define QCP_LIB_DECL
89    #endif
90 */
91 #define QCP_LIB_DECL
92
93 /*!
94   The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
95 */
96 namespace QCP
97 {
98 /*!
99   Defines the sides of a rectangular entity to which margins can be applied.
100   
101   \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
102 */
103 enum MarginSide { msLeft     = 0x01 ///< <tt>0x01</tt> left margin
104                   ,msRight   = 0x02 ///< <tt>0x02</tt> right margin
105                   ,msTop     = 0x04 ///< <tt>0x04</tt> top margin
106                   ,msBottom  = 0x08 ///< <tt>0x08</tt> bottom margin
107                   ,msAll     = 0xFF ///< <tt>0xFF</tt> all margins
108                   ,msNone    = 0x00 ///< <tt>0x00</tt> no margin
109                 };
110 Q_DECLARE_FLAGS(MarginSides, MarginSide)
111
112 /*!
113   Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
114   neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
115   element how it is drawn. Typically it provides a \a setAntialiased function for this.
116   
117   \c AntialiasedElements is a flag of or-combined elements of this enum type.
118   
119   \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
120 */
121 enum AntialiasedElement { aeAxes           = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
122                           ,aeGrid          = 0x0002 ///< <tt>0x0002</tt> Grid lines
123                           ,aeSubGrid       = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
124                           ,aeLegend        = 0x0008 ///< <tt>0x0008</tt> Legend box
125                           ,aeLegendItems   = 0x0010 ///< <tt>0x0010</tt> Legend items
126                           ,aePlottables    = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see element \ref aeErrorBars)
127                           ,aeItems         = 0x0040 ///< <tt>0x0040</tt> Main lines of items
128                           ,aeScatters      = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
129                           ,aeErrorBars     = 0x0100 ///< <tt>0x0100</tt> Error bars
130                           ,aeFills         = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs)
131                           ,aeZeroLine      = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
132                           ,aeAll           = 0xFFFF ///< <tt>0xFFFF</tt> All elements
133                           ,aeNone          = 0x0000 ///< <tt>0x0000</tt> No elements
134                         };
135 Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
136
137 /*!
138   Defines plotting hints that control various aspects of the quality and speed of plotting.
139   
140   \see QCustomPlot::setPlottingHints
141 */
142 enum PlottingHint { phNone            = 0x000 ///< <tt>0x000</tt> No hints are set
143                     ,phFastPolylines  = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality
144                                               ///<                especially of the line segment joins. (Only relevant for solid line pens.)
145                     ,phForceRepaint   = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint.
146                                               ///<                This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
147                     ,phCacheLabels    = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance.
148                   };
149 Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
150
151 /*!
152   Defines the mouse interactions possible with QCustomPlot.
153   
154   \c Interactions is a flag of or-combined elements of this enum type.
155   
156   \see QCustomPlot::setInteractions
157 */
158 enum Interaction { iRangeDrag         = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
159                    ,iRangeZoom        = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
160                    ,iMultiSelect      = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
161                    ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
162                    ,iSelectAxes       = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
163                    ,iSelectLegend     = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
164                    ,iSelectItems      = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
165                    ,iSelectOther      = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...)
166                  };
167 Q_DECLARE_FLAGS(Interactions, Interaction)
168
169 /*! \internal
170   
171   Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
172   is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
173   compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
174 */
175 inline bool isInvalidData(double value)
176 {
177   return qIsNaN(value) || qIsInf(value);
178 }
179
180 /*! \internal
181   \overload
182   
183   Checks two arguments instead of one.
184 */
185 inline bool isInvalidData(double value1, double value2)
186 {
187   return isInvalidData(value1) || isInvalidData(value2);
188 }
189
190 /*! \internal
191   
192   Sets the specified \a side of \a margins to \a value
193   
194   \see getMarginValue
195 */
196 inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
197 {
198   switch (side)
199   {
200     case QCP::msLeft: margins.setLeft(value); break;
201     case QCP::msRight: margins.setRight(value); break;
202     case QCP::msTop: margins.setTop(value); break;
203     case QCP::msBottom: margins.setBottom(value); break;
204     case QCP::msAll: margins = QMargins(value, value, value, value); break;
205     default: break;
206   }
207 }
208
209 /*! \internal
210   
211   Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
212   \ref QCP::msAll, returns 0.
213   
214   \see setMarginValue
215 */
216 inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
217 {
218   switch (side)
219   {
220     case QCP::msLeft: return margins.left();
221     case QCP::msRight: return margins.right();
222     case QCP::msTop: return margins.top();
223     case QCP::msBottom: return margins.bottom();
224     default: break;
225   }
226   return 0;
227 }
228
229 } // end of namespace QCP
230
231 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
232 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
233 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
234 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
235
236
237 class QCP_LIB_DECL QCPScatterStyle
238 {
239   Q_GADGET
240 public:
241   /*!
242     Defines the shape used for scatter points.
243
244     On plottables/items that draw scatters, the sizes of these visualizations (with exception of
245     \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
246     drawn with the pen and brush specified with \ref setPen and \ref setBrush.
247   */
248   Q_ENUMS(ScatterShape)
249   enum ScatterShape { ssNone       ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
250                       ,ssDot       ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
251                       ,ssCross     ///< \enumimage{ssCross.png} a cross
252                       ,ssPlus      ///< \enumimage{ssPlus.png} a plus
253                       ,ssCircle    ///< \enumimage{ssCircle.png} a circle
254                       ,ssDisc      ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
255                       ,ssSquare    ///< \enumimage{ssSquare.png} a square
256                       ,ssDiamond   ///< \enumimage{ssDiamond.png} a diamond
257                       ,ssStar      ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
258                       ,ssTriangle  ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
259                       ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
260                       ,ssCrossSquare      ///< \enumimage{ssCrossSquare.png} a square with a cross inside
261                       ,ssPlusSquare       ///< \enumimage{ssPlusSquare.png} a square with a plus inside
262                       ,ssCrossCircle      ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
263                       ,ssPlusCircle       ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
264                       ,ssPeace     ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
265                       ,ssPixmap    ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
266                       ,ssCustom    ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
267                     };
268
269   QCPScatterStyle();
270   QCPScatterStyle(ScatterShape shape, double size=6);
271   QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
272   QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
273   QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
274   QCPScatterStyle(const QPixmap &pixmap);
275   QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
276   
277   // getters:
278   double size() const { return mSize; }
279   ScatterShape shape() const { return mShape; }
280   QPen pen() const { return mPen; }
281   QBrush brush() const { return mBrush; }
282   QPixmap pixmap() const { return mPixmap; }
283   QPainterPath customPath() const { return mCustomPath; }
284
285   // setters:
286   void setSize(double size);
287   void setShape(ScatterShape shape);
288   void setPen(const QPen &pen);
289   void setBrush(const QBrush &brush);
290   void setPixmap(const QPixmap &pixmap);
291   void setCustomPath(const QPainterPath &customPath);
292
293   // non-property methods:
294   bool isNone() const { return mShape == ssNone; }
295   bool isPenDefined() const { return mPenDefined; }
296   void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
297   void drawShape(QCPPainter *painter, QPointF pos) const;
298   void drawShape(QCPPainter *painter, double x, double y) const;
299
300 protected:
301   // property members:
302   double mSize;
303   ScatterShape mShape;
304   QPen mPen;
305   QBrush mBrush;
306   QPixmap mPixmap;
307   QPainterPath mCustomPath;
308   
309   // non-property members:
310   bool mPenDefined;
311 };
312 Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
313
314
315 class QCP_LIB_DECL QCPPainter : public QPainter
316 {
317   Q_GADGET
318 public:
319   /*!
320     Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
321     depending on whether they are wanted on the respective output device.
322   */
323   enum PainterMode { pmDefault       = 0x00   ///< <tt>0x00</tt> Default mode for painting on screen devices
324                      ,pmVectorized   = 0x01   ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
325                      ,pmNoCaching    = 0x02   ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
326                      ,pmNonCosmetic  = 0x04   ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)
327                    };
328   Q_FLAGS(PainterMode PainterModes)
329   Q_DECLARE_FLAGS(PainterModes, PainterMode)
330   
331   QCPPainter();
332   QCPPainter(QPaintDevice *device);
333   ~QCPPainter();
334   
335   // getters:
336   bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
337   PainterModes modes() const { return mModes; }
338
339   // setters:
340   void setAntialiasing(bool enabled);
341   void setMode(PainterMode mode, bool enabled=true);
342   void setModes(PainterModes modes);
343
344   // methods hiding non-virtual base class functions (QPainter bug workarounds):
345   bool begin(QPaintDevice *device);
346   void setPen(const QPen &pen);
347   void setPen(const QColor &color);
348   void setPen(Qt::PenStyle penStyle);
349   void drawLine(const QLineF &line);
350   void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
351   void save();
352   void restore();
353   
354   // non-virtual methods:
355   void makeNonCosmetic();
356   
357 protected:
358   // property members:
359   PainterModes mModes;
360   bool mIsAntialiasing;
361   
362   // non-property members:
363   QStack<bool> mAntialiasingStack;
364 };
365 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
366
367
368 class QCP_LIB_DECL QCPLayer : public QObject
369 {
370   Q_OBJECT
371   /// \cond INCLUDE_QPROPERTIES
372   Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
373   Q_PROPERTY(QString name READ name)
374   Q_PROPERTY(int index READ index)
375   Q_PROPERTY(QList<QCPLayerable*> children READ children)
376   Q_PROPERTY(bool visible READ visible WRITE setVisible)
377   /// \endcond
378 public:
379   QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
380   ~QCPLayer();
381   
382   // getters:
383   QCustomPlot *parentPlot() const { return mParentPlot; }
384   QString name() const { return mName; }
385   int index() const { return mIndex; }
386   QList<QCPLayerable*> children() const { return mChildren; }
387   bool visible() const { return mVisible; }
388   
389   // setters:
390   void setVisible(bool visible);
391   
392 protected:
393   // property members:
394   QCustomPlot *mParentPlot;
395   QString mName;
396   int mIndex;
397   QList<QCPLayerable*> mChildren;
398   bool mVisible;
399   
400   // non-virtual methods:
401   void addChild(QCPLayerable *layerable, bool prepend);
402   void removeChild(QCPLayerable *layerable);
403   
404 private:
405   Q_DISABLE_COPY(QCPLayer)
406   
407   friend class QCustomPlot;
408   friend class QCPLayerable;
409 };
410
411 class QCP_LIB_DECL QCPLayerable : public QObject
412 {
413   Q_OBJECT
414   /// \cond INCLUDE_QPROPERTIES
415   Q_PROPERTY(bool visible READ visible WRITE setVisible)
416   Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
417   Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
418   Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
419   Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
420   /// \endcond
421 public:
422   QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0);
423   ~QCPLayerable();
424   
425   // getters:
426   bool visible() const { return mVisible; }
427   QCustomPlot *parentPlot() const { return mParentPlot; }
428   QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
429   QCPLayer *layer() const { return mLayer; }
430   bool antialiased() const { return mAntialiased; }
431   
432   // setters:
433   void setVisible(bool on);
434   Q_SLOT bool setLayer(QCPLayer *layer);
435   bool setLayer(const QString &layerName);
436   void setAntialiased(bool enabled);
437   
438   // introduced virtual methods:
439   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
440   
441   // non-property methods:
442   bool realVisibility() const;
443   
444 signals:
445   void layerChanged(QCPLayer *newLayer);
446   
447 protected:
448   // property members:
449   bool mVisible;
450   QCustomPlot *mParentPlot;
451   QPointer<QCPLayerable> mParentLayerable;
452   QCPLayer *mLayer;
453   bool mAntialiased;
454   
455   // introduced virtual methods:
456   virtual void parentPlotInitialized(QCustomPlot *parentPlot);
457   virtual QCP::Interaction selectionCategory() const;
458   virtual QRect clipRect() const;
459   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
460   virtual void draw(QCPPainter *painter) = 0;
461   // events:
462   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
463   virtual void deselectEvent(bool *selectionStateChanged);
464   
465   // non-property methods:
466   void initializeParentPlot(QCustomPlot *parentPlot);
467   void setParentLayerable(QCPLayerable* parentLayerable);
468   bool moveToLayer(QCPLayer *layer, bool prepend);
469   void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
470   
471 private:
472   Q_DISABLE_COPY(QCPLayerable)
473   
474   friend class QCustomPlot;
475   friend class QCPAxisRect;
476 };
477
478
479 class QCP_LIB_DECL QCPRange
480 {
481 public:
482   double lower, upper;
483   
484   QCPRange();
485   QCPRange(double lower, double upper);
486   
487   bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; }
488   bool operator!=(const QCPRange& other) const { return !(*this == other); }
489   
490   QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; }
491   QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; }
492   QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; }
493   QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
494   friend inline const QCPRange operator+(const QCPRange&, double);
495   friend inline const QCPRange operator+(double, const QCPRange&);
496   friend inline const QCPRange operator-(const QCPRange& range, double value);
497   friend inline const QCPRange operator*(const QCPRange& range, double value);
498   friend inline const QCPRange operator*(double value, const QCPRange& range);
499   friend inline const QCPRange operator/(const QCPRange& range, double value);
500   
501   double size() const;
502   double center() const;
503   void normalize();
504   void expand(const QCPRange &otherRange);
505   QCPRange expanded(const QCPRange &otherRange) const;
506   QCPRange sanitizedForLogScale() const;
507   QCPRange sanitizedForLinScale() const;
508   bool contains(double value) const;
509   
510   static bool validRange(double lower, double upper);
511   static bool validRange(const QCPRange &range);
512   static const double minRange; //1e-280;
513   static const double maxRange; //1e280;
514   
515 };
516 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
517
518 /* documentation of inline functions */
519
520 /*! \fn QCPRange &QCPRange::operator+=(const double& value)
521   
522   Adds \a value to both boundaries of the range.
523 */
524
525 /*! \fn QCPRange &QCPRange::operator-=(const double& value)
526   
527   Subtracts \a value from both boundaries of the range.
528 */
529
530 /*! \fn QCPRange &QCPRange::operator*=(const double& value)
531   
532   Multiplies both boundaries of the range by \a value.
533 */
534
535 /*! \fn QCPRange &QCPRange::operator/=(const double& value)
536   
537   Divides both boundaries of the range by \a value.
538 */
539
540 /* end documentation of inline functions */
541
542 /*!
543   Adds \a value to both boundaries of the range.
544 */
545 inline const QCPRange operator+(const QCPRange& range, double value)
546 {
547   QCPRange result(range);
548   result += value;
549   return result;
550 }
551
552 /*!
553   Adds \a value to both boundaries of the range.
554 */
555 inline const QCPRange operator+(double value, const QCPRange& range)
556 {
557   QCPRange result(range);
558   result += value;
559   return result;
560 }
561
562 /*!
563   Subtracts \a value from both boundaries of the range.
564 */
565 inline const QCPRange operator-(const QCPRange& range, double value)
566 {
567   QCPRange result(range);
568   result -= value;
569   return result;
570 }
571
572 /*!
573   Multiplies both boundaries of the range by \a value.
574 */
575 inline const QCPRange operator*(const QCPRange& range, double value)
576 {
577   QCPRange result(range);
578   result *= value;
579   return result;
580 }
581
582 /*!
583   Multiplies both boundaries of the range by \a value.
584 */
585 inline const QCPRange operator*(double value, const QCPRange& range)
586 {
587   QCPRange result(range);
588   result *= value;
589   return result;
590 }
591
592 /*!
593   Divides both boundaries of the range by \a value.
594 */
595 inline const QCPRange operator/(const QCPRange& range, double value)
596 {
597   QCPRange result(range);
598   result /= value;
599   return result;
600 }
601
602
603 class QCP_LIB_DECL QCPMarginGroup : public QObject
604 {
605   Q_OBJECT
606 public:
607   QCPMarginGroup(QCustomPlot *parentPlot);
608   ~QCPMarginGroup();
609   
610   // non-virtual methods:
611   QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
612   bool isEmpty() const;
613   void clear();
614   
615 protected:
616   // non-property members:
617   QCustomPlot *mParentPlot;
618   QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
619   
620   // non-virtual methods:
621   int commonMargin(QCP::MarginSide side) const;
622   void addChild(QCP::MarginSide side, QCPLayoutElement *element);
623   void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
624   
625 private:
626   Q_DISABLE_COPY(QCPMarginGroup)
627   
628   friend class QCPLayoutElement;
629 };
630
631
632 class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
633 {
634   Q_OBJECT
635   /// \cond INCLUDE_QPROPERTIES
636   Q_PROPERTY(QCPLayout* layout READ layout)
637   Q_PROPERTY(QRect rect READ rect)
638   Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
639   Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
640   Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
641   Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
642   Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
643   /// \endcond
644 public:
645   /*!
646     Defines the phases of the update process, that happens just before a replot. At each phase,
647     \ref update is called with the according UpdatePhase value.
648   */
649   enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout
650                      ,upMargins    ///< Phase in which the margins are calculated and set
651                      ,upLayout     ///< Final phase in which the layout system places the rects of the elements
652                    };
653   Q_ENUMS(UpdatePhase)
654
655   explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
656   virtual ~QCPLayoutElement();
657   
658   // getters:
659   QCPLayout *layout() const { return mParentLayout; }
660   QRect rect() const { return mRect; }
661   QRect outerRect() const { return mOuterRect; }
662   QMargins margins() const { return mMargins; }
663   QMargins minimumMargins() const { return mMinimumMargins; }
664   QCP::MarginSides autoMargins() const { return mAutoMargins; }
665   QSize minimumSize() const { return mMinimumSize; }
666   QSize maximumSize() const { return mMaximumSize; }
667   QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
668   QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
669   
670   // setters:
671   void setOuterRect(const QRect &rect);
672   void setMargins(const QMargins &margins);
673   void setMinimumMargins(const QMargins &margins);
674   void setAutoMargins(QCP::MarginSides sides);
675   void setMinimumSize(const QSize &size);
676   void setMinimumSize(int width, int height);
677   void setMaximumSize(const QSize &size);
678   void setMaximumSize(int width, int height);
679   void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
680   
681   // introduced virtual methods:
682   virtual void update(UpdatePhase phase);
683   virtual QSize minimumSizeHint() const;
684   virtual QSize maximumSizeHint() const;
685   virtual QList<QCPLayoutElement*> elements(bool recursive) const;
686   
687   // reimplemented virtual methods:
688   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
689   
690 protected:
691   // property members:
692   QCPLayout *mParentLayout;
693   QSize mMinimumSize, mMaximumSize;
694   QRect mRect, mOuterRect;
695   QMargins mMargins, mMinimumMargins;
696   QCP::MarginSides mAutoMargins;
697   QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
698   
699   // introduced virtual methods:
700   virtual int calculateAutoMargin(QCP::MarginSide side);
701   // events:
702   virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
703   virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
704   virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
705   virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
706   virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
707   
708   // reimplemented virtual methods:
709   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
710   virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
711   virtual void parentPlotInitialized(QCustomPlot *parentPlot);
712
713 private:
714   Q_DISABLE_COPY(QCPLayoutElement)
715   
716   friend class QCustomPlot;
717   friend class QCPLayout;
718   friend class QCPMarginGroup;
719 };
720
721
722 class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
723 {
724   Q_OBJECT
725 public:
726   explicit QCPLayout();
727   
728   // reimplemented virtual methods:
729   virtual void update(UpdatePhase phase);
730   virtual QList<QCPLayoutElement*> elements(bool recursive) const;
731   
732   // introduced virtual methods:
733   virtual int elementCount() const = 0;
734   virtual QCPLayoutElement* elementAt(int index) const = 0;
735   virtual QCPLayoutElement* takeAt(int index) = 0;
736   virtual bool take(QCPLayoutElement* element) = 0;
737   virtual void simplify();
738   
739   // non-virtual methods:
740   bool removeAt(int index);
741   bool remove(QCPLayoutElement* element);
742   void clear();
743   
744 protected:
745   // introduced virtual methods:
746   virtual void updateLayout();
747   
748   // non-virtual methods:
749   void sizeConstraintsChanged() const;
750   void adoptElement(QCPLayoutElement *el);
751   void releaseElement(QCPLayoutElement *el);
752   QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
753   
754 private:
755   Q_DISABLE_COPY(QCPLayout)
756   friend class QCPLayoutElement;
757 };
758
759
760 class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
761 {
762   Q_OBJECT
763   /// \cond INCLUDE_QPROPERTIES
764   Q_PROPERTY(int rowCount READ rowCount)
765   Q_PROPERTY(int columnCount READ columnCount)
766   Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
767   Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
768   Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
769   Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
770   /// \endcond
771 public:
772   explicit QCPLayoutGrid();
773   virtual ~QCPLayoutGrid();
774   
775   // getters:
776   int rowCount() const;
777   int columnCount() const;
778   QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
779   QList<double> rowStretchFactors() const { return mRowStretchFactors; }
780   int columnSpacing() const { return mColumnSpacing; }
781   int rowSpacing() const { return mRowSpacing; }
782   
783   // setters:
784   void setColumnStretchFactor(int column, double factor);
785   void setColumnStretchFactors(const QList<double> &factors);
786   void setRowStretchFactor(int row, double factor);
787   void setRowStretchFactors(const QList<double> &factors);
788   void setColumnSpacing(int pixels);
789   void setRowSpacing(int pixels);
790   
791   // reimplemented virtual methods:
792   virtual void updateLayout();
793   virtual int elementCount() const;
794   virtual QCPLayoutElement* elementAt(int index) const;
795   virtual QCPLayoutElement* takeAt(int index);
796   virtual bool take(QCPLayoutElement* element);
797   virtual QList<QCPLayoutElement*> elements(bool recursive) const;
798   virtual void simplify();
799   virtual QSize minimumSizeHint() const;
800   virtual QSize maximumSizeHint() const;
801   
802   // non-virtual methods:
803   QCPLayoutElement *element(int row, int column) const;
804   bool addElement(int row, int column, QCPLayoutElement *element);
805   bool hasElement(int row, int column);
806   void expandTo(int newRowCount, int newColumnCount);
807   void insertRow(int newIndex);
808   void insertColumn(int newIndex);
809   
810 protected:
811   // property members:
812   QList<QList<QCPLayoutElement*> > mElements;
813   QList<double> mColumnStretchFactors;
814   QList<double> mRowStretchFactors;
815   int mColumnSpacing, mRowSpacing;
816   
817   // non-virtual methods:
818   void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
819   void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
820   
821 private:
822   Q_DISABLE_COPY(QCPLayoutGrid)
823 };
824
825
826 class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
827 {
828   Q_OBJECT
829 public:
830   /*!
831     Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
832   */
833   enum InsetPlacement { ipFree            ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
834                         ,ipBorderAligned  ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
835                       };
836   
837   explicit QCPLayoutInset();
838   virtual ~QCPLayoutInset();
839   
840   // getters:
841   InsetPlacement insetPlacement(int index) const;
842   Qt::Alignment insetAlignment(int index) const;
843   QRectF insetRect(int index) const;
844   
845   // setters:
846   void setInsetPlacement(int index, InsetPlacement placement);
847   void setInsetAlignment(int index, Qt::Alignment alignment);
848   void setInsetRect(int index, const QRectF &rect);
849   
850   // reimplemented virtual methods:
851   virtual void updateLayout();
852   virtual int elementCount() const;
853   virtual QCPLayoutElement* elementAt(int index) const;
854   virtual QCPLayoutElement* takeAt(int index);
855   virtual bool take(QCPLayoutElement* element);
856   virtual void simplify() {}
857   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
858   
859   // non-virtual methods:
860   void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
861   void addElement(QCPLayoutElement *element, const QRectF &rect);
862   
863 protected:
864   // property members:
865   QList<QCPLayoutElement*> mElements;
866   QList<InsetPlacement> mInsetPlacement;
867   QList<Qt::Alignment> mInsetAlignment;
868   QList<QRectF> mInsetRect;
869   
870 private:
871   Q_DISABLE_COPY(QCPLayoutInset)
872 };
873
874
875 class QCP_LIB_DECL QCPLineEnding
876 {
877   Q_GADGET
878 public:
879   /*!
880     Defines the type of ending decoration for line-like items, e.g. an arrow.
881     
882     \image html QCPLineEnding.png
883     
884     The width and length of these decorations can be controlled with the functions \ref setWidth
885     and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
886     support a width, the length property is ignored.
887     
888     \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
889   */
890   Q_ENUMS(EndingStyle)
891   enum EndingStyle { esNone          ///< No ending decoration
892                      ,esFlatArrow    ///< A filled arrow head with a straight/flat back (a triangle)
893                      ,esSpikeArrow   ///< A filled arrow head with an indented back
894                      ,esLineArrow    ///< A non-filled arrow head with open back
895                      ,esDisc         ///< A filled circle
896                      ,esSquare       ///< A filled square
897                      ,esDiamond      ///< A filled diamond (45° rotated square)
898                      ,esBar          ///< A bar perpendicular to the line
899                      ,esHalfBar      ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted)
900                      ,esSkewedBar    ///< A bar that is skewed (skew controllable via \ref setLength)
901                    };
902   
903   QCPLineEnding();
904   QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
905   
906   // getters:
907   EndingStyle style() const { return mStyle; }
908   double width() const { return mWidth; }
909   double length() const { return mLength; }
910   bool inverted() const { return mInverted; }
911   
912   // setters:
913   void setStyle(EndingStyle style);
914   void setWidth(double width);
915   void setLength(double length);
916   void setInverted(bool inverted);
917   
918   // non-property methods:
919   double boundingDistance() const;
920   double realLength() const;
921   void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
922   void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
923   
924 protected:
925   // property members:
926   EndingStyle mStyle;
927   double mWidth, mLength;
928   bool mInverted;
929 };
930 Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
931
932
933 class QCP_LIB_DECL QCPGrid :public QCPLayerable
934 {
935   Q_OBJECT
936   /// \cond INCLUDE_QPROPERTIES
937   Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
938   Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
939   Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
940   Q_PROPERTY(QPen pen READ pen WRITE setPen)
941   Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
942   Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
943   /// \endcond
944 public:
945   QCPGrid(QCPAxis *parentAxis);
946   
947   // getters:
948   bool subGridVisible() const { return mSubGridVisible; }
949   bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
950   bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
951   QPen pen() const { return mPen; }
952   QPen subGridPen() const { return mSubGridPen; }
953   QPen zeroLinePen() const { return mZeroLinePen; }
954   
955   // setters:
956   void setSubGridVisible(bool visible);
957   void setAntialiasedSubGrid(bool enabled);
958   void setAntialiasedZeroLine(bool enabled);
959   void setPen(const QPen &pen);
960   void setSubGridPen(const QPen &pen);
961   void setZeroLinePen(const QPen &pen);
962   
963 protected:
964   // property members:
965   bool mSubGridVisible;
966   bool mAntialiasedSubGrid, mAntialiasedZeroLine;
967   QPen mPen, mSubGridPen, mZeroLinePen;
968   // non-property members:
969   QCPAxis *mParentAxis;
970   
971   // reimplemented virtual methods:
972   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
973   virtual void draw(QCPPainter *painter);
974   
975   // non-virtual methods:
976   void drawGridLines(QCPPainter *painter) const;
977   void drawSubGridLines(QCPPainter *painter) const;
978   
979   friend class QCPAxis;
980 };
981
982
983 class QCP_LIB_DECL QCPAxis : public QCPLayerable
984 {
985   Q_OBJECT
986   /// \cond INCLUDE_QPROPERTIES
987   Q_PROPERTY(AxisType axisType READ axisType)
988   Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
989   Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
990   Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
991   Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
992   Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
993   Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
994   Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
995   Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
996   Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
997   Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
998   Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
999   Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
1000   Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
1001   Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
1002   Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
1003   Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
1004   Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
1005   Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide)
1006   Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
1007   Q_PROPERTY(Qt::TimeSpec dateTimeSpec READ dateTimeSpec WRITE setDateTimeSpec)
1008   Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
1009   Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
1010   Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
1011   Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
1012   Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
1013   Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
1014   Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
1015   Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
1016   Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
1017   Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
1018   Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
1019   Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
1020   Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
1021   Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
1022   Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
1023   Q_PROPERTY(QString label READ label WRITE setLabel)
1024   Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
1025   Q_PROPERTY(int padding READ padding WRITE setPadding)
1026   Q_PROPERTY(int offset READ offset WRITE setOffset)
1027   Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged)
1028   Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged)
1029   Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
1030   Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
1031   Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
1032   Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
1033   Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
1034   Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
1035   Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
1036   Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
1037   Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
1038   Q_PROPERTY(QCPGrid* grid READ grid)
1039   /// \endcond
1040 public:
1041   /*!
1042     Defines at which side of the axis rect the axis will appear. This also affects how the tick
1043     marks are drawn, on which side the labels are placed etc.
1044   */
1045   enum AxisType { atLeft    = 0x01  ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect
1046                   ,atRight  = 0x02  ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect
1047                   ,atTop    = 0x04  ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect
1048                   ,atBottom = 0x08  ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect
1049                 };
1050   Q_FLAGS(AxisType AxisTypes)
1051   Q_DECLARE_FLAGS(AxisTypes, AxisType)
1052   /*!
1053     When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the
1054     coordinate of the tick is interpreted, i.e. translated into a string.
1055     
1056     \see setTickLabelType
1057   */
1058   enum LabelType { ltNumber    ///< Tick coordinate is regarded as normal number and will be displayed as such. (see \ref setNumberFormat)
1059                    ,ltDateTime ///< Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC) and will be displayed and formatted as such. (for details, see \ref setDateTimeFormat)
1060                  };
1061   Q_ENUMS(LabelType)
1062   /*!
1063     Defines on which side of the axis the tick labels (numbers) shall appear.
1064     
1065     \see setTickLabelSide
1066   */
1067   enum LabelSide { lsInside    ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect
1068                    ,lsOutside  ///< Tick labels will be displayed outside the axis rect
1069                  };
1070   Q_ENUMS(LabelSide)
1071   /*!
1072     Defines the scale of an axis.
1073     \see setScaleType
1074   */
1075   enum ScaleType { stLinear       ///< Linear scaling
1076                    ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see \ref setScaleLogBase).
1077                  };
1078   Q_ENUMS(ScaleType)
1079   /*!
1080     Defines the selectable parts of an axis.
1081     \see setSelectableParts, setSelectedParts
1082   */
1083   enum SelectablePart { spNone        = 0      ///< None of the selectable parts
1084                         ,spAxis       = 0x001  ///< The axis backbone and tick marks
1085                         ,spTickLabels = 0x002  ///< Tick labels (numbers) of this axis (as a whole, not individually)
1086                         ,spAxisLabel  = 0x004  ///< The axis label
1087                       };
1088   Q_FLAGS(SelectablePart SelectableParts)
1089   Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
1090   
1091   explicit QCPAxis(QCPAxisRect *parent, AxisType type);
1092   virtual ~QCPAxis();
1093   
1094   // getters:
1095   AxisType axisType() const { return mAxisType; }
1096   QCPAxisRect *axisRect() const { return mAxisRect; }
1097   ScaleType scaleType() const { return mScaleType; }
1098   double scaleLogBase() const { return mScaleLogBase; }
1099   const QCPRange range() const { return mRange; }
1100   bool rangeReversed() const { return mRangeReversed; }
1101   bool autoTicks() const { return mAutoTicks; }
1102   int autoTickCount() const { return mAutoTickCount; }
1103   bool autoTickLabels() const { return mAutoTickLabels; }
1104   bool autoTickStep() const { return mAutoTickStep; }
1105   bool autoSubTicks() const { return mAutoSubTicks; }
1106   bool ticks() const { return mTicks; }
1107   bool tickLabels() const { return mTickLabels; }
1108   int tickLabelPadding() const;
1109   LabelType tickLabelType() const { return mTickLabelType; }
1110   QFont tickLabelFont() const { return mTickLabelFont; }
1111   QColor tickLabelColor() const { return mTickLabelColor; }
1112   double tickLabelRotation() const;
1113   LabelSide tickLabelSide() const;
1114   QString dateTimeFormat() const { return mDateTimeFormat; }
1115   Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
1116   QString numberFormat() const;
1117   int numberPrecision() const { return mNumberPrecision; }
1118   double tickStep() const { return mTickStep; }
1119   QVector<double> tickVector() const { return mTickVector; }
1120   QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
1121   int tickLengthIn() const;
1122   int tickLengthOut() const;
1123   int subTickCount() const { return mSubTickCount; }
1124   int subTickLengthIn() const;
1125   int subTickLengthOut() const;
1126   QPen basePen() const { return mBasePen; }
1127   QPen tickPen() const { return mTickPen; }
1128   QPen subTickPen() const { return mSubTickPen; }
1129   QFont labelFont() const { return mLabelFont; }
1130   QColor labelColor() const { return mLabelColor; }
1131   QString label() const { return mLabel; }
1132   int labelPadding() const;
1133   int padding() const { return mPadding; }
1134   int offset() const;
1135   SelectableParts selectedParts() const { return mSelectedParts; }
1136   SelectableParts selectableParts() const { return mSelectableParts; }
1137   QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
1138   QFont selectedLabelFont() const { return mSelectedLabelFont; }
1139   QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
1140   QColor selectedLabelColor() const { return mSelectedLabelColor; }
1141   QPen selectedBasePen() const { return mSelectedBasePen; }
1142   QPen selectedTickPen() const { return mSelectedTickPen; }
1143   QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
1144   QCPLineEnding lowerEnding() const;
1145   QCPLineEnding upperEnding() const;
1146   QCPGrid *grid() const { return mGrid; }
1147   
1148   // setters:
1149   Q_SLOT void setScaleType(QCPAxis::ScaleType type);
1150   void setScaleLogBase(double base);
1151   Q_SLOT void setRange(const QCPRange &range);
1152   void setRange(double lower, double upper);
1153   void setRange(double position, double size, Qt::AlignmentFlag alignment);
1154   void setRangeLower(double lower);
1155   void setRangeUpper(double upper);
1156   void setRangeReversed(bool reversed);
1157   void setAutoTicks(bool on);
1158   void setAutoTickCount(int approximateCount);
1159   void setAutoTickLabels(bool on);
1160   void setAutoTickStep(bool on);
1161   void setAutoSubTicks(bool on);
1162   void setTicks(bool show);
1163   void setTickLabels(bool show);
1164   void setTickLabelPadding(int padding);
1165   void setTickLabelType(LabelType type);
1166   void setTickLabelFont(const QFont &font);
1167   void setTickLabelColor(const QColor &color);
1168   void setTickLabelRotation(double degrees);
1169   void setTickLabelSide(LabelSide side);
1170   void setDateTimeFormat(const QString &format);
1171   void setDateTimeSpec(const Qt::TimeSpec &timeSpec);
1172   void setNumberFormat(const QString &formatCode);
1173   void setNumberPrecision(int precision);
1174   void setTickStep(double step);
1175   void setTickVector(const QVector<double> &vec);
1176   void setTickVectorLabels(const QVector<QString> &vec);
1177   void setTickLength(int inside, int outside=0);
1178   void setTickLengthIn(int inside);
1179   void setTickLengthOut(int outside);
1180   void setSubTickCount(int count);
1181   void setSubTickLength(int inside, int outside=0);
1182   void setSubTickLengthIn(int inside);
1183   void setSubTickLengthOut(int outside);
1184   void setBasePen(const QPen &pen);
1185   void setTickPen(const QPen &pen);
1186   void setSubTickPen(const QPen &pen);
1187   void setLabelFont(const QFont &font);
1188   void setLabelColor(const QColor &color);
1189   void setLabel(const QString &str);
1190   void setLabelPadding(int padding);
1191   void setPadding(int padding);
1192   void setOffset(int offset);
1193   void setSelectedTickLabelFont(const QFont &font);
1194   void setSelectedLabelFont(const QFont &font);
1195   void setSelectedTickLabelColor(const QColor &color);
1196   void setSelectedLabelColor(const QColor &color);
1197   void setSelectedBasePen(const QPen &pen);
1198   void setSelectedTickPen(const QPen &pen);
1199   void setSelectedSubTickPen(const QPen &pen);
1200   Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
1201   Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
1202   void setLowerEnding(const QCPLineEnding &ending);
1203   void setUpperEnding(const QCPLineEnding &ending);
1204   
1205   // reimplemented virtual methods:
1206   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1207   
1208   // non-property methods:
1209   Qt::Orientation orientation() const { return mOrientation; }
1210   void moveRange(double diff);
1211   void scaleRange(double factor, double center);
1212   void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
1213   void rescale(bool onlyVisiblePlottables=false);
1214   double pixelToCoord(double value) const;
1215   double coordToPixel(double value) const;
1216   SelectablePart getPartAt(const QPointF &pos) const;
1217   QList<QCPAbstractPlottable*> plottables() const;
1218   QList<QCPGraph*> graphs() const;
1219   QList<QCPAbstractItem*> items() const;
1220   
1221   static AxisType marginSideToAxisType(QCP::MarginSide side);
1222   static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; }
1223   static AxisType opposite(AxisType type);
1224   
1225 signals:
1226   void ticksRequest();
1227   void rangeChanged(const QCPRange &newRange);
1228   void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
1229   void scaleTypeChanged(QCPAxis::ScaleType scaleType);
1230   void selectionChanged(const QCPAxis::SelectableParts &parts);
1231   void selectableChanged(const QCPAxis::SelectableParts &parts);
1232
1233 protected:
1234   // property members:
1235   // axis base:
1236   AxisType mAxisType;
1237   QCPAxisRect *mAxisRect;
1238   //int mOffset; // in QCPAxisPainter
1239   int mPadding;
1240   Qt::Orientation mOrientation;
1241   SelectableParts mSelectableParts, mSelectedParts;
1242   QPen mBasePen, mSelectedBasePen;
1243   //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter
1244   // axis label:
1245   //int mLabelPadding; // in QCPAxisPainter
1246   QString mLabel;
1247   QFont mLabelFont, mSelectedLabelFont;
1248   QColor mLabelColor, mSelectedLabelColor;
1249   // tick labels:
1250   //int mTickLabelPadding; // in QCPAxisPainter
1251   bool mTickLabels, mAutoTickLabels;
1252   //double mTickLabelRotation; // in QCPAxisPainter
1253   LabelType mTickLabelType;
1254   QFont mTickLabelFont, mSelectedTickLabelFont;
1255   QColor mTickLabelColor, mSelectedTickLabelColor;
1256   QString mDateTimeFormat;
1257   Qt::TimeSpec mDateTimeSpec;
1258   int mNumberPrecision;
1259   QLatin1Char mNumberFormatChar;
1260   bool mNumberBeautifulPowers;
1261   //bool mNumberMultiplyCross; // QCPAxisPainter
1262   // ticks and subticks:
1263   bool mTicks;
1264   double mTickStep;
1265   int mSubTickCount, mAutoTickCount;
1266   bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
1267   //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter
1268   QPen mTickPen, mSelectedTickPen;
1269   QPen mSubTickPen, mSelectedSubTickPen;
1270   // scale and range:
1271   QCPRange mRange;
1272   bool mRangeReversed;
1273   ScaleType mScaleType;
1274   double mScaleLogBase, mScaleLogBaseLogInv;
1275   
1276   // non-property members:
1277   QCPGrid *mGrid;
1278   QCPAxisPainterPrivate *mAxisPainter;
1279   int mLowestVisibleTick, mHighestVisibleTick;
1280   QVector<double> mTickVector;
1281   QVector<QString> mTickVectorLabels;
1282   QVector<double> mSubTickVector;
1283   bool mCachedMarginValid;
1284   int mCachedMargin;
1285   
1286   // introduced virtual methods:
1287   virtual void setupTickVectors();
1288   virtual void generateAutoTicks();
1289   virtual int calculateAutoSubTickCount(double tickStep) const;
1290   virtual int calculateMargin();
1291   
1292   // reimplemented virtual methods:
1293   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1294   virtual void draw(QCPPainter *painter);
1295   virtual QCP::Interaction selectionCategory() const;
1296   // events:
1297   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1298   virtual void deselectEvent(bool *selectionStateChanged);
1299   
1300   // non-virtual methods:
1301   void visibleTickBounds(int &lowIndex, int &highIndex) const;
1302   double baseLog(double value) const;
1303   double basePow(double value) const;
1304   QPen getBasePen() const;
1305   QPen getTickPen() const;
1306   QPen getSubTickPen() const;
1307   QFont getTickLabelFont() const;
1308   QFont getLabelFont() const;
1309   QColor getTickLabelColor() const;
1310   QColor getLabelColor() const;
1311   
1312 private:
1313   Q_DISABLE_COPY(QCPAxis)
1314   
1315   friend class QCustomPlot;
1316   friend class QCPGrid;
1317   friend class QCPAxisRect;
1318 };
1319 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
1320 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
1321 Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
1322
1323
1324 class QCPAxisPainterPrivate
1325 {
1326 public:
1327   explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot);
1328   virtual ~QCPAxisPainterPrivate();
1329   
1330   virtual void draw(QCPPainter *painter);
1331   virtual int size() const;
1332   void clearCache();
1333   
1334   QRect axisSelectionBox() const { return mAxisSelectionBox; }
1335   QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; }
1336   QRect labelSelectionBox() const { return mLabelSelectionBox; }
1337   
1338   // public property members:
1339   QCPAxis::AxisType type;
1340   QPen basePen;
1341   QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters
1342   int labelPadding; // directly accessed by QCPAxis setters/getters
1343   QFont labelFont;
1344   QColor labelColor;
1345   QString label;
1346   int tickLabelPadding; // directly accessed by QCPAxis setters/getters
1347   double tickLabelRotation; // directly accessed by QCPAxis setters/getters
1348   QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters
1349   bool substituteExponent;
1350   bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters
1351   int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters
1352   QPen tickPen, subTickPen;
1353   QFont tickLabelFont;
1354   QColor tickLabelColor;
1355   QRect axisRect, viewportRect;
1356   double offset; // directly accessed by QCPAxis setters/getters
1357   bool abbreviateDecimalPowers;
1358   bool reversedEndings;
1359   
1360   QVector<double> subTickPositions;
1361   QVector<double> tickPositions;
1362   QVector<QString> tickLabels;
1363   
1364 protected:
1365   struct CachedLabel
1366   {
1367     QPointF offset;
1368     QPixmap pixmap;
1369   };
1370   struct TickLabelData
1371   {
1372     QString basePart, expPart;
1373     QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
1374     QFont baseFont, expFont;
1375   };
1376   QCustomPlot *mParentPlot;
1377   QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters
1378   QCache<QString, CachedLabel> mLabelCache;
1379   QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
1380   
1381   virtual QByteArray generateLabelParameterHash() const;
1382   
1383   virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
1384   virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
1385   virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
1386   virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
1387   virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
1388 };
1389
1390
1391 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
1392 {
1393   Q_OBJECT
1394   /// \cond INCLUDE_QPROPERTIES
1395   Q_PROPERTY(QString name READ name WRITE setName)
1396   Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
1397   Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
1398   Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
1399   Q_PROPERTY(QPen pen READ pen WRITE setPen)
1400   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
1401   Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
1402   Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
1403   Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
1404   Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
1405   Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1406   Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1407   /// \endcond
1408 public:
1409   QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
1410   
1411   // getters:
1412   QString name() const { return mName; }
1413   bool antialiasedFill() const { return mAntialiasedFill; }
1414   bool antialiasedScatters() const { return mAntialiasedScatters; }
1415   bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
1416   QPen pen() const { return mPen; }
1417   QPen selectedPen() const { return mSelectedPen; }
1418   QBrush brush() const { return mBrush; }
1419   QBrush selectedBrush() const { return mSelectedBrush; }
1420   QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1421   QCPAxis *valueAxis() const { return mValueAxis.data(); }
1422   bool selectable() const { return mSelectable; }
1423   bool selected() const { return mSelected; }
1424   
1425   // setters:
1426   void setName(const QString &name);
1427   void setAntialiasedFill(bool enabled);
1428   void setAntialiasedScatters(bool enabled);
1429   void setAntialiasedErrorBars(bool enabled);
1430   void setPen(const QPen &pen);
1431   void setSelectedPen(const QPen &pen);
1432   void setBrush(const QBrush &brush);
1433   void setSelectedBrush(const QBrush &brush);
1434   void setKeyAxis(QCPAxis *axis);
1435   void setValueAxis(QCPAxis *axis);
1436   Q_SLOT void setSelectable(bool selectable);
1437   Q_SLOT void setSelected(bool selected);
1438
1439   // introduced virtual methods:
1440   virtual void clearData() = 0;
1441   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1442   virtual bool addToLegend();
1443   virtual bool removeFromLegend() const;
1444   
1445   // non-property methods:
1446   void rescaleAxes(bool onlyEnlarge=false) const;
1447   void rescaleKeyAxis(bool onlyEnlarge=false) const;
1448   void rescaleValueAxis(bool onlyEnlarge=false) const;
1449   
1450 signals:
1451   void selectionChanged(bool selected);
1452   void selectableChanged(bool selectable);
1453   
1454 protected:
1455   /*!
1456     Represents negative and positive sign domain for passing to \ref getKeyRange and \ref getValueRange.
1457   */
1458   enum SignDomain { sdNegative  ///< The negative sign domain, i.e. numbers smaller than zero
1459                     ,sdBoth     ///< Both sign domains, including zero, i.e. all (rational) numbers
1460                     ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
1461                   };
1462   
1463   // property members:
1464   QString mName;
1465   bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
1466   QPen mPen, mSelectedPen;
1467   QBrush mBrush, mSelectedBrush;
1468   QPointer<QCPAxis> mKeyAxis, mValueAxis;
1469   bool mSelectable, mSelected;
1470   
1471   // reimplemented virtual methods:
1472   virtual QRect clipRect() const;
1473   virtual void draw(QCPPainter *painter) = 0;
1474   virtual QCP::Interaction selectionCategory() const;
1475   void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1476   // events:
1477   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1478   virtual void deselectEvent(bool *selectionStateChanged);
1479   
1480   // introduced virtual methods:
1481   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
1482   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1483   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1484   
1485   // non-virtual methods:
1486   void coordsToPixels(double key, double value, double &x, double &y) const;
1487   const QPointF coordsToPixels(double key, double value) const;
1488   void pixelsToCoords(double x, double y, double &key, double &value) const;
1489   void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
1490   QPen mainPen() const;
1491   QBrush mainBrush() const;
1492   void applyFillAntialiasingHint(QCPPainter *painter) const;
1493   void applyScattersAntialiasingHint(QCPPainter *painter) const;
1494   void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
1495   double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1496
1497 private:
1498   Q_DISABLE_COPY(QCPAbstractPlottable)
1499   
1500   friend class QCustomPlot;
1501   friend class QCPAxis;
1502   friend class QCPPlottableLegendItem;
1503 };
1504
1505
1506 class QCP_LIB_DECL QCPItemAnchor
1507 {
1508 public:
1509   QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
1510   virtual ~QCPItemAnchor();
1511   
1512   // getters:
1513   QString name() const { return mName; }
1514   virtual QPointF pixelPoint() const;
1515   
1516 protected:
1517   // property members:
1518   QString mName;
1519   
1520   // non-property members:
1521   QCustomPlot *mParentPlot;
1522   QCPAbstractItem *mParentItem;
1523   int mAnchorId;
1524   QSet<QCPItemPosition*> mChildrenX, mChildrenY;
1525   
1526   // introduced virtual methods:
1527   virtual QCPItemPosition *toQCPItemPosition() { return 0; }
1528   
1529   // non-virtual methods:
1530   void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1531   void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1532   void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1533   void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1534   
1535 private:
1536   Q_DISABLE_COPY(QCPItemAnchor)
1537   
1538   friend class QCPItemPosition;
1539 };
1540
1541
1542
1543 class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
1544 {
1545 public:
1546   /*!
1547     Defines the ways an item position can be specified. Thus it defines what the numbers passed to
1548     \ref setCoords actually mean.
1549     
1550     \see setType
1551   */
1552   enum PositionType { ptAbsolute        ///< Static positioning in pixels, starting from the top left corner of the viewport/widget.
1553                       ,ptViewportRatio  ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top
1554                                         ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
1555                                         ///< vertically at the top of the viewport/widget, etc.
1556                       ,ptAxisRectRatio  ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top
1557                                         ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
1558                                         ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1.
1559                       ,ptPlotCoords     ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes).
1560                     };
1561   
1562   QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
1563   virtual ~QCPItemPosition();
1564   
1565   // getters:
1566   PositionType type() const { return typeX(); }
1567   PositionType typeX() const { return mPositionTypeX; }
1568   PositionType typeY() const { return mPositionTypeY; }
1569   QCPItemAnchor *parentAnchor() const { return parentAnchorX(); }
1570   QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; }
1571   QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; }
1572   double key() const { return mKey; }
1573   double value() const { return mValue; }
1574   QPointF coords() const { return QPointF(mKey, mValue); }
1575   QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1576   QCPAxis *valueAxis() const { return mValueAxis.data(); }
1577   QCPAxisRect *axisRect() const;
1578   virtual QPointF pixelPoint() const;
1579   
1580   // setters:
1581   void setType(PositionType type);
1582   void setTypeX(PositionType type);
1583   void setTypeY(PositionType type);
1584   bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1585   bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1586   bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1587   void setCoords(double key, double value);
1588   void setCoords(const QPointF &coords);
1589   void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
1590   void setAxisRect(QCPAxisRect *axisRect);
1591   void setPixelPoint(const QPointF &pixelPoint);
1592   
1593 protected:
1594   // property members:
1595   PositionType mPositionTypeX, mPositionTypeY;
1596   QPointer<QCPAxis> mKeyAxis, mValueAxis;
1597   QPointer<QCPAxisRect> mAxisRect;
1598   double mKey, mValue;
1599   QCPItemAnchor *mParentAnchorX, *mParentAnchorY;
1600   
1601   // reimplemented virtual methods:
1602   virtual QCPItemPosition *toQCPItemPosition() { return this; }
1603   
1604 private:
1605   Q_DISABLE_COPY(QCPItemPosition)
1606   
1607 };
1608
1609
1610 class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
1611 {
1612   Q_OBJECT
1613   /// \cond INCLUDE_QPROPERTIES
1614   Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
1615   Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
1616   Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1617   Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1618   /// \endcond
1619 public:
1620   QCPAbstractItem(QCustomPlot *parentPlot);
1621   virtual ~QCPAbstractItem();
1622   
1623   // getters:
1624   bool clipToAxisRect() const { return mClipToAxisRect; }
1625   QCPAxisRect *clipAxisRect() const;
1626   bool selectable() const { return mSelectable; }
1627   bool selected() const { return mSelected; }
1628   
1629   // setters:
1630   void setClipToAxisRect(bool clip);
1631   void setClipAxisRect(QCPAxisRect *rect);
1632   Q_SLOT void setSelectable(bool selectable);
1633   Q_SLOT void setSelected(bool selected);
1634   
1635   // reimplemented virtual methods:
1636   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1637   
1638   // non-virtual methods:
1639   QList<QCPItemPosition*> positions() const { return mPositions; }
1640   QList<QCPItemAnchor*> anchors() const { return mAnchors; }
1641   QCPItemPosition *position(const QString &name) const;
1642   QCPItemAnchor *anchor(const QString &name) const;
1643   bool hasAnchor(const QString &name) const;
1644   
1645 signals:
1646   void selectionChanged(bool selected);
1647   void selectableChanged(bool selectable);
1648   
1649 protected:
1650   // property members:
1651   bool mClipToAxisRect;
1652   QPointer<QCPAxisRect> mClipAxisRect;
1653   QList<QCPItemPosition*> mPositions;
1654   QList<QCPItemAnchor*> mAnchors;
1655   bool mSelectable, mSelected;
1656   
1657   // reimplemented virtual methods:
1658   virtual QCP::Interaction selectionCategory() const;
1659   virtual QRect clipRect() const;
1660   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1661   virtual void draw(QCPPainter *painter) = 0;
1662   // events:
1663   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1664   virtual void deselectEvent(bool *selectionStateChanged);
1665   
1666   // introduced virtual methods:
1667   virtual QPointF anchorPixelPoint(int anchorId) const;
1668   
1669   // non-virtual methods:
1670   double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1671   double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
1672   QCPItemPosition *createPosition(const QString &name);
1673   QCPItemAnchor *createAnchor(const QString &name, int anchorId);
1674   
1675 private:
1676   Q_DISABLE_COPY(QCPAbstractItem)
1677   
1678   friend class QCustomPlot;
1679   friend class QCPItemAnchor;
1680 };
1681
1682
1683 class QCP_LIB_DECL QCustomPlot : public QWidget
1684 {
1685   Q_OBJECT
1686   /// \cond INCLUDE_QPROPERTIES
1687   Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
1688   Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1689   Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1690   Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1691   Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
1692   Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
1693   Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
1694   Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
1695   Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
1696   /// \endcond
1697 public:
1698   /*!
1699     Defines how a layer should be inserted relative to an other layer.
1700
1701     \see addLayer, moveLayer
1702   */
1703   enum LayerInsertMode { limBelow  ///< Layer is inserted below other layer
1704                          ,limAbove ///< Layer is inserted above other layer
1705                        };
1706   Q_ENUMS(LayerInsertMode)
1707   
1708   /*!
1709     Defines with what timing the QCustomPlot surface is refreshed after a replot.
1710
1711     \see replot
1712   */
1713   enum RefreshPriority { rpImmediate ///< The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot
1714                          ,rpQueued   ///< Queues the refresh such that it is performed at a slightly delayed point in time after the replot, by calling QWidget::update() after the replot
1715                          ,rpHint     ///< Whether to use immediate repaint or queued update depends on whether the plotting hint \ref QCP::phForceRepaint is set, see \ref setPlottingHints.
1716                        };
1717   
1718   explicit QCustomPlot(QWidget *parent = 0);
1719   virtual ~QCustomPlot();
1720   
1721   // getters:
1722   QRect viewport() const { return mViewport; }
1723   QPixmap background() const { return mBackgroundPixmap; }
1724   bool backgroundScaled() const { return mBackgroundScaled; }
1725   Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1726   QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
1727   QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
1728   QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
1729   bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
1730   const QCP::Interactions interactions() const { return mInteractions; }
1731   int selectionTolerance() const { return mSelectionTolerance; }
1732   bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
1733   QCP::PlottingHints plottingHints() const { return mPlottingHints; }
1734   Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
1735
1736   // setters:
1737   void setViewport(const QRect &rect);
1738   void setBackground(const QPixmap &pm);
1739   void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
1740   void setBackground(const QBrush &brush);
1741   void setBackgroundScaled(bool scaled);
1742   void setBackgroundScaledMode(Qt::AspectRatioMode mode);
1743   void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
1744   void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
1745   void setNotAntialiasedElements(const QCP::AntialiasedElements &notAntialiasedElements);
1746   void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
1747   void setAutoAddPlottableToLegend(bool on);
1748   void setInteractions(const QCP::Interactions &interactions);
1749   void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
1750   void setSelectionTolerance(int pixels);
1751   void setNoAntialiasingOnDrag(bool enabled);
1752   void setPlottingHints(const QCP::PlottingHints &hints);
1753   void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
1754   void setMultiSelectModifier(Qt::KeyboardModifier modifier);
1755   
1756   // non-property methods:
1757   // plottable interface:
1758   QCPAbstractPlottable *plottable(int index);
1759   QCPAbstractPlottable *plottable();
1760   bool addPlottable(QCPAbstractPlottable *plottable);
1761   bool removePlottable(QCPAbstractPlottable *plottable);
1762   bool removePlottable(int index);
1763   int clearPlottables();
1764   int plottableCount() const;
1765   QList<QCPAbstractPlottable*> selectedPlottables() const;
1766   QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
1767   bool hasPlottable(QCPAbstractPlottable *plottable) const;
1768  
1769   // specialized interface for QCPGraph:
1770   QCPGraph *graph(int index) const;
1771   QCPGraph *graph() const;
1772   QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
1773   bool removeGraph(QCPGraph *graph);
1774   bool removeGraph(int index);
1775   int clearGraphs();
1776   int graphCount() const;
1777   QList<QCPGraph*> selectedGraphs() const;
1778
1779   // item interface:
1780   QCPAbstractItem *item(int index) const;
1781   QCPAbstractItem *item() const;
1782   bool addItem(QCPAbstractItem* item);
1783   bool removeItem(QCPAbstractItem *item);
1784   bool removeItem(int index);
1785   int clearItems();
1786   int itemCount() const;
1787   QList<QCPAbstractItem*> selectedItems() const;
1788   QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
1789   bool hasItem(QCPAbstractItem *item) const;
1790   
1791   // layer interface:
1792   QCPLayer *layer(const QString &name) const;
1793   QCPLayer *layer(int index) const;
1794   QCPLayer *currentLayer() const;
1795   bool setCurrentLayer(const QString &name);
1796   bool setCurrentLayer(QCPLayer *layer);
1797   int layerCount() const;
1798   bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
1799   bool removeLayer(QCPLayer *layer);
1800   bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
1801   
1802   // axis rect/layout interface:
1803   int axisRectCount() const;
1804   QCPAxisRect* axisRect(int index=0) const;
1805   QList<QCPAxisRect*> axisRects() const;
1806   QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
1807   Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
1808   
1809   QList<QCPAxis*> selectedAxes() const;
1810   QList<QCPLegend*> selectedLegends() const;
1811   Q_SLOT void deselectAll();
1812   
1813   bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0, const QString &pdfCreator=QString(), const QString &pdfTitle=QString());
1814   bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1815   bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1816   bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
1817   bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
1818   QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
1819   void toPainter(QCPPainter *painter, int width=0, int height=0);
1820   Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpHint);
1821   
1822   QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
1823   QCPLegend *legend;
1824   
1825 signals:
1826   void mouseDoubleClick(QMouseEvent *event);
1827   void mousePress(QMouseEvent *event);
1828   void mouseMove(QMouseEvent *event);
1829   void mouseRelease(QMouseEvent *event);
1830   void mouseWheel(QWheelEvent *event);
1831   
1832   void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1833   void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1834   void itemClick(QCPAbstractItem *item, QMouseEvent *event);
1835   void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
1836   void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1837   void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1838   void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1839   void legendDoubleClick(QCPLegend *legend,  QCPAbstractLegendItem *item, QMouseEvent *event);
1840   void titleClick(QMouseEvent *event, QCPPlotTitle *title);
1841   void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
1842   
1843   void selectionChangedByUser();
1844   void beforeReplot();
1845   void afterReplot();
1846   
1847 protected:
1848   // property members:
1849   QRect mViewport;
1850   QCPLayoutGrid *mPlotLayout;
1851   bool mAutoAddPlottableToLegend;
1852   QList<QCPAbstractPlottable*> mPlottables;
1853   QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
1854   QList<QCPAbstractItem*> mItems;
1855   QList<QCPLayer*> mLayers;
1856   QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
1857   QCP::Interactions mInteractions;
1858   int mSelectionTolerance;
1859   bool mNoAntialiasingOnDrag;
1860   QBrush mBackgroundBrush;
1861   QPixmap mBackgroundPixmap;
1862   QPixmap mScaledBackgroundPixmap;
1863   bool mBackgroundScaled;
1864   Qt::AspectRatioMode mBackgroundScaledMode;
1865   QCPLayer *mCurrentLayer;
1866   QCP::PlottingHints mPlottingHints;
1867   Qt::KeyboardModifier mMultiSelectModifier;
1868   
1869   // non-property members:
1870   QPixmap mPaintBuffer;
1871   QPoint mMousePressPos;
1872   QPointer<QCPLayoutElement> mMouseEventElement;
1873   bool mReplotting;
1874   
1875   // reimplemented virtual methods:
1876   virtual QSize minimumSizeHint() const;
1877   virtual QSize sizeHint() const;
1878   virtual void paintEvent(QPaintEvent *event);
1879   virtual void resizeEvent(QResizeEvent *event);
1880   virtual void mouseDoubleClickEvent(QMouseEvent *event);
1881   virtual void mousePressEvent(QMouseEvent *event);
1882   virtual void mouseMoveEvent(QMouseEvent *event);
1883   virtual void mouseReleaseEvent(QMouseEvent *event);
1884   virtual void wheelEvent(QWheelEvent *event);
1885   
1886   // introduced virtual methods:
1887   virtual void draw(QCPPainter *painter);
1888   virtual void axisRemoved(QCPAxis *axis);
1889   virtual void legendRemoved(QCPLegend *legend);
1890   
1891   // non-virtual methods:
1892   void updateLayerIndices() const;
1893   QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const;
1894   void drawBackground(QCPPainter *painter);
1895   
1896   friend class QCPLegend;
1897   friend class QCPAxis;
1898   friend class QCPLayer;
1899   friend class QCPAxisRect;
1900 };
1901
1902
1903 class QCP_LIB_DECL QCPColorGradient
1904 {
1905   Q_GADGET
1906 public:
1907   /*!
1908     Defines the color spaces in which color interpolation between gradient stops can be performed.
1909     
1910     \see setColorInterpolation
1911   */
1912   enum ColorInterpolation { ciRGB  ///< Color channels red, green and blue are linearly interpolated
1913                             ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)
1914                           };
1915   Q_ENUMS(ColorInterpolation)
1916   
1917   /*!
1918     Defines the available presets that can be loaded with \ref loadPreset. See the documentation
1919     there for an image of the presets.
1920   */
1921   enum GradientPreset { gpGrayscale  ///< Continuous lightness from black to white (suited for non-biased data representation)
1922                         ,gpHot       ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation)
1923                         ,gpCold      ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation)
1924                         ,gpNight     ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)
1925                         ,gpCandy     ///< Blue over pink to white
1926                         ,gpGeography ///< Colors suitable to represent different elevations on geographical maps
1927                         ,gpIon       ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)
1928                         ,gpThermal   ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white
1929                         ,gpPolar     ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values
1930                         ,gpSpectrum  ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)
1931                         ,gpJet       ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)
1932                         ,gpHues      ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic)
1933                       };
1934   Q_ENUMS(GradientPreset)
1935   
1936   QCPColorGradient(GradientPreset preset=gpCold);
1937   bool operator==(const QCPColorGradient &other) const;
1938   bool operator!=(const QCPColorGradient &other) const { return !(*this == other); }
1939   
1940   // getters:
1941   int levelCount() const { return mLevelCount; }
1942   QMap<double, QColor> colorStops() const { return mColorStops; }
1943   ColorInterpolation colorInterpolation() const { return mColorInterpolation; }
1944   bool periodic() const { return mPeriodic; }
1945   
1946   // setters:
1947   void setLevelCount(int n);
1948   void setColorStops(const QMap<double, QColor> &colorStops);
1949   void setColorStopAt(double position, const QColor &color);
1950   void setColorInterpolation(ColorInterpolation interpolation);
1951   void setPeriodic(bool enabled);
1952   
1953   // non-property methods:
1954   void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
1955   QRgb color(double position, const QCPRange &range, bool logarithmic=false);
1956   void loadPreset(GradientPreset preset);
1957   void clearColorStops();
1958   QCPColorGradient inverted() const;
1959   
1960 protected:
1961   void updateColorBuffer();
1962   
1963   // property members:
1964   int mLevelCount;
1965   QMap<double, QColor> mColorStops;
1966   ColorInterpolation mColorInterpolation;
1967   bool mPeriodic;
1968   
1969   // non-property members:
1970   QVector<QRgb> mColorBuffer;
1971   bool mColorBufferInvalidated;
1972 };
1973
1974
1975 class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
1976 {
1977   Q_OBJECT
1978   /// \cond INCLUDE_QPROPERTIES
1979   Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1980   Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1981   Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1982   Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
1983   Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
1984   /// \endcond
1985 public:
1986   explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
1987   virtual ~QCPAxisRect();
1988   
1989   // getters:
1990   QPixmap background() const { return mBackgroundPixmap; }
1991   bool backgroundScaled() const { return mBackgroundScaled; }
1992   Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1993   Qt::Orientations rangeDrag() const { return mRangeDrag; }
1994   Qt::Orientations rangeZoom() const { return mRangeZoom; }
1995   QCPAxis *rangeDragAxis(Qt::Orientation orientation);
1996   QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
1997   double rangeZoomFactor(Qt::Orientation orientation);
1998   
1999   // setters:
2000   void setBackground(const QPixmap &pm);
2001   void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
2002   void setBackground(const QBrush &brush);
2003   void setBackgroundScaled(bool scaled);
2004   void setBackgroundScaledMode(Qt::AspectRatioMode mode);
2005   void setRangeDrag(Qt::Orientations orientations);
2006   void setRangeZoom(Qt::Orientations orientations);
2007   void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
2008   void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
2009   void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
2010   void setRangeZoomFactor(double factor);
2011   
2012   // non-property methods:
2013   int axisCount(QCPAxis::AxisType type) const;
2014   QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
2015   QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
2016   QList<QCPAxis*> axes() const;
2017   QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0);
2018   QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
2019   bool removeAxis(QCPAxis *axis);
2020   QCPLayoutInset *insetLayout() const { return mInsetLayout; }
2021   
2022   void setupFullAxesBox(bool connectRanges=false);
2023   QList<QCPAbstractPlottable*> plottables() const;
2024   QList<QCPGraph*> graphs() const;
2025   QList<QCPAbstractItem*> items() const;
2026   
2027   // read-only interface imitating a QRect:
2028   int left() const { return mRect.left(); }
2029   int right() const { return mRect.right(); }
2030   int top() const { return mRect.top(); }
2031   int bottom() const { return mRect.bottom(); }
2032   int width() const { return mRect.width(); }
2033   int height() const { return mRect.height(); }
2034   QSize size() const { return mRect.size(); }
2035   QPoint topLeft() const { return mRect.topLeft(); }
2036   QPoint topRight() const { return mRect.topRight(); }
2037   QPoint bottomLeft() const { return mRect.bottomLeft(); }
2038   QPoint bottomRight() const { return mRect.bottomRight(); }
2039   QPoint center() const { return mRect.center(); }
2040   
2041   // reimplemented virtual methods:
2042   virtual void update(UpdatePhase phase);
2043   virtual QList<QCPLayoutElement*> elements(bool recursive) const;
2044
2045 protected:
2046   // property members:
2047   QBrush mBackgroundBrush;
2048   QPixmap mBackgroundPixmap;
2049   QPixmap mScaledBackgroundPixmap;
2050   bool mBackgroundScaled;
2051   Qt::AspectRatioMode mBackgroundScaledMode;
2052   QCPLayoutInset *mInsetLayout;
2053   Qt::Orientations mRangeDrag, mRangeZoom;
2054   QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
2055   double mRangeZoomFactorHorz, mRangeZoomFactorVert;
2056   // non-property members:
2057   QCPRange mDragStartHorzRange, mDragStartVertRange;
2058   QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
2059   QPoint mDragStart;
2060   bool mDragging;
2061   QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
2062   
2063   // reimplemented virtual methods:
2064   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2065   virtual void draw(QCPPainter *painter);
2066   virtual int calculateAutoMargin(QCP::MarginSide side);
2067   // events:
2068   virtual void mousePressEvent(QMouseEvent *event);
2069   virtual void mouseMoveEvent(QMouseEvent *event);
2070   virtual void mouseReleaseEvent(QMouseEvent *event);
2071   virtual void wheelEvent(QWheelEvent *event);
2072   
2073   // non-property methods:
2074   void drawBackground(QCPPainter *painter);
2075   void updateAxesOffset(QCPAxis::AxisType type);
2076   
2077 private:
2078   Q_DISABLE_COPY(QCPAxisRect)
2079   
2080   friend class QCustomPlot;
2081 };
2082
2083
2084 class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
2085 {
2086   Q_OBJECT
2087   /// \cond INCLUDE_QPROPERTIES
2088   Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
2089   Q_PROPERTY(QFont font READ font WRITE setFont)
2090   Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2091   Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2092   Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2093   Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged)
2094   Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged)
2095   /// \endcond
2096 public:
2097   explicit QCPAbstractLegendItem(QCPLegend *parent);
2098   
2099   // getters:
2100   QCPLegend *parentLegend() const { return mParentLegend; }
2101   QFont font() const { return mFont; }
2102   QColor textColor() const { return mTextColor; }
2103   QFont selectedFont() const { return mSelectedFont; }
2104   QColor selectedTextColor() const { return mSelectedTextColor; }
2105   bool selectable() const { return mSelectable; }
2106   bool selected() const { return mSelected; }
2107   
2108   // setters:
2109   void setFont(const QFont &font);
2110   void setTextColor(const QColor &color);
2111   void setSelectedFont(const QFont &font);
2112   void setSelectedTextColor(const QColor &color);
2113   Q_SLOT void setSelectable(bool selectable);
2114   Q_SLOT void setSelected(bool selected);
2115   
2116   // reimplemented virtual methods:
2117   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2118   
2119 signals:
2120   void selectionChanged(bool selected);
2121   void selectableChanged(bool selectable);
2122   
2123 protected:
2124   // property members:
2125   QCPLegend *mParentLegend;
2126   QFont mFont;
2127   QColor mTextColor;
2128   QFont mSelectedFont;
2129   QColor mSelectedTextColor;
2130   bool mSelectable, mSelected;
2131   
2132   // reimplemented virtual methods:
2133   virtual QCP::Interaction selectionCategory() const;
2134   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2135   virtual QRect clipRect() const;
2136   virtual void draw(QCPPainter *painter) = 0;
2137   // events:
2138   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2139   virtual void deselectEvent(bool *selectionStateChanged);
2140   
2141 private:
2142   Q_DISABLE_COPY(QCPAbstractLegendItem)
2143   
2144   friend class QCPLegend;
2145 };
2146
2147
2148 class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
2149 {
2150   Q_OBJECT
2151 public:
2152   QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
2153   
2154   // getters:
2155   QCPAbstractPlottable *plottable() { return mPlottable; }
2156   
2157 protected:
2158   // property members:
2159   QCPAbstractPlottable *mPlottable;
2160   
2161   // reimplemented virtual methods:
2162   virtual void draw(QCPPainter *painter);
2163   virtual QSize minimumSizeHint() const;
2164   
2165   // non-virtual methods:
2166   QPen getIconBorderPen() const;
2167   QColor getTextColor() const;
2168   QFont getFont() const;
2169 };
2170
2171
2172 class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
2173 {
2174   Q_OBJECT
2175   /// \cond INCLUDE_QPROPERTIES
2176   Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
2177   Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2178   Q_PROPERTY(QFont font READ font WRITE setFont)
2179   Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2180   Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
2181   Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
2182   Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
2183   Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged)
2184   Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged)
2185   Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
2186   Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
2187   Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2188   Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2189   Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2190   /// \endcond
2191 public:
2192   /*!
2193     Defines the selectable parts of a legend
2194     
2195     \see setSelectedParts, setSelectableParts
2196   */
2197   enum SelectablePart { spNone       = 0x000  ///< <tt>0x000</tt> None
2198                         ,spLegendBox  = 0x001 ///< <tt>0x001</tt> The legend box (frame)
2199                         ,spItems      = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems)
2200                       };
2201   Q_FLAGS(SelectablePart SelectableParts)
2202   Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
2203   
2204   explicit QCPLegend();
2205   virtual ~QCPLegend();
2206   
2207   // getters:
2208   QPen borderPen() const { return mBorderPen; }
2209   QBrush brush() const { return mBrush; }
2210   QFont font() const { return mFont; }
2211   QColor textColor() const { return mTextColor; }
2212   QSize iconSize() const { return mIconSize; }
2213   int iconTextPadding() const { return mIconTextPadding; }
2214   QPen iconBorderPen() const { return mIconBorderPen; }
2215   SelectableParts selectableParts() const { return mSelectableParts; }
2216   SelectableParts selectedParts() const;
2217   QPen selectedBorderPen() const { return mSelectedBorderPen; }
2218   QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
2219   QBrush selectedBrush() const { return mSelectedBrush; }
2220   QFont selectedFont() const { return mSelectedFont; }
2221   QColor selectedTextColor() const { return mSelectedTextColor; }
2222   
2223   // setters:
2224   void setBorderPen(const QPen &pen);
2225   void setBrush(const QBrush &brush);
2226   void setFont(const QFont &font);
2227   void setTextColor(const QColor &color);
2228   void setIconSize(const QSize &size);
2229   void setIconSize(int width, int height);
2230   void setIconTextPadding(int padding);
2231   void setIconBorderPen(const QPen &pen);
2232   Q_SLOT void setSelectableParts(const SelectableParts &selectableParts);
2233   Q_SLOT void setSelectedParts(const SelectableParts &selectedParts);
2234   void setSelectedBorderPen(const QPen &pen);
2235   void setSelectedIconBorderPen(const QPen &pen);
2236   void setSelectedBrush(const QBrush &brush);
2237   void setSelectedFont(const QFont &font);
2238   void setSelectedTextColor(const QColor &color);
2239   
2240   // reimplemented virtual methods:
2241   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2242   
2243   // non-virtual methods:
2244   QCPAbstractLegendItem *item(int index) const;
2245   QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
2246   int itemCount() const;
2247   bool hasItem(QCPAbstractLegendItem *item) const;
2248   bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
2249   bool addItem(QCPAbstractLegendItem *item);
2250   bool removeItem(int index);
2251   bool removeItem(QCPAbstractLegendItem *item);
2252   void clearItems();
2253   QList<QCPAbstractLegendItem*> selectedItems() const;
2254   
2255 signals:
2256   void selectionChanged(QCPLegend::SelectableParts parts);
2257   void selectableChanged(QCPLegend::SelectableParts parts);
2258   
2259 protected:
2260   // property members:
2261   QPen mBorderPen, mIconBorderPen;
2262   QBrush mBrush;
2263   QFont mFont;
2264   QColor mTextColor;
2265   QSize mIconSize;
2266   int mIconTextPadding;
2267   SelectableParts mSelectedParts, mSelectableParts;
2268   QPen mSelectedBorderPen, mSelectedIconBorderPen;
2269   QBrush mSelectedBrush;
2270   QFont mSelectedFont;
2271   QColor mSelectedTextColor;
2272   
2273   // reimplemented virtual methods:
2274   virtual void parentPlotInitialized(QCustomPlot *parentPlot);
2275   virtual QCP::Interaction selectionCategory() const;
2276   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2277   virtual void draw(QCPPainter *painter);
2278   // events:
2279   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2280   virtual void deselectEvent(bool *selectionStateChanged);
2281   
2282   // non-virtual methods:
2283   QPen getBorderPen() const;
2284   QBrush getBrush() const;
2285   
2286 private:
2287   Q_DISABLE_COPY(QCPLegend)
2288   
2289   friend class QCustomPlot;
2290   friend class QCPAbstractLegendItem;
2291 };
2292 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
2293 Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
2294
2295
2296 class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
2297 {
2298   Q_OBJECT
2299   /// \cond INCLUDE_QPROPERTIES
2300   Q_PROPERTY(QString text READ text WRITE setText)
2301   Q_PROPERTY(QFont font READ font WRITE setFont)
2302   Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2303   Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2304   Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2305   Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
2306   Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
2307   /// \endcond
2308 public:
2309   explicit QCPPlotTitle(QCustomPlot *parentPlot);
2310   explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text);
2311   
2312   // getters:
2313   QString text() const { return mText; }
2314   QFont font() const { return mFont; }
2315   QColor textColor() const { return mTextColor; }
2316   QFont selectedFont() const { return mSelectedFont; }
2317   QColor selectedTextColor() const { return mSelectedTextColor; }
2318   bool selectable() const { return mSelectable; }
2319   bool selected() const { return mSelected; }
2320   
2321   // setters:
2322   void setText(const QString &text);
2323   void setFont(const QFont &font);
2324   void setTextColor(const QColor &color);
2325   void setSelectedFont(const QFont &font);
2326   void setSelectedTextColor(const QColor &color);
2327   Q_SLOT void setSelectable(bool selectable);
2328   Q_SLOT void setSelected(bool selected);
2329   
2330   // reimplemented virtual methods:
2331   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2332   
2333 signals:
2334   void selectionChanged(bool selected);
2335   void selectableChanged(bool selectable);
2336   
2337 protected:
2338   // property members:
2339   QString mText;
2340   QFont mFont;
2341   QColor mTextColor;
2342   QFont mSelectedFont;
2343   QColor mSelectedTextColor;
2344   QRect mTextBoundingRect;
2345   bool mSelectable, mSelected;
2346   
2347   // reimplemented virtual methods:
2348   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2349   virtual void draw(QCPPainter *painter);
2350   virtual QSize minimumSizeHint() const;
2351   virtual QSize maximumSizeHint() const;
2352   // events:
2353   virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2354   virtual void deselectEvent(bool *selectionStateChanged);
2355   
2356   // non-virtual methods:
2357   QFont mainFont() const;
2358   QColor mainTextColor() const;
2359   
2360 private:
2361   Q_DISABLE_COPY(QCPPlotTitle)
2362 };
2363
2364
2365 class QCPColorScaleAxisRectPrivate : public QCPAxisRect
2366 {
2367   Q_OBJECT
2368 public:
2369   explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale);
2370 protected:
2371   QCPColorScale *mParentColorScale;
2372   QImage mGradientImage;
2373   bool mGradientImageInvalidated;
2374   // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
2375   using QCPAxisRect::calculateAutoMargin;
2376   using QCPAxisRect::mousePressEvent;
2377   using QCPAxisRect::mouseMoveEvent;
2378   using QCPAxisRect::mouseReleaseEvent;
2379   using QCPAxisRect::wheelEvent;
2380   using QCPAxisRect::update;
2381   virtual void draw(QCPPainter *painter);
2382   void updateGradientImage();
2383   Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
2384   Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
2385   friend class QCPColorScale;
2386 };
2387
2388
2389 class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
2390 {
2391   Q_OBJECT
2392   /// \cond INCLUDE_QPROPERTIES
2393   Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
2394   Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
2395   Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
2396   Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
2397   Q_PROPERTY(QString label READ label WRITE setLabel)
2398   Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
2399   Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
2400   Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
2401   /// \endcond
2402 public:
2403   explicit QCPColorScale(QCustomPlot *parentPlot);
2404   virtual ~QCPColorScale();
2405   
2406   // getters:
2407   QCPAxis *axis() const { return mColorAxis.data(); }
2408   QCPAxis::AxisType type() const { return mType; }
2409   QCPRange dataRange() const { return mDataRange; }
2410   QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
2411   QCPColorGradient gradient() const { return mGradient; }
2412   QString label() const;
2413   int barWidth () const { return mBarWidth; }
2414   bool rangeDrag() const;
2415   bool rangeZoom() const;
2416   
2417   // setters:
2418   void setType(QCPAxis::AxisType type);
2419   Q_SLOT void setDataRange(const QCPRange &dataRange);
2420   Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
2421   Q_SLOT void setGradient(const QCPColorGradient &gradient);
2422   void setLabel(const QString &str);
2423   void setBarWidth(int width);
2424   void setRangeDrag(bool enabled);
2425   void setRangeZoom(bool enabled);
2426   
2427   // non-property methods:
2428   QList<QCPColorMap*> colorMaps() const;
2429   void rescaleDataRange(bool onlyVisibleMaps);
2430   
2431   // reimplemented virtual methods:
2432   virtual void update(UpdatePhase phase);
2433   
2434 signals:
2435   void dataRangeChanged(QCPRange newRange);
2436   void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
2437   void gradientChanged(QCPColorGradient newGradient);
2438
2439 protected:
2440   // property members:
2441   QCPAxis::AxisType mType;
2442   QCPRange mDataRange;
2443   QCPAxis::ScaleType mDataScaleType;
2444   QCPColorGradient mGradient;
2445   int mBarWidth;
2446   
2447   // non-property members:
2448   QPointer<QCPColorScaleAxisRectPrivate> mAxisRect;
2449   QPointer<QCPAxis> mColorAxis;
2450   
2451   // reimplemented virtual methods:
2452   virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2453   // events:
2454   virtual void mousePressEvent(QMouseEvent *event);
2455   virtual void mouseMoveEvent(QMouseEvent *event);
2456   virtual void mouseReleaseEvent(QMouseEvent *event);
2457   virtual void wheelEvent(QWheelEvent *event);
2458   
2459 private:
2460   Q_DISABLE_COPY(QCPColorScale)
2461   
2462   friend class QCPColorScaleAxisRectPrivate;
2463 };
2464
2465
2466 /*! \file */
2467
2468
2469
2470 class QCP_LIB_DECL QCPData
2471 {
2472 public:
2473   QCPData();
2474   QCPData(double key, double value);
2475   double key, value;
2476   double keyErrorPlus, keyErrorMinus;
2477   double valueErrorPlus, valueErrorMinus;
2478 };
2479 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
2480
2481 /*! \typedef QCPDataMap
2482   Container for storing \ref QCPData items in a sorted fashion. The key of the map
2483   is the key member of the QCPData instance.
2484   
2485   This is the container in which QCPGraph holds its data.
2486   \see QCPData, QCPGraph::setData
2487 */
2488 typedef QMap<double, QCPData> QCPDataMap;
2489 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
2490 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
2491
2492
2493 class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
2494 {
2495   Q_OBJECT
2496   /// \cond INCLUDE_QPROPERTIES
2497   Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2498   Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2499   Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
2500   Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
2501   Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
2502   Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
2503   Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
2504   Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling)
2505   /// \endcond
2506 public:
2507   /*!
2508     Defines how the graph's line is represented visually in the plot. The line is drawn with the
2509     current pen of the graph (\ref setPen).
2510     \see setLineStyle
2511   */
2512   enum LineStyle { lsNone        ///< data points are not connected with any lines (e.g. data only represented
2513                                  ///< with symbols according to the scatter style, see \ref setScatterStyle)
2514                    ,lsLine       ///< data points are connected by a straight line
2515                    ,lsStepLeft   ///< line is drawn as steps where the step height is the value of the left data point
2516                    ,lsStepRight  ///< line is drawn as steps where the step height is the value of the right data point
2517                    ,lsStepCenter ///< line is drawn as steps where the step is in between two data points
2518                    ,lsImpulse    ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line
2519                  };
2520   Q_ENUMS(LineStyle)
2521   /*!
2522     Defines what kind of error bars are drawn for each data point
2523   */
2524   enum ErrorType { etNone   ///< No error bars are shown
2525                    ,etKey   ///< Error bars for the key dimension of the data point are shown
2526                    ,etValue ///< Error bars for the value dimension of the data point are shown
2527                    ,etBoth  ///< Error bars for both key and value dimensions of the data point are shown
2528                  };
2529   Q_ENUMS(ErrorType)
2530   
2531   explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
2532   virtual ~QCPGraph();
2533   
2534   // getters:
2535   QCPDataMap *data() const { return mData; }
2536   LineStyle lineStyle() const { return mLineStyle; }
2537   QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2538   ErrorType errorType() const { return mErrorType; }
2539   QPen errorPen() const { return mErrorPen; }
2540   double errorBarSize() const { return mErrorBarSize; }
2541   bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
2542   QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
2543   bool adaptiveSampling() const { return mAdaptiveSampling; }
2544   
2545   // setters:
2546   void setData(QCPDataMap *data, bool copy=false);
2547   void setData(const QVector<double> &key, const QVector<double> &value);
2548   void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
2549   void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
2550   void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
2551   void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
2552   void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
2553   void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
2554   void setLineStyle(LineStyle ls);
2555   void setScatterStyle(const QCPScatterStyle &style);
2556   void setErrorType(ErrorType errorType);
2557   void setErrorPen(const QPen &pen);
2558   void setErrorBarSize(double size);
2559   void setErrorBarSkipSymbol(bool enabled);
2560   void setChannelFillGraph(QCPGraph *targetGraph);
2561   void setAdaptiveSampling(bool enabled);
2562   
2563   // non-property methods:
2564   void addData(const QCPDataMap &dataMap);
2565   void addData(const QCPData &data);
2566   void addData(double key, double value);
2567   void addData(const QVector<double> &keys, const QVector<double> &values);
2568   void removeDataBefore(double key);
2569   void removeDataAfter(double key);
2570   void removeData(double fromKey, double toKey);
2571   void removeData(double key);
2572   
2573   // reimplemented virtual methods:
2574   virtual void clearData();
2575   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2576   using QCPAbstractPlottable::rescaleAxes;
2577   using QCPAbstractPlottable::rescaleKeyAxis;
2578   using QCPAbstractPlottable::rescaleValueAxis;
2579   void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2580   void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2581   void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2582   
2583 protected:
2584   // property members:
2585   QCPDataMap *mData;
2586   QPen mErrorPen;
2587   LineStyle mLineStyle;
2588   QCPScatterStyle mScatterStyle;
2589   ErrorType mErrorType;
2590   double mErrorBarSize;
2591   bool mErrorBarSkipSymbol;
2592   QPointer<QCPGraph> mChannelFillGraph;
2593   bool mAdaptiveSampling;
2594   
2595   // reimplemented virtual methods:
2596   virtual void draw(QCPPainter *painter);
2597   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2598   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2599   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2600   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2601   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2602   
2603   // introduced virtual methods:
2604   virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
2605   virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *scatterData) const;
2606   virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
2607   virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
2608   
2609   // non-virtual methods:
2610   void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const;
2611   void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const;
2612   void getScatterPlotData(QVector<QCPData> *scatterData) const;
2613   void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2614   void getStepLeftPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2615   void getStepRightPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2616   void getStepCenterPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2617   void getImpulsePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2618   void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
2619   void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper) const;
2620   int countDataInBounds(const QCPDataMap::const_iterator &lower, const QCPDataMap::const_iterator &upper, int maxCount) const;
2621   void addFillBasePoints(QVector<QPointF> *lineData) const;
2622   void removeFillBasePoints(QVector<QPointF> *lineData) const;
2623   QPointF lowerFillBasePoint(double lowerKey) const;
2624   QPointF upperFillBasePoint(double upperKey) const;
2625   const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
2626   int findIndexBelowX(const QVector<QPointF> *data, double x) const;
2627   int findIndexAboveX(const QVector<QPointF> *data, double x) const;
2628   int findIndexBelowY(const QVector<QPointF> *data, double y) const;
2629   int findIndexAboveY(const QVector<QPointF> *data, double y) const;
2630   double pointDistance(const QPointF &pixelPoint) const;
2631   
2632   friend class QCustomPlot;
2633   friend class QCPLegend;
2634 };
2635
2636
2637 /*! \file */
2638
2639
2640
2641 class QCP_LIB_DECL QCPCurveData
2642 {
2643 public:
2644   QCPCurveData();
2645   QCPCurveData(double t, double key, double value);
2646   double t, key, value;
2647 };
2648 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
2649
2650 /*! \typedef QCPCurveDataMap
2651   Container for storing \ref QCPCurveData items in a sorted fashion. The key of the map
2652   is the t member of the QCPCurveData instance.
2653   
2654   This is the container in which QCPCurve holds its data.
2655   \see QCPCurveData, QCPCurve::setData
2656 */
2657
2658 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
2659 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
2660 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
2661
2662
2663 class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
2664 {
2665   Q_OBJECT
2666   /// \cond INCLUDE_QPROPERTIES
2667   Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2668   Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2669   /// \endcond
2670 public:
2671   /*!
2672     Defines how the curve's line is represented visually in the plot. The line is drawn with the
2673     current pen of the curve (\ref setPen).
2674     \see setLineStyle
2675   */
2676   enum LineStyle { lsNone  ///< No line is drawn between data points (e.g. only scatters)
2677                    ,lsLine ///< Data points are connected with a straight line
2678                  };
2679   explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
2680   virtual ~QCPCurve();
2681   
2682   // getters:
2683   QCPCurveDataMap *data() const { return mData; }
2684   QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2685   LineStyle lineStyle() const { return mLineStyle; }
2686   
2687   // setters:
2688   void setData(QCPCurveDataMap *data, bool copy=false);
2689   void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
2690   void setData(const QVector<double> &key, const QVector<double> &value);
2691   void setScatterStyle(const QCPScatterStyle &style);
2692   void setLineStyle(LineStyle style);
2693   
2694   // non-property methods:
2695   void addData(const QCPCurveDataMap &dataMap);
2696   void addData(const QCPCurveData &data);
2697   void addData(double t, double key, double value);
2698   void addData(double key, double value);
2699   void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
2700   void removeDataBefore(double t);
2701   void removeDataAfter(double t);
2702   void removeData(double fromt, double tot);
2703   void removeData(double t);
2704   
2705   // reimplemented virtual methods:
2706   virtual void clearData();
2707   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2708   
2709 protected:
2710   // property members:
2711   QCPCurveDataMap *mData;
2712   QCPScatterStyle mScatterStyle;
2713   LineStyle mLineStyle;
2714   
2715   // reimplemented virtual methods:
2716   virtual void draw(QCPPainter *painter);
2717   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2718   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2719   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2720   
2721   // introduced virtual methods:
2722   virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
2723   
2724   // non-virtual methods:
2725   void getCurveData(QVector<QPointF> *lineData) const;
2726   int getRegion(double x, double y, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2727   QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2728   QVector<QPointF> getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2729   bool mayTraverse(int prevRegion, int currentRegion) const;
2730   bool getTraverse(double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom, QPointF &crossA, QPointF &crossB) const;
2731   void getTraverseCornerPoints(int prevRegion, int currentRegion, double rectLeft, double rectTop, double rectRight, double rectBottom, QVector<QPointF> &beforeTraverse, QVector<QPointF> &afterTraverse) const;
2732   double pointDistance(const QPointF &pixelPoint) const;
2733   
2734   friend class QCustomPlot;
2735   friend class QCPLegend;
2736 };
2737
2738
2739 /*! \file */
2740
2741
2742
2743 class QCP_LIB_DECL QCPBarsGroup : public QObject
2744 {
2745   Q_OBJECT
2746   /// \cond INCLUDE_QPROPERTIES
2747   Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType)
2748   Q_PROPERTY(double spacing READ spacing WRITE setSpacing)
2749   /// \endcond
2750 public:
2751   /*!
2752     Defines the ways the spacing between bars in the group can be specified. Thus it defines what
2753     the number passed to \ref setSpacing actually means.
2754     
2755     \see setSpacingType, setSpacing
2756   */
2757   enum SpacingType { stAbsolute       ///< Bar spacing is in absolute pixels
2758                      ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size
2759                      ,stPlotCoords    ///< Bar spacing is in key coordinates and thus scales with the key axis range
2760                  };
2761   QCPBarsGroup(QCustomPlot *parentPlot);
2762   ~QCPBarsGroup();
2763   
2764   // getters:
2765   SpacingType spacingType() const { return mSpacingType; }
2766   double spacing() const { return mSpacing; }
2767   
2768   // setters:
2769   void setSpacingType(SpacingType spacingType);
2770   void setSpacing(double spacing);
2771   
2772   // non-virtual methods:
2773   QList<QCPBars*> bars() const { return mBars; }
2774   QCPBars* bars(int index) const;
2775   int size() const { return mBars.size(); }
2776   bool isEmpty() const { return mBars.isEmpty(); }
2777   void clear();
2778   bool contains(QCPBars *bars) const { return mBars.contains(bars); }
2779   void append(QCPBars *bars);
2780   void insert(int i, QCPBars *bars);
2781   void remove(QCPBars *bars);
2782   
2783 protected:
2784   // non-property members:
2785   QCustomPlot *mParentPlot;
2786   SpacingType mSpacingType;
2787   double mSpacing;
2788   QList<QCPBars*> mBars;
2789   
2790   // non-virtual methods:
2791   void registerBars(QCPBars *bars);
2792   void unregisterBars(QCPBars *bars);
2793   
2794   // virtual methods:
2795   double keyPixelOffset(const QCPBars *bars, double keyCoord);
2796   double getPixelSpacing(const QCPBars *bars, double keyCoord);
2797   
2798 private:
2799   Q_DISABLE_COPY(QCPBarsGroup)
2800   
2801   friend class QCPBars;
2802 };
2803
2804
2805 class QCP_LIB_DECL QCPBarData
2806 {
2807 public:
2808   QCPBarData();
2809   QCPBarData(double key, double value);
2810   double key, value;
2811 };
2812 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
2813
2814 /*! \typedef QCPBarDataMap
2815   Container for storing \ref QCPBarData items in a sorted fashion. The key of the map
2816   is the key member of the QCPBarData instance.
2817   
2818   This is the container in which QCPBars holds its data.
2819   \see QCPBarData, QCPBars::setData
2820 */
2821 typedef QMap<double, QCPBarData> QCPBarDataMap;
2822 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
2823 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
2824
2825
2826 class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
2827 {
2828   Q_OBJECT
2829   /// \cond INCLUDE_QPROPERTIES
2830   Q_PROPERTY(double width READ width WRITE setWidth)
2831   Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType)
2832   Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup)
2833   Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue)
2834   Q_PROPERTY(QCPBars* barBelow READ barBelow)
2835   Q_PROPERTY(QCPBars* barAbove READ barAbove)
2836   /// \endcond
2837 public:
2838   /*!
2839     Defines the ways the width of the bar can be specified. Thus it defines what the number passed
2840     to \ref setWidth actually means.
2841     
2842     \see setWidthType, setWidth
2843   */
2844   enum WidthType { wtAbsolute       ///< Bar width is in absolute pixels
2845                    ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size
2846                    ,wtPlotCoords    ///< Bar width is in key coordinates and thus scales with the key axis range
2847                  };
2848    Q_ENUMS(WidthType)
2849   
2850   explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
2851   virtual ~QCPBars();
2852   
2853   // getters:
2854   double width() const { return mWidth; }
2855   WidthType widthType() const { return mWidthType; }
2856   QCPBarsGroup *barsGroup() const { return mBarsGroup; }
2857   double baseValue() const { return mBaseValue; }
2858   QCPBars *barBelow() const { return mBarBelow.data(); }
2859   QCPBars *barAbove() const { return mBarAbove.data(); }
2860   QCPBarDataMap *data() const { return mData; }
2861   
2862   // setters:
2863   void setWidth(double width);
2864   void setWidthType(WidthType widthType);
2865   void setBarsGroup(QCPBarsGroup *barsGroup);
2866   void setBaseValue(double baseValue);
2867   void setData(QCPBarDataMap *data, bool copy=false);
2868   void setData(const QVector<double> &key, const QVector<double> &value);
2869   
2870   // non-property methods:
2871   void moveBelow(QCPBars *bars);
2872   void moveAbove(QCPBars *bars);
2873   void addData(const QCPBarDataMap &dataMap);
2874   void addData(const QCPBarData &data);
2875   void addData(double key, double value);
2876   void addData(const QVector<double> &keys, const QVector<double> &values);
2877   void removeDataBefore(double key);
2878   void removeDataAfter(double key);
2879   void removeData(double fromKey, double toKey);
2880   void removeData(double key);
2881   
2882   // reimplemented virtual methods:
2883   virtual void clearData();
2884   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2885   
2886 protected:
2887   // property members:
2888   QCPBarDataMap *mData;
2889   double mWidth;
2890   WidthType mWidthType;
2891   QCPBarsGroup *mBarsGroup;
2892   double mBaseValue;
2893   QPointer<QCPBars> mBarBelow, mBarAbove;
2894   
2895   // reimplemented virtual methods:
2896   virtual void draw(QCPPainter *painter);
2897   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2898   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2899   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2900   
2901   // non-virtual methods:
2902   void getVisibleDataBounds(QCPBarDataMap::const_iterator &lower, QCPBarDataMap::const_iterator &upperEnd) const;
2903   QPolygonF getBarPolygon(double key, double value) const;
2904   void getPixelWidth(double key, double &lower, double &upper) const;
2905   double getStackedBaseValue(double key, bool positive) const;
2906   static void connectBars(QCPBars* lower, QCPBars* upper);
2907   
2908   friend class QCustomPlot;
2909   friend class QCPLegend;
2910   friend class QCPBarsGroup;
2911 };
2912
2913
2914 /*! \file */
2915
2916
2917
2918 class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
2919 {
2920   Q_OBJECT
2921   /// \cond INCLUDE_QPROPERTIES
2922   Q_PROPERTY(double key READ key WRITE setKey)
2923   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
2924   Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
2925   Q_PROPERTY(double median READ median WRITE setMedian)
2926   Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
2927   Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
2928   Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers)
2929   Q_PROPERTY(double width READ width WRITE setWidth)
2930   Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
2931   Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
2932   Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
2933   Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
2934   Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
2935   /// \endcond
2936 public:
2937   explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
2938   
2939   // getters:
2940   double key() const { return mKey; }
2941   double minimum() const { return mMinimum; }
2942   double lowerQuartile() const { return mLowerQuartile; }
2943   double median() const { return mMedian; }
2944   double upperQuartile() const { return mUpperQuartile; }
2945   double maximum() const { return mMaximum; }
2946   QVector<double> outliers() const { return mOutliers; }
2947   double width() const { return mWidth; }
2948   double whiskerWidth() const { return mWhiskerWidth; }
2949   QPen whiskerPen() const { return mWhiskerPen; }
2950   QPen whiskerBarPen() const { return mWhiskerBarPen; }
2951   QPen medianPen() const { return mMedianPen; }
2952   QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
2953
2954   // setters:
2955   void setKey(double key);
2956   void setMinimum(double value);
2957   void setLowerQuartile(double value);
2958   void setMedian(double value);
2959   void setUpperQuartile(double value);
2960   void setMaximum(double value);
2961   void setOutliers(const QVector<double> &values);
2962   void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
2963   void setWidth(double width);
2964   void setWhiskerWidth(double width);
2965   void setWhiskerPen(const QPen &pen);
2966   void setWhiskerBarPen(const QPen &pen);
2967   void setMedianPen(const QPen &pen);
2968   void setOutlierStyle(const QCPScatterStyle &style);
2969   
2970   // non-property methods:
2971   virtual void clearData();
2972   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2973   
2974 protected:
2975   // property members:
2976   QVector<double> mOutliers;
2977   double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
2978   double mWidth;
2979   double mWhiskerWidth;
2980   QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
2981   QCPScatterStyle mOutlierStyle;
2982   
2983   // reimplemented virtual methods:
2984   virtual void draw(QCPPainter *painter);
2985   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2986   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2987   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2988   
2989   // introduced virtual methods:
2990   virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
2991   virtual void drawMedian(QCPPainter *painter) const;
2992   virtual void drawWhiskers(QCPPainter *painter) const;
2993   virtual void drawOutliers(QCPPainter *painter) const;
2994   
2995   friend class QCustomPlot;
2996   friend class QCPLegend;
2997 };
2998
2999
3000 class QCP_LIB_DECL QCPColorMapData
3001 {
3002 public:
3003   QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange);
3004   ~QCPColorMapData();
3005   QCPColorMapData(const QCPColorMapData &other);
3006   QCPColorMapData &operator=(const QCPColorMapData &other);
3007   
3008   // getters:
3009   int keySize() const { return mKeySize; }
3010   int valueSize() const { return mValueSize; }
3011   QCPRange keyRange() const { return mKeyRange; }
3012   QCPRange valueRange() const { return mValueRange; }
3013   QCPRange dataBounds() const { return mDataBounds; }
3014   double data(double key, double value);
3015   double cell(int keyIndex, int valueIndex);
3016   
3017   // setters:
3018   void setSize(int keySize, int valueSize);
3019   void setKeySize(int keySize);
3020   void setValueSize(int valueSize);
3021   void setRange(const QCPRange &keyRange, const QCPRange &valueRange);
3022   void setKeyRange(const QCPRange &keyRange);
3023   void setValueRange(const QCPRange &valueRange);
3024   void setData(double key, double value, double z);
3025   void setCell(int keyIndex, int valueIndex, double z);
3026   
3027   // non-property methods:
3028   void recalculateDataBounds();
3029   void clear();
3030   void fill(double z);
3031   bool isEmpty() const { return mIsEmpty; }
3032   void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const;
3033   void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const;
3034   
3035 protected:
3036   // property members:
3037   int mKeySize, mValueSize;
3038   QCPRange mKeyRange, mValueRange;
3039   bool mIsEmpty;
3040   // non-property members:
3041   double *mData;
3042   QCPRange mDataBounds;
3043   bool mDataModified;
3044   
3045   friend class QCPColorMap;
3046 };
3047
3048
3049 class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
3050 {
3051   Q_OBJECT
3052   /// \cond INCLUDE_QPROPERTIES
3053   Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
3054   Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
3055   Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
3056   Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
3057   Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
3058   Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
3059   /// \endcond
3060 public:
3061   explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis);
3062   virtual ~QCPColorMap();
3063   
3064   // getters:
3065   QCPColorMapData *data() const { return mMapData; }
3066   QCPRange dataRange() const { return mDataRange; }
3067   QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
3068   bool interpolate() const { return mInterpolate; }
3069   bool tightBoundary() const { return mTightBoundary; }
3070   QCPColorGradient gradient() const { return mGradient; }
3071   QCPColorScale *colorScale() const { return mColorScale.data(); }
3072   
3073   // setters:
3074   void setData(QCPColorMapData *data, bool copy=false);
3075   Q_SLOT void setDataRange(const QCPRange &dataRange);
3076   Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
3077   Q_SLOT void setGradient(const QCPColorGradient &gradient);
3078   void setInterpolate(bool enabled);
3079   void setTightBoundary(bool enabled);
3080   void setColorScale(QCPColorScale *colorScale);
3081   
3082   // non-property methods:
3083   void rescaleDataRange(bool recalculateDataBounds=false);
3084   Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18));
3085   
3086   // reimplemented virtual methods:
3087   virtual void clearData();
3088   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3089   
3090 signals:
3091   void dataRangeChanged(QCPRange newRange);
3092   void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
3093   void gradientChanged(QCPColorGradient newGradient);
3094   
3095 protected:
3096   // property members:
3097   QCPRange mDataRange;
3098   QCPAxis::ScaleType mDataScaleType;
3099   QCPColorMapData *mMapData;
3100   QCPColorGradient mGradient;
3101   bool mInterpolate;
3102   bool mTightBoundary;
3103   QPointer<QCPColorScale> mColorScale;
3104   // non-property members:
3105   QImage mMapImage, mUndersampledMapImage;
3106   QPixmap mLegendIcon;
3107   bool mMapImageInvalidated;
3108   
3109   // introduced virtual methods:
3110   virtual void updateMapImage();
3111   
3112   // reimplemented virtual methods:
3113   virtual void draw(QCPPainter *painter);
3114   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
3115   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3116   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3117   
3118   friend class QCustomPlot;
3119   friend class QCPLegend;
3120 };
3121
3122
3123 /*! \file */
3124
3125
3126
3127 class QCP_LIB_DECL QCPFinancialData
3128 {
3129 public:
3130   QCPFinancialData();
3131   QCPFinancialData(double key, double open, double high, double low, double close);
3132   double key, open, high, low, close;
3133 };
3134 Q_DECLARE_TYPEINFO(QCPFinancialData, Q_MOVABLE_TYPE);
3135
3136 /*! \typedef QCPFinancialDataMap
3137   Container for storing \ref QCPFinancialData items in a sorted fashion. The key of the map
3138   is the key member of the QCPFinancialData instance.
3139   
3140   This is the container in which QCPFinancial holds its data.
3141   \see QCPFinancial, QCPFinancial::setData
3142 */
3143 typedef QMap<double, QCPFinancialData> QCPFinancialDataMap;
3144 typedef QMapIterator<double, QCPFinancialData> QCPFinancialDataMapIterator;
3145 typedef QMutableMapIterator<double, QCPFinancialData> QCPFinancialDataMutableMapIterator;
3146
3147
3148 class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable
3149 {
3150   Q_OBJECT
3151   /// \cond INCLUDE_QPROPERTIES
3152   Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle)
3153   Q_PROPERTY(double width READ width WRITE setWidth)
3154   Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored)
3155   Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive)
3156   Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative)
3157   Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive)
3158   Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative)
3159   /// \endcond
3160 public:
3161   /*!
3162     Defines the possible representations of OHLC data in the plot.
3163     
3164     \see setChartStyle
3165   */
3166   enum ChartStyle { csOhlc         ///< Open-High-Low-Close bar representation
3167                    ,csCandlestick  ///< Candlestick representation
3168                   };
3169   Q_ENUMS(ChartStyle)
3170   
3171   explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis);
3172   virtual ~QCPFinancial();
3173   
3174   // getters:
3175   QCPFinancialDataMap *data() const { return mData; }
3176   ChartStyle chartStyle() const { return mChartStyle; }
3177   double width() const { return mWidth; }
3178   bool twoColored() const { return mTwoColored; }
3179   QBrush brushPositive() const { return mBrushPositive; }
3180   QBrush brushNegative() const { return mBrushNegative; }
3181   QPen penPositive() const { return mPenPositive; }
3182   QPen penNegative() const { return mPenNegative; }
3183   
3184   
3185   // setters:
3186   void setData(QCPFinancialDataMap *data, bool copy=false);
3187   void setData(const QVector<double> &key, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close);
3188   void setChartStyle(ChartStyle style);
3189   void setWidth(double width);
3190   void setTwoColored(bool twoColored);
3191   void setBrushPositive(const QBrush &brush);
3192   void setBrushNegative(const QBrush &brush);
3193   void setPenPositive(const QPen &pen);
3194   void setPenNegative(const QPen &pen);
3195   
3196   // non-property methods:
3197   void addData(const QCPFinancialDataMap &dataMap);
3198   void addData(const QCPFinancialData &data);
3199   void addData(double key, double open, double high, double low, double close);
3200   void addData(const QVector<double> &key, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close);
3201   void removeDataBefore(double key);
3202   void removeDataAfter(double key);
3203   void removeData(double fromKey, double toKey);
3204   void removeData(double key);
3205   
3206   // reimplemented virtual methods:
3207   virtual void clearData();
3208   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3209   
3210   // static methods:
3211   static QCPFinancialDataMap timeSeriesToOhlc(const QVector<double> &time, const QVector<double> &value, double timeBinSize, double timeBinOffset = 0);
3212   
3213 protected:
3214   // property members:
3215   QCPFinancialDataMap *mData;
3216   ChartStyle mChartStyle;
3217   double mWidth;
3218   bool mTwoColored;
3219   QBrush mBrushPositive, mBrushNegative;
3220   QPen mPenPositive, mPenNegative;
3221   
3222   // reimplemented virtual methods:
3223   virtual void draw(QCPPainter *painter);
3224   virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
3225   virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3226   virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3227   
3228   // non-virtual methods:
3229   void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end);
3230   void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end);
3231   double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end) const;
3232   double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end) const;
3233   void getVisibleDataBounds(QCPFinancialDataMap::const_iterator &lower, QCPFinancialDataMap::const_iterator &upper) const;
3234   
3235   friend class QCustomPlot;
3236   friend class QCPLegend;
3237 };
3238
3239
3240 class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
3241 {
3242   Q_OBJECT
3243   /// \cond INCLUDE_QPROPERTIES
3244   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3245   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3246   /// \endcond
3247 public:
3248   QCPItemStraightLine(QCustomPlot *parentPlot);
3249   virtual ~QCPItemStraightLine();
3250   
3251   // getters:
3252   QPen pen() const { return mPen; }
3253   QPen selectedPen() const { return mSelectedPen; }
3254   
3255   // setters;
3256   void setPen(const QPen &pen);
3257   void setSelectedPen(const QPen &pen);
3258   
3259   // reimplemented virtual methods:
3260   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3261   
3262   QCPItemPosition * const point1;
3263   QCPItemPosition * const point2;
3264   
3265 protected:
3266   // property members:
3267   QPen mPen, mSelectedPen;
3268   
3269   // reimplemented virtual methods:
3270   virtual void draw(QCPPainter *painter);
3271   
3272   // non-virtual methods:
3273   double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
3274   QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
3275   QPen mainPen() const;
3276 };
3277
3278
3279 class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
3280 {
3281   Q_OBJECT
3282   /// \cond INCLUDE_QPROPERTIES
3283   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3284   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3285   Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3286   Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3287   /// \endcond
3288 public:
3289   QCPItemLine(QCustomPlot *parentPlot);
3290   virtual ~QCPItemLine();
3291   
3292   // getters:
3293   QPen pen() const { return mPen; }
3294   QPen selectedPen() const { return mSelectedPen; }
3295   QCPLineEnding head() const { return mHead; }
3296   QCPLineEnding tail() const { return mTail; }
3297   
3298   // setters;
3299   void setPen(const QPen &pen);
3300   void setSelectedPen(const QPen &pen);
3301   void setHead(const QCPLineEnding &head);
3302   void setTail(const QCPLineEnding &tail);
3303   
3304   // reimplemented virtual methods:
3305   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3306   
3307   QCPItemPosition * const start;
3308   QCPItemPosition * const end;
3309   
3310 protected:
3311   // property members:
3312   QPen mPen, mSelectedPen;
3313   QCPLineEnding mHead, mTail;
3314   
3315   // reimplemented virtual methods:
3316   virtual void draw(QCPPainter *painter);
3317   
3318   // non-virtual methods:
3319   QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
3320   QPen mainPen() const;
3321 };
3322
3323
3324 class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
3325 {
3326   Q_OBJECT
3327   /// \cond INCLUDE_QPROPERTIES
3328   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3329   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3330   Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3331   Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3332   /// \endcond
3333 public:
3334   QCPItemCurve(QCustomPlot *parentPlot);
3335   virtual ~QCPItemCurve();
3336   
3337   // getters:
3338   QPen pen() const { return mPen; }
3339   QPen selectedPen() const { return mSelectedPen; }
3340   QCPLineEnding head() const { return mHead; }
3341   QCPLineEnding tail() const { return mTail; }
3342   
3343   // setters;
3344   void setPen(const QPen &pen);
3345   void setSelectedPen(const QPen &pen);
3346   void setHead(const QCPLineEnding &head);
3347   void setTail(const QCPLineEnding &tail);
3348   
3349   // reimplemented virtual methods:
3350   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3351   
3352   QCPItemPosition * const start;
3353   QCPItemPosition * const startDir;
3354   QCPItemPosition * const endDir;
3355   QCPItemPosition * const end;
3356   
3357 protected:
3358   // property members:
3359   QPen mPen, mSelectedPen;
3360   QCPLineEnding mHead, mTail;
3361   
3362   // reimplemented virtual methods:
3363   virtual void draw(QCPPainter *painter);
3364   
3365   // non-virtual methods:
3366   QPen mainPen() const;
3367 };
3368
3369
3370 class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
3371 {
3372   Q_OBJECT
3373   /// \cond INCLUDE_QPROPERTIES
3374   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3375   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3376   Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3377   Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3378   /// \endcond
3379 public:
3380   QCPItemRect(QCustomPlot *parentPlot);
3381   virtual ~QCPItemRect();
3382   
3383   // getters:
3384   QPen pen() const { return mPen; }
3385   QPen selectedPen() const { return mSelectedPen; }
3386   QBrush brush() const { return mBrush; }
3387   QBrush selectedBrush() const { return mSelectedBrush; }
3388   
3389   // setters;
3390   void setPen(const QPen &pen);
3391   void setSelectedPen(const QPen &pen);
3392   void setBrush(const QBrush &brush);
3393   void setSelectedBrush(const QBrush &brush);
3394   
3395   // reimplemented virtual methods:
3396   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3397   
3398   QCPItemPosition * const topLeft;
3399   QCPItemPosition * const bottomRight;
3400   QCPItemAnchor * const top;
3401   QCPItemAnchor * const topRight;
3402   QCPItemAnchor * const right;
3403   QCPItemAnchor * const bottom;
3404   QCPItemAnchor * const bottomLeft;
3405   QCPItemAnchor * const left;
3406   
3407 protected:
3408   enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3409   
3410   // property members:
3411   QPen mPen, mSelectedPen;
3412   QBrush mBrush, mSelectedBrush;
3413   
3414   // reimplemented virtual methods:
3415   virtual void draw(QCPPainter *painter);
3416   virtual QPointF anchorPixelPoint(int anchorId) const;
3417   
3418   // non-virtual methods:
3419   QPen mainPen() const;
3420   QBrush mainBrush() const;
3421 };
3422
3423
3424 class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
3425 {
3426   Q_OBJECT
3427   /// \cond INCLUDE_QPROPERTIES
3428   Q_PROPERTY(QColor color READ color WRITE setColor)
3429   Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
3430   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3431   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3432   Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3433   Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3434   Q_PROPERTY(QFont font READ font WRITE setFont)
3435   Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
3436   Q_PROPERTY(QString text READ text WRITE setText)
3437   Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
3438   Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
3439   Q_PROPERTY(double rotation READ rotation WRITE setRotation)
3440   Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
3441   /// \endcond
3442 public:
3443   QCPItemText(QCustomPlot *parentPlot);
3444   virtual ~QCPItemText();
3445   
3446   // getters:
3447   QColor color() const { return mColor; }
3448   QColor selectedColor() const { return mSelectedColor; }
3449   QPen pen() const { return mPen; }
3450   QPen selectedPen() const { return mSelectedPen; }
3451   QBrush brush() const { return mBrush; }
3452   QBrush selectedBrush() const { return mSelectedBrush; }
3453   QFont font() const { return mFont; }
3454   QFont selectedFont() const { return mSelectedFont; }
3455   QString text() const { return mText; }
3456   Qt::Alignment positionAlignment() const { return mPositionAlignment; }
3457   Qt::Alignment textAlignment() const { return mTextAlignment; }
3458   double rotation() const { return mRotation; }
3459   QMargins padding() const { return mPadding; }
3460   
3461   // setters;
3462   void setColor(const QColor &color);
3463   void setSelectedColor(const QColor &color);
3464   void setPen(const QPen &pen);
3465   void setSelectedPen(const QPen &pen);
3466   void setBrush(const QBrush &brush);
3467   void setSelectedBrush(const QBrush &brush);
3468   void setFont(const QFont &font);
3469   void setSelectedFont(const QFont &font);
3470   void setText(const QString &text);
3471   void setPositionAlignment(Qt::Alignment alignment);
3472   void setTextAlignment(Qt::Alignment alignment);
3473   void setRotation(double degrees);
3474   void setPadding(const QMargins &padding);
3475   
3476   // reimplemented virtual methods:
3477   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3478   
3479   QCPItemPosition * const position;
3480   QCPItemAnchor * const topLeft;
3481   QCPItemAnchor * const top;
3482   QCPItemAnchor * const topRight;
3483   QCPItemAnchor * const right;
3484   QCPItemAnchor * const bottomRight;
3485   QCPItemAnchor * const bottom;
3486   QCPItemAnchor * const bottomLeft;
3487   QCPItemAnchor * const left;
3488   
3489 protected:
3490   enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
3491   
3492   // property members:
3493   QColor mColor, mSelectedColor;
3494   QPen mPen, mSelectedPen;
3495   QBrush mBrush, mSelectedBrush;
3496   QFont mFont, mSelectedFont;
3497   QString mText;
3498   Qt::Alignment mPositionAlignment;
3499   Qt::Alignment mTextAlignment;
3500   double mRotation;
3501   QMargins mPadding;
3502   
3503   // reimplemented virtual methods:
3504   virtual void draw(QCPPainter *painter);
3505   virtual QPointF anchorPixelPoint(int anchorId) const;
3506   
3507   // non-virtual methods:
3508   QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
3509   QFont mainFont() const;
3510   QColor mainColor() const;
3511   QPen mainPen() const;
3512   QBrush mainBrush() const;
3513 };
3514
3515
3516 class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
3517 {
3518   Q_OBJECT
3519   /// \cond INCLUDE_QPROPERTIES
3520   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3521   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3522   Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3523   Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3524   /// \endcond
3525 public:
3526   QCPItemEllipse(QCustomPlot *parentPlot);
3527   virtual ~QCPItemEllipse();
3528   
3529   // getters:
3530   QPen pen() const { return mPen; }
3531   QPen selectedPen() const { return mSelectedPen; }
3532   QBrush brush() const { return mBrush; }
3533   QBrush selectedBrush() const { return mSelectedBrush; }
3534   
3535   // setters;
3536   void setPen(const QPen &pen);
3537   void setSelectedPen(const QPen &pen);
3538   void setBrush(const QBrush &brush);
3539   void setSelectedBrush(const QBrush &brush);
3540   
3541   // reimplemented virtual methods:
3542   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3543   
3544   QCPItemPosition * const topLeft;
3545   QCPItemPosition * const bottomRight;
3546   QCPItemAnchor * const topLeftRim;
3547   QCPItemAnchor * const top;
3548   QCPItemAnchor * const topRightRim;
3549   QCPItemAnchor * const right;
3550   QCPItemAnchor * const bottomRightRim;
3551   QCPItemAnchor * const bottom;
3552   QCPItemAnchor * const bottomLeftRim;
3553   QCPItemAnchor * const left;
3554   QCPItemAnchor * const center;
3555   
3556 protected:
3557   enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
3558   
3559   // property members:
3560   QPen mPen, mSelectedPen;
3561   QBrush mBrush, mSelectedBrush;
3562   
3563   // reimplemented virtual methods:
3564   virtual void draw(QCPPainter *painter);
3565   virtual QPointF anchorPixelPoint(int anchorId) const;
3566   
3567   // non-virtual methods:
3568   QPen mainPen() const;
3569   QBrush mainBrush() const;
3570 };
3571
3572
3573 class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
3574 {
3575   Q_OBJECT
3576   /// \cond INCLUDE_QPROPERTIES
3577   Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
3578   Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
3579   Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
3580   Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode)
3581   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3582   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3583   /// \endcond
3584 public:
3585   QCPItemPixmap(QCustomPlot *parentPlot);
3586   virtual ~QCPItemPixmap();
3587   
3588   // getters:
3589   QPixmap pixmap() const { return mPixmap; }
3590   bool scaled() const { return mScaled; }
3591   Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
3592   Qt::TransformationMode transformationMode() const { return mTransformationMode; }
3593   QPen pen() const { return mPen; }
3594   QPen selectedPen() const { return mSelectedPen; }
3595   
3596   // setters;
3597   void setPixmap(const QPixmap &pixmap);
3598   void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation);
3599   void setPen(const QPen &pen);
3600   void setSelectedPen(const QPen &pen);
3601   
3602   // reimplemented virtual methods:
3603   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3604   
3605   QCPItemPosition * const topLeft;
3606   QCPItemPosition * const bottomRight;
3607   QCPItemAnchor * const top;
3608   QCPItemAnchor * const topRight;
3609   QCPItemAnchor * const right;
3610   QCPItemAnchor * const bottom;
3611   QCPItemAnchor * const bottomLeft;
3612   QCPItemAnchor * const left;
3613   
3614 protected:
3615   enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3616   
3617   // property members:
3618   QPixmap mPixmap;
3619   QPixmap mScaledPixmap;
3620   bool mScaled;
3621   bool mScaledPixmapInvalidated;
3622   Qt::AspectRatioMode mAspectRatioMode;
3623   Qt::TransformationMode mTransformationMode;
3624   QPen mPen, mSelectedPen;
3625   
3626   // reimplemented virtual methods:
3627   virtual void draw(QCPPainter *painter);
3628   virtual QPointF anchorPixelPoint(int anchorId) const;
3629   
3630   // non-virtual methods:
3631   void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
3632   QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
3633   QPen mainPen() const;
3634 };
3635
3636
3637 class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
3638 {
3639   Q_OBJECT
3640   /// \cond INCLUDE_QPROPERTIES
3641   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3642   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3643   Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3644   Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3645   Q_PROPERTY(double size READ size WRITE setSize)
3646   Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
3647   Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
3648   Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
3649   Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
3650   /// \endcond
3651 public:
3652   /*!
3653     The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize.
3654     
3655     \see setStyle
3656   */
3657   enum TracerStyle { tsNone        ///< The tracer is not visible
3658                      ,tsPlus       ///< A plus shaped crosshair with limited size
3659                      ,tsCrosshair  ///< A plus shaped crosshair which spans the complete axis rect
3660                      ,tsCircle     ///< A circle
3661                      ,tsSquare     ///< A square
3662                    };
3663   Q_ENUMS(TracerStyle)
3664
3665   QCPItemTracer(QCustomPlot *parentPlot);
3666   virtual ~QCPItemTracer();
3667
3668   // getters:
3669   QPen pen() const { return mPen; }
3670   QPen selectedPen() const { return mSelectedPen; }
3671   QBrush brush() const { return mBrush; }
3672   QBrush selectedBrush() const { return mSelectedBrush; }
3673   double size() const { return mSize; }
3674   TracerStyle style() const { return mStyle; }
3675   QCPGraph *graph() const { return mGraph; }
3676   double graphKey() const { return mGraphKey; }
3677   bool interpolating() const { return mInterpolating; }
3678
3679   // setters;
3680   void setPen(const QPen &pen);
3681   void setSelectedPen(const QPen &pen);
3682   void setBrush(const QBrush &brush);
3683   void setSelectedBrush(const QBrush &brush);
3684   void setSize(double size);
3685   void setStyle(TracerStyle style);
3686   void setGraph(QCPGraph *graph);
3687   void setGraphKey(double key);
3688   void setInterpolating(bool enabled);
3689
3690   // reimplemented virtual methods:
3691   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3692   
3693   // non-virtual methods:
3694   void updatePosition();
3695
3696   QCPItemPosition * const position;
3697
3698 protected:
3699   // property members:
3700   QPen mPen, mSelectedPen;
3701   QBrush mBrush, mSelectedBrush;
3702   double mSize;
3703   TracerStyle mStyle;
3704   QCPGraph *mGraph;
3705   double mGraphKey;
3706   bool mInterpolating;
3707
3708   // reimplemented virtual methods:
3709   virtual void draw(QCPPainter *painter);
3710
3711   // non-virtual methods:
3712   QPen mainPen() const;
3713   QBrush mainBrush() const;
3714 };
3715
3716
3717 class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
3718 {
3719   Q_OBJECT
3720   /// \cond INCLUDE_QPROPERTIES
3721   Q_PROPERTY(QPen pen READ pen WRITE setPen)
3722   Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3723   Q_PROPERTY(double length READ length WRITE setLength)
3724   Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
3725   /// \endcond
3726 public:
3727   enum BracketStyle { bsSquare  ///< A brace with angled edges
3728                       ,bsRound  ///< A brace with round edges
3729                       ,bsCurly  ///< A curly brace
3730                       ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
3731   };
3732
3733   QCPItemBracket(QCustomPlot *parentPlot);
3734   virtual ~QCPItemBracket();
3735   
3736   // getters:
3737   QPen pen() const { return mPen; }
3738   QPen selectedPen() const { return mSelectedPen; }
3739   double length() const { return mLength; }
3740   BracketStyle style() const { return mStyle; }
3741   
3742   // setters;
3743   void setPen(const QPen &pen);
3744   void setSelectedPen(const QPen &pen);
3745   void setLength(double length);
3746   void setStyle(BracketStyle style);
3747   
3748   // reimplemented virtual methods:
3749   virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3750   
3751   QCPItemPosition * const left;
3752   QCPItemPosition * const right;
3753   QCPItemAnchor * const center;
3754   
3755 protected:
3756   // property members:
3757   enum AnchorIndex {aiCenter};
3758   QPen mPen, mSelectedPen;
3759   double mLength;
3760   BracketStyle mStyle;
3761   
3762   // reimplemented virtual methods:
3763   virtual void draw(QCPPainter *painter);
3764   virtual QPointF anchorPixelPoint(int anchorId) const;
3765   
3766   // non-virtual methods:
3767   QPen mainPen() const;
3768 };
3769
3770 #endif // QCUSTOMPLOT_H
3771