1 /***************************************************************************
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011-2015 Emanuel Eichhammer **
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. **
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. **
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/. **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
24 ****************************************************************************/
33 #include <QPaintEvent>
34 #include <QMouseEvent>
48 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
49 # include <qnumeric.h>
51 # include <QPrintEngine>
54 # include <QtPrintSupport/QtPrintSupport>
60 class QCPLayoutElement;
64 class QCPAxisPainterPrivate;
65 class QCPAbstractPlottable;
67 class QCPAbstractItem;
68 class QCPItemPosition;
72 class QCPAbstractLegendItem;
81 // decl definitions for shared library compilation/usage:
83 #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
84 # define QCP_LIB_DECL Q_DECL_EXPORT
85 #elif defined(QCUSTOMPLOT_USE_LIBRARY)
86 # define QCP_LIB_DECL Q_DECL_IMPORT
94 The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
99 Defines the sides of a rectangular entity to which margins can be applied.
101 \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
103 enum MarginSide { msLeft = 0x01 ///< <tt>0x01</tt> left margin
104 ,msRight = 0x02 ///< <tt>0x02</tt> right margin
105 ,msTop = 0x04 ///< <tt>0x04</tt> top margin
106 ,msBottom = 0x08 ///< <tt>0x08</tt> bottom margin
107 ,msAll = 0xFF ///< <tt>0xFF</tt> all margins
108 ,msNone = 0x00 ///< <tt>0x00</tt> no margin
110 Q_DECLARE_FLAGS(MarginSides, MarginSide)
113 Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
114 neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
115 element how it is drawn. Typically it provides a \a setAntialiased function for this.
117 \c AntialiasedElements is a flag of or-combined elements of this enum type.
119 \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
121 enum AntialiasedElement { aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
122 ,aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines
123 ,aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
124 ,aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box
125 ,aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items
126 ,aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see element \ref aeErrorBars)
127 ,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
128 ,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
129 ,aeErrorBars = 0x0100 ///< <tt>0x0100</tt> Error bars
130 ,aeFills = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs)
131 ,aeZeroLine = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
132 ,aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements
133 ,aeNone = 0x0000 ///< <tt>0x0000</tt> No elements
135 Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
138 Defines plotting hints that control various aspects of the quality and speed of plotting.
140 \see QCustomPlot::setPlottingHints
142 enum PlottingHint { phNone = 0x000 ///< <tt>0x000</tt> No hints are set
143 ,phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality
144 ///< especially of the line segment joins. (Only relevant for solid line pens.)
145 ,phForceRepaint = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint.
146 ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
147 ,phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance.
149 Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
152 Defines the mouse interactions possible with QCustomPlot.
154 \c Interactions is a flag of or-combined elements of this enum type.
156 \see QCustomPlot::setInteractions
158 enum Interaction { iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
159 ,iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
160 ,iMultiSelect = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
161 ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
162 ,iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
163 ,iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
164 ,iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
165 ,iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...)
167 Q_DECLARE_FLAGS(Interactions, Interaction)
171 Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
172 is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
173 compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
175 inline bool isInvalidData(double value)
177 return qIsNaN(value) || qIsInf(value);
183 Checks two arguments instead of one.
185 inline bool isInvalidData(double value1, double value2)
187 return isInvalidData(value1) || isInvalidData(value2);
192 Sets the specified \a side of \a margins to \a value
196 inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
200 case QCP::msLeft: margins.setLeft(value); break;
201 case QCP::msRight: margins.setRight(value); break;
202 case QCP::msTop: margins.setTop(value); break;
203 case QCP::msBottom: margins.setBottom(value); break;
204 case QCP::msAll: margins = QMargins(value, value, value, value); break;
211 Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
212 \ref QCP::msAll, returns 0.
216 inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
220 case QCP::msLeft: return margins.left();
221 case QCP::msRight: return margins.right();
222 case QCP::msTop: return margins.top();
223 case QCP::msBottom: return margins.bottom();
229 } // end of namespace QCP
231 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
232 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
233 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
234 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
237 class QCP_LIB_DECL QCPScatterStyle
242 Defines the shape used for scatter points.
244 On plottables/items that draw scatters, the sizes of these visualizations (with exception of
245 \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
246 drawn with the pen and brush specified with \ref setPen and \ref setBrush.
248 Q_ENUMS(ScatterShape)
249 enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
250 ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
251 ,ssCross ///< \enumimage{ssCross.png} a cross
252 ,ssPlus ///< \enumimage{ssPlus.png} a plus
253 ,ssCircle ///< \enumimage{ssCircle.png} a circle
254 ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
255 ,ssSquare ///< \enumimage{ssSquare.png} a square
256 ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond
257 ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
258 ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
259 ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
260 ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
261 ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
262 ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
263 ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
264 ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
265 ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
266 ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
270 QCPScatterStyle(ScatterShape shape, double size=6);
271 QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
272 QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
273 QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
274 QCPScatterStyle(const QPixmap &pixmap);
275 QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
278 double size() const { return mSize; }
279 ScatterShape shape() const { return mShape; }
280 QPen pen() const { return mPen; }
281 QBrush brush() const { return mBrush; }
282 QPixmap pixmap() const { return mPixmap; }
283 QPainterPath customPath() const { return mCustomPath; }
286 void setSize(double size);
287 void setShape(ScatterShape shape);
288 void setPen(const QPen &pen);
289 void setBrush(const QBrush &brush);
290 void setPixmap(const QPixmap &pixmap);
291 void setCustomPath(const QPainterPath &customPath);
293 // non-property methods:
294 bool isNone() const { return mShape == ssNone; }
295 bool isPenDefined() const { return mPenDefined; }
296 void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
297 void drawShape(QCPPainter *painter, QPointF pos) const;
298 void drawShape(QCPPainter *painter, double x, double y) const;
307 QPainterPath mCustomPath;
309 // non-property members:
312 Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
315 class QCP_LIB_DECL QCPPainter : public QPainter
320 Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
321 depending on whether they are wanted on the respective output device.
323 enum PainterMode { pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices
324 ,pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
325 ,pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
326 ,pmNonCosmetic = 0x04 ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)
328 Q_FLAGS(PainterMode PainterModes)
329 Q_DECLARE_FLAGS(PainterModes, PainterMode)
332 QCPPainter(QPaintDevice *device);
336 bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
337 PainterModes modes() const { return mModes; }
340 void setAntialiasing(bool enabled);
341 void setMode(PainterMode mode, bool enabled=true);
342 void setModes(PainterModes modes);
344 // methods hiding non-virtual base class functions (QPainter bug workarounds):
345 bool begin(QPaintDevice *device);
346 void setPen(const QPen &pen);
347 void setPen(const QColor &color);
348 void setPen(Qt::PenStyle penStyle);
349 void drawLine(const QLineF &line);
350 void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
354 // non-virtual methods:
355 void makeNonCosmetic();
360 bool mIsAntialiasing;
362 // non-property members:
363 QStack<bool> mAntialiasingStack;
365 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
368 class QCP_LIB_DECL QCPLayer : public QObject
371 /// \cond INCLUDE_QPROPERTIES
372 Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
373 Q_PROPERTY(QString name READ name)
374 Q_PROPERTY(int index READ index)
375 Q_PROPERTY(QList<QCPLayerable*> children READ children)
376 Q_PROPERTY(bool visible READ visible WRITE setVisible)
379 QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
383 QCustomPlot *parentPlot() const { return mParentPlot; }
384 QString name() const { return mName; }
385 int index() const { return mIndex; }
386 QList<QCPLayerable*> children() const { return mChildren; }
387 bool visible() const { return mVisible; }
390 void setVisible(bool visible);
394 QCustomPlot *mParentPlot;
397 QList<QCPLayerable*> mChildren;
400 // non-virtual methods:
401 void addChild(QCPLayerable *layerable, bool prepend);
402 void removeChild(QCPLayerable *layerable);
405 Q_DISABLE_COPY(QCPLayer)
407 friend class QCustomPlot;
408 friend class QCPLayerable;
411 class QCP_LIB_DECL QCPLayerable : public QObject
414 /// \cond INCLUDE_QPROPERTIES
415 Q_PROPERTY(bool visible READ visible WRITE setVisible)
416 Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
417 Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
418 Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
419 Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
422 QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0);
426 bool visible() const { return mVisible; }
427 QCustomPlot *parentPlot() const { return mParentPlot; }
428 QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
429 QCPLayer *layer() const { return mLayer; }
430 bool antialiased() const { return mAntialiased; }
433 void setVisible(bool on);
434 Q_SLOT bool setLayer(QCPLayer *layer);
435 bool setLayer(const QString &layerName);
436 void setAntialiased(bool enabled);
438 // introduced virtual methods:
439 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
441 // non-property methods:
442 bool realVisibility() const;
445 void layerChanged(QCPLayer *newLayer);
450 QCustomPlot *mParentPlot;
451 QPointer<QCPLayerable> mParentLayerable;
455 // introduced virtual methods:
456 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
457 virtual QCP::Interaction selectionCategory() const;
458 virtual QRect clipRect() const;
459 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
460 virtual void draw(QCPPainter *painter) = 0;
462 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
463 virtual void deselectEvent(bool *selectionStateChanged);
465 // non-property methods:
466 void initializeParentPlot(QCustomPlot *parentPlot);
467 void setParentLayerable(QCPLayerable* parentLayerable);
468 bool moveToLayer(QCPLayer *layer, bool prepend);
469 void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
472 Q_DISABLE_COPY(QCPLayerable)
474 friend class QCustomPlot;
475 friend class QCPAxisRect;
479 class QCP_LIB_DECL QCPRange
485 QCPRange(double lower, double upper);
487 bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; }
488 bool operator!=(const QCPRange& other) const { return !(*this == other); }
490 QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; }
491 QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; }
492 QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; }
493 QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
494 friend inline const QCPRange operator+(const QCPRange&, double);
495 friend inline const QCPRange operator+(double, const QCPRange&);
496 friend inline const QCPRange operator-(const QCPRange& range, double value);
497 friend inline const QCPRange operator*(const QCPRange& range, double value);
498 friend inline const QCPRange operator*(double value, const QCPRange& range);
499 friend inline const QCPRange operator/(const QCPRange& range, double value);
502 double center() const;
504 void expand(const QCPRange &otherRange);
505 QCPRange expanded(const QCPRange &otherRange) const;
506 QCPRange sanitizedForLogScale() const;
507 QCPRange sanitizedForLinScale() const;
508 bool contains(double value) const;
510 static bool validRange(double lower, double upper);
511 static bool validRange(const QCPRange &range);
512 static const double minRange; //1e-280;
513 static const double maxRange; //1e280;
516 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
518 /* documentation of inline functions */
520 /*! \fn QCPRange &QCPRange::operator+=(const double& value)
522 Adds \a value to both boundaries of the range.
525 /*! \fn QCPRange &QCPRange::operator-=(const double& value)
527 Subtracts \a value from both boundaries of the range.
530 /*! \fn QCPRange &QCPRange::operator*=(const double& value)
532 Multiplies both boundaries of the range by \a value.
535 /*! \fn QCPRange &QCPRange::operator/=(const double& value)
537 Divides both boundaries of the range by \a value.
540 /* end documentation of inline functions */
543 Adds \a value to both boundaries of the range.
545 inline const QCPRange operator+(const QCPRange& range, double value)
547 QCPRange result(range);
553 Adds \a value to both boundaries of the range.
555 inline const QCPRange operator+(double value, const QCPRange& range)
557 QCPRange result(range);
563 Subtracts \a value from both boundaries of the range.
565 inline const QCPRange operator-(const QCPRange& range, double value)
567 QCPRange result(range);
573 Multiplies both boundaries of the range by \a value.
575 inline const QCPRange operator*(const QCPRange& range, double value)
577 QCPRange result(range);
583 Multiplies both boundaries of the range by \a value.
585 inline const QCPRange operator*(double value, const QCPRange& range)
587 QCPRange result(range);
593 Divides both boundaries of the range by \a value.
595 inline const QCPRange operator/(const QCPRange& range, double value)
597 QCPRange result(range);
603 class QCP_LIB_DECL QCPMarginGroup : public QObject
607 QCPMarginGroup(QCustomPlot *parentPlot);
610 // non-virtual methods:
611 QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
612 bool isEmpty() const;
616 // non-property members:
617 QCustomPlot *mParentPlot;
618 QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
620 // non-virtual methods:
621 int commonMargin(QCP::MarginSide side) const;
622 void addChild(QCP::MarginSide side, QCPLayoutElement *element);
623 void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
626 Q_DISABLE_COPY(QCPMarginGroup)
628 friend class QCPLayoutElement;
632 class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
635 /// \cond INCLUDE_QPROPERTIES
636 Q_PROPERTY(QCPLayout* layout READ layout)
637 Q_PROPERTY(QRect rect READ rect)
638 Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
639 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
640 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
641 Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
642 Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
646 Defines the phases of the update process, that happens just before a replot. At each phase,
647 \ref update is called with the according UpdatePhase value.
649 enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout
650 ,upMargins ///< Phase in which the margins are calculated and set
651 ,upLayout ///< Final phase in which the layout system places the rects of the elements
655 explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
656 virtual ~QCPLayoutElement();
659 QCPLayout *layout() const { return mParentLayout; }
660 QRect rect() const { return mRect; }
661 QRect outerRect() const { return mOuterRect; }
662 QMargins margins() const { return mMargins; }
663 QMargins minimumMargins() const { return mMinimumMargins; }
664 QCP::MarginSides autoMargins() const { return mAutoMargins; }
665 QSize minimumSize() const { return mMinimumSize; }
666 QSize maximumSize() const { return mMaximumSize; }
667 QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
668 QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
671 void setOuterRect(const QRect &rect);
672 void setMargins(const QMargins &margins);
673 void setMinimumMargins(const QMargins &margins);
674 void setAutoMargins(QCP::MarginSides sides);
675 void setMinimumSize(const QSize &size);
676 void setMinimumSize(int width, int height);
677 void setMaximumSize(const QSize &size);
678 void setMaximumSize(int width, int height);
679 void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
681 // introduced virtual methods:
682 virtual void update(UpdatePhase phase);
683 virtual QSize minimumSizeHint() const;
684 virtual QSize maximumSizeHint() const;
685 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
687 // reimplemented virtual methods:
688 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
692 QCPLayout *mParentLayout;
693 QSize mMinimumSize, mMaximumSize;
694 QRect mRect, mOuterRect;
695 QMargins mMargins, mMinimumMargins;
696 QCP::MarginSides mAutoMargins;
697 QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
699 // introduced virtual methods:
700 virtual int calculateAutoMargin(QCP::MarginSide side);
702 virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
703 virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
704 virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
705 virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
706 virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
708 // reimplemented virtual methods:
709 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
710 virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
711 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
714 Q_DISABLE_COPY(QCPLayoutElement)
716 friend class QCustomPlot;
717 friend class QCPLayout;
718 friend class QCPMarginGroup;
722 class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
726 explicit QCPLayout();
728 // reimplemented virtual methods:
729 virtual void update(UpdatePhase phase);
730 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
732 // introduced virtual methods:
733 virtual int elementCount() const = 0;
734 virtual QCPLayoutElement* elementAt(int index) const = 0;
735 virtual QCPLayoutElement* takeAt(int index) = 0;
736 virtual bool take(QCPLayoutElement* element) = 0;
737 virtual void simplify();
739 // non-virtual methods:
740 bool removeAt(int index);
741 bool remove(QCPLayoutElement* element);
745 // introduced virtual methods:
746 virtual void updateLayout();
748 // non-virtual methods:
749 void sizeConstraintsChanged() const;
750 void adoptElement(QCPLayoutElement *el);
751 void releaseElement(QCPLayoutElement *el);
752 QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
755 Q_DISABLE_COPY(QCPLayout)
756 friend class QCPLayoutElement;
760 class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
763 /// \cond INCLUDE_QPROPERTIES
764 Q_PROPERTY(int rowCount READ rowCount)
765 Q_PROPERTY(int columnCount READ columnCount)
766 Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
767 Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
768 Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
769 Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
772 explicit QCPLayoutGrid();
773 virtual ~QCPLayoutGrid();
776 int rowCount() const;
777 int columnCount() const;
778 QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
779 QList<double> rowStretchFactors() const { return mRowStretchFactors; }
780 int columnSpacing() const { return mColumnSpacing; }
781 int rowSpacing() const { return mRowSpacing; }
784 void setColumnStretchFactor(int column, double factor);
785 void setColumnStretchFactors(const QList<double> &factors);
786 void setRowStretchFactor(int row, double factor);
787 void setRowStretchFactors(const QList<double> &factors);
788 void setColumnSpacing(int pixels);
789 void setRowSpacing(int pixels);
791 // reimplemented virtual methods:
792 virtual void updateLayout();
793 virtual int elementCount() const;
794 virtual QCPLayoutElement* elementAt(int index) const;
795 virtual QCPLayoutElement* takeAt(int index);
796 virtual bool take(QCPLayoutElement* element);
797 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
798 virtual void simplify();
799 virtual QSize minimumSizeHint() const;
800 virtual QSize maximumSizeHint() const;
802 // non-virtual methods:
803 QCPLayoutElement *element(int row, int column) const;
804 bool addElement(int row, int column, QCPLayoutElement *element);
805 bool hasElement(int row, int column);
806 void expandTo(int newRowCount, int newColumnCount);
807 void insertRow(int newIndex);
808 void insertColumn(int newIndex);
812 QList<QList<QCPLayoutElement*> > mElements;
813 QList<double> mColumnStretchFactors;
814 QList<double> mRowStretchFactors;
815 int mColumnSpacing, mRowSpacing;
817 // non-virtual methods:
818 void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
819 void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
822 Q_DISABLE_COPY(QCPLayoutGrid)
826 class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
831 Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
833 enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
834 ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
837 explicit QCPLayoutInset();
838 virtual ~QCPLayoutInset();
841 InsetPlacement insetPlacement(int index) const;
842 Qt::Alignment insetAlignment(int index) const;
843 QRectF insetRect(int index) const;
846 void setInsetPlacement(int index, InsetPlacement placement);
847 void setInsetAlignment(int index, Qt::Alignment alignment);
848 void setInsetRect(int index, const QRectF &rect);
850 // reimplemented virtual methods:
851 virtual void updateLayout();
852 virtual int elementCount() const;
853 virtual QCPLayoutElement* elementAt(int index) const;
854 virtual QCPLayoutElement* takeAt(int index);
855 virtual bool take(QCPLayoutElement* element);
856 virtual void simplify() {}
857 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
859 // non-virtual methods:
860 void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
861 void addElement(QCPLayoutElement *element, const QRectF &rect);
865 QList<QCPLayoutElement*> mElements;
866 QList<InsetPlacement> mInsetPlacement;
867 QList<Qt::Alignment> mInsetAlignment;
868 QList<QRectF> mInsetRect;
871 Q_DISABLE_COPY(QCPLayoutInset)
875 class QCP_LIB_DECL QCPLineEnding
880 Defines the type of ending decoration for line-like items, e.g. an arrow.
882 \image html QCPLineEnding.png
884 The width and length of these decorations can be controlled with the functions \ref setWidth
885 and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
886 support a width, the length property is ignored.
888 \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
891 enum EndingStyle { esNone ///< No ending decoration
892 ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
893 ,esSpikeArrow ///< A filled arrow head with an indented back
894 ,esLineArrow ///< A non-filled arrow head with open back
895 ,esDisc ///< A filled circle
896 ,esSquare ///< A filled square
897 ,esDiamond ///< A filled diamond (45° rotated square)
898 ,esBar ///< A bar perpendicular to the line
899 ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted)
900 ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
904 QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
907 EndingStyle style() const { return mStyle; }
908 double width() const { return mWidth; }
909 double length() const { return mLength; }
910 bool inverted() const { return mInverted; }
913 void setStyle(EndingStyle style);
914 void setWidth(double width);
915 void setLength(double length);
916 void setInverted(bool inverted);
918 // non-property methods:
919 double boundingDistance() const;
920 double realLength() const;
921 void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
922 void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
927 double mWidth, mLength;
930 Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
933 class QCP_LIB_DECL QCPGrid :public QCPLayerable
936 /// \cond INCLUDE_QPROPERTIES
937 Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
938 Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
939 Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
940 Q_PROPERTY(QPen pen READ pen WRITE setPen)
941 Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
942 Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
945 QCPGrid(QCPAxis *parentAxis);
948 bool subGridVisible() const { return mSubGridVisible; }
949 bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
950 bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
951 QPen pen() const { return mPen; }
952 QPen subGridPen() const { return mSubGridPen; }
953 QPen zeroLinePen() const { return mZeroLinePen; }
956 void setSubGridVisible(bool visible);
957 void setAntialiasedSubGrid(bool enabled);
958 void setAntialiasedZeroLine(bool enabled);
959 void setPen(const QPen &pen);
960 void setSubGridPen(const QPen &pen);
961 void setZeroLinePen(const QPen &pen);
965 bool mSubGridVisible;
966 bool mAntialiasedSubGrid, mAntialiasedZeroLine;
967 QPen mPen, mSubGridPen, mZeroLinePen;
968 // non-property members:
969 QCPAxis *mParentAxis;
971 // reimplemented virtual methods:
972 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
973 virtual void draw(QCPPainter *painter);
975 // non-virtual methods:
976 void drawGridLines(QCPPainter *painter) const;
977 void drawSubGridLines(QCPPainter *painter) const;
979 friend class QCPAxis;
983 class QCP_LIB_DECL QCPAxis : public QCPLayerable
986 /// \cond INCLUDE_QPROPERTIES
987 Q_PROPERTY(AxisType axisType READ axisType)
988 Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
989 Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
990 Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
991 Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
992 Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
993 Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
994 Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
995 Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
996 Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
997 Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
998 Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
999 Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
1000 Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
1001 Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
1002 Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
1003 Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
1004 Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
1005 Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide)
1006 Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
1007 Q_PROPERTY(Qt::TimeSpec dateTimeSpec READ dateTimeSpec WRITE setDateTimeSpec)
1008 Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
1009 Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
1010 Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
1011 Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
1012 Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
1013 Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
1014 Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
1015 Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
1016 Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
1017 Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
1018 Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
1019 Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
1020 Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
1021 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
1022 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
1023 Q_PROPERTY(QString label READ label WRITE setLabel)
1024 Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
1025 Q_PROPERTY(int padding READ padding WRITE setPadding)
1026 Q_PROPERTY(int offset READ offset WRITE setOffset)
1027 Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged)
1028 Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged)
1029 Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
1030 Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
1031 Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
1032 Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
1033 Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
1034 Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
1035 Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
1036 Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
1037 Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
1038 Q_PROPERTY(QCPGrid* grid READ grid)
1042 Defines at which side of the axis rect the axis will appear. This also affects how the tick
1043 marks are drawn, on which side the labels are placed etc.
1045 enum AxisType { atLeft = 0x01 ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect
1046 ,atRight = 0x02 ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect
1047 ,atTop = 0x04 ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect
1048 ,atBottom = 0x08 ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect
1050 Q_FLAGS(AxisType AxisTypes)
1051 Q_DECLARE_FLAGS(AxisTypes, AxisType)
1053 When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the
1054 coordinate of the tick is interpreted, i.e. translated into a string.
1056 \see setTickLabelType
1058 enum LabelType { ltNumber ///< Tick coordinate is regarded as normal number and will be displayed as such. (see \ref setNumberFormat)
1059 ,ltDateTime ///< Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC) and will be displayed and formatted as such. (for details, see \ref setDateTimeFormat)
1063 Defines on which side of the axis the tick labels (numbers) shall appear.
1065 \see setTickLabelSide
1067 enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect
1068 ,lsOutside ///< Tick labels will be displayed outside the axis rect
1072 Defines the scale of an axis.
1075 enum ScaleType { stLinear ///< Linear scaling
1076 ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see \ref setScaleLogBase).
1080 Defines the selectable parts of an axis.
1081 \see setSelectableParts, setSelectedParts
1083 enum SelectablePart { spNone = 0 ///< None of the selectable parts
1084 ,spAxis = 0x001 ///< The axis backbone and tick marks
1085 ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
1086 ,spAxisLabel = 0x004 ///< The axis label
1088 Q_FLAGS(SelectablePart SelectableParts)
1089 Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
1091 explicit QCPAxis(QCPAxisRect *parent, AxisType type);
1095 AxisType axisType() const { return mAxisType; }
1096 QCPAxisRect *axisRect() const { return mAxisRect; }
1097 ScaleType scaleType() const { return mScaleType; }
1098 double scaleLogBase() const { return mScaleLogBase; }
1099 const QCPRange range() const { return mRange; }
1100 bool rangeReversed() const { return mRangeReversed; }
1101 bool autoTicks() const { return mAutoTicks; }
1102 int autoTickCount() const { return mAutoTickCount; }
1103 bool autoTickLabels() const { return mAutoTickLabels; }
1104 bool autoTickStep() const { return mAutoTickStep; }
1105 bool autoSubTicks() const { return mAutoSubTicks; }
1106 bool ticks() const { return mTicks; }
1107 bool tickLabels() const { return mTickLabels; }
1108 int tickLabelPadding() const;
1109 LabelType tickLabelType() const { return mTickLabelType; }
1110 QFont tickLabelFont() const { return mTickLabelFont; }
1111 QColor tickLabelColor() const { return mTickLabelColor; }
1112 double tickLabelRotation() const;
1113 LabelSide tickLabelSide() const;
1114 QString dateTimeFormat() const { return mDateTimeFormat; }
1115 Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
1116 QString numberFormat() const;
1117 int numberPrecision() const { return mNumberPrecision; }
1118 double tickStep() const { return mTickStep; }
1119 QVector<double> tickVector() const { return mTickVector; }
1120 QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
1121 int tickLengthIn() const;
1122 int tickLengthOut() const;
1123 int subTickCount() const { return mSubTickCount; }
1124 int subTickLengthIn() const;
1125 int subTickLengthOut() const;
1126 QPen basePen() const { return mBasePen; }
1127 QPen tickPen() const { return mTickPen; }
1128 QPen subTickPen() const { return mSubTickPen; }
1129 QFont labelFont() const { return mLabelFont; }
1130 QColor labelColor() const { return mLabelColor; }
1131 QString label() const { return mLabel; }
1132 int labelPadding() const;
1133 int padding() const { return mPadding; }
1135 SelectableParts selectedParts() const { return mSelectedParts; }
1136 SelectableParts selectableParts() const { return mSelectableParts; }
1137 QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
1138 QFont selectedLabelFont() const { return mSelectedLabelFont; }
1139 QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
1140 QColor selectedLabelColor() const { return mSelectedLabelColor; }
1141 QPen selectedBasePen() const { return mSelectedBasePen; }
1142 QPen selectedTickPen() const { return mSelectedTickPen; }
1143 QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
1144 QCPLineEnding lowerEnding() const;
1145 QCPLineEnding upperEnding() const;
1146 QCPGrid *grid() const { return mGrid; }
1149 Q_SLOT void setScaleType(QCPAxis::ScaleType type);
1150 void setScaleLogBase(double base);
1151 Q_SLOT void setRange(const QCPRange &range);
1152 void setRange(double lower, double upper);
1153 void setRange(double position, double size, Qt::AlignmentFlag alignment);
1154 void setRangeLower(double lower);
1155 void setRangeUpper(double upper);
1156 void setRangeReversed(bool reversed);
1157 void setAutoTicks(bool on);
1158 void setAutoTickCount(int approximateCount);
1159 void setAutoTickLabels(bool on);
1160 void setAutoTickStep(bool on);
1161 void setAutoSubTicks(bool on);
1162 void setTicks(bool show);
1163 void setTickLabels(bool show);
1164 void setTickLabelPadding(int padding);
1165 void setTickLabelType(LabelType type);
1166 void setTickLabelFont(const QFont &font);
1167 void setTickLabelColor(const QColor &color);
1168 void setTickLabelRotation(double degrees);
1169 void setTickLabelSide(LabelSide side);
1170 void setDateTimeFormat(const QString &format);
1171 void setDateTimeSpec(const Qt::TimeSpec &timeSpec);
1172 void setNumberFormat(const QString &formatCode);
1173 void setNumberPrecision(int precision);
1174 void setTickStep(double step);
1175 void setTickVector(const QVector<double> &vec);
1176 void setTickVectorLabels(const QVector<QString> &vec);
1177 void setTickLength(int inside, int outside=0);
1178 void setTickLengthIn(int inside);
1179 void setTickLengthOut(int outside);
1180 void setSubTickCount(int count);
1181 void setSubTickLength(int inside, int outside=0);
1182 void setSubTickLengthIn(int inside);
1183 void setSubTickLengthOut(int outside);
1184 void setBasePen(const QPen &pen);
1185 void setTickPen(const QPen &pen);
1186 void setSubTickPen(const QPen &pen);
1187 void setLabelFont(const QFont &font);
1188 void setLabelColor(const QColor &color);
1189 void setLabel(const QString &str);
1190 void setLabelPadding(int padding);
1191 void setPadding(int padding);
1192 void setOffset(int offset);
1193 void setSelectedTickLabelFont(const QFont &font);
1194 void setSelectedLabelFont(const QFont &font);
1195 void setSelectedTickLabelColor(const QColor &color);
1196 void setSelectedLabelColor(const QColor &color);
1197 void setSelectedBasePen(const QPen &pen);
1198 void setSelectedTickPen(const QPen &pen);
1199 void setSelectedSubTickPen(const QPen &pen);
1200 Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
1201 Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
1202 void setLowerEnding(const QCPLineEnding &ending);
1203 void setUpperEnding(const QCPLineEnding &ending);
1205 // reimplemented virtual methods:
1206 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1208 // non-property methods:
1209 Qt::Orientation orientation() const { return mOrientation; }
1210 void moveRange(double diff);
1211 void scaleRange(double factor, double center);
1212 void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
1213 void rescale(bool onlyVisiblePlottables=false);
1214 double pixelToCoord(double value) const;
1215 double coordToPixel(double value) const;
1216 SelectablePart getPartAt(const QPointF &pos) const;
1217 QList<QCPAbstractPlottable*> plottables() const;
1218 QList<QCPGraph*> graphs() const;
1219 QList<QCPAbstractItem*> items() const;
1221 static AxisType marginSideToAxisType(QCP::MarginSide side);
1222 static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; }
1223 static AxisType opposite(AxisType type);
1226 void ticksRequest();
1227 void rangeChanged(const QCPRange &newRange);
1228 void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
1229 void scaleTypeChanged(QCPAxis::ScaleType scaleType);
1230 void selectionChanged(const QCPAxis::SelectableParts &parts);
1231 void selectableChanged(const QCPAxis::SelectableParts &parts);
1234 // property members:
1237 QCPAxisRect *mAxisRect;
1238 //int mOffset; // in QCPAxisPainter
1240 Qt::Orientation mOrientation;
1241 SelectableParts mSelectableParts, mSelectedParts;
1242 QPen mBasePen, mSelectedBasePen;
1243 //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter
1245 //int mLabelPadding; // in QCPAxisPainter
1247 QFont mLabelFont, mSelectedLabelFont;
1248 QColor mLabelColor, mSelectedLabelColor;
1250 //int mTickLabelPadding; // in QCPAxisPainter
1251 bool mTickLabels, mAutoTickLabels;
1252 //double mTickLabelRotation; // in QCPAxisPainter
1253 LabelType mTickLabelType;
1254 QFont mTickLabelFont, mSelectedTickLabelFont;
1255 QColor mTickLabelColor, mSelectedTickLabelColor;
1256 QString mDateTimeFormat;
1257 Qt::TimeSpec mDateTimeSpec;
1258 int mNumberPrecision;
1259 QLatin1Char mNumberFormatChar;
1260 bool mNumberBeautifulPowers;
1261 //bool mNumberMultiplyCross; // QCPAxisPainter
1262 // ticks and subticks:
1265 int mSubTickCount, mAutoTickCount;
1266 bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
1267 //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter
1268 QPen mTickPen, mSelectedTickPen;
1269 QPen mSubTickPen, mSelectedSubTickPen;
1272 bool mRangeReversed;
1273 ScaleType mScaleType;
1274 double mScaleLogBase, mScaleLogBaseLogInv;
1276 // non-property members:
1278 QCPAxisPainterPrivate *mAxisPainter;
1279 int mLowestVisibleTick, mHighestVisibleTick;
1280 QVector<double> mTickVector;
1281 QVector<QString> mTickVectorLabels;
1282 QVector<double> mSubTickVector;
1283 bool mCachedMarginValid;
1286 // introduced virtual methods:
1287 virtual void setupTickVectors();
1288 virtual void generateAutoTicks();
1289 virtual int calculateAutoSubTickCount(double tickStep) const;
1290 virtual int calculateMargin();
1292 // reimplemented virtual methods:
1293 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1294 virtual void draw(QCPPainter *painter);
1295 virtual QCP::Interaction selectionCategory() const;
1297 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1298 virtual void deselectEvent(bool *selectionStateChanged);
1300 // non-virtual methods:
1301 void visibleTickBounds(int &lowIndex, int &highIndex) const;
1302 double baseLog(double value) const;
1303 double basePow(double value) const;
1304 QPen getBasePen() const;
1305 QPen getTickPen() const;
1306 QPen getSubTickPen() const;
1307 QFont getTickLabelFont() const;
1308 QFont getLabelFont() const;
1309 QColor getTickLabelColor() const;
1310 QColor getLabelColor() const;
1313 Q_DISABLE_COPY(QCPAxis)
1315 friend class QCustomPlot;
1316 friend class QCPGrid;
1317 friend class QCPAxisRect;
1319 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
1320 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
1321 Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
1324 class QCPAxisPainterPrivate
1327 explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot);
1328 virtual ~QCPAxisPainterPrivate();
1330 virtual void draw(QCPPainter *painter);
1331 virtual int size() const;
1334 QRect axisSelectionBox() const { return mAxisSelectionBox; }
1335 QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; }
1336 QRect labelSelectionBox() const { return mLabelSelectionBox; }
1338 // public property members:
1339 QCPAxis::AxisType type;
1341 QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters
1342 int labelPadding; // directly accessed by QCPAxis setters/getters
1346 int tickLabelPadding; // directly accessed by QCPAxis setters/getters
1347 double tickLabelRotation; // directly accessed by QCPAxis setters/getters
1348 QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters
1349 bool substituteExponent;
1350 bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters
1351 int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters
1352 QPen tickPen, subTickPen;
1353 QFont tickLabelFont;
1354 QColor tickLabelColor;
1355 QRect axisRect, viewportRect;
1356 double offset; // directly accessed by QCPAxis setters/getters
1357 bool abbreviateDecimalPowers;
1358 bool reversedEndings;
1360 QVector<double> subTickPositions;
1361 QVector<double> tickPositions;
1362 QVector<QString> tickLabels;
1370 struct TickLabelData
1372 QString basePart, expPart;
1373 QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
1374 QFont baseFont, expFont;
1376 QCustomPlot *mParentPlot;
1377 QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters
1378 QCache<QString, CachedLabel> mLabelCache;
1379 QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
1381 virtual QByteArray generateLabelParameterHash() const;
1383 virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
1384 virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
1385 virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
1386 virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
1387 virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
1391 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
1394 /// \cond INCLUDE_QPROPERTIES
1395 Q_PROPERTY(QString name READ name WRITE setName)
1396 Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
1397 Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
1398 Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
1399 Q_PROPERTY(QPen pen READ pen WRITE setPen)
1400 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
1401 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
1402 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
1403 Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
1404 Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
1405 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1406 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1409 QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
1412 QString name() const { return mName; }
1413 bool antialiasedFill() const { return mAntialiasedFill; }
1414 bool antialiasedScatters() const { return mAntialiasedScatters; }
1415 bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
1416 QPen pen() const { return mPen; }
1417 QPen selectedPen() const { return mSelectedPen; }
1418 QBrush brush() const { return mBrush; }
1419 QBrush selectedBrush() const { return mSelectedBrush; }
1420 QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1421 QCPAxis *valueAxis() const { return mValueAxis.data(); }
1422 bool selectable() const { return mSelectable; }
1423 bool selected() const { return mSelected; }
1426 void setName(const QString &name);
1427 void setAntialiasedFill(bool enabled);
1428 void setAntialiasedScatters(bool enabled);
1429 void setAntialiasedErrorBars(bool enabled);
1430 void setPen(const QPen &pen);
1431 void setSelectedPen(const QPen &pen);
1432 void setBrush(const QBrush &brush);
1433 void setSelectedBrush(const QBrush &brush);
1434 void setKeyAxis(QCPAxis *axis);
1435 void setValueAxis(QCPAxis *axis);
1436 Q_SLOT void setSelectable(bool selectable);
1437 Q_SLOT void setSelected(bool selected);
1439 // introduced virtual methods:
1440 virtual void clearData() = 0;
1441 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1442 virtual bool addToLegend();
1443 virtual bool removeFromLegend() const;
1445 // non-property methods:
1446 void rescaleAxes(bool onlyEnlarge=false) const;
1447 void rescaleKeyAxis(bool onlyEnlarge=false) const;
1448 void rescaleValueAxis(bool onlyEnlarge=false) const;
1451 void selectionChanged(bool selected);
1452 void selectableChanged(bool selectable);
1456 Represents negative and positive sign domain for passing to \ref getKeyRange and \ref getValueRange.
1458 enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
1459 ,sdBoth ///< Both sign domains, including zero, i.e. all (rational) numbers
1460 ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
1463 // property members:
1465 bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
1466 QPen mPen, mSelectedPen;
1467 QBrush mBrush, mSelectedBrush;
1468 QPointer<QCPAxis> mKeyAxis, mValueAxis;
1469 bool mSelectable, mSelected;
1471 // reimplemented virtual methods:
1472 virtual QRect clipRect() const;
1473 virtual void draw(QCPPainter *painter) = 0;
1474 virtual QCP::Interaction selectionCategory() const;
1475 void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1477 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1478 virtual void deselectEvent(bool *selectionStateChanged);
1480 // introduced virtual methods:
1481 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
1482 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1483 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1485 // non-virtual methods:
1486 void coordsToPixels(double key, double value, double &x, double &y) const;
1487 const QPointF coordsToPixels(double key, double value) const;
1488 void pixelsToCoords(double x, double y, double &key, double &value) const;
1489 void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
1490 QPen mainPen() const;
1491 QBrush mainBrush() const;
1492 void applyFillAntialiasingHint(QCPPainter *painter) const;
1493 void applyScattersAntialiasingHint(QCPPainter *painter) const;
1494 void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
1495 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1498 Q_DISABLE_COPY(QCPAbstractPlottable)
1500 friend class QCustomPlot;
1501 friend class QCPAxis;
1502 friend class QCPPlottableLegendItem;
1506 class QCP_LIB_DECL QCPItemAnchor
1509 QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
1510 virtual ~QCPItemAnchor();
1513 QString name() const { return mName; }
1514 virtual QPointF pixelPoint() const;
1517 // property members:
1520 // non-property members:
1521 QCustomPlot *mParentPlot;
1522 QCPAbstractItem *mParentItem;
1524 QSet<QCPItemPosition*> mChildrenX, mChildrenY;
1526 // introduced virtual methods:
1527 virtual QCPItemPosition *toQCPItemPosition() { return 0; }
1529 // non-virtual methods:
1530 void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1531 void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1532 void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1533 void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1536 Q_DISABLE_COPY(QCPItemAnchor)
1538 friend class QCPItemPosition;
1543 class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
1547 Defines the ways an item position can be specified. Thus it defines what the numbers passed to
1548 \ref setCoords actually mean.
1552 enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget.
1553 ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top
1554 ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
1555 ///< vertically at the top of the viewport/widget, etc.
1556 ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top
1557 ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
1558 ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1.
1559 ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes).
1562 QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
1563 virtual ~QCPItemPosition();
1566 PositionType type() const { return typeX(); }
1567 PositionType typeX() const { return mPositionTypeX; }
1568 PositionType typeY() const { return mPositionTypeY; }
1569 QCPItemAnchor *parentAnchor() const { return parentAnchorX(); }
1570 QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; }
1571 QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; }
1572 double key() const { return mKey; }
1573 double value() const { return mValue; }
1574 QPointF coords() const { return QPointF(mKey, mValue); }
1575 QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1576 QCPAxis *valueAxis() const { return mValueAxis.data(); }
1577 QCPAxisRect *axisRect() const;
1578 virtual QPointF pixelPoint() const;
1581 void setType(PositionType type);
1582 void setTypeX(PositionType type);
1583 void setTypeY(PositionType type);
1584 bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1585 bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1586 bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1587 void setCoords(double key, double value);
1588 void setCoords(const QPointF &coords);
1589 void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
1590 void setAxisRect(QCPAxisRect *axisRect);
1591 void setPixelPoint(const QPointF &pixelPoint);
1594 // property members:
1595 PositionType mPositionTypeX, mPositionTypeY;
1596 QPointer<QCPAxis> mKeyAxis, mValueAxis;
1597 QPointer<QCPAxisRect> mAxisRect;
1598 double mKey, mValue;
1599 QCPItemAnchor *mParentAnchorX, *mParentAnchorY;
1601 // reimplemented virtual methods:
1602 virtual QCPItemPosition *toQCPItemPosition() { return this; }
1605 Q_DISABLE_COPY(QCPItemPosition)
1610 class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
1613 /// \cond INCLUDE_QPROPERTIES
1614 Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
1615 Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
1616 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1617 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1620 QCPAbstractItem(QCustomPlot *parentPlot);
1621 virtual ~QCPAbstractItem();
1624 bool clipToAxisRect() const { return mClipToAxisRect; }
1625 QCPAxisRect *clipAxisRect() const;
1626 bool selectable() const { return mSelectable; }
1627 bool selected() const { return mSelected; }
1630 void setClipToAxisRect(bool clip);
1631 void setClipAxisRect(QCPAxisRect *rect);
1632 Q_SLOT void setSelectable(bool selectable);
1633 Q_SLOT void setSelected(bool selected);
1635 // reimplemented virtual methods:
1636 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1638 // non-virtual methods:
1639 QList<QCPItemPosition*> positions() const { return mPositions; }
1640 QList<QCPItemAnchor*> anchors() const { return mAnchors; }
1641 QCPItemPosition *position(const QString &name) const;
1642 QCPItemAnchor *anchor(const QString &name) const;
1643 bool hasAnchor(const QString &name) const;
1646 void selectionChanged(bool selected);
1647 void selectableChanged(bool selectable);
1650 // property members:
1651 bool mClipToAxisRect;
1652 QPointer<QCPAxisRect> mClipAxisRect;
1653 QList<QCPItemPosition*> mPositions;
1654 QList<QCPItemAnchor*> mAnchors;
1655 bool mSelectable, mSelected;
1657 // reimplemented virtual methods:
1658 virtual QCP::Interaction selectionCategory() const;
1659 virtual QRect clipRect() const;
1660 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1661 virtual void draw(QCPPainter *painter) = 0;
1663 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1664 virtual void deselectEvent(bool *selectionStateChanged);
1666 // introduced virtual methods:
1667 virtual QPointF anchorPixelPoint(int anchorId) const;
1669 // non-virtual methods:
1670 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1671 double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
1672 QCPItemPosition *createPosition(const QString &name);
1673 QCPItemAnchor *createAnchor(const QString &name, int anchorId);
1676 Q_DISABLE_COPY(QCPAbstractItem)
1678 friend class QCustomPlot;
1679 friend class QCPItemAnchor;
1683 class QCP_LIB_DECL QCustomPlot : public QWidget
1686 /// \cond INCLUDE_QPROPERTIES
1687 Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
1688 Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1689 Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1690 Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1691 Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
1692 Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
1693 Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
1694 Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
1695 Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
1699 Defines how a layer should be inserted relative to an other layer.
1701 \see addLayer, moveLayer
1703 enum LayerInsertMode { limBelow ///< Layer is inserted below other layer
1704 ,limAbove ///< Layer is inserted above other layer
1706 Q_ENUMS(LayerInsertMode)
1709 Defines with what timing the QCustomPlot surface is refreshed after a replot.
1713 enum RefreshPriority { rpImmediate ///< The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot
1714 ,rpQueued ///< Queues the refresh such that it is performed at a slightly delayed point in time after the replot, by calling QWidget::update() after the replot
1715 ,rpHint ///< Whether to use immediate repaint or queued update depends on whether the plotting hint \ref QCP::phForceRepaint is set, see \ref setPlottingHints.
1718 explicit QCustomPlot(QWidget *parent = 0);
1719 virtual ~QCustomPlot();
1722 QRect viewport() const { return mViewport; }
1723 QPixmap background() const { return mBackgroundPixmap; }
1724 bool backgroundScaled() const { return mBackgroundScaled; }
1725 Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1726 QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
1727 QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
1728 QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
1729 bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
1730 const QCP::Interactions interactions() const { return mInteractions; }
1731 int selectionTolerance() const { return mSelectionTolerance; }
1732 bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
1733 QCP::PlottingHints plottingHints() const { return mPlottingHints; }
1734 Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
1737 void setViewport(const QRect &rect);
1738 void setBackground(const QPixmap &pm);
1739 void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
1740 void setBackground(const QBrush &brush);
1741 void setBackgroundScaled(bool scaled);
1742 void setBackgroundScaledMode(Qt::AspectRatioMode mode);
1743 void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
1744 void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
1745 void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements);
1746 void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
1747 void setAutoAddPlottableToLegend(bool on);
1748 void setInteractions(const QCP::Interactions &interactions);
1749 void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
1750 void setSelectionTolerance(int pixels);
1751 void setNoAntialiasingOnDrag(bool enabled);
1752 void setPlottingHints(const QCP::PlottingHints &hints);
1753 void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
1754 void setMultiSelectModifier(Qt::KeyboardModifier modifier);
1756 // non-property methods:
1757 // plottable interface:
1758 QCPAbstractPlottable *plottable(int index);
1759 QCPAbstractPlottable *plottable();
1760 bool addPlottable(QCPAbstractPlottable *plottable);
1761 bool removePlottable(QCPAbstractPlottable *plottable);
1762 bool removePlottable(int index);
1763 int clearPlottables();
1764 int plottableCount() const;
1765 QList<QCPAbstractPlottable*> selectedPlottables() const;
1766 QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
1767 bool hasPlottable(QCPAbstractPlottable *plottable) const;
1769 // specialized interface for QCPGraph:
1770 QCPGraph *graph(int index) const;
1771 QCPGraph *graph() const;
1772 QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
1773 bool removeGraph(QCPGraph *graph);
1774 bool removeGraph(int index);
1776 int graphCount() const;
1777 QList<QCPGraph*> selectedGraphs() const;
1780 QCPAbstractItem *item(int index) const;
1781 QCPAbstractItem *item() const;
1782 bool addItem(QCPAbstractItem* item);
1783 bool removeItem(QCPAbstractItem *item);
1784 bool removeItem(int index);
1786 int itemCount() const;
1787 QList<QCPAbstractItem*> selectedItems() const;
1788 QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
1789 bool hasItem(QCPAbstractItem *item) const;
1792 QCPLayer *layer(const QString &name) const;
1793 QCPLayer *layer(int index) const;
1794 QCPLayer *currentLayer() const;
1795 bool setCurrentLayer(const QString &name);
1796 bool setCurrentLayer(QCPLayer *layer);
1797 int layerCount() const;
1798 bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
1799 bool removeLayer(QCPLayer *layer);
1800 bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
1802 // axis rect/layout interface:
1803 int axisRectCount() const;
1804 QCPAxisRect* axisRect(int index=0) const;
1805 QList<QCPAxisRect*> axisRects() const;
1806 QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
1807 Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
1809 QList<QCPAxis*> selectedAxes() const;
1810 QList<QCPLegend*> selectedLegends() const;
1811 Q_SLOT void deselectAll();
1813 bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0, const QString &pdfCreator=QString(), const QString &pdfTitle=QString());
1814 bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1815 bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1816 bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
1817 bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
1818 QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
1819 void toPainter(QCPPainter *painter, int width=0, int height=0);
1820 Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpHint);
1822 QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
1826 void mouseDoubleClick(QMouseEvent *event);
1827 void mousePress(QMouseEvent *event);
1828 void mouseMove(QMouseEvent *event);
1829 void mouseRelease(QMouseEvent *event);
1830 void mouseWheel(QWheelEvent *event);
1832 void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1833 void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1834 void itemClick(QCPAbstractItem *item, QMouseEvent *event);
1835 void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
1836 void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1837 void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1838 void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1839 void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1840 void titleClick(QMouseEvent *event, QCPPlotTitle *title);
1841 void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
1843 void selectionChangedByUser();
1844 void beforeReplot();
1848 // property members:
1850 QCPLayoutGrid *mPlotLayout;
1851 bool mAutoAddPlottableToLegend;
1852 QList<QCPAbstractPlottable*> mPlottables;
1853 QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
1854 QList<QCPAbstractItem*> mItems;
1855 QList<QCPLayer*> mLayers;
1856 QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
1857 QCP::Interactions mInteractions;
1858 int mSelectionTolerance;
1859 bool mNoAntialiasingOnDrag;
1860 QBrush mBackgroundBrush;
1861 QPixmap mBackgroundPixmap;
1862 QPixmap mScaledBackgroundPixmap;
1863 bool mBackgroundScaled;
1864 Qt::AspectRatioMode mBackgroundScaledMode;
1865 QCPLayer *mCurrentLayer;
1866 QCP::PlottingHints mPlottingHints;
1867 Qt::KeyboardModifier mMultiSelectModifier;
1869 // non-property members:
1870 QPixmap mPaintBuffer;
1871 QPoint mMousePressPos;
1872 QPointer<QCPLayoutElement> mMouseEventElement;
1875 // reimplemented virtual methods:
1876 virtual QSize minimumSizeHint() const;
1877 virtual QSize sizeHint() const;
1878 virtual void paintEvent(QPaintEvent *event);
1879 virtual void resizeEvent(QResizeEvent *event);
1880 virtual void mouseDoubleClickEvent(QMouseEvent *event);
1881 virtual void mousePressEvent(QMouseEvent *event);
1882 virtual void mouseMoveEvent(QMouseEvent *event);
1883 virtual void mouseReleaseEvent(QMouseEvent *event);
1884 virtual void wheelEvent(QWheelEvent *event);
1886 // introduced virtual methods:
1887 virtual void draw(QCPPainter *painter);
1888 virtual void axisRemoved(QCPAxis *axis);
1889 virtual void legendRemoved(QCPLegend *legend);
1891 // non-virtual methods:
1892 void updateLayerIndices() const;
1893 QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const;
1894 void drawBackground(QCPPainter *painter);
1896 friend class QCPLegend;
1897 friend class QCPAxis;
1898 friend class QCPLayer;
1899 friend class QCPAxisRect;
1903 class QCP_LIB_DECL QCPColorGradient
1908 Defines the color spaces in which color interpolation between gradient stops can be performed.
1910 \see setColorInterpolation
1912 enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated
1913 ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)
1915 Q_ENUMS(ColorInterpolation)
1918 Defines the available presets that can be loaded with \ref loadPreset. See the documentation
1919 there for an image of the presets.
1921 enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation)
1922 ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation)
1923 ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation)
1924 ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)
1925 ,gpCandy ///< Blue over pink to white
1926 ,gpGeography ///< Colors suitable to represent different elevations on geographical maps
1927 ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)
1928 ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white
1929 ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values
1930 ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)
1931 ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)
1932 ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic)
1934 Q_ENUMS(GradientPreset)
1936 QCPColorGradient(GradientPreset preset=gpCold);
1937 bool operator==(const QCPColorGradient &other) const;
1938 bool operator!=(const QCPColorGradient &other) const { return !(*this == other); }
1941 int levelCount() const { return mLevelCount; }
1942 QMap<double, QColor> colorStops() const { return mColorStops; }
1943 ColorInterpolation colorInterpolation() const { return mColorInterpolation; }
1944 bool periodic() const { return mPeriodic; }
1947 void setLevelCount(int n);
1948 void setColorStops(const QMap<double, QColor> &colorStops);
1949 void setColorStopAt(double position, const QColor &color);
1950 void setColorInterpolation(ColorInterpolation interpolation);
1951 void setPeriodic(bool enabled);
1953 // non-property methods:
1954 void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
1955 QRgb color(double position, const QCPRange &range, bool logarithmic=false);
1956 void loadPreset(GradientPreset preset);
1957 void clearColorStops();
1958 QCPColorGradient inverted() const;
1961 void updateColorBuffer();
1963 // property members:
1965 QMap<double, QColor> mColorStops;
1966 ColorInterpolation mColorInterpolation;
1969 // non-property members:
1970 QVector<QRgb> mColorBuffer;
1971 bool mColorBufferInvalidated;
1975 class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
1978 /// \cond INCLUDE_QPROPERTIES
1979 Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1980 Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1981 Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1982 Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
1983 Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
1986 explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
1987 virtual ~QCPAxisRect();
1990 QPixmap background() const { return mBackgroundPixmap; }
1991 bool backgroundScaled() const { return mBackgroundScaled; }
1992 Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1993 Qt::Orientations rangeDrag() const { return mRangeDrag; }
1994 Qt::Orientations rangeZoom() const { return mRangeZoom; }
1995 QCPAxis *rangeDragAxis(Qt::Orientation orientation);
1996 QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
1997 double rangeZoomFactor(Qt::Orientation orientation);
2000 void setBackground(const QPixmap &pm);
2001 void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
2002 void setBackground(const QBrush &brush);
2003 void setBackgroundScaled(bool scaled);
2004 void setBackgroundScaledMode(Qt::AspectRatioMode mode);
2005 void setRangeDrag(Qt::Orientations orientations);
2006 void setRangeZoom(Qt::Orientations orientations);
2007 void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
2008 void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
2009 void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
2010 void setRangeZoomFactor(double factor);
2012 // non-property methods:
2013 int axisCount(QCPAxis::AxisType type) const;
2014 QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
2015 QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
2016 QList<QCPAxis*> axes() const;
2017 QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0);
2018 QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
2019 bool removeAxis(QCPAxis *axis);
2020 QCPLayoutInset *insetLayout() const { return mInsetLayout; }
2022 void setupFullAxesBox(bool connectRanges=false);
2023 QList<QCPAbstractPlottable*> plottables() const;
2024 QList<QCPGraph*> graphs() const;
2025 QList<QCPAbstractItem*> items() const;
2027 // read-only interface imitating a QRect:
2028 int left() const { return mRect.left(); }
2029 int right() const { return mRect.right(); }
2030 int top() const { return mRect.top(); }
2031 int bottom() const { return mRect.bottom(); }
2032 int width() const { return mRect.width(); }
2033 int height() const { return mRect.height(); }
2034 QSize size() const { return mRect.size(); }
2035 QPoint topLeft() const { return mRect.topLeft(); }
2036 QPoint topRight() const { return mRect.topRight(); }
2037 QPoint bottomLeft() const { return mRect.bottomLeft(); }
2038 QPoint bottomRight() const { return mRect.bottomRight(); }
2039 QPoint center() const { return mRect.center(); }
2041 // reimplemented virtual methods:
2042 virtual void update(UpdatePhase phase);
2043 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
2046 // property members:
2047 QBrush mBackgroundBrush;
2048 QPixmap mBackgroundPixmap;
2049 QPixmap mScaledBackgroundPixmap;
2050 bool mBackgroundScaled;
2051 Qt::AspectRatioMode mBackgroundScaledMode;
2052 QCPLayoutInset *mInsetLayout;
2053 Qt::Orientations mRangeDrag, mRangeZoom;
2054 QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
2055 double mRangeZoomFactorHorz, mRangeZoomFactorVert;
2056 // non-property members:
2057 QCPRange mDragStartHorzRange, mDragStartVertRange;
2058 QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
2061 QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
2063 // reimplemented virtual methods:
2064 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2065 virtual void draw(QCPPainter *painter);
2066 virtual int calculateAutoMargin(QCP::MarginSide side);
2068 virtual void mousePressEvent(QMouseEvent *event);
2069 virtual void mouseMoveEvent(QMouseEvent *event);
2070 virtual void mouseReleaseEvent(QMouseEvent *event);
2071 virtual void wheelEvent(QWheelEvent *event);
2073 // non-property methods:
2074 void drawBackground(QCPPainter *painter);
2075 void updateAxesOffset(QCPAxis::AxisType type);
2078 Q_DISABLE_COPY(QCPAxisRect)
2080 friend class QCustomPlot;
2084 class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
2087 /// \cond INCLUDE_QPROPERTIES
2088 Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
2089 Q_PROPERTY(QFont font READ font WRITE setFont)
2090 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2091 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2092 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2093 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged)
2094 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged)
2097 explicit QCPAbstractLegendItem(QCPLegend *parent);
2100 QCPLegend *parentLegend() const { return mParentLegend; }
2101 QFont font() const { return mFont; }
2102 QColor textColor() const { return mTextColor; }
2103 QFont selectedFont() const { return mSelectedFont; }
2104 QColor selectedTextColor() const { return mSelectedTextColor; }
2105 bool selectable() const { return mSelectable; }
2106 bool selected() const { return mSelected; }
2109 void setFont(const QFont &font);
2110 void setTextColor(const QColor &color);
2111 void setSelectedFont(const QFont &font);
2112 void setSelectedTextColor(const QColor &color);
2113 Q_SLOT void setSelectable(bool selectable);
2114 Q_SLOT void setSelected(bool selected);
2116 // reimplemented virtual methods:
2117 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2120 void selectionChanged(bool selected);
2121 void selectableChanged(bool selectable);
2124 // property members:
2125 QCPLegend *mParentLegend;
2128 QFont mSelectedFont;
2129 QColor mSelectedTextColor;
2130 bool mSelectable, mSelected;
2132 // reimplemented virtual methods:
2133 virtual QCP::Interaction selectionCategory() const;
2134 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2135 virtual QRect clipRect() const;
2136 virtual void draw(QCPPainter *painter) = 0;
2138 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2139 virtual void deselectEvent(bool *selectionStateChanged);
2142 Q_DISABLE_COPY(QCPAbstractLegendItem)
2144 friend class QCPLegend;
2148 class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
2152 QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
2155 QCPAbstractPlottable *plottable() { return mPlottable; }
2158 // property members:
2159 QCPAbstractPlottable *mPlottable;
2161 // reimplemented virtual methods:
2162 virtual void draw(QCPPainter *painter);
2163 virtual QSize minimumSizeHint() const;
2165 // non-virtual methods:
2166 QPen getIconBorderPen() const;
2167 QColor getTextColor() const;
2168 QFont getFont() const;
2172 class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
2175 /// \cond INCLUDE_QPROPERTIES
2176 Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
2177 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2178 Q_PROPERTY(QFont font READ font WRITE setFont)
2179 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2180 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
2181 Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
2182 Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
2183 Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged)
2184 Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged)
2185 Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
2186 Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
2187 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2188 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2189 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2193 Defines the selectable parts of a legend
2195 \see setSelectedParts, setSelectableParts
2197 enum SelectablePart { spNone = 0x000 ///< <tt>0x000</tt> None
2198 ,spLegendBox = 0x001 ///< <tt>0x001</tt> The legend box (frame)
2199 ,spItems = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems)
2201 Q_FLAGS(SelectablePart SelectableParts)
2202 Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
2204 explicit QCPLegend();
2205 virtual ~QCPLegend();
2208 QPen borderPen() const { return mBorderPen; }
2209 QBrush brush() const { return mBrush; }
2210 QFont font() const { return mFont; }
2211 QColor textColor() const { return mTextColor; }
2212 QSize iconSize() const { return mIconSize; }
2213 int iconTextPadding() const { return mIconTextPadding; }
2214 QPen iconBorderPen() const { return mIconBorderPen; }
2215 SelectableParts selectableParts() const { return mSelectableParts; }
2216 SelectableParts selectedParts() const;
2217 QPen selectedBorderPen() const { return mSelectedBorderPen; }
2218 QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
2219 QBrush selectedBrush() const { return mSelectedBrush; }
2220 QFont selectedFont() const { return mSelectedFont; }
2221 QColor selectedTextColor() const { return mSelectedTextColor; }
2224 void setBorderPen(const QPen &pen);
2225 void setBrush(const QBrush &brush);
2226 void setFont(const QFont &font);
2227 void setTextColor(const QColor &color);
2228 void setIconSize(const QSize &size);
2229 void setIconSize(int width, int height);
2230 void setIconTextPadding(int padding);
2231 void setIconBorderPen(const QPen &pen);
2232 Q_SLOT void setSelectableParts(const SelectableParts &selectableParts);
2233 Q_SLOT void setSelectedParts(const SelectableParts &selectedParts);
2234 void setSelectedBorderPen(const QPen &pen);
2235 void setSelectedIconBorderPen(const QPen &pen);
2236 void setSelectedBrush(const QBrush &brush);
2237 void setSelectedFont(const QFont &font);
2238 void setSelectedTextColor(const QColor &color);
2240 // reimplemented virtual methods:
2241 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2243 // non-virtual methods:
2244 QCPAbstractLegendItem *item(int index) const;
2245 QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
2246 int itemCount() const;
2247 bool hasItem(QCPAbstractLegendItem *item) const;
2248 bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
2249 bool addItem(QCPAbstractLegendItem *item);
2250 bool removeItem(int index);
2251 bool removeItem(QCPAbstractLegendItem *item);
2253 QList<QCPAbstractLegendItem*> selectedItems() const;
2256 void selectionChanged(QCPLegend::SelectableParts parts);
2257 void selectableChanged(QCPLegend::SelectableParts parts);
2260 // property members:
2261 QPen mBorderPen, mIconBorderPen;
2266 int mIconTextPadding;
2267 SelectableParts mSelectedParts, mSelectableParts;
2268 QPen mSelectedBorderPen, mSelectedIconBorderPen;
2269 QBrush mSelectedBrush;
2270 QFont mSelectedFont;
2271 QColor mSelectedTextColor;
2273 // reimplemented virtual methods:
2274 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
2275 virtual QCP::Interaction selectionCategory() const;
2276 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2277 virtual void draw(QCPPainter *painter);
2279 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2280 virtual void deselectEvent(bool *selectionStateChanged);
2282 // non-virtual methods:
2283 QPen getBorderPen() const;
2284 QBrush getBrush() const;
2287 Q_DISABLE_COPY(QCPLegend)
2289 friend class QCustomPlot;
2290 friend class QCPAbstractLegendItem;
2292 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
2293 Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
2296 class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
2299 /// \cond INCLUDE_QPROPERTIES
2300 Q_PROPERTY(QString text READ text WRITE setText)
2301 Q_PROPERTY(QFont font READ font WRITE setFont)
2302 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2303 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2304 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2305 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
2306 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
2309 explicit QCPPlotTitle(QCustomPlot *parentPlot);
2310 explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text);
2313 QString text() const { return mText; }
2314 QFont font() const { return mFont; }
2315 QColor textColor() const { return mTextColor; }
2316 QFont selectedFont() const { return mSelectedFont; }
2317 QColor selectedTextColor() const { return mSelectedTextColor; }
2318 bool selectable() const { return mSelectable; }
2319 bool selected() const { return mSelected; }
2322 void setText(const QString &text);
2323 void setFont(const QFont &font);
2324 void setTextColor(const QColor &color);
2325 void setSelectedFont(const QFont &font);
2326 void setSelectedTextColor(const QColor &color);
2327 Q_SLOT void setSelectable(bool selectable);
2328 Q_SLOT void setSelected(bool selected);
2330 // reimplemented virtual methods:
2331 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2334 void selectionChanged(bool selected);
2335 void selectableChanged(bool selectable);
2338 // property members:
2342 QFont mSelectedFont;
2343 QColor mSelectedTextColor;
2344 QRect mTextBoundingRect;
2345 bool mSelectable, mSelected;
2347 // reimplemented virtual methods:
2348 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2349 virtual void draw(QCPPainter *painter);
2350 virtual QSize minimumSizeHint() const;
2351 virtual QSize maximumSizeHint() const;
2353 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2354 virtual void deselectEvent(bool *selectionStateChanged);
2356 // non-virtual methods:
2357 QFont mainFont() const;
2358 QColor mainTextColor() const;
2361 Q_DISABLE_COPY(QCPPlotTitle)
2365 class QCPColorScaleAxisRectPrivate : public QCPAxisRect
2369 explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale);
2371 QCPColorScale *mParentColorScale;
2372 QImage mGradientImage;
2373 bool mGradientImageInvalidated;
2374 // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
2375 using QCPAxisRect::calculateAutoMargin;
2376 using QCPAxisRect::mousePressEvent;
2377 using QCPAxisRect::mouseMoveEvent;
2378 using QCPAxisRect::mouseReleaseEvent;
2379 using QCPAxisRect::wheelEvent;
2380 using QCPAxisRect::update;
2381 virtual void draw(QCPPainter *painter);
2382 void updateGradientImage();
2383 Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
2384 Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
2385 friend class QCPColorScale;
2389 class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
2392 /// \cond INCLUDE_QPROPERTIES
2393 Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
2394 Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
2395 Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
2396 Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
2397 Q_PROPERTY(QString label READ label WRITE setLabel)
2398 Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
2399 Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
2400 Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
2403 explicit QCPColorScale(QCustomPlot *parentPlot);
2404 virtual ~QCPColorScale();
2407 QCPAxis *axis() const { return mColorAxis.data(); }
2408 QCPAxis::AxisType type() const { return mType; }
2409 QCPRange dataRange() const { return mDataRange; }
2410 QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
2411 QCPColorGradient gradient() const { return mGradient; }
2412 QString label() const;
2413 int barWidth () const { return mBarWidth; }
2414 bool rangeDrag() const;
2415 bool rangeZoom() const;
2418 void setType(QCPAxis::AxisType type);
2419 Q_SLOT void setDataRange(const QCPRange &dataRange);
2420 Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
2421 Q_SLOT void setGradient(const QCPColorGradient &gradient);
2422 void setLabel(const QString &str);
2423 void setBarWidth(int width);
2424 void setRangeDrag(bool enabled);
2425 void setRangeZoom(bool enabled);
2427 // non-property methods:
2428 QList<QCPColorMap*> colorMaps() const;
2429 void rescaleDataRange(bool onlyVisibleMaps);
2431 // reimplemented virtual methods:
2432 virtual void update(UpdatePhase phase);
2435 void dataRangeChanged(QCPRange newRange);
2436 void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
2437 void gradientChanged(QCPColorGradient newGradient);
2440 // property members:
2441 QCPAxis::AxisType mType;
2442 QCPRange mDataRange;
2443 QCPAxis::ScaleType mDataScaleType;
2444 QCPColorGradient mGradient;
2447 // non-property members:
2448 QPointer<QCPColorScaleAxisRectPrivate> mAxisRect;
2449 QPointer<QCPAxis> mColorAxis;
2451 // reimplemented virtual methods:
2452 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2454 virtual void mousePressEvent(QMouseEvent *event);
2455 virtual void mouseMoveEvent(QMouseEvent *event);
2456 virtual void mouseReleaseEvent(QMouseEvent *event);
2457 virtual void wheelEvent(QWheelEvent *event);
2460 Q_DISABLE_COPY(QCPColorScale)
2462 friend class QCPColorScaleAxisRectPrivate;
2470 class QCP_LIB_DECL QCPData
2474 QCPData(double key, double value);
2476 double keyErrorPlus, keyErrorMinus;
2477 double valueErrorPlus, valueErrorMinus;
2479 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
2481 /*! \typedef QCPDataMap
2482 Container for storing \ref QCPData items in a sorted fashion. The key of the map
2483 is the key member of the QCPData instance.
2485 This is the container in which QCPGraph holds its data.
2486 \see QCPData, QCPGraph::setData
2488 typedef QMap<double, QCPData> QCPDataMap;
2489 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
2490 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
2493 class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
2496 /// \cond INCLUDE_QPROPERTIES
2497 Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2498 Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2499 Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
2500 Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
2501 Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
2502 Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
2503 Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
2504 Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling)
2508 Defines how the graph's line is represented visually in the plot. The line is drawn with the
2509 current pen of the graph (\ref setPen).
2512 enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented
2513 ///< with symbols according to the scatter style, see \ref setScatterStyle)
2514 ,lsLine ///< data points are connected by a straight line
2515 ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point
2516 ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point
2517 ,lsStepCenter ///< line is drawn as steps where the step is in between two data points
2518 ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line
2522 Defines what kind of error bars are drawn for each data point
2524 enum ErrorType { etNone ///< No error bars are shown
2525 ,etKey ///< Error bars for the key dimension of the data point are shown
2526 ,etValue ///< Error bars for the value dimension of the data point are shown
2527 ,etBoth ///< Error bars for both key and value dimensions of the data point are shown
2531 explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
2532 virtual ~QCPGraph();
2535 QCPDataMap *data() const { return mData; }
2536 LineStyle lineStyle() const { return mLineStyle; }
2537 QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2538 ErrorType errorType() const { return mErrorType; }
2539 QPen errorPen() const { return mErrorPen; }
2540 double errorBarSize() const { return mErrorBarSize; }
2541 bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
2542 QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
2543 bool adaptiveSampling() const { return mAdaptiveSampling; }
2546 void setData(QCPDataMap *data, bool copy=false);
2547 void setData(const QVector<double> &key, const QVector<double> &value);
2548 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
2549 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
2550 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
2551 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
2552 void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
2553 void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
2554 void setLineStyle(LineStyle ls);
2555 void setScatterStyle(const QCPScatterStyle &style);
2556 void setErrorType(ErrorType errorType);
2557 void setErrorPen(const QPen &pen);
2558 void setErrorBarSize(double size);
2559 void setErrorBarSkipSymbol(bool enabled);
2560 void setChannelFillGraph(QCPGraph *targetGraph);
2561 void setAdaptiveSampling(bool enabled);
2563 // non-property methods:
2564 void addData(const QCPDataMap &dataMap);
2565 void addData(const QCPData &data);
2566 void addData(double key, double value);
2567 void addData(const QVector<double> &keys, const QVector<double> &values);
2568 void removeDataBefore(double key);
2569 void removeDataAfter(double key);
2570 void removeData(double fromKey, double toKey);
2571 void removeData(double key);
2573 // reimplemented virtual methods:
2574 virtual void clearData();
2575 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2576 using QCPAbstractPlottable::rescaleAxes;
2577 using QCPAbstractPlottable::rescaleKeyAxis;
2578 using QCPAbstractPlottable::rescaleValueAxis;
2579 void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2580 void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2581 void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2584 // property members:
2587 LineStyle mLineStyle;
2588 QCPScatterStyle mScatterStyle;
2589 ErrorType mErrorType;
2590 double mErrorBarSize;
2591 bool mErrorBarSkipSymbol;
2592 QPointer<QCPGraph> mChannelFillGraph;
2593 bool mAdaptiveSampling;
2595 // reimplemented virtual methods:
2596 virtual void draw(QCPPainter *painter);
2597 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2598 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2599 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2600 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2601 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2603 // introduced virtual methods:
2604 virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
2605 virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *scatterData) const;
2606 virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
2607 virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
2609 // non-virtual methods:
2610 void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const;
2611 void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const;
2612 void getScatterPlotData(QVector<QCPData> *scatterData) const;
2613 void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2614 void getStepLeftPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2615 void getStepRightPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2616 void getStepCenterPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2617 void getImpulsePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2618 void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
2619 void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper) const;
2620 int countDataInBounds(const QCPDataMap::const_iterator &lower, const QCPDataMap::const_iterator &upper, int maxCount) const;
2621 void addFillBasePoints(QVector<QPointF> *lineData) const;
2622 void removeFillBasePoints(QVector<QPointF> *lineData) const;
2623 QPointF lowerFillBasePoint(double lowerKey) const;
2624 QPointF upperFillBasePoint(double upperKey) const;
2625 const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
2626 int findIndexBelowX(const QVector<QPointF> *data, double x) const;
2627 int findIndexAboveX(const QVector<QPointF> *data, double x) const;
2628 int findIndexBelowY(const QVector<QPointF> *data, double y) const;
2629 int findIndexAboveY(const QVector<QPointF> *data, double y) const;
2630 double pointDistance(const QPointF &pixelPoint) const;
2632 friend class QCustomPlot;
2633 friend class QCPLegend;
2641 class QCP_LIB_DECL QCPCurveData
2645 QCPCurveData(double t, double key, double value);
2646 double t, key, value;
2648 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
2650 /*! \typedef QCPCurveDataMap
2651 Container for storing \ref QCPCurveData items in a sorted fashion. The key of the map
2652 is the t member of the QCPCurveData instance.
2654 This is the container in which QCPCurve holds its data.
2655 \see QCPCurveData, QCPCurve::setData
2658 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
2659 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
2660 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
2663 class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
2666 /// \cond INCLUDE_QPROPERTIES
2667 Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2668 Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2672 Defines how the curve's line is represented visually in the plot. The line is drawn with the
2673 current pen of the curve (\ref setPen).
2676 enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters)
2677 ,lsLine ///< Data points are connected with a straight line
2679 explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
2680 virtual ~QCPCurve();
2683 QCPCurveDataMap *data() const { return mData; }
2684 QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2685 LineStyle lineStyle() const { return mLineStyle; }
2688 void setData(QCPCurveDataMap *data, bool copy=false);
2689 void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
2690 void setData(const QVector<double> &key, const QVector<double> &value);
2691 void setScatterStyle(const QCPScatterStyle &style);
2692 void setLineStyle(LineStyle style);
2694 // non-property methods:
2695 void addData(const QCPCurveDataMap &dataMap);
2696 void addData(const QCPCurveData &data);
2697 void addData(double t, double key, double value);
2698 void addData(double key, double value);
2699 void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
2700 void removeDataBefore(double t);
2701 void removeDataAfter(double t);
2702 void removeData(double fromt, double tot);
2703 void removeData(double t);
2705 // reimplemented virtual methods:
2706 virtual void clearData();
2707 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2710 // property members:
2711 QCPCurveDataMap *mData;
2712 QCPScatterStyle mScatterStyle;
2713 LineStyle mLineStyle;
2715 // reimplemented virtual methods:
2716 virtual void draw(QCPPainter *painter);
2717 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2718 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2719 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2721 // introduced virtual methods:
2722 virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
2724 // non-virtual methods:
2725 void getCurveData(QVector<QPointF> *lineData) const;
2726 int getRegion(double x, double y, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2727 QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2728 QVector<QPointF> getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2729 bool mayTraverse(int prevRegion, int currentRegion) const;
2730 bool getTraverse(double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom, QPointF &crossA, QPointF &crossB) const;
2731 void getTraverseCornerPoints(int prevRegion, int currentRegion, double rectLeft, double rectTop, double rectRight, double rectBottom, QVector<QPointF> &beforeTraverse, QVector<QPointF> &afterTraverse) const;
2732 double pointDistance(const QPointF &pixelPoint) const;
2734 friend class QCustomPlot;
2735 friend class QCPLegend;
2743 class QCP_LIB_DECL QCPBarsGroup : public QObject
2746 /// \cond INCLUDE_QPROPERTIES
2747 Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType)
2748 Q_PROPERTY(double spacing READ spacing WRITE setSpacing)
2752 Defines the ways the spacing between bars in the group can be specified. Thus it defines what
2753 the number passed to \ref setSpacing actually means.
2755 \see setSpacingType, setSpacing
2757 enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels
2758 ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size
2759 ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range
2761 QCPBarsGroup(QCustomPlot *parentPlot);
2765 SpacingType spacingType() const { return mSpacingType; }
2766 double spacing() const { return mSpacing; }
2769 void setSpacingType(SpacingType spacingType);
2770 void setSpacing(double spacing);
2772 // non-virtual methods:
2773 QList<QCPBars*> bars() const { return mBars; }
2774 QCPBars* bars(int index) const;
2775 int size() const { return mBars.size(); }
2776 bool isEmpty() const { return mBars.isEmpty(); }
2778 bool contains(QCPBars *bars) const { return mBars.contains(bars); }
2779 void append(QCPBars *bars);
2780 void insert(int i, QCPBars *bars);
2781 void remove(QCPBars *bars);
2784 // non-property members:
2785 QCustomPlot *mParentPlot;
2786 SpacingType mSpacingType;
2788 QList<QCPBars*> mBars;
2790 // non-virtual methods:
2791 void registerBars(QCPBars *bars);
2792 void unregisterBars(QCPBars *bars);
2795 double keyPixelOffset(const QCPBars *bars, double keyCoord);
2796 double getPixelSpacing(const QCPBars *bars, double keyCoord);
2799 Q_DISABLE_COPY(QCPBarsGroup)
2801 friend class QCPBars;
2805 class QCP_LIB_DECL QCPBarData
2809 QCPBarData(double key, double value);
2812 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
2814 /*! \typedef QCPBarDataMap
2815 Container for storing \ref QCPBarData items in a sorted fashion. The key of the map
2816 is the key member of the QCPBarData instance.
2818 This is the container in which QCPBars holds its data.
2819 \see QCPBarData, QCPBars::setData
2821 typedef QMap<double, QCPBarData> QCPBarDataMap;
2822 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
2823 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
2826 class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
2829 /// \cond INCLUDE_QPROPERTIES
2830 Q_PROPERTY(double width READ width WRITE setWidth)
2831 Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType)
2832 Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup)
2833 Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue)
2834 Q_PROPERTY(QCPBars* barBelow READ barBelow)
2835 Q_PROPERTY(QCPBars* barAbove READ barAbove)
2839 Defines the ways the width of the bar can be specified. Thus it defines what the number passed
2840 to \ref setWidth actually means.
2842 \see setWidthType, setWidth
2844 enum WidthType { wtAbsolute ///< Bar width is in absolute pixels
2845 ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size
2846 ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range
2850 explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
2854 double width() const { return mWidth; }
2855 WidthType widthType() const { return mWidthType; }
2856 QCPBarsGroup *barsGroup() const { return mBarsGroup; }
2857 double baseValue() const { return mBaseValue; }
2858 QCPBars *barBelow() const { return mBarBelow.data(); }
2859 QCPBars *barAbove() const { return mBarAbove.data(); }
2860 QCPBarDataMap *data() const { return mData; }
2863 void setWidth(double width);
2864 void setWidthType(WidthType widthType);
2865 void setBarsGroup(QCPBarsGroup *barsGroup);
2866 void setBaseValue(double baseValue);
2867 void setData(QCPBarDataMap *data, bool copy=false);
2868 void setData(const QVector<double> &key, const QVector<double> &value);
2870 // non-property methods:
2871 void moveBelow(QCPBars *bars);
2872 void moveAbove(QCPBars *bars);
2873 void addData(const QCPBarDataMap &dataMap);
2874 void addData(const QCPBarData &data);
2875 void addData(double key, double value);
2876 void addData(const QVector<double> &keys, const QVector<double> &values);
2877 void removeDataBefore(double key);
2878 void removeDataAfter(double key);
2879 void removeData(double fromKey, double toKey);
2880 void removeData(double key);
2882 // reimplemented virtual methods:
2883 virtual void clearData();
2884 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2887 // property members:
2888 QCPBarDataMap *mData;
2890 WidthType mWidthType;
2891 QCPBarsGroup *mBarsGroup;
2893 QPointer<QCPBars> mBarBelow, mBarAbove;
2895 // reimplemented virtual methods:
2896 virtual void draw(QCPPainter *painter);
2897 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2898 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2899 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2901 // non-virtual methods:
2902 void getVisibleDataBounds(QCPBarDataMap::const_iterator &lower, QCPBarDataMap::const_iterator &upperEnd) const;
2903 QPolygonF getBarPolygon(double key, double value) const;
2904 void getPixelWidth(double key, double &lower, double &upper) const;
2905 double getStackedBaseValue(double key, bool positive) const;
2906 static void connectBars(QCPBars* lower, QCPBars* upper);
2908 friend class QCustomPlot;
2909 friend class QCPLegend;
2910 friend class QCPBarsGroup;
2918 class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
2921 /// \cond INCLUDE_QPROPERTIES
2922 Q_PROPERTY(double key READ key WRITE setKey)
2923 Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
2924 Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
2925 Q_PROPERTY(double median READ median WRITE setMedian)
2926 Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
2927 Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
2928 Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers)
2929 Q_PROPERTY(double width READ width WRITE setWidth)
2930 Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
2931 Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
2932 Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
2933 Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
2934 Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
2937 explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
2940 double key() const { return mKey; }
2941 double minimum() const { return mMinimum; }
2942 double lowerQuartile() const { return mLowerQuartile; }
2943 double median() const { return mMedian; }
2944 double upperQuartile() const { return mUpperQuartile; }
2945 double maximum() const { return mMaximum; }
2946 QVector<double> outliers() const { return mOutliers; }
2947 double width() const { return mWidth; }
2948 double whiskerWidth() const { return mWhiskerWidth; }
2949 QPen whiskerPen() const { return mWhiskerPen; }
2950 QPen whiskerBarPen() const { return mWhiskerBarPen; }
2951 QPen medianPen() const { return mMedianPen; }
2952 QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
2955 void setKey(double key);
2956 void setMinimum(double value);
2957 void setLowerQuartile(double value);
2958 void setMedian(double value);
2959 void setUpperQuartile(double value);
2960 void setMaximum(double value);
2961 void setOutliers(const QVector<double> &values);
2962 void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
2963 void setWidth(double width);
2964 void setWhiskerWidth(double width);
2965 void setWhiskerPen(const QPen &pen);
2966 void setWhiskerBarPen(const QPen &pen);
2967 void setMedianPen(const QPen &pen);
2968 void setOutlierStyle(const QCPScatterStyle &style);
2970 // non-property methods:
2971 virtual void clearData();
2972 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2975 // property members:
2976 QVector<double> mOutliers;
2977 double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
2979 double mWhiskerWidth;
2980 QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
2981 QCPScatterStyle mOutlierStyle;
2983 // reimplemented virtual methods:
2984 virtual void draw(QCPPainter *painter);
2985 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2986 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2987 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2989 // introduced virtual methods:
2990 virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
2991 virtual void drawMedian(QCPPainter *painter) const;
2992 virtual void drawWhiskers(QCPPainter *painter) const;
2993 virtual void drawOutliers(QCPPainter *painter) const;
2995 friend class QCustomPlot;
2996 friend class QCPLegend;
3000 class QCP_LIB_DECL QCPColorMapData
3003 QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange);
3005 QCPColorMapData(const QCPColorMapData &other);
3006 QCPColorMapData &operator=(const QCPColorMapData &other);
3009 int keySize() const { return mKeySize; }
3010 int valueSize() const { return mValueSize; }
3011 QCPRange keyRange() const { return mKeyRange; }
3012 QCPRange valueRange() const { return mValueRange; }
3013 QCPRange dataBounds() const { return mDataBounds; }
3014 double data(double key, double value);
3015 double cell(int keyIndex, int valueIndex);
3018 void setSize(int keySize, int valueSize);
3019 void setKeySize(int keySize);
3020 void setValueSize(int valueSize);
3021 void setRange(const QCPRange &keyRange, const QCPRange &valueRange);
3022 void setKeyRange(const QCPRange &keyRange);
3023 void setValueRange(const QCPRange &valueRange);
3024 void setData(double key, double value, double z);
3025 void setCell(int keyIndex, int valueIndex, double z);
3027 // non-property methods:
3028 void recalculateDataBounds();
3030 void fill(double z);
3031 bool isEmpty() const { return mIsEmpty; }
3032 void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const;
3033 void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const;
3036 // property members:
3037 int mKeySize, mValueSize;
3038 QCPRange mKeyRange, mValueRange;
3040 // non-property members:
3042 QCPRange mDataBounds;
3045 friend class QCPColorMap;
3049 class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
3052 /// \cond INCLUDE_QPROPERTIES
3053 Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
3054 Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
3055 Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
3056 Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
3057 Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
3058 Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
3061 explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis);
3062 virtual ~QCPColorMap();
3065 QCPColorMapData *data() const { return mMapData; }
3066 QCPRange dataRange() const { return mDataRange; }
3067 QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
3068 bool interpolate() const { return mInterpolate; }
3069 bool tightBoundary() const { return mTightBoundary; }
3070 QCPColorGradient gradient() const { return mGradient; }
3071 QCPColorScale *colorScale() const { return mColorScale.data(); }
3074 void setData(QCPColorMapData *data, bool copy=false);
3075 Q_SLOT void setDataRange(const QCPRange &dataRange);
3076 Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
3077 Q_SLOT void setGradient(const QCPColorGradient &gradient);
3078 void setInterpolate(bool enabled);
3079 void setTightBoundary(bool enabled);
3080 void setColorScale(QCPColorScale *colorScale);
3082 // non-property methods:
3083 void rescaleDataRange(bool recalculateDataBounds=false);
3084 Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18));
3086 // reimplemented virtual methods:
3087 virtual void clearData();
3088 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3091 void dataRangeChanged(QCPRange newRange);
3092 void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
3093 void gradientChanged(QCPColorGradient newGradient);
3096 // property members:
3097 QCPRange mDataRange;
3098 QCPAxis::ScaleType mDataScaleType;
3099 QCPColorMapData *mMapData;
3100 QCPColorGradient mGradient;
3102 bool mTightBoundary;
3103 QPointer<QCPColorScale> mColorScale;
3104 // non-property members:
3105 QImage mMapImage, mUndersampledMapImage;
3106 QPixmap mLegendIcon;
3107 bool mMapImageInvalidated;
3109 // introduced virtual methods:
3110 virtual void updateMapImage();
3112 // reimplemented virtual methods:
3113 virtual void draw(QCPPainter *painter);
3114 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
3115 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3116 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3118 friend class QCustomPlot;
3119 friend class QCPLegend;
3127 class QCP_LIB_DECL QCPFinancialData
3131 QCPFinancialData(double key, double open, double high, double low, double close);
3132 double key, open, high, low, close;
3134 Q_DECLARE_TYPEINFO(QCPFinancialData, Q_MOVABLE_TYPE);
3136 /*! \typedef QCPFinancialDataMap
3137 Container for storing \ref QCPFinancialData items in a sorted fashion. The key of the map
3138 is the key member of the QCPFinancialData instance.
3140 This is the container in which QCPFinancial holds its data.
3141 \see QCPFinancial, QCPFinancial::setData
3143 typedef QMap<double, QCPFinancialData> QCPFinancialDataMap;
3144 typedef QMapIterator<double, QCPFinancialData> QCPFinancialDataMapIterator;
3145 typedef QMutableMapIterator<double, QCPFinancialData> QCPFinancialDataMutableMapIterator;
3148 class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable
3151 /// \cond INCLUDE_QPROPERTIES
3152 Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle)
3153 Q_PROPERTY(double width READ width WRITE setWidth)
3154 Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored)
3155 Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive)
3156 Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative)
3157 Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive)
3158 Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative)
3162 Defines the possible representations of OHLC data in the plot.
3166 enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation
3167 ,csCandlestick ///< Candlestick representation
3171 explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis);
3172 virtual ~QCPFinancial();
3175 QCPFinancialDataMap *data() const { return mData; }
3176 ChartStyle chartStyle() const { return mChartStyle; }
3177 double width() const { return mWidth; }
3178 bool twoColored() const { return mTwoColored; }
3179 QBrush brushPositive() const { return mBrushPositive; }
3180 QBrush brushNegative() const { return mBrushNegative; }
3181 QPen penPositive() const { return mPenPositive; }
3182 QPen penNegative() const { return mPenNegative; }
3186 void setData(QCPFinancialDataMap *data, bool copy=false);
3187 void setData(const QVector<double> &key, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close);
3188 void setChartStyle(ChartStyle style);
3189 void setWidth(double width);
3190 void setTwoColored(bool twoColored);
3191 void setBrushPositive(const QBrush &brush);
3192 void setBrushNegative(const QBrush &brush);
3193 void setPenPositive(const QPen &pen);
3194 void setPenNegative(const QPen &pen);
3196 // non-property methods:
3197 void addData(const QCPFinancialDataMap &dataMap);
3198 void addData(const QCPFinancialData &data);
3199 void addData(double key, double open, double high, double low, double close);
3200 void addData(const QVector<double> &key, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close);
3201 void removeDataBefore(double key);
3202 void removeDataAfter(double key);
3203 void removeData(double fromKey, double toKey);
3204 void removeData(double key);
3206 // reimplemented virtual methods:
3207 virtual void clearData();
3208 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3211 static QCPFinancialDataMap timeSeriesToOhlc(const QVector<double> &time, const QVector<double> &value, double timeBinSize, double timeBinOffset = 0);
3214 // property members:
3215 QCPFinancialDataMap *mData;
3216 ChartStyle mChartStyle;
3219 QBrush mBrushPositive, mBrushNegative;
3220 QPen mPenPositive, mPenNegative;
3222 // reimplemented virtual methods:
3223 virtual void draw(QCPPainter *painter);
3224 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
3225 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3226 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3228 // non-virtual methods:
3229 void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end);
3230 void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end);
3231 double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end) const;
3232 double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end) const;
3233 void getVisibleDataBounds(QCPFinancialDataMap::const_iterator &lower, QCPFinancialDataMap::const_iterator &upper) const;
3235 friend class QCustomPlot;
3236 friend class QCPLegend;
3240 class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
3243 /// \cond INCLUDE_QPROPERTIES
3244 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3245 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3248 QCPItemStraightLine(QCustomPlot *parentPlot);
3249 virtual ~QCPItemStraightLine();
3252 QPen pen() const { return mPen; }
3253 QPen selectedPen() const { return mSelectedPen; }
3256 void setPen(const QPen &pen);
3257 void setSelectedPen(const QPen &pen);
3259 // reimplemented virtual methods:
3260 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3262 QCPItemPosition * const point1;
3263 QCPItemPosition * const point2;
3266 // property members:
3267 QPen mPen, mSelectedPen;
3269 // reimplemented virtual methods:
3270 virtual void draw(QCPPainter *painter);
3272 // non-virtual methods:
3273 double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
3274 QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
3275 QPen mainPen() const;
3279 class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
3282 /// \cond INCLUDE_QPROPERTIES
3283 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3284 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3285 Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3286 Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3289 QCPItemLine(QCustomPlot *parentPlot);
3290 virtual ~QCPItemLine();
3293 QPen pen() const { return mPen; }
3294 QPen selectedPen() const { return mSelectedPen; }
3295 QCPLineEnding head() const { return mHead; }
3296 QCPLineEnding tail() const { return mTail; }
3299 void setPen(const QPen &pen);
3300 void setSelectedPen(const QPen &pen);
3301 void setHead(const QCPLineEnding &head);
3302 void setTail(const QCPLineEnding &tail);
3304 // reimplemented virtual methods:
3305 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3307 QCPItemPosition * const start;
3308 QCPItemPosition * const end;
3311 // property members:
3312 QPen mPen, mSelectedPen;
3313 QCPLineEnding mHead, mTail;
3315 // reimplemented virtual methods:
3316 virtual void draw(QCPPainter *painter);
3318 // non-virtual methods:
3319 QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
3320 QPen mainPen() const;
3324 class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
3327 /// \cond INCLUDE_QPROPERTIES
3328 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3329 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3330 Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3331 Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3334 QCPItemCurve(QCustomPlot *parentPlot);
3335 virtual ~QCPItemCurve();
3338 QPen pen() const { return mPen; }
3339 QPen selectedPen() const { return mSelectedPen; }
3340 QCPLineEnding head() const { return mHead; }
3341 QCPLineEnding tail() const { return mTail; }
3344 void setPen(const QPen &pen);
3345 void setSelectedPen(const QPen &pen);
3346 void setHead(const QCPLineEnding &head);
3347 void setTail(const QCPLineEnding &tail);
3349 // reimplemented virtual methods:
3350 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3352 QCPItemPosition * const start;
3353 QCPItemPosition * const startDir;
3354 QCPItemPosition * const endDir;
3355 QCPItemPosition * const end;
3358 // property members:
3359 QPen mPen, mSelectedPen;
3360 QCPLineEnding mHead, mTail;
3362 // reimplemented virtual methods:
3363 virtual void draw(QCPPainter *painter);
3365 // non-virtual methods:
3366 QPen mainPen() const;
3370 class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
3373 /// \cond INCLUDE_QPROPERTIES
3374 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3375 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3376 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3377 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3380 QCPItemRect(QCustomPlot *parentPlot);
3381 virtual ~QCPItemRect();
3384 QPen pen() const { return mPen; }
3385 QPen selectedPen() const { return mSelectedPen; }
3386 QBrush brush() const { return mBrush; }
3387 QBrush selectedBrush() const { return mSelectedBrush; }
3390 void setPen(const QPen &pen);
3391 void setSelectedPen(const QPen &pen);
3392 void setBrush(const QBrush &brush);
3393 void setSelectedBrush(const QBrush &brush);
3395 // reimplemented virtual methods:
3396 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3398 QCPItemPosition * const topLeft;
3399 QCPItemPosition * const bottomRight;
3400 QCPItemAnchor * const top;
3401 QCPItemAnchor * const topRight;
3402 QCPItemAnchor * const right;
3403 QCPItemAnchor * const bottom;
3404 QCPItemAnchor * const bottomLeft;
3405 QCPItemAnchor * const left;
3408 enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3410 // property members:
3411 QPen mPen, mSelectedPen;
3412 QBrush mBrush, mSelectedBrush;
3414 // reimplemented virtual methods:
3415 virtual void draw(QCPPainter *painter);
3416 virtual QPointF anchorPixelPoint(int anchorId) const;
3418 // non-virtual methods:
3419 QPen mainPen() const;
3420 QBrush mainBrush() const;
3424 class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
3427 /// \cond INCLUDE_QPROPERTIES
3428 Q_PROPERTY(QColor color READ color WRITE setColor)
3429 Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
3430 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3431 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3432 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3433 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3434 Q_PROPERTY(QFont font READ font WRITE setFont)
3435 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
3436 Q_PROPERTY(QString text READ text WRITE setText)
3437 Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
3438 Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
3439 Q_PROPERTY(double rotation READ rotation WRITE setRotation)
3440 Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
3443 QCPItemText(QCustomPlot *parentPlot);
3444 virtual ~QCPItemText();
3447 QColor color() const { return mColor; }
3448 QColor selectedColor() const { return mSelectedColor; }
3449 QPen pen() const { return mPen; }
3450 QPen selectedPen() const { return mSelectedPen; }
3451 QBrush brush() const { return mBrush; }
3452 QBrush selectedBrush() const { return mSelectedBrush; }
3453 QFont font() const { return mFont; }
3454 QFont selectedFont() const { return mSelectedFont; }
3455 QString text() const { return mText; }
3456 Qt::Alignment positionAlignment() const { return mPositionAlignment; }
3457 Qt::Alignment textAlignment() const { return mTextAlignment; }
3458 double rotation() const { return mRotation; }
3459 QMargins padding() const { return mPadding; }
3462 void setColor(const QColor &color);
3463 void setSelectedColor(const QColor &color);
3464 void setPen(const QPen &pen);
3465 void setSelectedPen(const QPen &pen);
3466 void setBrush(const QBrush &brush);
3467 void setSelectedBrush(const QBrush &brush);
3468 void setFont(const QFont &font);
3469 void setSelectedFont(const QFont &font);
3470 void setText(const QString &text);
3471 void setPositionAlignment(Qt::Alignment alignment);
3472 void setTextAlignment(Qt::Alignment alignment);
3473 void setRotation(double degrees);
3474 void setPadding(const QMargins &padding);
3476 // reimplemented virtual methods:
3477 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3479 QCPItemPosition * const position;
3480 QCPItemAnchor * const topLeft;
3481 QCPItemAnchor * const top;
3482 QCPItemAnchor * const topRight;
3483 QCPItemAnchor * const right;
3484 QCPItemAnchor * const bottomRight;
3485 QCPItemAnchor * const bottom;
3486 QCPItemAnchor * const bottomLeft;
3487 QCPItemAnchor * const left;
3490 enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
3492 // property members:
3493 QColor mColor, mSelectedColor;
3494 QPen mPen, mSelectedPen;
3495 QBrush mBrush, mSelectedBrush;
3496 QFont mFont, mSelectedFont;
3498 Qt::Alignment mPositionAlignment;
3499 Qt::Alignment mTextAlignment;
3503 // reimplemented virtual methods:
3504 virtual void draw(QCPPainter *painter);
3505 virtual QPointF anchorPixelPoint(int anchorId) const;
3507 // non-virtual methods:
3508 QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
3509 QFont mainFont() const;
3510 QColor mainColor() const;
3511 QPen mainPen() const;
3512 QBrush mainBrush() const;
3516 class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
3519 /// \cond INCLUDE_QPROPERTIES
3520 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3521 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3522 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3523 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3526 QCPItemEllipse(QCustomPlot *parentPlot);
3527 virtual ~QCPItemEllipse();
3530 QPen pen() const { return mPen; }
3531 QPen selectedPen() const { return mSelectedPen; }
3532 QBrush brush() const { return mBrush; }
3533 QBrush selectedBrush() const { return mSelectedBrush; }
3536 void setPen(const QPen &pen);
3537 void setSelectedPen(const QPen &pen);
3538 void setBrush(const QBrush &brush);
3539 void setSelectedBrush(const QBrush &brush);
3541 // reimplemented virtual methods:
3542 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3544 QCPItemPosition * const topLeft;
3545 QCPItemPosition * const bottomRight;
3546 QCPItemAnchor * const topLeftRim;
3547 QCPItemAnchor * const top;
3548 QCPItemAnchor * const topRightRim;
3549 QCPItemAnchor * const right;
3550 QCPItemAnchor * const bottomRightRim;
3551 QCPItemAnchor * const bottom;
3552 QCPItemAnchor * const bottomLeftRim;
3553 QCPItemAnchor * const left;
3554 QCPItemAnchor * const center;
3557 enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
3559 // property members:
3560 QPen mPen, mSelectedPen;
3561 QBrush mBrush, mSelectedBrush;
3563 // reimplemented virtual methods:
3564 virtual void draw(QCPPainter *painter);
3565 virtual QPointF anchorPixelPoint(int anchorId) const;
3567 // non-virtual methods:
3568 QPen mainPen() const;
3569 QBrush mainBrush() const;
3573 class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
3576 /// \cond INCLUDE_QPROPERTIES
3577 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
3578 Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
3579 Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
3580 Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode)
3581 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3582 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3585 QCPItemPixmap(QCustomPlot *parentPlot);
3586 virtual ~QCPItemPixmap();
3589 QPixmap pixmap() const { return mPixmap; }
3590 bool scaled() const { return mScaled; }
3591 Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
3592 Qt::TransformationMode transformationMode() const { return mTransformationMode; }
3593 QPen pen() const { return mPen; }
3594 QPen selectedPen() const { return mSelectedPen; }
3597 void setPixmap(const QPixmap &pixmap);
3598 void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation);
3599 void setPen(const QPen &pen);
3600 void setSelectedPen(const QPen &pen);
3602 // reimplemented virtual methods:
3603 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3605 QCPItemPosition * const topLeft;
3606 QCPItemPosition * const bottomRight;
3607 QCPItemAnchor * const top;
3608 QCPItemAnchor * const topRight;
3609 QCPItemAnchor * const right;
3610 QCPItemAnchor * const bottom;
3611 QCPItemAnchor * const bottomLeft;
3612 QCPItemAnchor * const left;
3615 enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3617 // property members:
3619 QPixmap mScaledPixmap;
3621 bool mScaledPixmapInvalidated;
3622 Qt::AspectRatioMode mAspectRatioMode;
3623 Qt::TransformationMode mTransformationMode;
3624 QPen mPen, mSelectedPen;
3626 // reimplemented virtual methods:
3627 virtual void draw(QCPPainter *painter);
3628 virtual QPointF anchorPixelPoint(int anchorId) const;
3630 // non-virtual methods:
3631 void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
3632 QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
3633 QPen mainPen() const;
3637 class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
3640 /// \cond INCLUDE_QPROPERTIES
3641 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3642 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3643 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3644 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3645 Q_PROPERTY(double size READ size WRITE setSize)
3646 Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
3647 Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
3648 Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
3649 Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
3653 The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize.
3657 enum TracerStyle { tsNone ///< The tracer is not visible
3658 ,tsPlus ///< A plus shaped crosshair with limited size
3659 ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect
3660 ,tsCircle ///< A circle
3661 ,tsSquare ///< A square
3663 Q_ENUMS(TracerStyle)
3665 QCPItemTracer(QCustomPlot *parentPlot);
3666 virtual ~QCPItemTracer();
3669 QPen pen() const { return mPen; }
3670 QPen selectedPen() const { return mSelectedPen; }
3671 QBrush brush() const { return mBrush; }
3672 QBrush selectedBrush() const { return mSelectedBrush; }
3673 double size() const { return mSize; }
3674 TracerStyle style() const { return mStyle; }
3675 QCPGraph *graph() const { return mGraph; }
3676 double graphKey() const { return mGraphKey; }
3677 bool interpolating() const { return mInterpolating; }
3680 void setPen(const QPen &pen);
3681 void setSelectedPen(const QPen &pen);
3682 void setBrush(const QBrush &brush);
3683 void setSelectedBrush(const QBrush &brush);
3684 void setSize(double size);
3685 void setStyle(TracerStyle style);
3686 void setGraph(QCPGraph *graph);
3687 void setGraphKey(double key);
3688 void setInterpolating(bool enabled);
3690 // reimplemented virtual methods:
3691 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3693 // non-virtual methods:
3694 void updatePosition();
3696 QCPItemPosition * const position;
3699 // property members:
3700 QPen mPen, mSelectedPen;
3701 QBrush mBrush, mSelectedBrush;
3706 bool mInterpolating;
3708 // reimplemented virtual methods:
3709 virtual void draw(QCPPainter *painter);
3711 // non-virtual methods:
3712 QPen mainPen() const;
3713 QBrush mainBrush() const;
3717 class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
3720 /// \cond INCLUDE_QPROPERTIES
3721 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3722 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3723 Q_PROPERTY(double length READ length WRITE setLength)
3724 Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
3727 enum BracketStyle { bsSquare ///< A brace with angled edges
3728 ,bsRound ///< A brace with round edges
3729 ,bsCurly ///< A curly brace
3730 ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
3733 QCPItemBracket(QCustomPlot *parentPlot);
3734 virtual ~QCPItemBracket();
3737 QPen pen() const { return mPen; }
3738 QPen selectedPen() const { return mSelectedPen; }
3739 double length() const { return mLength; }
3740 BracketStyle style() const { return mStyle; }
3743 void setPen(const QPen &pen);
3744 void setSelectedPen(const QPen &pen);
3745 void setLength(double length);
3746 void setStyle(BracketStyle style);
3748 // reimplemented virtual methods:
3749 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3751 QCPItemPosition * const left;
3752 QCPItemPosition * const right;
3753 QCPItemAnchor * const center;
3756 // property members:
3757 enum AnchorIndex {aiCenter};
3758 QPen mPen, mSelectedPen;
3760 BracketStyle mStyle;
3762 // reimplemented virtual methods:
3763 virtual void draw(QCPPainter *painter);
3764 virtual QPointF anchorPixelPoint(int anchorId) const;
3766 // non-virtual methods:
3767 QPen mainPen() const;
3770 #endif // QCUSTOMPLOT_H