Aquila  2.0 prealpha
Cognitive Robotics Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plot2d.h
Go to the documentation of this file.
1 //#######################################################################//
2 // //
3 // QCustomPlot, a simple to use, modern plotting widget for Qt //
4 // Copyright (C) 2012 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.WorksLikeClockwork.com/ //
22 // Date: 09.06.12 //
23 //#######################################################################//
24 
25 #ifndef QCUSTOMPLOT_H
26 #define QCUSTOMPLOT_H
27 
28 #include <QObject>
29 #include <QWidget>
30 #include <QPainter>
31 #include <QPaintEvent>
32 #include <QPixmap>
33 #include <QVector>
34 #include <QString>
35 #include <QPrinter>
36 #include <QDateTime>
37 #include <QMultiMap>
38 #include <QFlags>
39 #include <QDebug>
40 #include <QVector2D>
41 #include <QStack>
42 #include <qmath.h>
43 #include <limits>
44 
45 //decl definitions for shared library compilation/usage:
46 #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
47 # define QCP_LIB_DECL Q_DECL_EXPORT
48 #elif defined(QCUSTOMPLOT_USE_LIBRARY)
49 # define QCP_LIB_DECL Q_DECL_IMPORT
50 #else
51 # define QCP_LIB_DECL
52 #endif
53 
54 class QCustomPlot;
55 class QCPLegend;
56 class QCPRange;
57 class QCPLayerable;
58 class QCPAbstractItem;
59 class QCPItemPosition;
60 class QCPAxis;
61 class QCPData;
62 
66 namespace QCP
67 {
94  };
95 
106 enum AntialiasedElement { aeAxes = 0x0001
107  ,aeGrid = 0x0002
108  ,aeSubGrid = 0x0004
109  ,aeLegend = 0x0008
110  ,aeLegendItems = 0x0010
111  ,aePlottables = 0x0020
112  ,aeItems = 0x0040
113  ,aeScatters = 0x0080
114  ,aeErrorBars = 0x0100
115  ,aeFills = 0x0200
116  ,aeZeroLine = 0x0400
117  ,aeAll = 0xFFFF
118  ,aeNone = 0x0000
119  };
120 Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
121 
122 
126 enum PlottingHint { phNone = 0x000
127  ,phFastPolylines = 0x001
128 
129  ,phForceRepaint = 0x002
130 
131  };
132 Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
133 }
134 
135 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
136 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
137 
139 {
140 public:
141  QCPData();
142  QCPData(double key, double value);
143  double key, value;
144  double keyErrorPlus, keyErrorMinus;
145  double valueErrorPlus, valueErrorMinus;
146 };
147 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
148 
156 typedef QMap<double, QCPData> QCPDataMap;
157 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
158 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
159 
161 {
162 public:
163  QCPCurveData();
164  QCPCurveData(double t, double key, double value);
165  double t, key, value;
166 };
167 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
168 
177 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
178 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
179 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
180 
182 {
183 public:
184  QCPBarData();
185  QCPBarData(double key, double value);
186  double key, value;
187 };
188 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
189 
197 typedef QMap<double, QCPBarData> QCPBarDataMap;
198 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
199 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
200 
201 class QCP_LIB_DECL QCPPainter : public QPainter
202 {
203 public:
204  QCPPainter();
205  QCPPainter(QPaintDevice *device);
206  ~QCPPainter();
207 
208  //getters:
209  QPixmap scatterPixmap() const { return mScatterPixmap; }
210  bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
211  bool pdfExportMode() const { return mPdfExportMode; }
212  bool scaledExportMode() const { return mScaledExportMode; }
213 
214  //setters:
215  void setScatterPixmap(const QPixmap pm);
216  void setAntialiasing(bool enabled);
217  void setPdfExportMode(bool enabled);
218  void setScaledExportMode(bool enabled);
219 
220  //methods hiding non-virtual base class functions (QPainter bug workarounds):
221  void setPen(const QPen &pen);
222  void setPen(const QColor &color);
223  void setPen(Qt::PenStyle penStyle);
224  void drawLine(const QLineF &line);
225  void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
226  void save();
227  void restore();
228 
229  //helpers:
230  void fixScaledPen();
231  void drawScatter(double x, double y, double size, QCP::ScatterStyle style);
232 
233 protected:
234  QPixmap mScatterPixmap;
238  QStack<bool> mAntialiasingStack;
239 };
240 
242 {
243 public:
255  enum EndingStyle { esNone
256  ,esFlatArrow
257  ,esSpikeArrow
258  ,esLineArrow
259  ,esDisc
260  ,esSquare
261  ,esDiamond
262  ,esBar
263  };
264 
265  QCPLineEnding();
266  QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
267 
268  //getters:
269  EndingStyle style() const { return mStyle; }
270  double width() const { return mWidth; }
271  double length() const { return mLength; }
272  bool inverted() const { return mInverted; }
273 
274  //setters:
275  void setStyle(EndingStyle style);
276  void setWidth(double width);
277  void setLength(double length);
278  void setInverted(bool inverted);
279 
280  //non-property methods:
281  double boundingDistance() const;
282  void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
283  void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
284 
285 protected:
287  double mWidth, mLength;
288  bool mInverted;
289 };
290 Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
291 
293 {
294 public:
295  QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
296  ~QCPLayer();
297 
298  //getters:
299  QCustomPlot *parentPlot() const { return mParentPlot; }
300  QString name() const { return mName; }
301  int index() const;
302  QList<QCPLayerable*> children() const { return mChildren; }
303 
304 protected:
306  QString mName;
307  QList<QCPLayerable*> mChildren;
308 
309  void addChild(QCPLayerable *layerable, bool prepend);
310  void removeChild(QCPLayerable *layerable);
311 
312 private:
313  Q_DISABLE_COPY(QCPLayer)
314 
315  friend class QCPLayerable;
316 };
317 
318 class QCP_LIB_DECL QCPLayerable : public QObject
319 {
320  Q_OBJECT
321 public:
322  QCPLayerable(QCustomPlot *parentPlot);
323  ~QCPLayerable();
324 
325  //getters:
326  bool visible() const { return mVisible; }
327  QCustomPlot *parentPlot() const { return mParentPlot; }
328  QCPLayer *layer() const { return mLayer; }
329  bool antialiased() const { return mAntialiased; }
330 
331  //setters:
332  void setVisible(bool on);
333  bool setLayer(QCPLayer *layer);
334  bool setLayer(const QString &layerName);
335  void setAntialiased(bool enabled);
336 
337 protected:
338  bool mVisible;
342 
343  //non-property methods:
344  bool moveToLayer(QCPLayer *layer, bool prepend);
345 
346  void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
347  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
348  virtual QRect clipRect() const;
349  virtual void draw(QCPPainter *painter) = 0;
350 
351 private:
352  Q_DISABLE_COPY(QCPLayerable)
353 
354  friend class QCustomPlot;
355 };
356 
357 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
358 {
359  Q_OBJECT
360 public:
361  QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
363 
364  //getters:
365  QString name() const { return mName; }
366  bool antialiasedFill() const { return mAntialiasedFill; }
367  bool antialiasedScatters() const { return mAntialiasedScatters; }
368  bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
369  QPen pen() const { return mPen; }
370  QPen selectedPen() const { return mSelectedPen; }
371  QBrush brush() const { return mBrush; }
372  QBrush selectedBrush() const { return mSelectedBrush; }
373  QCPAxis *keyAxis() const { return mKeyAxis; }
374  QCPAxis *valueAxis() const { return mValueAxis; }
375  bool selectable() const { return mSelectable; }
376  bool selected() const { return mSelected; }
377 
378  //setters:
379  void setName(const QString &name);
380  void setAntialiasedFill(bool enabled);
381  void setAntialiasedScatters(bool enabled);
382  void setAntialiasedErrorBars(bool enabled);
383  void setPen(const QPen &pen);
384  void setSelectedPen(const QPen &pen);
385  void setBrush(const QBrush &brush);
386  void setSelectedBrush(const QBrush &brush);
387  void setKeyAxis(QCPAxis *axis);
388  void setValueAxis(QCPAxis *axis);
389  void setSelectable(bool selectable);
390  void setSelected(bool selected);
391 
392  //non-property methods:
393  void rescaleAxes(bool onlyEnlarge=false) const;
394  void rescaleKeyAxis(bool onlyEnlarge=false) const;
395  void rescaleValueAxis(bool onlyEnlarge=false) const;
396  virtual void clearData() = 0;
397  virtual double selectTest(const QPointF &pos) const = 0;
398  virtual bool addToLegend();
399  virtual bool removeFromLegend() const;
400 
401 signals:
402  void selectionChanged(bool selected);
403 
404 protected:
408  enum SignDomain { sdNegative
409  ,sdBoth
410  ,sdPositive
411  };
412  QString mName;
413  bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
414  QPen mPen, mSelectedPen;
415  QBrush mBrush, mSelectedBrush;
416  QCPAxis *mKeyAxis, *mValueAxis;
417  bool mSelected, mSelectable;
418 
419  virtual QRect clipRect() const;
420  virtual void draw(QCPPainter *painter) = 0;
421  virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0;
422  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
423  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
424 
425  //painting and coordinate transformation helpers:
426  void coordsToPixels(double key, double value, double &x, double &y) const;
427  const QPointF coordsToPixels(double key, double value) const;
428  void pixelsToCoords(double x, double y, double &key, double &value) const;
429  void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
430  QPen mainPen() const;
431  QBrush mainBrush() const;
432  void applyDefaultAntialiasingHint(QCPPainter *painter) const;
433  void applyFillAntialiasingHint(QCPPainter *painter) const;
434  void applyScattersAntialiasingHint(QCPPainter *painter) const;
435  void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
436 
437  //selection test helpers:
438  double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
439 
440 private:
441  Q_DISABLE_COPY(QCPAbstractPlottable)
442 
443  friend class QCustomPlot;
445 };
446 
448 {
449  Q_OBJECT
450 public:
456  enum LineStyle { lsNone
457 
458  ,lsLine
459  ,lsStepLeft
460  ,lsStepRight
461  ,lsStepCenter
462  ,lsImpulse
463  };
464  Q_ENUMS(LineStyle)
468  enum ErrorType { etNone
469  ,etKey
470  ,etValue
471  ,etBoth
472  };
473  Q_ENUMS(ErrorType)
474 
475  explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
476  virtual ~QCPGraph();
477 
478  //getters:
479  const QCPDataMap *data() const { return mData; }
480  LineStyle lineStyle() const { return mLineStyle; }
481  QCP::ScatterStyle scatterStyle() const { return mScatterStyle; }
482  double scatterSize() const { return mScatterSize; }
483  const QPixmap scatterPixmap() const { return mScatterPixmap; }
484  ErrorType errorType() const { return mErrorType; }
485  QPen errorPen() const { return mErrorPen; }
486  double errorBarSize() const { return mErrorBarSize; }
487  bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
488  QCPGraph *channelFillGraph() const { return mChannelFillGraph; }
489 
490  //setters:
491  void setData(QCPDataMap *data, bool copy=false);
492  void setData(const QVector<double> &key, const QVector<double> &value);
493  void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
494  void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
495  void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
496  void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
497  void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
498  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);
499  void setLineStyle(LineStyle ls);
500  void setScatterStyle(QCP::ScatterStyle ss);
501  void setScatterSize(double size);
502  void setScatterPixmap(const QPixmap &pixmap);
503  void setErrorType(ErrorType errorType);
504  void setErrorPen(const QPen &pen);
505  void setErrorBarSize(double size);
506  void setErrorBarSkipSymbol(bool enabled);
507  void setChannelFillGraph(QCPGraph *targetGraph);
508 
509  //non-property methods:
510  void addData(const QCPDataMap &dataMap);
511  void addData(const QCPData &data);
512  void addData(double key, double value);
513  void addData(const QVector<double> &keys, const QVector<double> &values);
514  void removeDataBefore(double key);
515  void removeDataAfter(double key);
516  void removeData(double fromKey, double toKey);
517  void removeData(double key);
518  virtual void clearData();
519  virtual double selectTest(const QPointF &pos) const;
523  virtual void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; //overloads base class interface
524  virtual void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; //overloads base class interface
525  virtual void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; //overloads base class interface
526 
527 protected:
529  QPen mErrorPen;
532  double mScatterSize;
533  QPixmap mScatterPixmap;
538 
539  virtual void draw(QCPPainter *painter);
540  virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
541 
542  //functions to generate plot data points in pixel coordinates:
543  void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
544  //plot style specific functions to generate plot data, used by getPlotData:
545  void getScatterPlotData(QVector<QCPData> *pointData) const;
546  void getLinePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
547  void getStepLeftPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
548  void getStepRightPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
549  void getStepCenterPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
550  void getImpulsePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
551 
552  //helper functions for drawing:
553  void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
554  void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *pointData) const;
555  void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
556  void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
557  void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
558 
559  //helper functions:
560  void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const;
561  void addFillBasePoints(QVector<QPointF> *lineData) const;
562  void removeFillBasePoints(QVector<QPointF> *lineData) const;
563  QPointF lowerFillBasePoint(double lowerKey) const;
564  QPointF upperFillBasePoint(double upperKey) const;
565  const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
566  int findIndexBelowX(const QVector<QPointF> *data, double x) const;
567  int findIndexAboveX(const QVector<QPointF> *data, double x) const;
568  int findIndexBelowY(const QVector<QPointF> *data, double y) const;
569  int findIndexAboveY(const QVector<QPointF> *data, double y) const;
570  double pointDistance(const QPointF &pixelPoint) const;
571  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
572  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
573  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; //overloads base class interface
574  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; //overloads base class interface
575 
576  friend class QCustomPlot;
577  friend class QCPLegend;
578 };
579 
581 {
582  Q_OBJECT
583 public:
589  enum LineStyle { lsNone,
590  lsLine
591  };
592  explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
593  virtual ~QCPCurve();
594 
595  //getters:
596  const QCPCurveDataMap *data() const { return mData; }
597  QCP::ScatterStyle scatterStyle() const { return mScatterStyle; }
598  double scatterSize() const { return mScatterSize; }
599  QPixmap scatterPixmap() const { return mScatterPixmap; }
600  LineStyle lineStyle() const { return mLineStyle; }
601 
602  //setters:
603  void setData(QCPCurveDataMap *data, bool copy=false);
604  void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
605  void setData(const QVector<double> &key, const QVector<double> &value);
606  void setScatterStyle(QCP::ScatterStyle style);
607  void setScatterSize(double size);
608  void setScatterPixmap(const QPixmap &pixmap);
609  void setLineStyle(LineStyle style);
610 
611  //non-property methods:
612  void addData(const QCPCurveDataMap &dataMap);
613  void addData(const QCPCurveData &data);
614  void addData(double t, double key, double value);
615  void addData(double key, double value);
616  void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
617  void removeDataBefore(double t);
618  void removeDataAfter(double t);
619  void removeData(double fromt, double tot);
620  void removeData(double t);
621  virtual void clearData();
622  virtual double selectTest(const QPointF &pos) const;
623 
624 protected:
627  double mScatterSize;
628  QPixmap mScatterPixmap;
630 
631  virtual void draw(QCPPainter *painter);
632  virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
633  //drawing helpers:
634  virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
635 
636  //helper functions:
637  void getCurveData(QVector<QPointF> *lineData) const;
638  double pointDistance(const QPointF &pixelPoint) const;
639 
640  QPointF outsideCoordsToPixels(double key, double value, int region) const;
641  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
642  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
643 
644  friend class QCustomPlot;
645  friend class QCPLegend;
646 };
647 
649 {
650  Q_OBJECT
651 public:
652  explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
653  virtual ~QCPBars();
654 
655  //getters:
656  double width() const { return mWidth; }
657  QCPBars *barBelow() const { return mBarBelow; }
658  QCPBars *barAbove() const { return mBarAbove; }
659  const QCPBarDataMap *data() const { return mData; }
660 
661  //setters:
662  void setWidth(double width);
663  void setData(QCPBarDataMap *data, bool copy=false);
664  void setData(const QVector<double> &key, const QVector<double> &value);
665 
666  //non-property methods:
667  void moveBelow(QCPBars *bars);
668  void moveAbove(QCPBars *bars);
669  void addData(const QCPBarDataMap &dataMap);
670  void addData(const QCPBarData &data);
671  void addData(double key, double value);
672  void addData(const QVector<double> &keys, const QVector<double> &values);
673  void removeDataBefore(double key);
674  void removeDataAfter(double key);
675  void removeData(double fromKey, double toKey);
676  void removeData(double key);
677  virtual void clearData();
678  virtual double selectTest(const QPointF &pos) const;
679 
680 protected:
682  double mWidth;
683  QCPBars *mBarBelow, *mBarAbove;
684 
685  virtual void draw(QCPPainter *painter);
686  virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
687 
688  QPolygonF getBarPolygon(double key, double value) const;
689  double getBaseValue(double key, bool positive) const;
690  static void connectBars(QCPBars* lower, QCPBars* upper);
691  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
692  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
693 
694  friend class QCustomPlot;
695  friend class QCPLegend;
696 };
697 
699 {
700  Q_OBJECT
701 public:
702  explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
703  virtual ~QCPStatisticalBox();
704 
705  //getters:
706  double key() const { return mKey; }
707  double minimum() const { return mMinimum; }
708  double lowerQuartile() const { return mLowerQuartile; }
709  double median() const { return mMedian; }
710  double upperQuartile() const { return mUpperQuartile; }
711  double maximum() const { return mMaximum; }
712  QVector<double> outliers() const { return mOutliers; }
713  double width() const { return mWidth; }
714  double whiskerWidth() const { return mWhiskerWidth; }
715  QPen whiskerPen() const { return mWhiskerPen; }
716  QPen whiskerBarPen() const { return mWhiskerBarPen; }
717  QPen medianPen() const { return mMedianPen; }
718  double outlierSize() const { return mOutlierSize; }
719  QPen outlierPen() const { return mOutlierPen; }
720  QCP::ScatterStyle outlierStyle() const { return mOutlierStyle; }
721 
722  //setters:
723  void setKey(double key);
724  void setMinimum(double value);
725  void setLowerQuartile(double value);
726  void setMedian(double value);
727  void setUpperQuartile(double value);
728  void setMaximum(double value);
729  void setOutliers(const QVector<double> &values);
730  void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
731  void setWidth(double width);
732  void setWhiskerWidth(double width);
733  void setWhiskerPen(const QPen &pen);
734  void setWhiskerBarPen(const QPen &pen);
735  void setMedianPen(const QPen &pen);
736  void setOutlierSize(double pixels);
737  void setOutlierPen(const QPen &pen);
738  void setOutlierStyle(QCP::ScatterStyle style);
739 
740  //non-property methods:
741  virtual void clearData();
742  virtual double selectTest(const QPointF &pos) const;
743 
744 protected:
745  QVector<double> mOutliers;
746  double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
747  double mWidth;
749  double mOutlierSize;
750  QPen mWhiskerPen, mWhiskerBarPen, mOutlierPen, mMedianPen;
752 
753  virtual void draw(QCPPainter *painter);
754  virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
755 
756  virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
757  virtual void drawMedian(QCPPainter *painter) const;
758  virtual void drawWhiskers(QCPPainter *painter) const;
759  virtual void drawOutliers(QCPPainter *painter) const;
760  virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
761  virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
762 
763  friend class QCustomPlot;
764  friend class QCPLegend;
765 };
766 
768 {
769 public:
770  QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
771  virtual ~QCPItemAnchor();
772 
773  QString name() const { return mName; }
774  virtual QPointF pixelPoint() const;
775 
776 protected:
777  QCustomPlot *mParentPlot;
780  QString mName;
781  //non-property members:
782  QSet<QCPItemPosition*> mChildren;
783 
784  void addChild(QCPItemPosition* pos); //called from pos when this anchor is set as parent
785  void removeChild(QCPItemPosition *pos); //called from pos when its parent anchor is reset or pos deleted
786 
787 private:
788  Q_DISABLE_COPY(QCPItemAnchor)
789 
790  friend class QCPItemPosition;
791 };
792 
793 class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
794 {
795 public:
802  enum PositionType { ptAbsolute
803  ,ptViewportRatio
804  ,ptAxisRectRatio
805  ,ptPlotCoords
806  };
807 
808  QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
809  virtual ~QCPItemPosition();
810 
811  //getters:
812  PositionType type() const { return mPositionType; }
813  QCPItemAnchor *parentAnchor() const { return mParentAnchor; }
814  double key() const { return mKey; }
815  double value() const { return mValue; }
816  QPointF coords() const { return QPointF(mKey, mValue); }
817  QCPAxis *keyAxis() const { return mKeyAxis; }
818  QCPAxis *valueAxis() const { return mValueAxis; }
819  virtual QPointF pixelPoint() const;
820 
821  //setters:
822  void setType(PositionType type);
823  bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
824  void setCoords(double key, double value);
825  void setCoords(const QPointF &coords);
826  void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
827  void setPixelPoint(const QPointF &pixelPoint);
828 
829 protected:
831  QCPAxis *mKeyAxis, *mValueAxis;
832  double mKey, mValue;
833  QCPItemAnchor *mParentAnchor;
834 
835 private:
836  Q_DISABLE_COPY(QCPItemPosition)
837 
838 };
839 
840 class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
841 {
842  Q_OBJECT
843 public:
844  QCPAbstractItem(QCustomPlot *parentPlot);
845  virtual ~QCPAbstractItem();
846 
847  //getters:
848  bool clipToAxisRect() const { return mClipToAxisRect; }
849  QCPAxis *clipKeyAxis() const { return mClipKeyAxis; }
850  QCPAxis *clipValueAxis() const { return mClipValueAxis; }
851  bool selectable() const { return mSelectable; }
852  bool selected() const { return mSelected; }
853 
854  //setters:
855  void setClipToAxisRect(bool clip);
856  void setClipAxes(QCPAxis *keyAxis, QCPAxis *valueAxis);
857  void setClipKeyAxis(QCPAxis *axis);
858  void setClipValueAxis(QCPAxis *axis);
859  void setSelectable(bool selectable);
860  void setSelected(bool selected);
861 
862  //non-property methods:
863  virtual double selectTest(const QPointF &pos) const = 0;
864  QList<QCPItemPosition*> positions() const { return mPositions; }
865  QList<QCPItemAnchor*> anchors() const { return mAnchors; }
866  QCPItemPosition *position(const QString &name) const;
867  QCPItemAnchor *anchor(const QString &name) const;
868  bool hasAnchor(const QString &name) const;
869 
870 protected:
872  QCPAxis *mClipKeyAxis, *mClipValueAxis;
873  bool mSelectable, mSelected;
874  QList<QCPItemPosition*> mPositions;
875  QList<QCPItemAnchor*> mAnchors;
876 
877  virtual QRect clipRect() const;
878  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
879  virtual void draw(QCPPainter *painter) = 0;
880 
881  //helper functions for subclasses:
882  double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
883  double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
884 
885  //anchor/position interface:
886  virtual QPointF anchorPixelPoint(int anchorId) const;
887  QCPItemPosition *createPosition(const QString &name);
888  QCPItemAnchor *createAnchor(const QString &name, int anchorId);
889 
890 signals:
891  void selectionChanged(bool selected);
892 
893 private:
894  Q_DISABLE_COPY(QCPAbstractItem)
895 
896  friend class QCustomPlot;
897  friend class QCPItemAnchor;
898 };
899 
901 {
902  Q_OBJECT
903 public:
904  QCPItemStraightLine(QCustomPlot *parentPlot);
905  virtual ~QCPItemStraightLine();
906 
907  //getters:
908  QPen pen() const { return mPen; }
909  QPen selectedPen() const { return mSelectedPen; }
910 
911  //setters;
912  void setPen(const QPen &pen);
913  void setSelectedPen(const QPen &pen);
914 
915  //non-property methods:
916  virtual double selectTest(const QPointF &pos) const;
917 
920 
921 protected:
922  QPen mPen, mSelectedPen;
923 
924  virtual void draw(QCPPainter *painter);
925 
926  //helper functions:
927  double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
928  QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
929  QPen mainPen() const;
930 };
931 
933 {
934  Q_OBJECT
935 public:
936  QCPItemLine(QCustomPlot *parentPlot);
937  virtual ~QCPItemLine();
938 
939  //getters:
940  QPen pen() const { return mPen; }
941  QPen selectedPen() const { return mSelectedPen; }
942  QCPLineEnding head() const { return mHead; }
943  QCPLineEnding tail() const { return mTail; }
944 
945  //setters;
946  void setPen(const QPen &pen);
947  void setSelectedPen(const QPen &pen);
948  void setHead(const QCPLineEnding &head);
949  void setTail(const QCPLineEnding &tail);
950 
951  //non-property methods:
952  virtual double selectTest(const QPointF &pos) const;
953 
956 
957 protected:
958  QPen mPen, mSelectedPen;
960 
961  virtual void draw(QCPPainter *painter);
962 
963  //helper functions:
964  QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
965  QPen mainPen() const;
966 };
967 
969 {
970  Q_OBJECT
971 public:
972  QCPItemEllipse(QCustomPlot *parentPlot);
973  virtual ~QCPItemEllipse();
974 
975  //getters:
976  QPen pen() const { return mPen; }
977  QPen selectedPen() const { return mSelectedPen; }
978  QBrush brush() const { return mBrush; }
979  QBrush selectedBrush() const { return mSelectedBrush; }
980 
981  //setters;
982  void setPen(const QPen &pen);
983  void setSelectedPen(const QPen &pen);
984  void setBrush(const QBrush &brush);
985  void setSelectedBrush(const QBrush &brush);
986 
987  //non-property methods:
988  virtual double selectTest(const QPointF &pos) const;
989 
1000 
1001 protected:
1002  enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft};
1003  QPen mPen, mSelectedPen;
1004  QBrush mBrush, mSelectedBrush;
1005 
1006  virtual void draw(QCPPainter *painter);
1007  virtual QPointF anchorPixelPoint(int anchorId) const;
1008 
1009  //helper functions:
1010  QPen mainPen() const;
1011  QBrush mainBrush() const;
1012 };
1013 
1015 {
1016  Q_OBJECT
1017 public:
1018  QCPItemRect(QCustomPlot *parentPlot);
1019  virtual ~QCPItemRect();
1020 
1021  //getters:
1022  QPen pen() const { return mPen; }
1023  QPen selectedPen() const { return mSelectedPen; }
1024  QBrush brush() const { return mBrush; }
1025  QBrush selectedBrush() const { return mSelectedBrush; }
1026 
1027  //setters;
1028  void setPen(const QPen &pen);
1029  void setSelectedPen(const QPen &pen);
1030  void setBrush(const QBrush &brush);
1031  void setSelectedBrush(const QBrush &brush);
1032 
1033  //non-property methods:
1034  virtual double selectTest(const QPointF &pos) const;
1035 
1044 
1045 protected:
1046  enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
1047  QPen mPen, mSelectedPen;
1048  QBrush mBrush, mSelectedBrush;
1049 
1050  virtual void draw(QCPPainter *painter);
1051  virtual QPointF anchorPixelPoint(int anchorId) const;
1052 
1053  //helper functions:
1054  QPen mainPen() const;
1055  QBrush mainBrush() const;
1056 };
1057 
1059 {
1060  Q_OBJECT
1061 public:
1062  QCPItemPixmap(QCustomPlot *parentPlot);
1063  virtual ~QCPItemPixmap();
1064 
1065  //getters:
1066  QPixmap pixmap() const { return mPixmap; }
1067  bool scaled() const { return mScaled; }
1068  Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
1069  QPen pen() const { return mPen; }
1070  QPen selectedPen() const { return mSelectedPen; }
1071 
1072  //setters;
1073  void setPixmap(const QPixmap &pixmap);
1074  void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);
1075  void setPen(const QPen &pen);
1076  void setSelectedPen(const QPen &pen);
1077 
1078  //non-property methods:
1079  virtual double selectTest(const QPointF &pos) const;
1080 
1089 
1090 protected:
1091  enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
1092  QPixmap mPixmap;
1093  QPixmap mScaledPixmap;
1094  bool mScaled;
1095  Qt::AspectRatioMode mAspectRatioMode;
1096  QPen mPen, mSelectedPen;
1097 
1098  virtual void draw(QCPPainter *painter);
1099  virtual QPointF anchorPixelPoint(int anchorId) const;
1100 
1101  //helper functions:
1102  void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
1103  QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
1104  QPen mainPen() const;
1105 };
1106 
1108 {
1109  Q_OBJECT
1110 public:
1111  QCPItemText(QCustomPlot *parentPlot);
1112  virtual ~QCPItemText();
1113 
1114  //getters:
1115  QColor color() const { return mColor; }
1116  QColor selectedColor() const { return mSelectedColor; }
1117  QPen pen() const { return mPen; }
1118  QPen selectedPen() const { return mSelectedPen; }
1119  QBrush brush() const { return mBrush; }
1120  QBrush selectedBrush() const { return mSelectedBrush; }
1121  QFont font() const { return mFont; }
1122  QFont selectedFont() const { return mSelectedFont; }
1123  QString text() const { return mText; }
1124  Qt::Alignment positionAlignment() const { return mPositionAlignment; }
1125  Qt::Alignment textAlignment() const { return mTextAlignment; }
1126  double rotation() const { return mRotation; }
1127  QMargins padding() const { return mPadding; }
1128 
1129  //setters;
1130  void setColor(const QColor &color);
1131  void setSelectedColor(const QColor &color);
1132  void setPen(const QPen &pen);
1133  void setSelectedPen(const QPen &pen);
1134  void setBrush(const QBrush &brush);
1135  void setSelectedBrush(const QBrush &brush);
1136  void setFont(const QFont &font);
1137  void setSelectedFont(const QFont &font);
1138  void setText(const QString &text);
1139  void setPositionAlignment(Qt::Alignment alignment);
1140  void setTextAlignment(Qt::Alignment alignment);
1141  void setRotation(double degrees);
1142  void setPadding(const QMargins &padding);
1143 
1144  //non-property methods:
1145  virtual double selectTest(const QPointF &pos) const;
1146 
1156 
1157 protected:
1158  enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
1159  QColor mColor, mSelectedColor;
1160  QPen mPen, mSelectedPen;
1161  QBrush mBrush, mSelectedBrush;
1162  QFont mFont, mSelectedFont;
1163  QString mText;
1164  Qt::Alignment mPositionAlignment;
1165  Qt::Alignment mTextAlignment;
1166  double mRotation;
1167  QMargins mPadding;
1168 
1169  virtual void draw(QCPPainter *painter);
1170  virtual QPointF anchorPixelPoint(int anchorId) const;
1171 
1172  //helper functions:
1173  QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
1174  QFont mainFont() const;
1175  QColor mainColor() const;
1176  QPen mainPen() const;
1177  QBrush mainBrush() const;
1178 };
1179 
1181 {
1182  Q_OBJECT
1183 public:
1184  QCPItemCurve(QCustomPlot *parentPlot);
1185  virtual ~QCPItemCurve();
1186 
1187  //getters:
1188  QPen pen() const { return mPen; }
1189  QPen selectedPen() const { return mSelectedPen; }
1190  QCPLineEnding head() const { return mHead; }
1191  QCPLineEnding tail() const { return mTail; }
1192 
1193  //setters;
1194  void setPen(const QPen &pen);
1195  void setSelectedPen(const QPen &pen);
1196  void setHead(const QCPLineEnding &head);
1197  void setTail(const QCPLineEnding &tail);
1198 
1199  //non-property methods:
1200  virtual double selectTest(const QPointF &pos) const;
1201 
1206 
1207 protected:
1208  QPen mPen, mSelectedPen;
1210 
1211  virtual void draw(QCPPainter *painter);
1212 
1213  //helper functions:
1214  QPen mainPen() const;
1215 };
1216 
1218 {
1219  Q_OBJECT
1220 public:
1221  enum BracketStyle { bsSquare
1222  ,bsRound
1223  ,bsCurly
1224  ,bsCalligraphic
1225  };
1226 
1227  QCPItemBracket(QCustomPlot *parentPlot);
1228  virtual ~QCPItemBracket();
1229 
1230  //getters:
1231  QPen pen() const { return mPen; }
1232  QPen selectedPen() const { return mSelectedPen; }
1233  double length() const { return mLength; }
1234  BracketStyle style() const { return mStyle; }
1235 
1236  //setters;
1237  void setPen(const QPen &pen);
1238  void setSelectedPen(const QPen &pen);
1239  void setLength(double length);
1240  void setStyle(BracketStyle style);
1241 
1242  //non-property methods:
1243  virtual double selectTest(const QPointF &pos) const;
1244 
1248 
1249 protected:
1250  enum AnchorIndex {aiCenter};
1251  QPen mPen, mSelectedPen;
1252  double mLength;
1254 
1255  virtual void draw(QCPPainter *painter);
1256  virtual QPointF anchorPixelPoint(int anchorId) const;
1257 
1258  //helper functions:
1259  QPen mainPen() const;
1260 };
1261 
1263 {
1264  Q_OBJECT
1265 public:
1271  enum TracerStyle { tsNone
1272  ,tsPlus
1273  ,tsCrosshair
1274  ,tsCircle
1275  ,tsSquare
1276  };
1277  Q_ENUMS(TracerStyle)
1278 
1279  QCPItemTracer(QCustomPlot *parentPlot);
1280  virtual ~QCPItemTracer();
1281 
1282  //getters:
1283  QPen pen() const { return mPen; }
1284  QPen selectedPen() const { return mSelectedPen; }
1285  QBrush brush() const { return mBrush; }
1286  QBrush selectedBrush() const { return mSelectedBrush; }
1287  double size() const { return mSize; }
1288  TracerStyle style() const { return mStyle; }
1289  QCPGraph *graph() const { return mGraph; }
1290  double graphKey() const { return mGraphKey; }
1291  bool interpolating() const { return mInterpolating; }
1292 
1293  //setters;
1294  void setPen(const QPen &pen);
1295  void setSelectedPen(const QPen &pen);
1296  void setBrush(const QBrush &brush);
1297  void setSelectedBrush(const QBrush &brush);
1298  void setSize(double size);
1299  void setStyle(TracerStyle style);
1300  void setGraph(QCPGraph *graph);
1301  void setGraphKey(double key);
1302  void setInterpolating(bool enabled);
1303 
1304  //non-property methods:
1305  virtual double selectTest(const QPointF &pos) const;
1306  void updatePosition();
1307 
1309 
1310 protected:
1311  QPen mPen, mSelectedPen;
1312  QBrush mBrush, mSelectedBrush;
1313  double mSize;
1316  double mGraphKey;
1318 
1319  virtual void draw(QCPPainter *painter);
1320 
1321  //helper functions:
1322  QPen mainPen() const;
1323  QBrush mainBrush() const;
1324 };
1325 
1327 {
1328 public:
1329  double lower, upper;
1330  QCPRange();
1331  QCPRange(double lower, double upper);
1332  double size() const;
1333  double center() const;
1334  void normalize();
1335  QCPRange sanitizedForLogScale() const;
1336  QCPRange sanitizedForLinScale() const;
1337  bool contains(double value) const;
1338 
1339  static bool validRange(double lower, double upper);
1340  static bool validRange(const QCPRange &range);
1341  static const double minRange; //1e-280;
1342  static const double maxRange; //1e280;
1343 };
1344 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
1345 
1346 class QCP_LIB_DECL QCPAbstractLegendItem : public QObject
1347 {
1348  Q_OBJECT
1349 public:
1352 
1353  //getters:
1354  bool antialiased() const { return mAntialiased; }
1355  QFont font() const { return mFont; }
1356  QColor textColor() const { return mTextColor; }
1357  QFont selectedFont() const { return mSelectedFont; }
1358  QColor selectedTextColor() const { return mSelectedTextColor; }
1359  bool selectable() const { return mSelectable; }
1360  bool selected() const { return mSelected; }
1361 
1362  //setters:
1363  void setAntialiased(bool enabled);
1364  void setFont(const QFont &font);
1365  void setTextColor(const QColor &color);
1366  void setSelectedFont(const QFont &font);
1367  void setSelectedTextColor(const QColor &color);
1368  void setSelectable(bool selectable);
1369  void setSelected(bool selected);
1370 
1371 signals:
1372  void selectionChanged(bool selected);
1373 
1374 protected:
1377  QFont mFont;
1378  QColor mTextColor;
1381  bool mSelectable, mSelected;
1382 
1383  virtual void draw(QCPPainter *painter, const QRect &rect) const = 0;
1384  virtual QSize size(const QSize &targetSize) const = 0;
1385  void applyAntialiasingHint(QCPPainter *painter) const;
1386 
1387 private:
1388  Q_DISABLE_COPY(QCPAbstractLegendItem)
1389 
1390  friend class QCPLegend;
1391 };
1392 
1394 {
1395  Q_OBJECT
1396 public:
1397  QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
1399 
1400  //getters:
1401  QCPAbstractPlottable *plottable() { return mPlottable; }
1402  bool textWrap() const { return mTextWrap; }
1403 
1404  //setters:
1405  void setTextWrap(bool wrap);
1406 
1407 protected:
1410 
1411  QPen getIconBorderPen() const;
1412  QColor getTextColor() const;
1413  QFont getFont() const;
1414 
1415  virtual void draw(QCPPainter *painter, const QRect &rect) const;
1416  virtual QSize size(const QSize &targetSize) const;
1417 };
1418 
1419 class QCP_LIB_DECL QCPLegend : public QCPLayerable
1420 {
1421  Q_OBJECT
1422 public:
1426  enum PositionStyle { psManual
1427  ,psTopLeft
1428  ,psTop
1429  ,psTopRight
1430  ,psRight
1431  ,psBottomRight
1432  ,psBottom
1433  ,psBottomLeft
1434  ,psLeft
1435  };
1436  Q_ENUMS(PositionStyle)
1437 
1438 
1441  enum SelectablePart { spNone = 0
1442  ,spLegendBox = 0x001
1443  ,spItems = 0x002
1444  };
1445  Q_ENUMS(SelectablePart)
1446  Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
1447 
1448  explicit QCPLegend(QCustomPlot *parentPlot);
1449  virtual ~QCPLegend();
1450 
1451  //getters:
1452  QPen borderPen() const { return mBorderPen; }
1453  QBrush brush() const { return mBrush; }
1454  QFont font() const { return mFont; }
1455  QColor textColor() const { return mTextColor; }
1456  PositionStyle positionStyle() const { return mPositionStyle; }
1457  QPoint position() const { return mPosition; }
1458  bool autoSize() const { return mAutoSize; }
1459  QSize size() const { return mSize; }
1460  QSize minimumSize() const { return mMinimumSize; }
1461  int paddingLeft() const { return mPaddingLeft; }
1462  int paddingRight() const { return mPaddingRight; }
1463  int paddingTop() const { return mPaddingTop; }
1464  int paddingBottom() const { return mPaddingBottom; }
1465  int marginLeft() const { return mMarginLeft; }
1466  int marginRight() const { return mMarginRight; }
1467  int marginTop() const { return mMarginTop; }
1468  int marginBottom() const { return mMarginBottom; }
1469  int itemSpacing() const { return mItemSpacing; }
1470  QSize iconSize() const { return mIconSize; }
1471  int iconTextPadding() const { return mIconTextPadding; }
1472  QPen iconBorderPen() const { return mIconBorderPen; }
1473  SelectableParts selectable() const { return mSelectable; }
1474  SelectableParts selected() const { return mSelected; }
1475  QPen selectedBorderPen() const { return mSelectedBorderPen; }
1476  QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
1477  QBrush selectedBrush() const { return mSelectedBrush; }
1478  QFont selectedFont() const { return mSelectedFont; }
1479  QColor selectedTextColor() const { return mSelectedTextColor; }
1480 
1481  //setters:
1482  void setBorderPen(const QPen &pen);
1483  void setBrush(const QBrush &brush);
1484  void setFont(const QFont &font);
1485  void setTextColor(const QColor &color);
1486  void setPositionStyle(PositionStyle legendPositionStyle);
1487  void setPosition(const QPoint &pixelPosition);
1488  void setAutoSize(bool on);
1489  void setSize(const QSize &size);
1490  void setSize(int width, int height);
1491  void setMinimumSize(const QSize &size);
1492  void setMinimumSize(int width, int height);
1493  void setPaddingLeft(int padding);
1494  void setPaddingRight(int padding);
1495  void setPaddingTop(int padding);
1496  void setPaddingBottom(int padding);
1497  void setPadding(int left, int right, int top, int bottom);
1498  void setMarginLeft(int margin);
1499  void setMarginRight(int margin);
1500  void setMarginTop(int margin);
1501  void setMarginBottom(int margin);
1502  void setMargin(int left, int right, int top, int bottom);
1503  void setItemSpacing(int spacing);
1504  void setIconSize(const QSize &size);
1505  void setIconSize(int width, int height);
1506  void setIconTextPadding(int padding);
1507  void setIconBorderPen(const QPen &pen);
1508  void setSelectable(const SelectableParts &selectable);
1509  void setSelected(const SelectableParts &selected);
1510  void setSelectedBorderPen(const QPen &pen);
1511  void setSelectedIconBorderPen(const QPen &pen);
1512  void setSelectedBrush(const QBrush &brush);
1513  void setSelectedFont(const QFont &font);
1514  void setSelectedTextColor(const QColor &color);
1515 
1516  //non-property methods:
1517  QCPAbstractLegendItem *item(int index) const;
1518  QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
1519  int itemCount() const;
1520  bool hasItem(QCPAbstractLegendItem *item) const;
1521  bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
1522  bool addItem(QCPAbstractLegendItem *item);
1523  bool removeItem(int index);
1524  bool removeItem(QCPAbstractLegendItem *item);
1525  void clearItems();
1526  QList<QCPAbstractLegendItem*> selectedItems() const;
1527  void reArrange();
1528 
1529  bool selectTestLegend(const QPointF &pos) const;
1530  QCPAbstractLegendItem *selectTestItem(const QPoint pos) const;
1531 
1532 signals:
1533  void selectionChanged(QCPLegend::SelectableParts selection);
1534 
1535 protected:
1536  //simple properties with getters and setters:
1537  QPen mBorderPen, mIconBorderPen;
1538  QBrush mBrush;
1539  QFont mFont;
1540  QColor mTextColor;
1541  QPoint mPosition;
1542  QSize mSize, mMinimumSize, mIconSize;
1545  int mPaddingLeft, mPaddingRight, mPaddingTop, mPaddingBottom;
1546  int mMarginLeft, mMarginRight, mMarginTop, mMarginBottom;
1547  int mItemSpacing, mIconTextPadding;
1548  SelectableParts mSelected, mSelectable;
1549  QPen mSelectedBorderPen, mSelectedIconBorderPen;
1553 
1554  //internal or not explicitly exposed properties:
1555  QList<QCPAbstractLegendItem*> mItems;
1556  QMap<QCPAbstractLegendItem*, QRect> mItemBoundingBoxes;
1557 
1558  virtual void updateSelectionState();
1559  virtual bool handleLegendSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
1560  //introduced methods:
1561  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1562  virtual void draw(QCPPainter *painter);
1563  virtual void calculateAutoSize();
1564  virtual void calculateAutoPosition();
1565 
1566  //drawing helpers:
1567  QPen getBorderPen() const;
1568  QBrush getBrush() const;
1569 
1570 private:
1571  Q_DISABLE_COPY(QCPLegend)
1572 
1573  friend class QCustomPlot;
1575 };
1576 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
1577 
1578 class QCP_LIB_DECL QCPGrid : public QCPLayerable
1579 {
1580  Q_OBJECT
1581 public:
1582  QCPGrid(QCPAxis *parentAxis);
1583  ~QCPGrid();
1584 
1585  //getters:
1586  bool subGridVisible() const { return mSubGridVisible; }
1587  bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
1588  bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
1589  QPen pen() const { return mPen; }
1590  QPen subGridPen() const { return mSubGridPen; }
1591  QPen zeroLinePen() const { return mZeroLinePen; }
1592 
1593  //setters:
1594  void setSubGridVisible(bool visible);
1595  void setAntialiasedSubGrid(bool enabled);
1596  void setAntialiasedZeroLine(bool enabled);
1597  void setPen(const QPen &pen);
1598  void setSubGridPen(const QPen &pen);
1599  void setZeroLinePen(const QPen &pen);
1600 
1601 protected:
1604  bool mAntialiasedSubGrid, mAntialiasedZeroLine;
1605  QPen mPen, mSubGridPen, mZeroLinePen;
1606 
1607  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1608  virtual void draw(QCPPainter *painter);
1609  //drawing helpers:
1610  void drawGridLines(QCPPainter *painter) const;
1611  void drawSubGridLines(QCPPainter *painter) const;
1612 
1613  friend class QCPAxis;
1614 };
1615 
1616 class QCP_LIB_DECL QCPAxis : public QCPLayerable
1617 {
1618  Q_OBJECT
1620  Q_PROPERTY(AxisType axisType READ axisType WRITE setAxisType)
1621  Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType)
1622  Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
1623  Q_PROPERTY(QRect axisRect READ axisRect WRITE setAxisRect)
1624  Q_PROPERTY(QCPRange range READ range WRITE setRange)
1625  Q_PROPERTY(bool grid READ grid WRITE setGrid)
1626  Q_PROPERTY(bool subGrid READ subGrid WRITE setSubGrid)
1627  Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
1628  Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
1629  Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
1630  Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
1631  Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
1632  Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
1633  Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
1634  Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
1635  Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
1636  Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
1637  Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
1638  Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
1639  Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
1640  Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
1641  Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
1642  Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
1643  Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
1644  Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
1645  Q_PROPERTY(QPen gridPen READ gridPen WRITE setGridPen)
1646  Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
1647  Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
1648  Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
1649  Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
1650  Q_PROPERTY(QString label READ label WRITE setLabel)
1651  Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
1653 public:
1659  enum AxisType { atLeft
1660  ,atRight
1661  ,atTop
1662  ,atBottom
1663  };
1664  Q_ENUMS(AxisType)
1671  enum LabelType { ltNumber
1672  ,ltDateTime
1673  };
1674  Q_ENUMS(LabelType)
1679  enum ScaleType { stLinear
1680  ,stLogarithmic
1681  };
1682  Q_ENUMS(ScaleType)
1687  enum SelectablePart { spNone = 0
1688  ,spAxis = 0x001
1689  ,spTickLabels = 0x002
1690  ,spAxisLabel = 0x004
1691  };
1692  Q_ENUMS(SelectablePart)
1693  Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
1694 
1695  explicit QCPAxis(QCustomPlot *parentPlot, AxisType type);
1696  virtual ~QCPAxis();
1697 
1698  //getters:
1699  AxisType axisType() const { return mAxisType; }
1700  QRect axisRect() const { return mAxisRect; }
1701  ScaleType scaleType() const { return mScaleType; }
1702  double scaleLogBase() const { return mScaleLogBase; }
1703  const QCPRange range() const { return mRange; }
1704  bool rangeReversed() const { return mRangeReversed; }
1705  bool antialiasedGrid() const { return mGrid->antialiased(); }
1706  bool antialiasedSubGrid() const { return mGrid->antialiasedSubGrid(); }
1707  bool antialiasedZeroLine() const { return mGrid->antialiasedZeroLine(); }
1708  bool grid() const { return mGrid->visible(); }
1709  bool subGrid() const { return mGrid->subGridVisible(); }
1710  bool autoTicks() const { return mAutoTicks; }
1711  int autoTickCount() const { return mAutoTickCount; }
1712  bool autoTickLabels() const { return mAutoTickLabels; }
1713  bool autoTickStep() const { return mAutoTickStep; }
1714  bool autoSubTicks() const { return mAutoSubTicks; }
1715  bool ticks() const { return mTicks; }
1716  bool tickLabels() const { return mTickLabels; }
1717  int tickLabelPadding() const { return mTickLabelPadding; }
1718  LabelType tickLabelType() const { return mTickLabelType; }
1719  QFont tickLabelFont() const { return mTickLabelFont; }
1720  QColor tickLabelColor() const { return mTickLabelColor; }
1721  double tickLabelRotation() const { return mTickLabelRotation; }
1722  QString dateTimeFormat() const { return mDateTimeFormat; }
1723  QString numberFormat() const;
1724  int numberPrecision() const { return mNumberPrecision; }
1725  double tickStep() const { return mTickStep; }
1726  QVector<double> tickVector() const { return mTickVector; }
1727  QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
1728  int tickLengthIn() const { return mTickLengthIn; }
1729  int tickLengthOut() const { return mTickLengthOut; }
1730  int subTickCount() const { return mSubTickCount; }
1731  int subTickLengthIn() const { return mSubTickLengthIn; }
1732  int subTickLengthOut() const { return mSubTickLengthOut; }
1733  QPen basePen() const { return mBasePen; }
1734  QPen gridPen() const { return mGrid->pen(); }
1735  QPen subGridPen() const { return mGrid->subGridPen(); }
1736  QPen zeroLinePen() const { return mGrid->zeroLinePen(); }
1737  QPen tickPen() const { return mTickPen; }
1738  QPen subTickPen() const { return mSubTickPen; }
1739  QFont labelFont() const { return mLabelFont; }
1740  QColor labelColor() const { return mLabelColor; }
1741  QString label() const { return mLabel; }
1742  int labelPadding() const { return mLabelPadding; }
1743  int padding() const { return mPadding; }
1744  SelectableParts selected() const { return mSelected; }
1745  SelectableParts selectable() const { return mSelectable; }
1746  QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
1747  QFont selectedLabelFont() const { return mSelectedLabelFont; }
1748  QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
1749  QColor selectedLabelColor() const { return mSelectedLabelColor; }
1750  QPen selectedBasePen() const { return mSelectedBasePen; }
1751  QPen selectedTickPen() const { return mSelectedTickPen; }
1752  QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
1753 
1754  //setters:
1755  void setScaleType(ScaleType type);
1756  void setScaleLogBase(double base);
1757  void setRange(double lower, double upper);
1758  void setRange(double position, double size, Qt::AlignmentFlag alignment);
1759  void setRangeLower(double lower);
1760  void setRangeUpper(double upper);
1761  void setRangeReversed(bool reversed);
1762  void setAntialiasedGrid(bool enabled);
1763  void setAntialiasedSubGrid(bool enabled);
1764  void setAntialiasedZeroLine(bool enabled);
1765  void setGrid(bool show);
1766  void setSubGrid(bool show);
1767  void setAutoTicks(bool on);
1768  void setAutoTickCount(int approximateCount);
1769  void setAutoTickLabels(bool on);
1770  void setAutoTickStep(bool on);
1771  void setAutoSubTicks(bool on);
1772  void setTicks(bool show);
1773  void setTickLabels(bool show);
1774  void setTickLabelPadding(int padding);
1775  void setTickLabelType(LabelType type);
1776  void setTickLabelFont(const QFont &font);
1777  void setTickLabelColor(const QColor &color);
1778  void setTickLabelRotation(double degrees);
1779  void setDateTimeFormat(const QString &format);
1780  void setNumberFormat(const QString &formatCode);
1781  void setNumberPrecision(int precision);
1782  void setTickStep(double step);
1783  void setTickVector(const QVector<double> &vec);
1784  void setTickVectorLabels(const QVector<QString> &vec);
1785  void setTickLength(int inside, int outside=0);
1786  void setSubTickCount(int count);
1787  void setSubTickLength(int inside, int outside=0);
1788  void setBasePen(const QPen &pen);
1789  void setGridPen(const QPen &pen);
1790  void setSubGridPen(const QPen &pen);
1791  void setZeroLinePen(const QPen &pen);
1792  void setTickPen(const QPen &pen);
1793  void setSubTickPen(const QPen &pen);
1794  void setLabelFont(const QFont &font);
1795  void setLabelColor(const QColor &color);
1796  void setLabel(const QString &str);
1797  void setLabelPadding(int padding);
1798  void setPadding(int padding);
1799  void setSelectedTickLabelFont(const QFont &font);
1800  void setSelectedLabelFont(const QFont &font);
1801  void setSelectedTickLabelColor(const QColor &color);
1802  void setSelectedLabelColor(const QColor &color);
1803  void setSelectedBasePen(const QPen &pen);
1804  void setSelectedTickPen(const QPen &pen);
1805  void setSelectedSubTickPen(const QPen &pen);
1806 
1807  //non-property methods:
1808  Qt::Orientation orientation() const { return mOrientation; }
1809  void moveRange(double diff);
1810  void scaleRange(double factor, double center);
1811  void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
1812  double pixelToCoord(double value) const;
1813  double coordToPixel(double value) const;
1814  SelectablePart selectTest(const QPointF &pos) const;
1815 
1816 public slots:
1817  //slot setters:
1818  void setRange(const QCPRange &range);
1819  void setSelectable(const QCPAxis::SelectableParts &selectable);
1820  void setSelected(const QCPAxis::SelectableParts &selected);
1821 
1822 signals:
1823  void ticksRequest();
1824  void rangeChanged(const QCPRange &newRange);
1825  void selectionChanged(QCPAxis::SelectableParts selection);
1826 
1827 protected:
1828  //simple properties with getters and setters:
1829  QVector<double> mTickVector;
1830  QVector<QString> mTickVectorLabels;
1833  QString mLabel;
1834  QRect mAxisRect;
1835  QPen mBasePen, mTickPen, mSubTickPen;
1836  QFont mTickLabelFont, mLabelFont;
1837  QColor mTickLabelColor, mLabelColor;
1841  double mTickStep;
1842  double mScaleLogBase, mScaleLogBaseLogInv;
1843  int mSubTickCount, mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut;
1845  int mTickLabelPadding, mLabelPadding, mPadding;
1847  bool mTicks, mTickLabels, mAutoTicks, mAutoTickLabels, mAutoTickStep, mAutoSubTicks;
1849  SelectableParts mSelectable, mSelected;
1850  QFont mSelectedTickLabelFont, mSelectedLabelFont;
1851  QColor mSelectedTickLabelColor, mSelectedLabelColor;
1852  QPen mSelectedBasePen, mSelectedTickPen, mSelectedSubTickPen;
1853  QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
1854 
1855  //internal or not explicitly exposed properties:
1857  QVector<double> mSubTickVector;
1858  QChar mExponentialChar, mPositiveSignChar;
1861  bool mNumberBeautifulPowers, mNumberMultiplyCross;
1862  Qt::Orientation mOrientation;
1863  int mLowestVisibleTick, mHighestVisibleTick;
1864 
1865  //internal setters:
1866  void setAxisType(AxisType type);
1867  void setAxisRect(const QRect &rect);
1868 
1869  //introduced methods:
1870  virtual void setupTickVectors();
1871  virtual void generateAutoTicks();
1872  virtual int calculateAutoSubTickCount(double tickStep) const;
1873  virtual int calculateMargin() const;
1874  virtual bool handleAxisSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
1875 
1876  //drawing:
1877  virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1878  virtual void draw(QCPPainter *painter);
1879  virtual void drawTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
1880  virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
1881 
1882  //basic non virtual helpers:
1883  void visibleTickBounds(int &lowIndex, int &highIndex) const;
1884  double baseLog(double value) const;
1885  double basePow(double value) const;
1886 
1887  //helpers to get the right pen/font depending on selection state:
1888  QPen getBasePen() const;
1889  QPen getTickPen() const;
1890  QPen getSubTickPen() const;
1891  QFont getTickLabelFont() const;
1892  QFont getLabelFont() const;
1893  QColor getTickLabelColor() const;
1894  QColor getLabelColor() const;
1895 
1896 private:
1897  Q_DISABLE_COPY(QCPAxis)
1898 
1899  friend class QCustomPlot;
1900  friend class QCPGrid;
1901 };
1902 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
1903 
1904 class QCP_LIB_DECL QCustomPlot : public QWidget
1905 {
1906  Q_OBJECT
1908  Q_PROPERTY(QString title READ title WRITE setTitle)
1909  Q_PROPERTY(QRect axisRect READ axisRect WRITE setAxisRect)
1910  Q_PROPERTY(int marginLeft READ marginLeft WRITE setMarginLeft)
1911  Q_PROPERTY(int marginRight READ marginRight WRITE setMarginRight)
1912  Q_PROPERTY(int marginTop READ marginTop WRITE setMarginTop)
1913  Q_PROPERTY(int marginBottom READ marginBottom WRITE setMarginBottom)
1914  Q_PROPERTY(int autoMargin READ autoMargin WRITE setAutoMargin)
1915  Q_PROPERTY(QColor color READ color WRITE setColor)
1916  Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
1917  Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
1919 public:
1926  enum Interaction { iRangeDrag = 0x001
1927  ,iRangeZoom = 0x002
1928  ,iMultiSelect = 0x004
1929  ,iSelectTitle = 0x008
1930  ,iSelectPlottables = 0x010
1931  ,iSelectAxes = 0x020
1932  ,iSelectLegend = 0x040
1933  ,iSelectItems = 0x080
1934  };
1935  Q_ENUMS(Interaction)
1936  Q_DECLARE_FLAGS(Interactions, Interaction)
1942  enum LayerInsertMode { limBelow
1943  ,limAbove
1944  };
1945  Q_ENUMS(LayerInsertMode)
1946 
1947  explicit QCustomPlot(QWidget *parent = 0);
1948  virtual ~QCustomPlot();
1949 
1950  //getters:
1951  QString title() const { return mTitle; }
1952  QFont titleFont() const { return mTitleFont; }
1953  QColor titleColor() const { return mTitleColor; }
1954  QRect axisRect() const { return mAxisRect; }
1955  QRect viewport() const { return mViewport; }
1956  int marginLeft() const { return mMarginLeft; }
1957  int marginRight() const { return mMarginRight; }
1958  int marginTop() const { return mMarginTop; }
1959  int marginBottom() const { return mMarginBottom; }
1960  bool autoMargin() const { return mAutoMargin; }
1961  QColor color() const { return mColor; }
1962  Qt::Orientations rangeDrag() const { return mRangeDrag; }
1963  Qt::Orientations rangeZoom() const { return mRangeZoom; }
1964  QCPAxis *rangeDragAxis(Qt::Orientation orientation);
1965  QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
1966  double rangeZoomFactor(Qt::Orientation orientation);
1967  QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
1968  QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
1969  bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
1970  QPixmap axisBackground() const { return mAxisBackground; }
1971  bool axisBackgroundScaled() const { return mAxisBackgroundScaled; }
1972  Qt::AspectRatioMode axisBackgroundScaledMode() const { return mAxisBackgroundScaledMode; }
1973  const Interactions interactions() const { return mInteractions; }
1974  int selectionTolerance() const { return mSelectionTolerance; }
1975  QFont selectedTitleFont() const { return mSelectedTitleFont; }
1976  QColor selectedTitleColor() const { return mSelectedTitleColor; }
1977  bool titleSelected() const { return mTitleSelected; }
1978  bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
1979  QCP::PlottingHints plottingHints() const { return mPlottingHints; }
1980  Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
1981 
1982  //setters:
1983  void setTitle(const QString &title);
1984  void setTitleFont(const QFont &font);
1985  void setTitleColor(const QColor &color);
1986  void setAxisRect(const QRect &arect);
1987  void setMarginLeft(int margin);
1988  void setMarginRight(int margin);
1989  void setMarginTop(int margin);
1990  void setMarginBottom(int margin);
1991  void setMargin(int left, int right, int top, int bottom);
1992  void setAutoMargin(bool enabled);
1993  void setColor(const QColor &color);
1994  void setRangeDrag(Qt::Orientations orientations);
1995  void setRangeZoom(Qt::Orientations orientations);
1996  void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
1997  void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
1998  void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
1999  void setRangeZoomFactor(double factor);
2000  void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
2001  void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
2002  void setNotAntialiasedElements(const QCP::AntialiasedElements &notAntialiasedElements);
2003  void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
2004  void setAutoAddPlottableToLegend(bool on);
2005  void setAxisBackground(const QPixmap &pm);
2006  void setAxisBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
2007  void setAxisBackgroundScaled(bool scaled);
2008  void setAxisBackgroundScaledMode(Qt::AspectRatioMode mode);
2009  void setInteractions(const Interactions &interactions);
2010  void setInteraction(const Interaction &interaction, bool enabled=true);
2011  void setSelectionTolerance(int pixels);
2012  void setSelectedTitleFont(const QFont &font);
2013  void setSelectedTitleColor(const QColor &color);
2014  void setTitleSelected(bool selected);
2015  void setNoAntialiasingOnDrag(bool enabled);
2016  void setPlottingHints(const QCP::PlottingHints &hints);
2017  void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
2018  void setMultiSelectModifier(Qt::KeyboardModifier modifier);
2019 
2020  //non-property methods:
2021  //plottable interface:
2022  QCPAbstractPlottable *plottable(int index);
2023  QCPAbstractPlottable *plottable();
2024  bool addPlottable(QCPAbstractPlottable *plottable);
2025  bool removePlottable(QCPAbstractPlottable *plottable);
2026  bool removePlottable(int index);
2027  int clearPlottables();
2028  int plottableCount() const;
2029  QList<QCPAbstractPlottable*> selectedPlottables() const;
2030  QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
2031  bool hasPlottable(QCPAbstractPlottable *plottable) const;
2032 
2033  //specialized interface for QCPGraph:
2034  QCPGraph *graph(int index) const;
2035  QCPGraph *graph() const;
2036  QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
2037  bool removeGraph(QCPGraph *graph);
2038  bool removeGraph(int index);
2039  int clearGraphs();
2040  int graphCount() const;
2041  QList<QCPGraph*> selectedGraphs() const;
2042 
2043  //item interface:
2044  QCPAbstractItem *item(int index) const;
2045  QCPAbstractItem *item() const;
2046  bool addItem(QCPAbstractItem* item);
2047  bool removeItem(QCPAbstractItem *item);
2048  bool removeItem(int index);
2049  int clearItems();
2050  int itemCount() const;
2051  QList<QCPAbstractItem*> selectedItems() const;
2052  QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
2053 
2054  //layer interface:
2055  QCPLayer *layer(const QString &name) const;
2056  QCPLayer *layer(int index) const;
2057  QCPLayer *currentLayer() const;
2058  bool setCurrentLayer(const QString &name);
2059  bool setCurrentLayer(QCPLayer *layer);
2060  int layerCount() const;
2061  bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
2062  bool removeLayer(QCPLayer *layer);
2063  bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
2064 
2065  QList<QCPAxis*> selectedAxes() const;
2066  QList<QCPLegend*> selectedLegends() const;
2067  void setupFullAxesBox();
2068  bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0);
2069  bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
2070  bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
2071  bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
2072  bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
2073 
2074  QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
2076 
2077 public slots:
2078  void deselectAll();
2079  void replot();
2080  void rescaleAxes();
2081 
2082 signals:
2083  void mouseDoubleClick(QMouseEvent *event);
2084  void mousePress(QMouseEvent *event);
2085  void mouseMove(QMouseEvent *event);
2086  void mouseRelease(QMouseEvent *event);
2087  void mouseWheel(QWheelEvent *event);
2088 
2089  void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
2090  void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
2091  void itemClick(QCPAbstractItem *item, QMouseEvent *event);
2092  void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
2093  void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
2094  void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
2095  void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
2096  void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
2097  void titleClick(QMouseEvent *event);
2098  void titleDoubleClick(QMouseEvent *event);
2099 
2100  void selectionChangedByUser();
2101  void beforeReplot();
2102  void afterReplot();
2103 
2104 protected:
2105  QString mTitle;
2106  QFont mTitleFont, mSelectedTitleFont;
2107  QColor mTitleColor, mSelectedTitleColor;
2108  QRect mViewport;
2109  QRect mAxisRect;
2110  int mMarginLeft, mMarginRight, mMarginTop, mMarginBottom;
2111  bool mAutoMargin, mAutoAddPlottableToLegend;
2112  QColor mColor;
2113  QList<QCPAbstractPlottable*> mPlottables;
2114  QList<QCPGraph*> mGraphs; //extra list of items also in mPlottables that are of type QCPGraph
2115  QList<QCPAbstractItem*> mItems;
2116  QList<QCPLayer*> mLayers;
2117  Qt::Orientations mRangeDrag, mRangeZoom;
2118  QCPAxis *mRangeDragHorzAxis, *mRangeDragVertAxis, *mRangeZoomHorzAxis, *mRangeZoomVertAxis;
2119  double mRangeZoomFactorHorz, mRangeZoomFactorVert;
2121  QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
2124  Qt::AspectRatioMode mAxisBackgroundScaledMode;
2125  Interactions mInteractions;
2130  //not explicitly exposed properties:
2131  QPixmap mPaintBuffer;
2132  QPoint mDragStart;
2133  QCPRange mDragStartHorzRange, mDragStartVertRange;
2136  QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
2138  QCP::PlottingHints mPlottingHints;
2139  Qt::KeyboardModifier mMultiSelectModifier;
2140 
2141  //reimplemented methods:
2142  virtual QSize minimumSizeHint() const;
2143  virtual void paintEvent(QPaintEvent *event);
2144  virtual void resizeEvent(QResizeEvent *event);
2145  virtual void mouseDoubleClickEvent(QMouseEvent *event);
2146  virtual void mousePressEvent(QMouseEvent *event);
2147  virtual void mouseMoveEvent(QMouseEvent *event);
2148  virtual void mouseReleaseEvent(QMouseEvent *event);
2149  virtual void wheelEvent(QWheelEvent *event);
2150  //event helpers:
2151  virtual bool handlePlottableSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
2152  virtual bool handleItemSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
2153  virtual bool handleAxisSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
2154  virtual bool handleTitleSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
2155 
2156  //introduced methods:
2157  virtual void draw(QCPPainter *painter);
2158  virtual void drawAxisBackground(QCPPainter *painter);
2159 
2160  //helpers:
2161  void updateAxisRect();
2162  bool selectTestTitle(const QPointF &pos) const;
2163  friend class QCPLegend;
2164  friend class QCPAxis;
2165  friend class QCPLayer;
2166 };
2167 Q_DECLARE_OPERATORS_FOR_FLAGS(QCustomPlot::Interactions)
2168 
2169 #endif//QCUSTOMPLOT_H