My Project
qcustomplot.h
Ir a la documentación de este archivo.
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 04.11.13 **
23 ** Version: 1.1.0 **
24 ****************************************************************************/
25 
26 #ifndef 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 #else
52 # include <QtNumeric>
53 # include <QtPrintSupport>
54 #endif
55 
56 class QCPPainter;
57 class QCustomPlot;
58 class QCPLayerable;
59 class QCPLayoutElement;
60 class QCPLayout;
61 class QCPAxis;
62 class QCPAxisRect;
64 class QCPGraph;
65 class QCPAbstractItem;
66 class QCPItemPosition;
67 class QCPLayer;
68 class QCPPlotTitle;
69 class QCPLegend;
71 
72 
76 // decl definitions for shared library compilation/usage:
77 #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
78 # define QCP_LIB_DECL Q_DECL_EXPORT
79 #elif defined(QCUSTOMPLOT_USE_LIBRARY)
80 # define QCP_LIB_DECL Q_DECL_IMPORT
81 #else
82 # define QCP_LIB_DECL
83 #endif
84 
88 namespace QCP
89 {
95 enum MarginSide { msLeft = 0x01
96  ,msRight = 0x02
97  ,msTop = 0x04
98  ,msBottom = 0x08
99  ,msAll = 0xFF
100  ,msNone = 0x00
101  };
102 Q_DECLARE_FLAGS(MarginSides, MarginSide)
103 
104 
113 enum AntialiasedElement { aeAxes = 0x0001
114  ,aeGrid = 0x0002
115  ,aeSubGrid = 0x0004
116  ,aeLegend = 0x0008
117  ,aeLegendItems = 0x0010
118  ,aePlottables = 0x0020
119  ,aeItems = 0x0040
120  ,aeScatters = 0x0080
121  ,aeErrorBars = 0x0100
122  ,aeFills = 0x0200
123  ,aeZeroLine = 0x0400
124  ,aeAll = 0xFFFF
125  ,aeNone = 0x0000
126  };
127 Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
128 
129 
134 enum PlottingHint { phNone = 0x000
135  ,phFastPolylines = 0x001
136  ,phForceRepaint = 0x002
138  ,phCacheLabels = 0x004
140  };
141 Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
142 
143 
150 enum Interaction { iRangeDrag = 0x001
151  ,iRangeZoom = 0x002
152  ,iMultiSelect = 0x004
154  ,iSelectAxes = 0x010
155  ,iSelectLegend = 0x020
156  ,iSelectItems = 0x040
157  ,iSelectOther = 0x080
158  };
159 Q_DECLARE_FLAGS(Interactions, Interaction)
160 
161 
167 inline bool isInvalidData(double value)
168 {
169  return qIsNaN(value) || qIsInf(value);
170 }
171 
177 inline bool isInvalidData(double value1, double value2)
178 {
179  return isInvalidData(value1) || isInvalidData(value2);
180 }
181 
188 inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
189 {
190  switch (side)
191  {
192  case QCP::msLeft: margins.setLeft(value); break;
193  case QCP::msRight: margins.setRight(value); break;
194  case QCP::msTop: margins.setTop(value); break;
195  case QCP::msBottom: margins.setBottom(value); break;
196  case QCP::msAll: margins = QMargins(value, value, value, value); break;
197  default: break;
198  }
199 }
200 
208 inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
209 {
210  switch (side)
211  {
212  case QCP::msLeft: return margins.left();
213  case QCP::msRight: return margins.right();
214  case QCP::msTop: return margins.top();
215  case QCP::msBottom: return margins.bottom();
216  default: break;
217  }
218  return 0;
219 }
220 
221 } // end of namespace QCP
222 
223 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
224 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
225 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
226 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
227 
228 
229 class QCP_LIB_DECL QCPScatterStyle
230 {
231  Q_GADGET
232 public:
240  Q_ENUMS(ScatterShape)
241  enum ScatterShape { ssNone
242  ,ssDot
243  ,ssCross
244  ,ssPlus
245  ,ssCircle
246  ,ssDisc
247  ,ssSquare
248  ,ssDiamond
249  ,ssStar
250  ,ssTriangle
251  ,ssTriangleInverted
252  ,ssCrossSquare
253  ,ssPlusSquare
254  ,ssCrossCircle
255  ,ssPlusCircle
256  ,ssPeace
257  ,ssPixmap
258  ,ssCustom
259  };
260 
261  QCPScatterStyle();
262  QCPScatterStyle(ScatterShape shape, double size=6);
263  QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
264  QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
265  QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
266  QCPScatterStyle(const QPixmap &pixmap);
267  QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
268 
269  // getters:
270  double size() const { return mSize; }
271  ScatterShape shape() const { return mShape; }
272  QPen pen() const { return mPen; }
273  QBrush brush() const { return mBrush; }
274  QPixmap pixmap() const { return mPixmap; }
275  QPainterPath customPath() const { return mCustomPath; }
276 
277  // setters:
278  void setSize(double size);
279  void setShape(ScatterShape shape);
280  void setPen(const QPen &pen);
281  void setBrush(const QBrush &brush);
282  void setPixmap(const QPixmap &pixmap);
283  void setCustomPath(const QPainterPath &customPath);
284 
285  // non-property methods:
286  bool isNone() const { return mShape == ssNone; }
287  bool isPenDefined() const { return mPenDefined; }
288  void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
289  void drawShape(QCPPainter *painter, QPointF pos) const;
290  void drawShape(QCPPainter *painter, double x, double y) const;
291 
292 protected:
293  // property members:
294  double mSize;
295  ScatterShape mShape;
296  QPen mPen;
297  QBrush mBrush;
298  QPixmap mPixmap;
299  QPainterPath mCustomPath;
300 
301  // non-property members:
302  bool mPenDefined;
303 };
304 Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
305 
306 
307 class QCP_LIB_DECL QCPPainter : public QPainter
308 {
309  Q_GADGET
310 public:
315  enum PainterMode {pmDefault = 0x00
316  ,pmVectorized = 0x01
317  ,pmNoCaching = 0x02
318  ,pmNonCosmetic = 0x04
319  };
320  Q_FLAGS(PainterMode PainterModes)
321  Q_DECLARE_FLAGS(PainterModes, PainterMode)
322 
323  QCPPainter();
324  QCPPainter(QPaintDevice *device);
325  ~QCPPainter();
326 
327  // getters:
328  bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
329  PainterModes modes() const { return mModes; }
330 
331  // setters:
332  void setAntialiasing(bool enabled);
333  void setMode(PainterMode mode, bool enabled=true);
334  void setModes(PainterModes modes);
335 
336  // methods hiding non-virtual base class functions (QPainter bug workarounds):
337  bool begin(QPaintDevice *device);
338  void setPen(const QPen &pen);
339  void setPen(const QColor &color);
340  void setPen(Qt::PenStyle penStyle);
341  void drawLine(const QLineF &line);
342  void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
343  void save();
344  void restore();
345 
346  // non-virtual methods:
347  void makeNonCosmetic();
348 
349 protected:
350  // property members:
351  PainterModes mModes;
352  bool mIsAntialiasing;
353 
354  // non-property members:
355  QStack<bool> mAntialiasingStack;
356 };
357 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
358 
359 
360 class QCP_LIB_DECL QCPLayer : public QObject
361 {
362  Q_OBJECT
364  Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
365  Q_PROPERTY(QString name READ name)
366  Q_PROPERTY(int index READ index)
367  Q_PROPERTY(QList<QCPLayerable*> children READ children)
369 public:
370  QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
371  ~QCPLayer();
372 
373  // getters:
374  QCustomPlot *parentPlot() const { return mParentPlot; }
375  QString name() const { return mName; }
376  int index() const { return mIndex; }
377  QList<QCPLayerable*> children() const { return mChildren; }
378 
379 protected:
380  // property members:
381  QCustomPlot *mParentPlot;
382  QString mName;
383  int mIndex;
384  QList<QCPLayerable*> mChildren;
385 
386  // non-virtual methods:
387  void addChild(QCPLayerable *layerable, bool prepend);
388  void removeChild(QCPLayerable *layerable);
389 
390 private:
391  Q_DISABLE_COPY(QCPLayer)
392 
393  friend class QCustomPlot;
394  friend class QCPLayerable;
395 };
396 
397 class QCP_LIB_DECL QCPLayerable : public QObject
398 {
399  Q_OBJECT
401  Q_PROPERTY(bool visible READ visible WRITE setVisible)
402  Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
403  Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
404  Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer)
405  Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
407 public:
408  QCPLayerable(QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0);
409  ~QCPLayerable();
410 
411  // getters:
412  bool visible() const { return mVisible; }
413  QCustomPlot *parentPlot() const { return mParentPlot; }
414  QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
415  QCPLayer *layer() const { return mLayer; }
416  bool antialiased() const { return mAntialiased; }
417 
418  // setters:
419  void setVisible(bool on);
420  bool setLayer(QCPLayer *layer);
421  bool setLayer(const QString &layerName);
422  void setAntialiased(bool enabled);
423 
424  // introduced virtual methods:
425  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
426 
427  // non-property methods:
428  bool realVisibility() const;
429 
430 protected:
431  // property members:
432  bool mVisible;
433  QCustomPlot *mParentPlot;
434  QPointer<QCPLayerable> mParentLayerable;
435  QCPLayer *mLayer;
436  bool mAntialiased;
437 
438  // introduced virtual methods:
439  virtual void parentPlotInitialized(QCustomPlot *parentPlot);
440  virtual QCP::Interaction selectionCategory() const;
441  virtual QRect clipRect() const;
442  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
443  virtual void draw(QCPPainter *painter) = 0;
444  // events:
445  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
446  virtual void deselectEvent(bool *selectionStateChanged);
447 
448  // non-property methods:
449  void initializeParentPlot(QCustomPlot *parentPlot);
450  void setParentLayerable(QCPLayerable* parentLayerable);
451  bool moveToLayer(QCPLayer *layer, bool prepend);
452  void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
453 
454 private:
455  Q_DISABLE_COPY(QCPLayerable)
456 
457  friend class QCustomPlot;
458  friend class QCPAxisRect;
459 };
460 
461 
462 class QCP_LIB_DECL QCPRange
463 {
464 public:
465  double lower, upper;
466 
467  QCPRange();
468  QCPRange(double lower, double upper);
469 
470  double size() const;
471  double center() const;
472  void normalize();
473  void expand(const QCPRange &otherRange);
474  QCPRange expanded(const QCPRange &otherRange) const;
475  QCPRange sanitizedForLogScale() const;
476  QCPRange sanitizedForLinScale() const;
477  bool contains(double value) const;
478 
479  static bool validRange(double lower, double upper);
480  static bool validRange(const QCPRange &range);
481  static const double minRange; //1e-280;
482  static const double maxRange; //1e280;
483 };
484 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
485 
486 
487 class QCP_LIB_DECL QCPMarginGroup : public QObject
488 {
489  Q_OBJECT
490 public:
491  QCPMarginGroup(QCustomPlot *parentPlot);
492  ~QCPMarginGroup();
493 
494  // non-virtual methods:
495  QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
496  bool isEmpty() const;
497  void clear();
498 
499 protected:
500  // non-property members:
501  QCustomPlot *mParentPlot;
502  QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
503 
504  // non-virtual methods:
505  int commonMargin(QCP::MarginSide side) const;
506  void addChild(QCP::MarginSide side, QCPLayoutElement *element);
507  void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
508 
509 private:
510  Q_DISABLE_COPY(QCPMarginGroup)
511 
512  friend class QCPLayoutElement;
513 };
514 
515 
516 class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
517 {
518  Q_OBJECT
520  Q_PROPERTY(QCPLayout* layout READ layout)
521  Q_PROPERTY(QRect rect READ rect)
522  Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
523  Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
524  Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
525  Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
526  Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
528 public:
529  explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
530  virtual ~QCPLayoutElement();
531 
532  // getters:
533  QCPLayout *layout() const { return mParentLayout; }
534  QRect rect() const { return mRect; }
535  QRect outerRect() const { return mOuterRect; }
536  QMargins margins() const { return mMargins; }
537  QMargins minimumMargins() const { return mMinimumMargins; }
538  QCP::MarginSides autoMargins() const { return mAutoMargins; }
539  QSize minimumSize() const { return mMinimumSize; }
540  QSize maximumSize() const { return mMaximumSize; }
541  QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
542  QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
543 
544  // setters:
545  void setOuterRect(const QRect &rect);
546  void setMargins(const QMargins &margins);
547  void setMinimumMargins(const QMargins &margins);
548  void setAutoMargins(QCP::MarginSides sides);
549  void setMinimumSize(const QSize &size);
550  void setMinimumSize(int width, int height);
551  void setMaximumSize(const QSize &size);
552  void setMaximumSize(int width, int height);
553  void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
554 
555  // introduced virtual methods:
556  virtual void update();
557  virtual QSize minimumSizeHint() const;
558  virtual QSize maximumSizeHint() const;
559  virtual QList<QCPLayoutElement*> elements(bool recursive) const;
560 
561  // reimplemented virtual methods:
562  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
563 
564 protected:
565  // property members:
566  QCPLayout *mParentLayout;
567  QSize mMinimumSize, mMaximumSize;
568  QRect mRect, mOuterRect;
569  QMargins mMargins, mMinimumMargins;
570  QCP::MarginSides mAutoMargins;
571  QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
572 
573  // introduced virtual methods:
574  virtual int calculateAutoMargin(QCP::MarginSide side);
575  // events:
576  virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
577  virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
578  virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
579  virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
580  virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
581 
582  // reimplemented virtual methods:
583  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
584  virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
585  virtual void parentPlotInitialized(QCustomPlot *parentPlot);
586 
587 private:
588  Q_DISABLE_COPY(QCPLayoutElement)
589 
590  friend class QCustomPlot;
591  friend class QCPLayout;
592  friend class QCPMarginGroup;
593 };
594 
595 
596 class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
597 {
598  Q_OBJECT
599 public:
600  explicit QCPLayout();
601 
602  // reimplemented virtual methods:
603  virtual void update();
604  virtual QList<QCPLayoutElement*> elements(bool recursive) const;
605 
606  // introduced virtual methods:
607  virtual int elementCount() const = 0;
608  virtual QCPLayoutElement* elementAt(int index) const = 0;
609  virtual QCPLayoutElement* takeAt(int index) = 0;
610  virtual bool take(QCPLayoutElement* element) = 0;
611  virtual void simplify();
612 
613  // non-virtual methods:
614  bool removeAt(int index);
615  bool remove(QCPLayoutElement* element);
616  void clear();
617 
618 protected:
619  // introduced virtual methods:
620  virtual void updateLayout();
621 
622  // non-virtual methods:
623  void sizeConstraintsChanged() const;
624  void adoptElement(QCPLayoutElement *el);
625  void releaseElement(QCPLayoutElement *el);
626  QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
627 
628 private:
629  Q_DISABLE_COPY(QCPLayout)
630  friend class QCPLayoutElement;
631 };
632 
633 
634 class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
635 {
636  Q_OBJECT
638  Q_PROPERTY(int rowCount READ rowCount)
639  Q_PROPERTY(int columnCount READ columnCount)
640  Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
641  Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
642  Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
643  Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
645 public:
646  explicit QCPLayoutGrid();
647  virtual ~QCPLayoutGrid();
648 
649  // getters:
650  int rowCount() const;
651  int columnCount() const;
652  QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
653  QList<double> rowStretchFactors() const { return mRowStretchFactors; }
654  int columnSpacing() const { return mColumnSpacing; }
655  int rowSpacing() const { return mRowSpacing; }
656 
657  // setters:
658  void setColumnStretchFactor(int column, double factor);
659  void setColumnStretchFactors(const QList<double> &factors);
660  void setRowStretchFactor(int row, double factor);
661  void setRowStretchFactors(const QList<double> &factors);
662  void setColumnSpacing(int pixels);
663  void setRowSpacing(int pixels);
664 
665  // reimplemented virtual methods:
666  virtual void updateLayout();
667  virtual int elementCount() const;
668  virtual QCPLayoutElement* elementAt(int index) const;
669  virtual QCPLayoutElement* takeAt(int index);
670  virtual bool take(QCPLayoutElement* element);
671  virtual QList<QCPLayoutElement*> elements(bool recursive) const;
672  virtual void simplify();
673  virtual QSize minimumSizeHint() const;
674  virtual QSize maximumSizeHint() const;
675 
676  // non-virtual methods:
677  QCPLayoutElement *element(int row, int column) const;
678  bool addElement(int row, int column, QCPLayoutElement *element);
679  bool hasElement(int row, int column);
680  void expandTo(int newRowCount, int newColumnCount);
681  void insertRow(int newIndex);
682  void insertColumn(int newIndex);
683 
684 protected:
685  // property members:
686  QList<QList<QCPLayoutElement*> > mElements;
687  QList<double> mColumnStretchFactors;
688  QList<double> mRowStretchFactors;
689  int mColumnSpacing, mRowSpacing;
690 
691  // non-virtual methods:
692  void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
693  void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
694 
695 private:
696  Q_DISABLE_COPY(QCPLayoutGrid)
697 };
698 
699 
700 class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
701 {
702  Q_OBJECT
703 public:
707  enum InsetPlacement {ipFree
708  ,ipBorderAligned
709  };
710 
711  explicit QCPLayoutInset();
712  virtual ~QCPLayoutInset();
713 
714  // getters:
715  InsetPlacement insetPlacement(int index) const;
716  Qt::Alignment insetAlignment(int index) const;
717  QRectF insetRect(int index) const;
718 
719  // setters:
720  void setInsetPlacement(int index, InsetPlacement placement);
721  void setInsetAlignment(int index, Qt::Alignment alignment);
722  void setInsetRect(int index, const QRectF &rect);
723 
724  // reimplemented virtual methods:
725  virtual void updateLayout();
726  virtual int elementCount() const;
727  virtual QCPLayoutElement* elementAt(int index) const;
728  virtual QCPLayoutElement* takeAt(int index);
729  virtual bool take(QCPLayoutElement* element);
730  virtual void simplify() {}
731  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
732 
733  // non-virtual methods:
734  void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
735  void addElement(QCPLayoutElement *element, const QRectF &rect);
736 
737 protected:
738  // property members:
739  QList<QCPLayoutElement*> mElements;
740  QList<InsetPlacement> mInsetPlacement;
741  QList<Qt::Alignment> mInsetAlignment;
742  QList<QRectF> mInsetRect;
743 
744 private:
745  Q_DISABLE_COPY(QCPLayoutInset)
746 };
747 
748 
749 class QCP_LIB_DECL QCPLineEnding
750 {
751  Q_GADGET
752 public:
764  Q_ENUMS(EndingStyle)
765  enum EndingStyle { esNone
766  ,esFlatArrow
767  ,esSpikeArrow
768  ,esLineArrow
769  ,esDisc
770  ,esSquare
771  ,esDiamond
772  ,esBar
773  ,esHalfBar
774  ,esSkewedBar
775  };
776 
777  QCPLineEnding();
778  QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
779 
780  // getters:
781  EndingStyle style() const { return mStyle; }
782  double width() const { return mWidth; }
783  double length() const { return mLength; }
784  bool inverted() const { return mInverted; }
785 
786  // setters:
787  void setStyle(EndingStyle style);
788  void setWidth(double width);
789  void setLength(double length);
790  void setInverted(bool inverted);
791 
792  // non-property methods:
793  double boundingDistance() const;
794  double realLength() const;
795  void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
796  void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
797 
798 protected:
799  // property members:
800  EndingStyle mStyle;
801  double mWidth, mLength;
802  bool mInverted;
803 };
804 Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
805 
806 
807 class QCP_LIB_DECL QCPGrid :public QCPLayerable
808 {
809  Q_OBJECT
811  Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
812  Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
813  Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
814  Q_PROPERTY(QPen pen READ pen WRITE setPen)
815  Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
816  Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
818 public:
819  QCPGrid(QCPAxis *parentAxis);
820 
821  // getters:
822  bool subGridVisible() const { return mSubGridVisible; }
823  bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
824  bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
825  QPen pen() const { return mPen; }
826  QPen subGridPen() const { return mSubGridPen; }
827  QPen zeroLinePen() const { return mZeroLinePen; }
828 
829  // setters:
830  void setSubGridVisible(bool visible);
831  void setAntialiasedSubGrid(bool enabled);
832  void setAntialiasedZeroLine(bool enabled);
833  void setPen(const QPen &pen);
834  void setSubGridPen(const QPen &pen);
835  void setZeroLinePen(const QPen &pen);
836 
837 protected:
838  // property members:
839  bool mSubGridVisible;
840  bool mAntialiasedSubGrid, mAntialiasedZeroLine;
841  QPen mPen, mSubGridPen, mZeroLinePen;
842  // non-property members:
843  QCPAxis *mParentAxis;
844 
845  // reimplemented virtual methods:
846  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
847  virtual void draw(QCPPainter *painter);
848 
849  // non-virtual methods:
850  void drawGridLines(QCPPainter *painter) const;
851  void drawSubGridLines(QCPPainter *painter) const;
852 
853  friend class QCPAxis;
854 };
855 
856 
857 class QCP_LIB_DECL QCPAxis : public QCPLayerable
858 {
859  Q_OBJECT
861  Q_PROPERTY(AxisType axisType READ axisType)
862  Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
863  Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType)
864  Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
865  Q_PROPERTY(QCPRange range READ range WRITE setRange)
866  Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
867  Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
868  Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
869  Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
870  Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
871  Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
872  Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
873  Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
874  Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
875  Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
876  Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
877  Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
878  Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
879  Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
880  Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
881  Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
882  Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
883  Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
884  Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
885  Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
886  Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
887  Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
888  Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
889  Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
890  Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
891  Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
892  Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
893  Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
894  Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
895  Q_PROPERTY(QString label READ label WRITE setLabel)
896  Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
897  Q_PROPERTY(int padding READ padding WRITE setPadding)
898  Q_PROPERTY(int offset READ offset WRITE setOffset)
899  Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts)
900  Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts)
901  Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
902  Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
903  Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
904  Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
905  Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
906  Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
907  Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
908  Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
909  Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
910  Q_PROPERTY(QCPGrid* grid READ grid)
912 public:
917  enum AxisType { atLeft = 0x01
918  ,atRight = 0x02
919  ,atTop = 0x04
920  ,atBottom = 0x08
921  };
922  Q_FLAGS(AxisType AxisTypes)
923  Q_DECLARE_FLAGS(AxisTypes, AxisType)
930  enum LabelType { ltNumber
931  ,ltDateTime
932  };
933  Q_ENUMS(LabelType)
938  enum ScaleType { stLinear
939  ,stLogarithmic
940  };
941  Q_ENUMS(ScaleType)
946  enum SelectablePart { spNone = 0
947  ,spAxis = 0x001
948  ,spTickLabels = 0x002
949  ,spAxisLabel = 0x004
950  };
951  Q_FLAGS(SelectablePart SelectableParts)
952  Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
953 
954  explicit QCPAxis(QCPAxisRect *parent, AxisType type);
955 
956  // getters:
957  AxisType axisType() const { return mAxisType; }
958  QCPAxisRect *axisRect() const { return mAxisRect; }
959  ScaleType scaleType() const { return mScaleType; }
960  double scaleLogBase() const { return mScaleLogBase; }
961  const QCPRange range() const { return mRange; }
962  bool rangeReversed() const { return mRangeReversed; }
963  bool autoTicks() const { return mAutoTicks; }
964  int autoTickCount() const { return mAutoTickCount; }
965  bool autoTickLabels() const { return mAutoTickLabels; }
966  bool autoTickStep() const { return mAutoTickStep; }
967  bool autoSubTicks() const { return mAutoSubTicks; }
968  bool ticks() const { return mTicks; }
969  bool tickLabels() const { return mTickLabels; }
970  int tickLabelPadding() const { return mTickLabelPadding; }
971  LabelType tickLabelType() const { return mTickLabelType; }
972  QFont tickLabelFont() const { return mTickLabelFont; }
973  QColor tickLabelColor() const { return mTickLabelColor; }
974  double tickLabelRotation() const { return mTickLabelRotation; }
975  QString dateTimeFormat() const { return mDateTimeFormat; }
976  Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
977  QString numberFormat() const;
978  int numberPrecision() const { return mNumberPrecision; }
979  double tickStep() const { return mTickStep; }
980  QVector<double> tickVector() const { return mTickVector; }
981  QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
982  int tickLengthIn() const { return mTickLengthIn; }
983  int tickLengthOut() const { return mTickLengthOut; }
984  int subTickCount() const { return mSubTickCount; }
985  int subTickLengthIn() const { return mSubTickLengthIn; }
986  int subTickLengthOut() const { return mSubTickLengthOut; }
987  QPen basePen() const { return mBasePen; }
988  QPen tickPen() const { return mTickPen; }
989  QPen subTickPen() const { return mSubTickPen; }
990  QFont labelFont() const { return mLabelFont; }
991  QColor labelColor() const { return mLabelColor; }
992  QString label() const { return mLabel; }
993  int labelPadding() const { return mLabelPadding; }
994  int padding() const { return mPadding; }
995  int offset() const { return mOffset; }
996  SelectableParts selectedParts() const { return mSelectedParts; }
997  SelectableParts selectableParts() const { return mSelectableParts; }
998  QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
999  QFont selectedLabelFont() const { return mSelectedLabelFont; }
1000  QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
1001  QColor selectedLabelColor() const { return mSelectedLabelColor; }
1002  QPen selectedBasePen() const { return mSelectedBasePen; }
1003  QPen selectedTickPen() const { return mSelectedTickPen; }
1004  QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
1005  QCPLineEnding lowerEnding() const { return mLowerEnding; }
1006  QCPLineEnding upperEnding() const { return mUpperEnding; }
1007  QCPGrid *grid() const { return mGrid; }
1008 
1009  // setters:
1010  void setScaleType(ScaleType type);
1011  void setScaleLogBase(double base);
1012  Q_SLOT void setRange(const QCPRange &range);
1013  void setRange(double lower, double upper);
1014  void setRange(double position, double size, Qt::AlignmentFlag alignment);
1015  void setRangeLower(double lower);
1016  void setRangeUpper(double upper);
1017  void setRangeReversed(bool reversed);
1018  void setAutoTicks(bool on);
1019  void setAutoTickCount(int approximateCount);
1020  void setAutoTickLabels(bool on);
1021  void setAutoTickStep(bool on);
1022  void setAutoSubTicks(bool on);
1023  void setTicks(bool show);
1024  void setTickLabels(bool show);
1025  void setTickLabelPadding(int padding);
1026  void setTickLabelType(LabelType type);
1027  void setTickLabelFont(const QFont &font);
1028  void setTickLabelColor(const QColor &color);
1029  void setTickLabelRotation(double degrees);
1030  void setDateTimeFormat(const QString &format);
1031  void setDateTimeSpec(const Qt::TimeSpec &timeSpec);
1032  void setNumberFormat(const QString &formatCode);
1033  void setNumberPrecision(int precision);
1034  void setTickStep(double step);
1035  void setTickVector(const QVector<double> &vec);
1036  void setTickVectorLabels(const QVector<QString> &vec);
1037  void setTickLength(int inside, int outside=0);
1038  void setTickLengthIn(int inside);
1039  void setTickLengthOut(int outside);
1040  void setSubTickCount(int count);
1041  void setSubTickLength(int inside, int outside=0);
1042  void setSubTickLengthIn(int inside);
1043  void setSubTickLengthOut(int outside);
1044  void setBasePen(const QPen &pen);
1045  void setTickPen(const QPen &pen);
1046  void setSubTickPen(const QPen &pen);
1047  void setLabelFont(const QFont &font);
1048  void setLabelColor(const QColor &color);
1049  void setLabel(const QString &str);
1050  void setLabelPadding(int padding);
1051  void setPadding(int padding);
1052  void setOffset(int offset);
1053  void setSelectedTickLabelFont(const QFont &font);
1054  void setSelectedLabelFont(const QFont &font);
1055  void setSelectedTickLabelColor(const QColor &color);
1056  void setSelectedLabelColor(const QColor &color);
1057  void setSelectedBasePen(const QPen &pen);
1058  void setSelectedTickPen(const QPen &pen);
1059  void setSelectedSubTickPen(const QPen &pen);
1060  Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
1061  Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
1062  void setLowerEnding(const QCPLineEnding &ending);
1063  void setUpperEnding(const QCPLineEnding &ending);
1064 
1065  // reimplemented virtual methods:
1066  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1067 
1068  // non-virtual methods:
1069  Qt::Orientation orientation() const { return mOrientation; }
1070  void moveRange(double diff);
1071  void scaleRange(double factor, double center);
1072  void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
1073  void rescale(bool onlyVisiblePlottables=false);
1074  double pixelToCoord(double value) const;
1075  double coordToPixel(double value) const;
1076  SelectablePart getPartAt(const QPointF &pos) const;
1077  QList<QCPAbstractPlottable*> plottables() const;
1078  QList<QCPGraph*> graphs() const;
1079  QList<QCPAbstractItem*> items() const;
1080 
1081  static AxisType marginSideToAxisType(QCP::MarginSide side);
1082 
1083 signals:
1084  void ticksRequest();
1085  void rangeChanged(const QCPRange &newRange);
1086  void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
1087  void selectionChanged(const QCPAxis::SelectableParts &parts);
1088 
1089 protected:
1091  {
1092  QPointF offset;
1093  QPixmap pixmap;
1094  };
1096  {
1097  QString basePart, expPart;
1098  QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
1099  QFont baseFont, expFont;
1100  };
1101 
1102  // property members:
1103  // axis base:
1104  AxisType mAxisType;
1105  QCPAxisRect *mAxisRect;
1106  int mOffset, mPadding;
1107  Qt::Orientation mOrientation;
1108  SelectableParts mSelectableParts, mSelectedParts;
1109  QPen mBasePen, mSelectedBasePen;
1110  QCPLineEnding mLowerEnding, mUpperEnding;
1111  // axis label:
1112  int mLabelPadding;
1113  QString mLabel;
1114  QFont mLabelFont, mSelectedLabelFont;
1115  QColor mLabelColor, mSelectedLabelColor;
1116  // tick labels:
1117  int mTickLabelPadding;
1118  bool mTickLabels, mAutoTickLabels;
1119  double mTickLabelRotation;
1120  LabelType mTickLabelType;
1121  QFont mTickLabelFont, mSelectedTickLabelFont;
1122  QColor mTickLabelColor, mSelectedTickLabelColor;
1123  QString mDateTimeFormat;
1124  Qt::TimeSpec mDateTimeSpec;
1125  int mNumberPrecision;
1126  char mNumberFormatChar;
1127  bool mNumberBeautifulPowers;
1128  bool mNumberMultiplyCross;
1129  // ticks and subticks:
1130  bool mTicks;
1131  double mTickStep;
1132  int mSubTickCount, mAutoTickCount;
1133  bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
1134  int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut;
1135  QPen mTickPen, mSelectedTickPen;
1136  QPen mSubTickPen, mSelectedSubTickPen;
1137  // scale and range:
1138  QCPRange mRange;
1139  bool mRangeReversed;
1140  ScaleType mScaleType;
1141  double mScaleLogBase, mScaleLogBaseLogInv;
1142 
1143  // non-property members:
1144  QCPGrid *mGrid;
1145  QCache<QString, CachedLabel> mLabelCache;
1146  int mLowestVisibleTick, mHighestVisibleTick;
1147  QChar mExponentialChar, mPositiveSignChar;
1148  QVector<double> mTickVector;
1149  QVector<QString> mTickVectorLabels;
1150  QVector<double> mSubTickVector;
1151  QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
1152  bool mCachedMarginValid;
1153  int mCachedMargin;
1154 
1155  // introduced virtual methods:
1156  virtual void setupTickVectors();
1157  virtual void generateAutoTicks();
1158  virtual int calculateAutoSubTickCount(double tickStep) const;
1159  virtual int calculateMargin();
1160  // tick label drawing/caching:
1161  virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
1162  virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
1163  virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
1164  virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
1165  virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
1166 
1167  // reimplemented virtual methods:
1168  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1169  virtual void draw(QCPPainter *painter);
1170  virtual QCP::Interaction selectionCategory() const;
1171  // events:
1172  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1173  virtual void deselectEvent(bool *selectionStateChanged);
1174 
1175  // non-virtual methods:
1176  void visibleTickBounds(int &lowIndex, int &highIndex) const;
1177  double baseLog(double value) const;
1178  double basePow(double value) const;
1179  QPen getBasePen() const;
1180  QPen getTickPen() const;
1181  QPen getSubTickPen() const;
1182  QFont getTickLabelFont() const;
1183  QFont getLabelFont() const;
1184  QColor getTickLabelColor() const;
1185  QColor getLabelColor() const;
1186 
1187 private:
1188  Q_DISABLE_COPY(QCPAxis)
1189 
1190  friend class QCustomPlot;
1191  friend class QCPGrid;
1192  friend class QCPAxisRect;
1193 };
1194 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
1195 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
1196 Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
1197 
1198 
1199 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
1200 {
1201  Q_OBJECT
1203  Q_PROPERTY(QString name READ name WRITE setName)
1204  Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
1205  Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
1206  Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
1207  Q_PROPERTY(QPen pen READ pen WRITE setPen)
1208  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
1209  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
1210  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
1211  Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
1212  Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
1213  Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
1214  Q_PROPERTY(bool selected READ selected WRITE setSelected)
1216 public:
1217  QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
1218 
1219  // getters:
1220  QString name() const { return mName; }
1221  bool antialiasedFill() const { return mAntialiasedFill; }
1222  bool antialiasedScatters() const { return mAntialiasedScatters; }
1223  bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
1224  QPen pen() const { return mPen; }
1225  QPen selectedPen() const { return mSelectedPen; }
1226  QBrush brush() const { return mBrush; }
1227  QBrush selectedBrush() const { return mSelectedBrush; }
1228  QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1229  QCPAxis *valueAxis() const { return mValueAxis.data(); }
1230  bool selectable() const { return mSelectable; }
1231  bool selected() const { return mSelected; }
1232 
1233  // setters:
1234  void setName(const QString &name);
1235  void setAntialiasedFill(bool enabled);
1236  void setAntialiasedScatters(bool enabled);
1237  void setAntialiasedErrorBars(bool enabled);
1238  void setPen(const QPen &pen);
1239  void setSelectedPen(const QPen &pen);
1240  void setBrush(const QBrush &brush);
1241  void setSelectedBrush(const QBrush &brush);
1242  void setKeyAxis(QCPAxis *axis);
1243  void setValueAxis(QCPAxis *axis);
1244  Q_SLOT void setSelectable(bool selectable);
1245  Q_SLOT void setSelected(bool selected);
1246 
1247  // introduced virtual methods:
1248  virtual void clearData() = 0;
1249  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1250  virtual bool addToLegend();
1251  virtual bool removeFromLegend() const;
1252 
1253  // non-property methods:
1254  void rescaleAxes(bool onlyEnlarge=false) const;
1255  void rescaleKeyAxis(bool onlyEnlarge=false) const;
1256  void rescaleValueAxis(bool onlyEnlarge=false) const;
1257 
1258 signals:
1259  void selectionChanged(bool selected);
1260 
1261 protected:
1265  enum SignDomain { sdNegative
1266  ,sdBoth
1267  ,sdPositive
1268  };
1269 
1270  // property members:
1271  QString mName;
1272  bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
1273  QPen mPen, mSelectedPen;
1274  QBrush mBrush, mSelectedBrush;
1275  QPointer<QCPAxis> mKeyAxis, mValueAxis;
1276  bool mSelectable, mSelected;
1277 
1278  // reimplemented virtual methods:
1279  virtual QRect clipRect() const;
1280  virtual void draw(QCPPainter *painter) = 0;
1281  virtual QCP::Interaction selectionCategory() const;
1282  void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1283  // events:
1284  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1285  virtual void deselectEvent(bool *selectionStateChanged);
1286 
1287  // introduced virtual methods:
1288  virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
1289  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
1290  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
1291 
1292  // non-virtual methods:
1293  void coordsToPixels(double key, double value, double &x, double &y) const;
1294  const QPointF coordsToPixels(double key, double value) const;
1295  void pixelsToCoords(double x, double y, double &key, double &value) const;
1296  void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
1297  QPen mainPen() const;
1298  QBrush mainBrush() const;
1299  void applyFillAntialiasingHint(QCPPainter *painter) const;
1300  void applyScattersAntialiasingHint(QCPPainter *painter) const;
1301  void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
1302  double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1303 
1304 private:
1305  Q_DISABLE_COPY(QCPAbstractPlottable)
1306 
1307  friend class QCustomPlot;
1308  friend class QCPAxis;
1309  friend class QCPPlottableLegendItem;
1310 };
1311 
1312 
1313 class QCP_LIB_DECL QCPItemAnchor
1314 {
1315 public:
1316  QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
1317  virtual ~QCPItemAnchor();
1318 
1319  // getters:
1320  QString name() const { return mName; }
1321  virtual QPointF pixelPoint() const;
1322 
1323 protected:
1324  // property members:
1325  QString mName;
1326 
1327  // non-property members:
1328  QCustomPlot *mParentPlot;
1329  QCPAbstractItem *mParentItem;
1330  int mAnchorId;
1331  QSet<QCPItemPosition*> mChildren;
1332 
1333  // introduced virtual methods:
1334  virtual QCPItemPosition *toQCPItemPosition() { return 0; }
1335 
1336  // non-virtual methods:
1337  void addChild(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1338  void removeChild(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1339 
1340 private:
1341  Q_DISABLE_COPY(QCPItemAnchor)
1342 
1343  friend class QCPItemPosition;
1344 };
1345 
1346 
1347 
1348 class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
1349 {
1350 public:
1357  enum PositionType { ptAbsolute
1358  ,ptViewportRatio
1359  ,ptAxisRectRatio
1360  ,ptPlotCoords
1361  };
1362 
1363  QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
1364  virtual ~QCPItemPosition();
1365 
1366  // getters:
1367  PositionType type() const { return mPositionType; }
1368  QCPItemAnchor *parentAnchor() const { return mParentAnchor; }
1369  double key() const { return mKey; }
1370  double value() const { return mValue; }
1371  QPointF coords() const { return QPointF(mKey, mValue); }
1372  QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1373  QCPAxis *valueAxis() const { return mValueAxis.data(); }
1374  QCPAxisRect *axisRect() const;
1375  virtual QPointF pixelPoint() const;
1376 
1377  // setters:
1378  void setType(PositionType type);
1379  bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1380  void setCoords(double key, double value);
1381  void setCoords(const QPointF &coords);
1382  void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
1383  void setAxisRect(QCPAxisRect *axisRect);
1384  void setPixelPoint(const QPointF &pixelPoint);
1385 
1386 protected:
1387  // property members:
1388  PositionType mPositionType;
1389  QPointer<QCPAxis> mKeyAxis, mValueAxis;
1390  QPointer<QCPAxisRect> mAxisRect;
1391  double mKey, mValue;
1392  QCPItemAnchor *mParentAnchor;
1393 
1394  // reimplemented virtual methods:
1395  virtual QCPItemPosition *toQCPItemPosition() { return this; }
1396 
1397 private:
1398  Q_DISABLE_COPY(QCPItemPosition)
1399 
1400 };
1401 
1402 
1403 class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
1404 {
1405  Q_OBJECT
1407  Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
1408  Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
1409  Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
1410  Q_PROPERTY(bool selected READ selected WRITE setSelected)
1412 public:
1413  QCPAbstractItem(QCustomPlot *parentPlot);
1414  virtual ~QCPAbstractItem();
1415 
1416  // getters:
1417  bool clipToAxisRect() const { return mClipToAxisRect; }
1418  QCPAxisRect *clipAxisRect() const;
1419  bool selectable() const { return mSelectable; }
1420  bool selected() const { return mSelected; }
1421 
1422  // setters:
1423  void setClipToAxisRect(bool clip);
1424  void setClipAxisRect(QCPAxisRect *rect);
1425  void setSelectable(bool selectable);
1426  void setSelected(bool selected);
1427 
1428  // reimplemented virtual methods:
1429  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1430 
1431  // non-virtual methods:
1432  QList<QCPItemPosition*> positions() const { return mPositions; }
1433  QList<QCPItemAnchor*> anchors() const { return mAnchors; }
1434  QCPItemPosition *position(const QString &name) const;
1435  QCPItemAnchor *anchor(const QString &name) const;
1436  bool hasAnchor(const QString &name) const;
1437 
1438 signals:
1439  void selectionChanged(bool selected);
1440 
1441 protected:
1442  // property members:
1443  bool mClipToAxisRect;
1444  QPointer<QCPAxisRect> mClipAxisRect;
1445  QList<QCPItemPosition*> mPositions;
1446  QList<QCPItemAnchor*> mAnchors;
1447  bool mSelectable, mSelected;
1448 
1449  // reimplemented virtual methods:
1450  virtual QCP::Interaction selectionCategory() const;
1451  virtual QRect clipRect() const;
1452  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1453  virtual void draw(QCPPainter *painter) = 0;
1454  // events:
1455  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1456  virtual void deselectEvent(bool *selectionStateChanged);
1457 
1458  // introduced virtual methods:
1459  virtual QPointF anchorPixelPoint(int anchorId) const;
1460 
1461  // non-virtual methods:
1462  double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1463  double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
1464  QCPItemPosition *createPosition(const QString &name);
1465  QCPItemAnchor *createAnchor(const QString &name, int anchorId);
1466 
1467 private:
1468  Q_DISABLE_COPY(QCPAbstractItem)
1469 
1470  friend class QCustomPlot;
1471  friend class QCPItemAnchor;
1472 };
1473 
1474 
1475 class QCP_LIB_DECL QCustomPlot : public QWidget
1476 {
1477  Q_OBJECT
1479  Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
1480  Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1481  Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1482  Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1483  Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
1484  Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
1485  Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
1486  Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
1487  Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
1489 public:
1495  enum LayerInsertMode { limBelow
1496  ,limAbove
1497  };
1498  Q_ENUMS(LayerInsertMode)
1499 
1500  explicit QCustomPlot(QWidget *parent = 0);
1501  virtual ~QCustomPlot();
1502 
1503  // getters:
1504  QRect viewport() const { return mViewport; }
1505  QPixmap background() const { return mBackgroundPixmap; }
1506  bool backgroundScaled() const { return mBackgroundScaled; }
1507  Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1508  QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
1509  QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
1510  QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
1511  bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
1512  const QCP::Interactions interactions() const { return mInteractions; }
1513  int selectionTolerance() const { return mSelectionTolerance; }
1514  bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
1515  QCP::PlottingHints plottingHints() const { return mPlottingHints; }
1516  Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
1517 
1518  // setters:
1519  void setViewport(const QRect &rect);
1520  void setBackground(const QPixmap &pm);
1521  void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
1522  void setBackground(const QBrush &brush);
1523  void setBackgroundScaled(bool scaled);
1524  void setBackgroundScaledMode(Qt::AspectRatioMode mode);
1525  void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
1526  void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
1527  void setNotAntialiasedElements(const QCP::AntialiasedElements &notAntialiasedElements);
1528  void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
1529  void setAutoAddPlottableToLegend(bool on);
1530  void setInteractions(const QCP::Interactions &interactions);
1531  void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
1532  void setSelectionTolerance(int pixels);
1533  void setNoAntialiasingOnDrag(bool enabled);
1534  void setPlottingHints(const QCP::PlottingHints &hints);
1535  void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
1536  void setMultiSelectModifier(Qt::KeyboardModifier modifier);
1537 
1538  // non-property methods:
1539  // plottable interface:
1540  QCPAbstractPlottable *plottable(int index);
1541  QCPAbstractPlottable *plottable();
1542  bool addPlottable(QCPAbstractPlottable *plottable);
1543  bool removePlottable(QCPAbstractPlottable *plottable);
1544  bool removePlottable(int index);
1545  int clearPlottables();
1546  int plottableCount() const;
1547  QList<QCPAbstractPlottable*> selectedPlottables() const;
1548  QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
1549  bool hasPlottable(QCPAbstractPlottable *plottable) const;
1550 
1551  // specialized interface for QCPGraph:
1552  QCPGraph *graph(int index) const;
1553  QCPGraph *graph() const;
1554  QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
1555  bool removeGraph(QCPGraph *graph);
1556  bool removeGraph(int index);
1557  int clearGraphs();
1558  int graphCount() const;
1559  QList<QCPGraph*> selectedGraphs() const;
1560 
1561  // item interface:
1562  QCPAbstractItem *item(int index) const;
1563  QCPAbstractItem *item() const;
1564  bool addItem(QCPAbstractItem* item);
1565  bool removeItem(QCPAbstractItem *item);
1566  bool removeItem(int index);
1567  int clearItems();
1568  int itemCount() const;
1569  QList<QCPAbstractItem*> selectedItems() const;
1570  QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
1571  bool hasItem(QCPAbstractItem *item) const;
1572 
1573  // layer interface:
1574  QCPLayer *layer(const QString &name) const;
1575  QCPLayer *layer(int index) const;
1576  QCPLayer *currentLayer() const;
1577  bool setCurrentLayer(const QString &name);
1578  bool setCurrentLayer(QCPLayer *layer);
1579  int layerCount() const;
1580  bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
1581  bool removeLayer(QCPLayer *layer);
1582  bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
1583 
1584  // axis rect/layout interface:
1585  int axisRectCount() const;
1586  QCPAxisRect* axisRect(int index=0) const;
1587  QList<QCPAxisRect*> axisRects() const;
1588  QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
1589  Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
1590 
1591  QList<QCPAxis*> selectedAxes() const;
1592  QList<QCPLegend*> selectedLegends() const;
1593  Q_SLOT void deselectAll();
1594 
1595  bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0);
1596  bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1597  bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1598  bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
1599  bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
1600  QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
1601  void toPainter(QCPPainter *painter, int width=0, int height=0);
1602  Q_SLOT void replot();
1603 
1604  QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
1605  QCPLegend *legend;
1606 
1607 signals:
1608  void mouseDoubleClick(QMouseEvent *event);
1609  void mousePress(QMouseEvent *event);
1610  void mouseMove(QMouseEvent *event);
1611  void mouseRelease(QMouseEvent *event);
1612  void mouseWheel(QWheelEvent *event);
1613 
1614  void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1615  void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1616  void itemClick(QCPAbstractItem *item, QMouseEvent *event);
1617  void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
1618  void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1619  void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1620  void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1621  void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1622  void titleClick(QMouseEvent *event, QCPPlotTitle *title);
1623  void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
1624 
1625  void selectionChangedByUser();
1626  void beforeReplot();
1627  void afterReplot();
1628 
1629 protected:
1630  // property members:
1631  QRect mViewport;
1632  QCPLayoutGrid *mPlotLayout;
1633  bool mAutoAddPlottableToLegend;
1634  QList<QCPAbstractPlottable*> mPlottables;
1635  QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
1636  QList<QCPAbstractItem*> mItems;
1637  QList<QCPLayer*> mLayers;
1638  QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
1639  QCP::Interactions mInteractions;
1640  int mSelectionTolerance;
1641  bool mNoAntialiasingOnDrag;
1642  QBrush mBackgroundBrush;
1643  QPixmap mBackgroundPixmap;
1644  QPixmap mScaledBackgroundPixmap;
1645  bool mBackgroundScaled;
1646  Qt::AspectRatioMode mBackgroundScaledMode;
1647  QCPLayer *mCurrentLayer;
1648  QCP::PlottingHints mPlottingHints;
1649  Qt::KeyboardModifier mMultiSelectModifier;
1650 
1651  // non-property members:
1652  QPixmap mPaintBuffer;
1653  QPoint mMousePressPos;
1654  QCPLayoutElement *mMouseEventElement;
1655  bool mReplotting;
1656 
1657  // reimplemented virtual methods:
1658  virtual QSize minimumSizeHint() const;
1659  virtual QSize sizeHint() const;
1660  virtual void paintEvent(QPaintEvent *event);
1661  virtual void resizeEvent(QResizeEvent *event);
1662  virtual void mouseDoubleClickEvent(QMouseEvent *event);
1663  virtual void mousePressEvent(QMouseEvent *event);
1664  virtual void mouseMoveEvent(QMouseEvent *event);
1665  virtual void mouseReleaseEvent(QMouseEvent *event);
1666  virtual void wheelEvent(QWheelEvent *event);
1667 
1668  // introduced virtual methods:
1669  virtual void draw(QCPPainter *painter);
1670  virtual void axisRemoved(QCPAxis *axis);
1671  virtual void legendRemoved(QCPLegend *legend);
1672 
1673  // non-virtual methods:
1674  void updateLayerIndices() const;
1675  QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const;
1676  void drawBackground(QCPPainter *painter);
1677 
1678  friend class QCPLegend;
1679  friend class QCPAxis;
1680  friend class QCPLayer;
1681  friend class QCPAxisRect;
1682 };
1683 
1684 
1689 class QCP_LIB_DECL QCPData
1690 {
1691 public:
1692  QCPData();
1693  QCPData(double key, double value);
1694  double key, value;
1695  double keyErrorPlus, keyErrorMinus;
1696  double valueErrorPlus, valueErrorMinus;
1697 };
1698 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
1699 
1707 typedef QMap<double, QCPData> QCPDataMap;
1708 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
1709 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
1710 
1711 
1712 class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
1713 {
1714  Q_OBJECT
1716  Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
1717  Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
1718  Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
1719  Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
1720  Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
1721  Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
1722  Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
1724 public:
1730  enum LineStyle { lsNone
1731  ,lsLine
1733  ,lsStepLeft
1734  ,lsStepRight
1735  ,lsStepCenter
1736  ,lsImpulse
1737  };
1738  Q_ENUMS(LineStyle)
1742  enum ErrorType { etNone
1743  ,etKey
1744  ,etValue
1745  ,etBoth
1746  };
1747  Q_ENUMS(ErrorType)
1748 
1749  explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
1750  virtual ~QCPGraph();
1751 
1752  // getters:
1753  const QCPDataMap *data() const { return mData; }
1754  LineStyle lineStyle() const { return mLineStyle; }
1755  QCPScatterStyle scatterStyle() const { return mScatterStyle; }
1756  ErrorType errorType() const { return mErrorType; }
1757  QPen errorPen() const { return mErrorPen; }
1758  double errorBarSize() const { return mErrorBarSize; }
1759  bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
1760  QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
1761 
1762  // setters:
1763  void setData(QCPDataMap *data, bool copy=false);
1764  void setData(const QVector<double> &key, const QVector<double> &value);
1765  void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
1766  void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
1767  void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
1768  void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
1769  void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
1770  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);
1771  void setLineStyle(LineStyle ls);
1772  void setScatterStyle(const QCPScatterStyle &style);
1773  void setErrorType(ErrorType errorType);
1774  void setErrorPen(const QPen &pen);
1775  void setErrorBarSize(double size);
1776  void setErrorBarSkipSymbol(bool enabled);
1777  void setChannelFillGraph(QCPGraph *targetGraph);
1778 
1779  // non-property methods:
1780  void addData(const QCPDataMap &dataMap);
1781  void addData(const QCPData &data);
1782  void addData(double key, double value);
1783  void addData(const QVector<double> &keys, const QVector<double> &values);
1784  void removeDataBefore(double key);
1785  void removeDataAfter(double key);
1786  void removeData(double fromKey, double toKey);
1787  void removeData(double key);
1788 
1789  // reimplemented virtual methods:
1790  virtual void clearData();
1791  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1795  void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
1796  void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
1797  void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
1798 
1799 protected:
1800  // property members:
1801  QCPDataMap *mData;
1802  QPen mErrorPen;
1803  LineStyle mLineStyle;
1804  QCPScatterStyle mScatterStyle;
1805  ErrorType mErrorType;
1806  double mErrorBarSize;
1807  bool mErrorBarSkipSymbol;
1808  QPointer<QCPGraph> mChannelFillGraph;
1809 
1810  // reimplemented virtual methods:
1811  virtual void draw(QCPPainter *painter);
1812  virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
1813  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
1814  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
1815  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
1816  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
1817 
1818  // introduced virtual methods:
1819  virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
1820  virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *pointData) const;
1821  virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
1822  virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
1823 
1824  // non-virtual methods:
1825  void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
1826  void getScatterPlotData(QVector<QCPData> *pointData) const;
1827  void getLinePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
1828  void getStepLeftPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
1829  void getStepRightPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
1830  void getStepCenterPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
1831  void getImpulsePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
1832  void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
1833  void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const;
1834  void addFillBasePoints(QVector<QPointF> *lineData) const;
1835  void removeFillBasePoints(QVector<QPointF> *lineData) const;
1836  QPointF lowerFillBasePoint(double lowerKey) const;
1837  QPointF upperFillBasePoint(double upperKey) const;
1838  const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
1839  int findIndexBelowX(const QVector<QPointF> *data, double x) const;
1840  int findIndexAboveX(const QVector<QPointF> *data, double x) const;
1841  int findIndexBelowY(const QVector<QPointF> *data, double y) const;
1842  int findIndexAboveY(const QVector<QPointF> *data, double y) const;
1843  double pointDistance(const QPointF &pixelPoint) const;
1844 
1845  friend class QCustomPlot;
1846  friend class QCPLegend;
1847 };
1848 
1849 
1854 class QCP_LIB_DECL QCPCurveData
1855 {
1856 public:
1857  QCPCurveData();
1858  QCPCurveData(double t, double key, double value);
1859  double t, key, value;
1860 };
1861 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
1862 
1871 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
1872 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
1873 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
1874 
1875 
1876 class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
1877 {
1878  Q_OBJECT
1880  Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
1881  Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
1883 public:
1890  lsLine
1891  };
1892  explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
1893  virtual ~QCPCurve();
1894 
1895  // getters:
1896  QCPCurveDataMap *data() const { return mData; }
1897  QCPScatterStyle scatterStyle() const { return mScatterStyle; }
1898  LineStyle lineStyle() const { return mLineStyle; }
1899 
1900  // setters:
1901  void setData(QCPCurveDataMap *data, bool copy=false);
1902  void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
1903  void setData(const QVector<double> &key, const QVector<double> &value);
1904  void setScatterStyle(const QCPScatterStyle &style);
1905  void setLineStyle(LineStyle style);
1906 
1907  // non-property methods:
1908  void addData(const QCPCurveDataMap &dataMap);
1909  void addData(const QCPCurveData &data);
1910  void addData(double t, double key, double value);
1911  void addData(double key, double value);
1912  void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
1913  void removeDataBefore(double t);
1914  void removeDataAfter(double t);
1915  void removeData(double fromt, double tot);
1916  void removeData(double t);
1917 
1918  // reimplemented virtual methods:
1919  virtual void clearData();
1920  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1921 
1922 protected:
1923  // property members:
1924  QCPCurveDataMap *mData;
1925  QCPScatterStyle mScatterStyle;
1926  LineStyle mLineStyle;
1927 
1928  // reimplemented virtual methods:
1929  virtual void draw(QCPPainter *painter);
1930  virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
1931  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
1932  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
1933 
1934  // introduced virtual methods:
1935  virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
1936 
1937  // non-virtual methods:
1938  void getCurveData(QVector<QPointF> *lineData) const;
1939  double pointDistance(const QPointF &pixelPoint) const;
1940  QPointF outsideCoordsToPixels(double key, double value, int region, QRect axisRect) const;
1941 
1942  friend class QCustomPlot;
1943  friend class QCPLegend;
1944 };
1945 
1946 
1951 class QCP_LIB_DECL QCPBarData
1952 {
1953 public:
1954  QCPBarData();
1955  QCPBarData(double key, double value);
1956  double key, value;
1957 };
1958 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
1959 
1967 typedef QMap<double, QCPBarData> QCPBarDataMap;
1968 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
1969 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
1970 
1971 
1972 class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
1973 {
1974  Q_OBJECT
1976  Q_PROPERTY(double width READ width WRITE setWidth)
1977  Q_PROPERTY(QCPBars* barBelow READ barBelow)
1978  Q_PROPERTY(QCPBars* barAbove READ barAbove)
1980 public:
1981  explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
1982  virtual ~QCPBars();
1983 
1984  // getters:
1985  double width() const { return mWidth; }
1986  QCPBars *barBelow() const { return mBarBelow.data(); }
1987  QCPBars *barAbove() const { return mBarAbove.data(); }
1988  QCPBarDataMap *data() const { return mData; }
1989 
1990  // setters:
1991  void setWidth(double width);
1992  void setData(QCPBarDataMap *data, bool copy=false);
1993  void setData(const QVector<double> &key, const QVector<double> &value);
1994 
1995  // non-property methods:
1996  void moveBelow(QCPBars *bars);
1997  void moveAbove(QCPBars *bars);
1998  void addData(const QCPBarDataMap &dataMap);
1999  void addData(const QCPBarData &data);
2000  void addData(double key, double value);
2001  void addData(const QVector<double> &keys, const QVector<double> &values);
2002  void removeDataBefore(double key);
2003  void removeDataAfter(double key);
2004  void removeData(double fromKey, double toKey);
2005  void removeData(double key);
2006 
2007  // reimplemented virtual methods:
2008  virtual void clearData();
2009  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2010 
2011 protected:
2012  // property members:
2013  QCPBarDataMap *mData;
2014  double mWidth;
2015  QPointer<QCPBars> mBarBelow, mBarAbove;
2016 
2017  // reimplemented virtual methods:
2018  virtual void draw(QCPPainter *painter);
2019  virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2020  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
2021  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
2022 
2023  // non-virtual methods:
2024  QPolygonF getBarPolygon(double key, double value) const;
2025  double getBaseValue(double key, bool positive) const;
2026  static void connectBars(QCPBars* lower, QCPBars* upper);
2027 
2028  friend class QCustomPlot;
2029  friend class QCPLegend;
2030 };
2031 
2032 
2037 class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
2038 {
2039  Q_OBJECT
2041  Q_PROPERTY(double key READ key WRITE setKey)
2042  Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
2043  Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
2044  Q_PROPERTY(double median READ median WRITE setMedian)
2045  Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
2046  Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
2047  Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers)
2048  Q_PROPERTY(double width READ width WRITE setWidth)
2049  Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
2050  Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
2051  Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
2052  Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
2053  Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
2055 public:
2056  explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
2057 
2058  // getters:
2059  double key() const { return mKey; }
2060  double minimum() const { return mMinimum; }
2061  double lowerQuartile() const { return mLowerQuartile; }
2062  double median() const { return mMedian; }
2063  double upperQuartile() const { return mUpperQuartile; }
2064  double maximum() const { return mMaximum; }
2065  QVector<double> outliers() const { return mOutliers; }
2066  double width() const { return mWidth; }
2067  double whiskerWidth() const { return mWhiskerWidth; }
2068  QPen whiskerPen() const { return mWhiskerPen; }
2069  QPen whiskerBarPen() const { return mWhiskerBarPen; }
2070  QPen medianPen() const { return mMedianPen; }
2071  QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
2072 
2073  // setters:
2074  void setKey(double key);
2075  void setMinimum(double value);
2076  void setLowerQuartile(double value);
2077  void setMedian(double value);
2078  void setUpperQuartile(double value);
2079  void setMaximum(double value);
2080  void setOutliers(const QVector<double> &values);
2081  void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
2082  void setWidth(double width);
2083  void setWhiskerWidth(double width);
2084  void setWhiskerPen(const QPen &pen);
2085  void setWhiskerBarPen(const QPen &pen);
2086  void setMedianPen(const QPen &pen);
2087  void setOutlierStyle(const QCPScatterStyle &style);
2088 
2089  // non-property methods:
2090  virtual void clearData();
2091  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2092 
2093 protected:
2094  // property members:
2095  QVector<double> mOutliers;
2096  double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
2097  double mWidth;
2098  double mWhiskerWidth;
2099  QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
2100  QCPScatterStyle mOutlierStyle;
2101 
2102  // reimplemented virtual methods:
2103  virtual void draw(QCPPainter *painter);
2104  virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2105  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
2106  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
2107 
2108  // introduced virtual methods:
2109  virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
2110  virtual void drawMedian(QCPPainter *painter) const;
2111  virtual void drawWhiskers(QCPPainter *painter) const;
2112  virtual void drawOutliers(QCPPainter *painter) const;
2113 
2114  friend class QCustomPlot;
2115  friend class QCPLegend;
2116 };
2117 
2118 
2119 class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
2120 {
2121  Q_OBJECT
2123  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2124  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2126 public:
2127  QCPItemStraightLine(QCustomPlot *parentPlot);
2128  virtual ~QCPItemStraightLine();
2129 
2130  // getters:
2131  QPen pen() const { return mPen; }
2132  QPen selectedPen() const { return mSelectedPen; }
2133 
2134  // setters;
2135  void setPen(const QPen &pen);
2136  void setSelectedPen(const QPen &pen);
2137 
2138  // reimplemented virtual methods:
2139  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2140 
2141  QCPItemPosition * const point1;
2142  QCPItemPosition * const point2;
2143 
2144 protected:
2145  // property members:
2146  QPen mPen, mSelectedPen;
2147 
2148  // reimplemented virtual methods:
2149  virtual void draw(QCPPainter *painter);
2150 
2151  // non-virtual methods:
2152  double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
2153  QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
2154  QPen mainPen() const;
2155 };
2156 
2157 
2158 class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
2159 {
2160  Q_OBJECT
2162  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2163  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2164  Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
2165  Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
2167 public:
2168  QCPItemLine(QCustomPlot *parentPlot);
2169  virtual ~QCPItemLine();
2170 
2171  // getters:
2172  QPen pen() const { return mPen; }
2173  QPen selectedPen() const { return mSelectedPen; }
2174  QCPLineEnding head() const { return mHead; }
2175  QCPLineEnding tail() const { return mTail; }
2176 
2177  // setters;
2178  void setPen(const QPen &pen);
2179  void setSelectedPen(const QPen &pen);
2180  void setHead(const QCPLineEnding &head);
2181  void setTail(const QCPLineEnding &tail);
2182 
2183  // reimplemented virtual methods:
2184  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2185 
2186  QCPItemPosition * const start;
2187  QCPItemPosition * const end;
2188 
2189 protected:
2190  // property members:
2191  QPen mPen, mSelectedPen;
2192  QCPLineEnding mHead, mTail;
2193 
2194  // reimplemented virtual methods:
2195  virtual void draw(QCPPainter *painter);
2196 
2197  // non-virtual methods:
2198  QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
2199  QPen mainPen() const;
2200 };
2201 
2202 
2203 class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
2204 {
2205  Q_OBJECT
2207  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2208  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2209  Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
2210  Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
2212 public:
2213  QCPItemCurve(QCustomPlot *parentPlot);
2214  virtual ~QCPItemCurve();
2215 
2216  // getters:
2217  QPen pen() const { return mPen; }
2218  QPen selectedPen() const { return mSelectedPen; }
2219  QCPLineEnding head() const { return mHead; }
2220  QCPLineEnding tail() const { return mTail; }
2221 
2222  // setters;
2223  void setPen(const QPen &pen);
2224  void setSelectedPen(const QPen &pen);
2225  void setHead(const QCPLineEnding &head);
2226  void setTail(const QCPLineEnding &tail);
2227 
2228  // reimplemented virtual methods:
2229  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2230 
2231  QCPItemPosition * const start;
2232  QCPItemPosition * const startDir;
2233  QCPItemPosition * const endDir;
2234  QCPItemPosition * const end;
2235 
2236 protected:
2237  // property members:
2238  QPen mPen, mSelectedPen;
2239  QCPLineEnding mHead, mTail;
2240 
2241  // reimplemented virtual methods:
2242  virtual void draw(QCPPainter *painter);
2243 
2244  // non-virtual methods:
2245  QPen mainPen() const;
2246 };
2247 
2248 
2249 class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
2250 {
2251  Q_OBJECT
2253  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2254  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2255  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2256  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2258 public:
2259  QCPItemRect(QCustomPlot *parentPlot);
2260  virtual ~QCPItemRect();
2261 
2262  // getters:
2263  QPen pen() const { return mPen; }
2264  QPen selectedPen() const { return mSelectedPen; }
2265  QBrush brush() const { return mBrush; }
2266  QBrush selectedBrush() const { return mSelectedBrush; }
2267 
2268  // setters;
2269  void setPen(const QPen &pen);
2270  void setSelectedPen(const QPen &pen);
2271  void setBrush(const QBrush &brush);
2272  void setSelectedBrush(const QBrush &brush);
2273 
2274  // reimplemented virtual methods:
2275  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2276 
2277  QCPItemPosition * const topLeft;
2278  QCPItemPosition * const bottomRight;
2279  QCPItemAnchor * const top;
2280  QCPItemAnchor * const topRight;
2281  QCPItemAnchor * const right;
2282  QCPItemAnchor * const bottom;
2283  QCPItemAnchor * const bottomLeft;
2284  QCPItemAnchor * const left;
2285 
2286 protected:
2287  enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
2288 
2289  // property members:
2290  QPen mPen, mSelectedPen;
2291  QBrush mBrush, mSelectedBrush;
2292 
2293  // reimplemented virtual methods:
2294  virtual void draw(QCPPainter *painter);
2295  virtual QPointF anchorPixelPoint(int anchorId) const;
2296 
2297  // non-virtual methods:
2298  QPen mainPen() const;
2299  QBrush mainBrush() const;
2300 };
2301 
2302 
2303 class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
2304 {
2305  Q_OBJECT
2307  Q_PROPERTY(QColor color READ color WRITE setColor)
2308  Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
2309  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2310  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2311  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2312  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2313  Q_PROPERTY(QFont font READ font WRITE setFont)
2314  Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2315  Q_PROPERTY(QString text READ text WRITE setText)
2316  Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
2317  Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
2318  Q_PROPERTY(double rotation READ rotation WRITE setRotation)
2319  Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
2321 public:
2322  QCPItemText(QCustomPlot *parentPlot);
2323  virtual ~QCPItemText();
2324 
2325  // getters:
2326  QColor color() const { return mColor; }
2327  QColor selectedColor() const { return mSelectedColor; }
2328  QPen pen() const { return mPen; }
2329  QPen selectedPen() const { return mSelectedPen; }
2330  QBrush brush() const { return mBrush; }
2331  QBrush selectedBrush() const { return mSelectedBrush; }
2332  QFont font() const { return mFont; }
2333  QFont selectedFont() const { return mSelectedFont; }
2334  QString text() const { return mText; }
2335  Qt::Alignment positionAlignment() const { return mPositionAlignment; }
2336  Qt::Alignment textAlignment() const { return mTextAlignment; }
2337  double rotation() const { return mRotation; }
2338  QMargins padding() const { return mPadding; }
2339 
2340  // setters;
2341  void setColor(const QColor &color);
2342  void setSelectedColor(const QColor &color);
2343  void setPen(const QPen &pen);
2344  void setSelectedPen(const QPen &pen);
2345  void setBrush(const QBrush &brush);
2346  void setSelectedBrush(const QBrush &brush);
2347  void setFont(const QFont &font);
2348  void setSelectedFont(const QFont &font);
2349  void setText(const QString &text);
2350  void setPositionAlignment(Qt::Alignment alignment);
2351  void setTextAlignment(Qt::Alignment alignment);
2352  void setRotation(double degrees);
2353  void setPadding(const QMargins &padding);
2354 
2355  // reimplemented virtual methods:
2356  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2357 
2358  QCPItemPosition * const position;
2359  QCPItemAnchor * const topLeft;
2360  QCPItemAnchor * const top;
2361  QCPItemAnchor * const topRight;
2362  QCPItemAnchor * const right;
2363  QCPItemAnchor * const bottomRight;
2364  QCPItemAnchor * const bottom;
2365  QCPItemAnchor * const bottomLeft;
2366  QCPItemAnchor * const left;
2367 
2368 protected:
2369  enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
2370 
2371  // property members:
2372  QColor mColor, mSelectedColor;
2373  QPen mPen, mSelectedPen;
2374  QBrush mBrush, mSelectedBrush;
2375  QFont mFont, mSelectedFont;
2376  QString mText;
2377  Qt::Alignment mPositionAlignment;
2378  Qt::Alignment mTextAlignment;
2379  double mRotation;
2380  QMargins mPadding;
2381 
2382  // reimplemented virtual methods:
2383  virtual void draw(QCPPainter *painter);
2384  virtual QPointF anchorPixelPoint(int anchorId) const;
2385 
2386  // non-virtual methods:
2387  QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
2388  QFont mainFont() const;
2389  QColor mainColor() const;
2390  QPen mainPen() const;
2391  QBrush mainBrush() const;
2392 };
2393 
2394 
2395 class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
2396 {
2397  Q_OBJECT
2399  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2400  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2401  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2402  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2404 public:
2405  QCPItemEllipse(QCustomPlot *parentPlot);
2406  virtual ~QCPItemEllipse();
2407 
2408  // getters:
2409  QPen pen() const { return mPen; }
2410  QPen selectedPen() const { return mSelectedPen; }
2411  QBrush brush() const { return mBrush; }
2412  QBrush selectedBrush() const { return mSelectedBrush; }
2413 
2414  // setters;
2415  void setPen(const QPen &pen);
2416  void setSelectedPen(const QPen &pen);
2417  void setBrush(const QBrush &brush);
2418  void setSelectedBrush(const QBrush &brush);
2419 
2420  // reimplemented virtual methods:
2421  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2422 
2423  QCPItemPosition * const topLeft;
2424  QCPItemPosition * const bottomRight;
2425  QCPItemAnchor * const topLeftRim;
2426  QCPItemAnchor * const top;
2427  QCPItemAnchor * const topRightRim;
2428  QCPItemAnchor * const right;
2429  QCPItemAnchor * const bottomRightRim;
2430  QCPItemAnchor * const bottom;
2431  QCPItemAnchor * const bottomLeftRim;
2432  QCPItemAnchor * const left;
2433  QCPItemAnchor * const center;
2434 
2435 protected:
2436  enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
2437 
2438  // property members:
2439  QPen mPen, mSelectedPen;
2440  QBrush mBrush, mSelectedBrush;
2441 
2442  // reimplemented virtual methods:
2443  virtual void draw(QCPPainter *painter);
2444  virtual QPointF anchorPixelPoint(int anchorId) const;
2445 
2446  // non-virtual methods:
2447  QPen mainPen() const;
2448  QBrush mainBrush() const;
2449 };
2450 
2451 
2452 class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
2453 {
2454  Q_OBJECT
2456  Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
2457  Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
2458  Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
2459  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2460  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2462 public:
2463  QCPItemPixmap(QCustomPlot *parentPlot);
2464  virtual ~QCPItemPixmap();
2465 
2466  // getters:
2467  QPixmap pixmap() const { return mPixmap; }
2468  bool scaled() const { return mScaled; }
2469  Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
2470  QPen pen() const { return mPen; }
2471  QPen selectedPen() const { return mSelectedPen; }
2472 
2473  // setters;
2474  void setPixmap(const QPixmap &pixmap);
2475  void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);
2476  void setPen(const QPen &pen);
2477  void setSelectedPen(const QPen &pen);
2478 
2479  // reimplemented virtual methods:
2480  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2481 
2482  QCPItemPosition * const topLeft;
2483  QCPItemPosition * const bottomRight;
2484  QCPItemAnchor * const top;
2485  QCPItemAnchor * const topRight;
2486  QCPItemAnchor * const right;
2487  QCPItemAnchor * const bottom;
2488  QCPItemAnchor * const bottomLeft;
2489  QCPItemAnchor * const left;
2490 
2491 protected:
2492  enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
2493 
2494  // property members:
2495  QPixmap mPixmap;
2496  QPixmap mScaledPixmap;
2497  bool mScaled;
2498  Qt::AspectRatioMode mAspectRatioMode;
2499  QPen mPen, mSelectedPen;
2500 
2501  // reimplemented virtual methods:
2502  virtual void draw(QCPPainter *painter);
2503  virtual QPointF anchorPixelPoint(int anchorId) const;
2504 
2505  // non-virtual methods:
2506  void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
2507  QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
2508  QPen mainPen() const;
2509 };
2510 
2511 
2512 class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
2513 {
2514  Q_OBJECT
2516  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2517  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2518  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2519  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2520  Q_PROPERTY(double size READ size WRITE setSize)
2521  Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
2522  Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
2523  Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
2524  Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
2526 public:
2532  enum TracerStyle { tsNone
2533  ,tsPlus
2534  ,tsCrosshair
2535  ,tsCircle
2536  ,tsSquare
2537  };
2538  Q_ENUMS(TracerStyle)
2539 
2540  QCPItemTracer(QCustomPlot *parentPlot);
2541  virtual ~QCPItemTracer();
2542 
2543  // getters:
2544  QPen pen() const { return mPen; }
2545  QPen selectedPen() const { return mSelectedPen; }
2546  QBrush brush() const { return mBrush; }
2547  QBrush selectedBrush() const { return mSelectedBrush; }
2548  double size() const { return mSize; }
2549  TracerStyle style() const { return mStyle; }
2550  QCPGraph *graph() const { return mGraph; }
2551  double graphKey() const { return mGraphKey; }
2552  bool interpolating() const { return mInterpolating; }
2553 
2554  // setters;
2555  void setPen(const QPen &pen);
2556  void setSelectedPen(const QPen &pen);
2557  void setBrush(const QBrush &brush);
2558  void setSelectedBrush(const QBrush &brush);
2559  void setSize(double size);
2560  void setStyle(TracerStyle style);
2561  void setGraph(QCPGraph *graph);
2562  void setGraphKey(double key);
2563  void setInterpolating(bool enabled);
2564 
2565  // reimplemented virtual methods:
2566  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2567 
2568  // non-virtual methods:
2569  void updatePosition();
2570 
2571  QCPItemPosition * const position;
2572 
2573 protected:
2574  // property members:
2575  QPen mPen, mSelectedPen;
2576  QBrush mBrush, mSelectedBrush;
2577  double mSize;
2578  TracerStyle mStyle;
2579  QCPGraph *mGraph;
2580  double mGraphKey;
2581  bool mInterpolating;
2582 
2583  // reimplemented virtual methods:
2584  virtual void draw(QCPPainter *painter);
2585 
2586  // non-virtual methods:
2587  QPen mainPen() const;
2588  QBrush mainBrush() const;
2589 };
2590 
2591 
2592 class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
2593 {
2594  Q_OBJECT
2596  Q_PROPERTY(QPen pen READ pen WRITE setPen)
2597  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
2598  Q_PROPERTY(double length READ length WRITE setLength)
2599  Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
2601 public:
2602  enum BracketStyle { bsSquare
2603  ,bsRound
2604  ,bsCurly
2605  ,bsCalligraphic
2606  };
2607 
2608  QCPItemBracket(QCustomPlot *parentPlot);
2609  virtual ~QCPItemBracket();
2610 
2611  // getters:
2612  QPen pen() const { return mPen; }
2613  QPen selectedPen() const { return mSelectedPen; }
2614  double length() const { return mLength; }
2615  BracketStyle style() const { return mStyle; }
2616 
2617  // setters;
2618  void setPen(const QPen &pen);
2619  void setSelectedPen(const QPen &pen);
2620  void setLength(double length);
2621  void setStyle(BracketStyle style);
2622 
2623  // reimplemented virtual methods:
2624  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2625 
2626  QCPItemPosition * const left;
2627  QCPItemPosition * const right;
2628  QCPItemAnchor * const center;
2629 
2630 protected:
2631  // property members:
2632  enum AnchorIndex {aiCenter};
2633  QPen mPen, mSelectedPen;
2634  double mLength;
2635  BracketStyle mStyle;
2636 
2637  // reimplemented virtual methods:
2638  virtual void draw(QCPPainter *painter);
2639  virtual QPointF anchorPixelPoint(int anchorId) const;
2640 
2641  // non-virtual methods:
2642  QPen mainPen() const;
2643 };
2644 
2645 
2646 class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
2647 {
2648  Q_OBJECT
2650  Q_PROPERTY(QPixmap background READ background WRITE setBackground)
2651  Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
2652  Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
2653  Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
2654  Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
2656 public:
2657  explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
2658  virtual ~QCPAxisRect();
2659 
2660  // getters:
2661  QPixmap background() const { return mBackgroundPixmap; }
2662  bool backgroundScaled() const { return mBackgroundScaled; }
2663  Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
2664  Qt::Orientations rangeDrag() const { return mRangeDrag; }
2665  Qt::Orientations rangeZoom() const { return mRangeZoom; }
2666  QCPAxis *rangeDragAxis(Qt::Orientation orientation);
2667  QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
2668  double rangeZoomFactor(Qt::Orientation orientation);
2669 
2670  // setters:
2671  void setBackground(const QPixmap &pm);
2672  void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
2673  void setBackground(const QBrush &brush);
2674  void setBackgroundScaled(bool scaled);
2675  void setBackgroundScaledMode(Qt::AspectRatioMode mode);
2676  void setRangeDrag(Qt::Orientations orientations);
2677  void setRangeZoom(Qt::Orientations orientations);
2678  void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
2679  void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
2680  void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
2681  void setRangeZoomFactor(double factor);
2682 
2683  // non-property methods:
2684  int axisCount(QCPAxis::AxisType type) const;
2685  QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
2686  QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
2687  QList<QCPAxis*> axes() const;
2688  QCPAxis *addAxis(QCPAxis::AxisType type);
2689  QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
2690  bool removeAxis(QCPAxis *axis);
2691  QCPLayoutInset *insetLayout() const { return mInsetLayout; }
2692 
2693  void setupFullAxesBox(bool connectRanges=false);
2694  QList<QCPAbstractPlottable*> plottables() const;
2695  QList<QCPGraph*> graphs() const;
2696  QList<QCPAbstractItem*> items() const;
2697 
2698  // read-only interface imitating a QRect:
2699  int left() const { return mRect.left(); }
2700  int right() const { return mRect.right(); }
2701  int top() const { return mRect.top(); }
2702  int bottom() const { return mRect.bottom(); }
2703  int width() const { return mRect.width(); }
2704  int height() const { return mRect.height(); }
2705  QSize size() const { return mRect.size(); }
2706  QPoint topLeft() const { return mRect.topLeft(); }
2707  QPoint topRight() const { return mRect.topRight(); }
2708  QPoint bottomLeft() const { return mRect.bottomLeft(); }
2709  QPoint bottomRight() const { return mRect.bottomRight(); }
2710  QPoint center() const { return mRect.center(); }
2711 
2712  // reimplemented virtual methods:
2713  virtual void update();
2714  virtual QList<QCPLayoutElement*> elements(bool recursive) const;
2715 
2716 protected:
2717  // property members:
2718  QBrush mBackgroundBrush;
2719  QPixmap mBackgroundPixmap;
2720  QPixmap mScaledBackgroundPixmap;
2721  bool mBackgroundScaled;
2722  Qt::AspectRatioMode mBackgroundScaledMode;
2723  QCPLayoutInset *mInsetLayout;
2724  Qt::Orientations mRangeDrag, mRangeZoom;
2725  QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
2726  double mRangeZoomFactorHorz, mRangeZoomFactorVert;
2727  // non-property members:
2728  QCPRange mDragStartHorzRange, mDragStartVertRange;
2729  QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
2730  QPoint mDragStart;
2731  bool mDragging;
2732  QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
2733 
2734  // reimplemented virtual methods:
2735  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2736  virtual void draw(QCPPainter *painter);
2737  virtual int calculateAutoMargin(QCP::MarginSide side);
2738  // events:
2739  virtual void mousePressEvent(QMouseEvent *event);
2740  virtual void mouseMoveEvent(QMouseEvent *event);
2741  virtual void mouseReleaseEvent(QMouseEvent *event);
2742  virtual void wheelEvent(QWheelEvent *event);
2743 
2744  // non-property methods:
2745  void drawBackground(QCPPainter *painter);
2746  void updateAxesOffset(QCPAxis::AxisType type);
2747 
2748 private:
2749  Q_DISABLE_COPY(QCPAxisRect)
2750 
2751  friend class QCustomPlot;
2752 };
2753 
2754 
2755 class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
2756 {
2757  Q_OBJECT
2759  Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
2760  Q_PROPERTY(QFont font READ font WRITE setFont)
2761  Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2762  Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2763  Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2764  Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
2765  Q_PROPERTY(bool selected READ selected WRITE setSelected)
2767 public:
2768  explicit QCPAbstractLegendItem(QCPLegend *parent);
2769 
2770  // getters:
2771  QCPLegend *parentLegend() const { return mParentLegend; }
2772  QFont font() const { return mFont; }
2773  QColor textColor() const { return mTextColor; }
2774  QFont selectedFont() const { return mSelectedFont; }
2775  QColor selectedTextColor() const { return mSelectedTextColor; }
2776  bool selectable() const { return mSelectable; }
2777  bool selected() const { return mSelected; }
2778 
2779  // setters:
2780  void setFont(const QFont &font);
2781  void setTextColor(const QColor &color);
2782  void setSelectedFont(const QFont &font);
2783  void setSelectedTextColor(const QColor &color);
2784  void setSelectable(bool selectable);
2785  void setSelected(bool selected);
2786 
2787  // reimplemented virtual methods:
2788  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2789 
2790 signals:
2791  void selectionChanged(bool selected);
2792 
2793 protected:
2794  // property members:
2795  QCPLegend *mParentLegend;
2796  QFont mFont;
2797  QColor mTextColor;
2798  QFont mSelectedFont;
2799  QColor mSelectedTextColor;
2800  bool mSelectable, mSelected;
2801 
2802  // reimplemented virtual methods:
2803  virtual QCP::Interaction selectionCategory() const;
2804  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2805  virtual QRect clipRect() const;
2806  virtual void draw(QCPPainter *painter) = 0;
2807  // events:
2808  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2809  virtual void deselectEvent(bool *selectionStateChanged);
2810 
2811 private:
2812  Q_DISABLE_COPY(QCPAbstractLegendItem)
2813 
2814  friend class QCPLegend;
2815 };
2816 
2817 
2818 class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
2819 {
2820  Q_OBJECT
2821 public:
2822  QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
2823 
2824  // getters:
2825  QCPAbstractPlottable *plottable() { return mPlottable; }
2826 
2827 protected:
2828  // property members:
2829  QCPAbstractPlottable *mPlottable;
2830 
2831  // reimplemented virtual methods:
2832  virtual void draw(QCPPainter *painter);
2833  virtual QSize minimumSizeHint() const;
2834 
2835  // non-virtual methods:
2836  QPen getIconBorderPen() const;
2837  QColor getTextColor() const;
2838  QFont getFont() const;
2839 };
2840 
2841 
2842 class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
2843 {
2844  Q_OBJECT
2846  Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
2847  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2848  Q_PROPERTY(QFont font READ font WRITE setFont)
2849  Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2850  Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
2851  Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
2852  Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
2853  Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts)
2854  Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts)
2855  Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
2856  Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
2857  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2858  Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2859  Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2861 public:
2867  enum SelectablePart { spNone = 0x000
2868  ,spLegendBox = 0x001
2869  ,spItems = 0x002
2870  };
2871  Q_FLAGS(SelectablePart SelectableParts)
2872  Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
2873 
2874  explicit QCPLegend();
2875  virtual ~QCPLegend();
2876 
2877  // getters:
2878  QPen borderPen() const { return mBorderPen; }
2879  QBrush brush() const { return mBrush; }
2880  QFont font() const { return mFont; }
2881  QColor textColor() const { return mTextColor; }
2882  QSize iconSize() const { return mIconSize; }
2883  int iconTextPadding() const { return mIconTextPadding; }
2884  QPen iconBorderPen() const { return mIconBorderPen; }
2885  SelectableParts selectableParts() const { return mSelectableParts; }
2886  SelectableParts selectedParts() const;
2887  QPen selectedBorderPen() const { return mSelectedBorderPen; }
2888  QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
2889  QBrush selectedBrush() const { return mSelectedBrush; }
2890  QFont selectedFont() const { return mSelectedFont; }
2891  QColor selectedTextColor() const { return mSelectedTextColor; }
2892 
2893  // setters:
2894  void setBorderPen(const QPen &pen);
2895  void setBrush(const QBrush &brush);
2896  void setFont(const QFont &font);
2897  void setTextColor(const QColor &color);
2898  void setIconSize(const QSize &size);
2899  void setIconSize(int width, int height);
2900  void setIconTextPadding(int padding);
2901  void setIconBorderPen(const QPen &pen);
2902  void setSelectableParts(const SelectableParts &selectableParts);
2903  void setSelectedParts(const SelectableParts &selectedParts);
2904  void setSelectedBorderPen(const QPen &pen);
2905  void setSelectedIconBorderPen(const QPen &pen);
2906  void setSelectedBrush(const QBrush &brush);
2907  void setSelectedFont(const QFont &font);
2908  void setSelectedTextColor(const QColor &color);
2909 
2910  // reimplemented virtual methods:
2911  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2912 
2913  // non-virtual methods:
2914  QCPAbstractLegendItem *item(int index) const;
2915  QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
2916  int itemCount() const;
2917  bool hasItem(QCPAbstractLegendItem *item) const;
2918  bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
2919  bool addItem(QCPAbstractLegendItem *item);
2920  bool removeItem(int index);
2921  bool removeItem(QCPAbstractLegendItem *item);
2922  void clearItems();
2923  QList<QCPAbstractLegendItem*> selectedItems() const;
2924 
2925 signals:
2926  void selectionChanged(QCPLegend::SelectableParts selection);
2927 
2928 protected:
2929  // property members:
2930  QPen mBorderPen, mIconBorderPen;
2931  QBrush mBrush;
2932  QFont mFont;
2933  QColor mTextColor;
2934  QSize mIconSize;
2935  int mIconTextPadding;
2936  SelectableParts mSelectedParts, mSelectableParts;
2937  QPen mSelectedBorderPen, mSelectedIconBorderPen;
2938  QBrush mSelectedBrush;
2939  QFont mSelectedFont;
2940  QColor mSelectedTextColor;
2941 
2942  // reimplemented virtual methods:
2943  virtual void parentPlotInitialized(QCustomPlot *parentPlot);
2944  virtual QCP::Interaction selectionCategory() const;
2945  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2946  virtual void draw(QCPPainter *painter);
2947  // events:
2948  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2949  virtual void deselectEvent(bool *selectionStateChanged);
2950 
2951  // non-virtual methods:
2952  QPen getBorderPen() const;
2953  QBrush getBrush() const;
2954 
2955 private:
2956  Q_DISABLE_COPY(QCPLegend)
2957 
2958  friend class QCustomPlot;
2959  friend class QCPAbstractLegendItem;
2960 };
2961 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
2962 Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
2963 
2964 
2965 class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
2966 {
2967  Q_OBJECT
2969  Q_PROPERTY(QString text READ text WRITE setText)
2970  Q_PROPERTY(QFont font READ font WRITE setFont)
2971  Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2972  Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2973  Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2974  Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
2975  Q_PROPERTY(bool selected READ selected WRITE setSelected)
2977 public:
2978  explicit QCPPlotTitle(QCustomPlot *parentPlot);
2979  explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text);
2980 
2981  // getters:
2982  QString text() const { return mText; }
2983  QFont font() const { return mFont; }
2984  QColor textColor() const { return mTextColor; }
2985  QFont selectedFont() const { return mSelectedFont; }
2986  QColor selectedTextColor() const { return mSelectedTextColor; }
2987  bool selectable() const { return mSelectable; }
2988  bool selected() const { return mSelected; }
2989 
2990  // setters:
2991  void setText(const QString &text);
2992  void setFont(const QFont &font);
2993  void setTextColor(const QColor &color);
2994  void setSelectedFont(const QFont &font);
2995  void setSelectedTextColor(const QColor &color);
2996  void setSelectable(bool selectable);
2997  void setSelected(bool selected);
2998 
2999  // reimplemented virtual methods:
3000  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3001 
3002 signals:
3003  void selectionChanged(bool selected);
3004 
3005 protected:
3006  // property members:
3007  QString mText;
3008  QFont mFont;
3009  QColor mTextColor;
3010  QFont mSelectedFont;
3011  QColor mSelectedTextColor;
3012  QRect mTextBoundingRect;
3013  bool mSelectable, mSelected;
3014 
3015  // reimplemented virtual methods:
3016  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
3017  virtual void draw(QCPPainter *painter);
3018  virtual QSize minimumSizeHint() const;
3019  virtual QSize maximumSizeHint() const;
3020  // events:
3021  virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
3022  virtual void deselectEvent(bool *selectionStateChanged);
3023 
3024  // non-virtual methods:
3025  QFont mainFont() const;
3026  QColor mainTextColor() const;
3027 
3028 private:
3029  Q_DISABLE_COPY(QCPPlotTitle)
3030 };
3031 
3032 #endif // QCUSTOMPLOT_H
3033 
AxisType
Definition: qcustomplot.h:917
QCPLayoutGrid * plotLayout() const
Definition: qcustomplot.h:1508
A bracket for referencing/highlighting certain parts in the plot.
Definition: qcustomplot.h:2592
QCPItemPosition * position(const QString &name) const
Definition: qcustomplot.cpp:7964
A margin group allows synchronization of margin sides if working with multiple layout elements...
Definition: qcustomplot.h:487
An arbitrary pixmap.
Definition: qcustomplot.h:2452
0xFFFF All elements
Definition: qcustomplot.h:124
QList< QCPLayoutElement * > elements(QCP::MarginSide side) const
Definition: qcustomplot.h:495
LayerInsertMode
Definition: qcustomplot.h:1495
static const double maxRange
Definition: qcustomplot.h:482
0x08 bottom margin
Definition: qcustomplot.h:98
QMap< double, QCPData > QCPDataMap
Definition: qcustomplot.h:1707
Holds the data of one single data point for QCPCurve.
Definition: qcustomplot.h:1854
No line is drawn between data points (e.g. only scatters)
Definition: qcustomplot.h:1889
void rescaleKeyAxis(bool onlyEnlarge=false) const
Definition: qcustomplot.cpp:6798
A legend item representing a plottable with an icon and the plottable name.
Definition: qcustomplot.h:2818
ScaleType
Definition: qcustomplot.h:938
virtual QList< QCPLayoutElement * > elements(bool recursive) const
Definition: qcustomplot.cpp:2075
PainterMode
Definition: qcustomplot.h:315
Definition: qcustomplot.h:137
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: qcustomplot.h:577
int bottom() const
Definition: qcustomplot.h:2702
The abstract base class for all entries in a QCPLegend.
Definition: qcustomplot.h:2755
virtual int elementCount() const =0
0x0001 Axis base line and tick marks
Definition: qcustomplot.h:113
0x0008 Legend box
Definition: qcustomplot.h:116
Responsible for drawing the grid of a QCPAxis.
Definition: qcustomplot.h:807
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes) ...
Definition: qcustomplot.h:150
EndingStyle
Definition: qcustomplot.h:765
0x00 no margin
Definition: qcustomplot.h:100
0x04 top margin
Definition: qcustomplot.h:97
An anchor of an item to which positions can be attached to.
Definition: qcustomplot.h:1313
0x0004 Sub grid lines
Definition: qcustomplot.h:115
virtual QList< QCPLayoutElement * > elements(bool recursive) const
Definition: qcustomplot.cpp:2246
0x0002 Grid lines
Definition: qcustomplot.h:114
0x01 left margin
Definition: qcustomplot.h:95
Base class for all drawable objects.
Definition: qcustomplot.h:397
TracerStyle
Definition: qcustomplot.h:2532
A plottable representing a bar chart in a plot.
Definition: qcustomplot.h:1972
0x080 All other objects are selectable (e.g. your own derived layerables, the plot title...
Definition: qcustomplot.h:157
A curved line from one point to another.
Definition: qcustomplot.h:2203
0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) ...
Definition: qcustomplot.h:120
QList< QCPLayerable * > children() const
Definition: qcustomplot.h:377
A layout that arranges child elements in a grid.
Definition: qcustomplot.h:634
Definition: qcustomplot.h:1090
virtual QCPLayoutElement * takeAt(int index)=0
ErrorType
Definition: qcustomplot.h:1742
QPoint bottomLeft() const
Definition: qcustomplot.h:2708
virtual QSize minimumSizeHint() const
Definition: qcustomplot.cpp:3039
0x0040 Main lines of items
Definition: qcustomplot.h:119
The abstract base class for all data representing objects in a plot.
Definition: qcustomplot.h:1199
ScatterShape
Definition: qcustomplot.h:241
A plottable representing a single statistical box in a plot.
Definition: qcustomplot.h:2037
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const =0
0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) ...
Definition: qcustomplot.h:153
virtual QSize minimumSizeHint() const
Definition: qcustomplot.cpp:2051
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const =0
Definition: qcustomplot.h:135
virtual void update()
Definition: qcustomplot.cpp:2019
A plottable representing a graph in a plot.
Definition: qcustomplot.h:1712
The abstract base class for all items in a plot.
Definition: qcustomplot.h:1403
0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance.
Definition: qcustomplot.h:139
Item that sticks to QCPGraph data points.
Definition: qcustomplot.h:2512
virtual QSize maximumSizeHint() const
Definition: qcustomplot.cpp:2063
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition: qcustomplot.h:1475
0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see QCPAbstractItem) ...
Definition: qcustomplot.h:156
virtual void wheelEvent(QWheelEvent *event)
Definition: qcustomplot.h:580
Manages a single axis inside a QCustomPlot.
Definition: qcustomplot.h:857
QList< QCPItemAnchor * > anchors() const
Definition: qcustomplot.h:1433
bool isPenDefined() const
Definition: qcustomplot.h:287
Represents the visual appearance of scatter points.
Definition: qcustomplot.h:229
int index() const
Definition: qcustomplot.h:376
Manages a legend inside a QCustomPlot.
Definition: qcustomplot.h:2842
QList< QCPItemPosition * > positions() const
Definition: qcustomplot.h:1432
QCPLayerable * parentLayerable() const
Definition: qcustomplot.h:414
virtual bool take(QCPLayoutElement *element)=0
0x0200 Borders of fills (e.g. under or between graphs)
Definition: qcustomplot.h:122
0x004 The user can select multiple objects by holding the modifier set by QCustomPlot::setMultiSelect...
Definition: qcustomplot.h:152
virtual void clearData()=0
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const
Definition: qcustomplot.cpp:2092
int height() const
Definition: qcustomplot.h:2704
A layer that may contain objects, to control the rendering order.
Definition: qcustomplot.h:360
Qt::Orientation orientation() const
Definition: qcustomplot.h:1069
A rectangle.
Definition: qcustomplot.h:2249
The abstract base class for all objects that form the layout system.
Definition: qcustomplot.h:516
PlottingHint
Definition: qcustomplot.h:134
A straight line that spans infinitely in both directions.
Definition: qcustomplot.h:2119
QMap< double, QCPBarData > QCPBarDataMap
Definition: qcustomplot.h:1967
SelectablePart
Definition: qcustomplot.h:2867
A layout that places child elements aligned to the border or arbitrarily positioned.
Definition: qcustomplot.h:700
0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) ...
Definition: qcustomplot.h:155
Handles the different ending decorations for line-like items.
Definition: qcustomplot.h:749
QPoint center() const
Definition: qcustomplot.h:2710
Holds the data of one single data point for QCPGraph.
Definition: qcustomplot.h:1689
Definition: qcustomplot.h:1095
virtual QCPItemPosition * toQCPItemPosition()
Definition: qcustomplot.h:1334
QPainter subclass used internally.
Definition: qcustomplot.h:307
LineStyle
Definition: qcustomplot.h:1730
LineStyle
Definition: qcustomplot.h:1889
int left() const
Definition: qcustomplot.h:2699
0x0100 Error bars
Definition: qcustomplot.h:121
SignDomain
Definition: qcustomplot.h:1265
static const double minRange
Definition: qcustomplot.h:481
bool isNone() const
Definition: qcustomplot.h:286
BracketStyle
Definition: qcustomplot.h:2602
void rescaleAxes(bool onlyEnlarge=false) const
Definition: qcustomplot.cpp:6787
0x0020 Main lines of plottables (excluding error bars, see element aeErrorBars)
Definition: qcustomplot.h:118
Interaction
Definition: qcustomplot.h:150
QCPBars * barBelow() const
Definition: qcustomplot.h:1986
int top() const
Definition: qcustomplot.h:2701
0x000 No hints are set
Definition: qcustomplot.h:134
virtual QCPItemPosition * toQCPItemPosition()
Definition: qcustomplot.h:1395
A plottable representing a parametric curve in a plot.
Definition: qcustomplot.h:1876
virtual QCPLayoutElement * elementAt(int index) const =0
QCPLayout * layout() const
Definition: qcustomplot.h:533
0x0000 No elements
Definition: qcustomplot.h:125
void rescaleValueAxis(bool onlyEnlarge=false) const
Definition: qcustomplot.cpp:6825
A layout element displaying a plot title text.
Definition: qcustomplot.h:2965
0x02 right margin
Definition: qcustomplot.h:96
QCPLayoutInset * insetLayout() const
Definition: qcustomplot.h:2691
An ellipse.
Definition: qcustomplot.h:2395
QPoint topLeft() const
Definition: qcustomplot.h:2706
virtual void simplify()
Definition: qcustomplot.cpp:2273
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition: qcustomplot.h:579
QRect rect() const
Definition: qcustomplot.h:534
SelectablePart
Definition: qcustomplot.h:946
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom, QCPAxisRect::setRangeZoomAxes)
Definition: qcustomplot.h:151
0x0010 Legend items
Definition: qcustomplot.h:117
The abstract base class for layouts.
Definition: qcustomplot.h:596
A text label.
Definition: qcustomplot.h:2303
QCPBars * barAbove() const
Definition: qcustomplot.h:1987
QSize size() const
Definition: qcustomplot.h:2705
virtual void mousePressEvent(QMouseEvent *event)
Definition: qcustomplot.h:576
PositionType
Definition: qcustomplot.h:1357
QPoint bottomRight() const
Definition: qcustomplot.h:2709
QPoint topRight() const
Definition: qcustomplot.h:2707
A line from one point to another.
Definition: qcustomplot.h:2158
Definition: qcustomplot.h:88
virtual QSize maximumSizeHint() const
Definition: qcustomplot.cpp:3054
0x0400 Zero-lines, see QCPGrid::setZeroLinePen
Definition: qcustomplot.h:123
Manages the position of an item.
Definition: qcustomplot.h:1348
QCPGrid * grid() const
Definition: qcustomplot.h:1007
Represents the range an axis is encompassing.
Definition: qcustomplot.h:462
0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
Definition: qcustomplot.h:154
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const
Definition: qcustomplot.cpp:1039
0xFF all margins
Definition: qcustomplot.h:99
Holds multiple axes and arranges them in a rectangular shape.
Definition: qcustomplot.h:2646
int width() const
Definition: qcustomplot.h:2703
InsetPlacement
Definition: qcustomplot.h:707
virtual void simplify()
Definition: qcustomplot.h:730
QMap< double, QCPCurveData > QCPCurveDataMap
Definition: qcustomplot.h:1871
MarginSide
Definition: qcustomplot.h:95
AntialiasedElement
Definition: qcustomplot.h:113
LabelType
Definition: qcustomplot.h:930
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: qcustomplot.h:578
int right() const
Definition: qcustomplot.h:2700
Holds the data of one single data point (one bar) for QCPBars.
Definition: qcustomplot.h:1951