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
91 #include <cp_QCustomPlot_Export.h>
92 #define QCP_LIB_DECL cp_QCustomPlot_EXPORT
95 The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
100 Defines the sides of a rectangular entity to which margins can be applied.
102 \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
104 enum MarginSide { msLeft = 0x01 ///< <tt>0x01</tt> left margin
105 ,msRight = 0x02 ///< <tt>0x02</tt> right margin
106 ,msTop = 0x04 ///< <tt>0x04</tt> top margin
107 ,msBottom = 0x08 ///< <tt>0x08</tt> bottom margin
108 ,msAll = 0xFF ///< <tt>0xFF</tt> all margins
109 ,msNone = 0x00 ///< <tt>0x00</tt> no margin
111 Q_DECLARE_FLAGS(MarginSides, MarginSide)
114 Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
115 neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
116 element how it is drawn. Typically it provides a \a setAntialiased function for this.
118 \c AntialiasedElements is a flag of or-combined elements of this enum type.
120 \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
122 enum AntialiasedElement { aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
123 ,aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines
124 ,aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
125 ,aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box
126 ,aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items
127 ,aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see element \ref aeErrorBars)
128 ,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
129 ,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
130 ,aeErrorBars = 0x0100 ///< <tt>0x0100</tt> Error bars
131 ,aeFills = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs)
132 ,aeZeroLine = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
133 ,aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements
134 ,aeNone = 0x0000 ///< <tt>0x0000</tt> No elements
136 Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
139 Defines plotting hints that control various aspects of the quality and speed of plotting.
141 \see QCustomPlot::setPlottingHints
143 enum PlottingHint { phNone = 0x000 ///< <tt>0x000</tt> No hints are set
144 ,phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality
145 ///< especially of the line segment joins. (Only relevant for solid line pens.)
146 ,phForceRepaint = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint.
147 ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
148 ,phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance.
150 Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
153 Defines the mouse interactions possible with QCustomPlot.
155 \c Interactions is a flag of or-combined elements of this enum type.
157 \see QCustomPlot::setInteractions
159 enum Interaction { iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
160 ,iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
161 ,iMultiSelect = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
162 ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
163 ,iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
164 ,iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
165 ,iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
166 ,iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...)
168 Q_DECLARE_FLAGS(Interactions, Interaction)
172 Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
173 is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
174 compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
176 inline bool isInvalidData(double value)
178 return qIsNaN(value) || qIsInf(value);
184 Checks two arguments instead of one.
186 inline bool isInvalidData(double value1, double value2)
188 return isInvalidData(value1) || isInvalidData(value2);
193 Sets the specified \a side of \a margins to \a value
197 inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
201 case QCP::msLeft: margins.setLeft(value); break;
202 case QCP::msRight: margins.setRight(value); break;
203 case QCP::msTop: margins.setTop(value); break;
204 case QCP::msBottom: margins.setBottom(value); break;
205 case QCP::msAll: margins = QMargins(value, value, value, value); break;
212 Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
213 \ref QCP::msAll, returns 0.
217 inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
221 case QCP::msLeft: return margins.left();
222 case QCP::msRight: return margins.right();
223 case QCP::msTop: return margins.top();
224 case QCP::msBottom: return margins.bottom();
230 } // end of namespace QCP
232 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
233 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
234 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
235 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
238 class QCP_LIB_DECL QCPScatterStyle
243 Defines the shape used for scatter points.
245 On plottables/items that draw scatters, the sizes of these visualizations (with exception of
246 \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
247 drawn with the pen and brush specified with \ref setPen and \ref setBrush.
249 Q_ENUMS(ScatterShape)
250 enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
251 ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
252 ,ssCross ///< \enumimage{ssCross.png} a cross
253 ,ssPlus ///< \enumimage{ssPlus.png} a plus
254 ,ssCircle ///< \enumimage{ssCircle.png} a circle
255 ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
256 ,ssSquare ///< \enumimage{ssSquare.png} a square
257 ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond
258 ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
259 ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
260 ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
261 ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
262 ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
263 ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
264 ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
265 ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
266 ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
267 ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
271 QCPScatterStyle(ScatterShape shape, double size=6);
272 QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
273 QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
274 QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
275 QCPScatterStyle(const QPixmap &pixmap);
276 QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
279 double size() const { return mSize; }
280 ScatterShape shape() const { return mShape; }
281 QPen pen() const { return mPen; }
282 QBrush brush() const { return mBrush; }
283 QPixmap pixmap() const { return mPixmap; }
284 QPainterPath customPath() const { return mCustomPath; }
287 void setSize(double size);
288 void setShape(ScatterShape shape);
289 void setPen(const QPen &pen);
290 void setBrush(const QBrush &brush);
291 void setPixmap(const QPixmap &pixmap);
292 void setCustomPath(const QPainterPath &customPath);
294 // non-property methods:
295 bool isNone() const { return mShape == ssNone; }
296 bool isPenDefined() const { return mPenDefined; }
297 void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
298 void drawShape(QCPPainter *painter, QPointF pos) const;
299 void drawShape(QCPPainter *painter, double x, double y) const;
308 QPainterPath mCustomPath;
310 // non-property members:
313 Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
316 class QCP_LIB_DECL QCPPainter : public QPainter
321 Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
322 depending on whether they are wanted on the respective output device.
324 enum PainterMode { pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices
325 ,pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
326 ,pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
327 ,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.)
329 Q_FLAGS(PainterMode PainterModes)
330 Q_DECLARE_FLAGS(PainterModes, PainterMode)
333 QCPPainter(QPaintDevice *device);
337 bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
338 PainterModes modes() const { return mModes; }
341 void setAntialiasing(bool enabled);
342 void setMode(PainterMode mode, bool enabled=true);
343 void setModes(PainterModes modes);
345 // methods hiding non-virtual base class functions (QPainter bug workarounds):
346 bool begin(QPaintDevice *device);
347 void setPen(const QPen &pen);
348 void setPen(const QColor &color);
349 void setPen(Qt::PenStyle penStyle);
350 void drawLine(const QLineF &line);
351 void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
355 // non-virtual methods:
356 void makeNonCosmetic();
361 bool mIsAntialiasing;
363 // non-property members:
364 QStack<bool> mAntialiasingStack;
366 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
369 class QCP_LIB_DECL QCPLayer : public QObject
372 /// \cond INCLUDE_QPROPERTIES
373 Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
374 Q_PROPERTY(QString name READ name)
375 Q_PROPERTY(int index READ index)
376 Q_PROPERTY(QList<QCPLayerable*> children READ children)
377 Q_PROPERTY(bool visible READ visible WRITE setVisible)
380 QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
384 QCustomPlot *parentPlot() const { return mParentPlot; }
385 QString name() const { return mName; }
386 int index() const { return mIndex; }
387 QList<QCPLayerable*> children() const { return mChildren; }
388 bool visible() const { return mVisible; }
391 void setVisible(bool visible);
395 QCustomPlot *mParentPlot;
398 QList<QCPLayerable*> mChildren;
401 // non-virtual methods:
402 void addChild(QCPLayerable *layerable, bool prepend);
403 void removeChild(QCPLayerable *layerable);
406 Q_DISABLE_COPY(QCPLayer)
408 friend class QCustomPlot;
409 friend class QCPLayerable;
412 class QCP_LIB_DECL QCPLayerable : public QObject
415 /// \cond INCLUDE_QPROPERTIES
416 Q_PROPERTY(bool visible READ visible WRITE setVisible)
417 Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
418 Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
419 Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
420 Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
423 QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0);
427 bool visible() const { return mVisible; }
428 QCustomPlot *parentPlot() const { return mParentPlot; }
429 QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
430 QCPLayer *layer() const { return mLayer; }
431 bool antialiased() const { return mAntialiased; }
434 void setVisible(bool on);
435 Q_SLOT bool setLayer(QCPLayer *layer);
436 bool setLayer(const QString &layerName);
437 void setAntialiased(bool enabled);
439 // introduced virtual methods:
440 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
442 // non-property methods:
443 bool realVisibility() const;
446 void layerChanged(QCPLayer *newLayer);
451 QCustomPlot *mParentPlot;
452 QPointer<QCPLayerable> mParentLayerable;
456 // introduced virtual methods:
457 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
458 virtual QCP::Interaction selectionCategory() const;
459 virtual QRect clipRect() const;
460 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
461 virtual void draw(QCPPainter *painter) = 0;
463 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
464 virtual void deselectEvent(bool *selectionStateChanged);
466 // non-property methods:
467 void initializeParentPlot(QCustomPlot *parentPlot);
468 void setParentLayerable(QCPLayerable* parentLayerable);
469 bool moveToLayer(QCPLayer *layer, bool prepend);
470 void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
473 Q_DISABLE_COPY(QCPLayerable)
475 friend class QCustomPlot;
476 friend class QCPAxisRect;
480 class QCP_LIB_DECL QCPRange
486 QCPRange(double lower, double upper);
488 bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; }
489 bool operator!=(const QCPRange& other) const { return !(*this == other); }
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 QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
495 friend inline const QCPRange operator+(const QCPRange&, double);
496 friend inline const QCPRange operator+(double, const QCPRange&);
497 friend inline const QCPRange operator-(const QCPRange& range, double value);
498 friend inline const QCPRange operator*(const QCPRange& range, double value);
499 friend inline const QCPRange operator*(double value, const QCPRange& range);
500 friend inline const QCPRange operator/(const QCPRange& range, double value);
503 double center() const;
505 void expand(const QCPRange &otherRange);
506 QCPRange expanded(const QCPRange &otherRange) const;
507 QCPRange sanitizedForLogScale() const;
508 QCPRange sanitizedForLinScale() const;
509 bool contains(double value) const;
511 static bool validRange(double lower, double upper);
512 static bool validRange(const QCPRange &range);
513 static const double minRange; //1e-280;
514 static const double maxRange; //1e280;
517 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
519 /* documentation of inline functions */
521 /*! \fn QCPRange &QCPRange::operator+=(const double& value)
523 Adds \a value to both boundaries of the range.
526 /*! \fn QCPRange &QCPRange::operator-=(const double& value)
528 Subtracts \a value from both boundaries of the range.
531 /*! \fn QCPRange &QCPRange::operator*=(const double& value)
533 Multiplies both boundaries of the range by \a value.
536 /*! \fn QCPRange &QCPRange::operator/=(const double& value)
538 Divides both boundaries of the range by \a value.
541 /* end documentation of inline functions */
544 Adds \a value to both boundaries of the range.
546 inline const QCPRange operator+(const QCPRange& range, double value)
548 QCPRange result(range);
554 Adds \a value to both boundaries of the range.
556 inline const QCPRange operator+(double value, const QCPRange& range)
558 QCPRange result(range);
564 Subtracts \a value from both boundaries of the range.
566 inline const QCPRange operator-(const QCPRange& range, double value)
568 QCPRange result(range);
574 Multiplies both boundaries of the range by \a value.
576 inline const QCPRange operator*(const QCPRange& range, double value)
578 QCPRange result(range);
584 Multiplies both boundaries of the range by \a value.
586 inline const QCPRange operator*(double value, const QCPRange& range)
588 QCPRange result(range);
594 Divides both boundaries of the range by \a value.
596 inline const QCPRange operator/(const QCPRange& range, double value)
598 QCPRange result(range);
604 class QCP_LIB_DECL QCPMarginGroup : public QObject
608 QCPMarginGroup(QCustomPlot *parentPlot);
611 // non-virtual methods:
612 QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
613 bool isEmpty() const;
617 // non-property members:
618 QCustomPlot *mParentPlot;
619 QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
621 // non-virtual methods:
622 int commonMargin(QCP::MarginSide side) const;
623 void addChild(QCP::MarginSide side, QCPLayoutElement *element);
624 void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
627 Q_DISABLE_COPY(QCPMarginGroup)
629 friend class QCPLayoutElement;
633 class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
636 /// \cond INCLUDE_QPROPERTIES
637 Q_PROPERTY(QCPLayout* layout READ layout)
638 Q_PROPERTY(QRect rect READ rect)
639 Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
640 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
641 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
642 Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
643 Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
647 Defines the phases of the update process, that happens just before a replot. At each phase,
648 \ref update is called with the according UpdatePhase value.
650 enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout
651 ,upMargins ///< Phase in which the margins are calculated and set
652 ,upLayout ///< Final phase in which the layout system places the rects of the elements
656 explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
657 virtual ~QCPLayoutElement();
660 QCPLayout *layout() const { return mParentLayout; }
661 QRect rect() const { return mRect; }
662 QRect outerRect() const { return mOuterRect; }
663 QMargins margins() const { return mMargins; }
664 QMargins minimumMargins() const { return mMinimumMargins; }
665 QCP::MarginSides autoMargins() const { return mAutoMargins; }
666 QSize minimumSize() const { return mMinimumSize; }
667 QSize maximumSize() const { return mMaximumSize; }
668 QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
669 QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
672 void setOuterRect(const QRect &rect);
673 void setMargins(const QMargins &margins);
674 void setMinimumMargins(const QMargins &margins);
675 void setAutoMargins(QCP::MarginSides sides);
676 void setMinimumSize(const QSize &size);
677 void setMinimumSize(int width, int height);
678 void setMaximumSize(const QSize &size);
679 void setMaximumSize(int width, int height);
680 void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
682 // introduced virtual methods:
683 virtual void update(UpdatePhase phase);
684 virtual QSize minimumSizeHint() const;
685 virtual QSize maximumSizeHint() const;
686 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
688 // reimplemented virtual methods:
689 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
693 QCPLayout *mParentLayout;
694 QSize mMinimumSize, mMaximumSize;
695 QRect mRect, mOuterRect;
696 QMargins mMargins, mMinimumMargins;
697 QCP::MarginSides mAutoMargins;
698 QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
700 // introduced virtual methods:
701 virtual int calculateAutoMargin(QCP::MarginSide side);
703 virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
704 virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
705 virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
706 virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
707 virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
709 // reimplemented virtual methods:
710 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
711 virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
712 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
715 Q_DISABLE_COPY(QCPLayoutElement)
717 friend class QCustomPlot;
718 friend class QCPLayout;
719 friend class QCPMarginGroup;
723 class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
727 explicit QCPLayout();
729 // reimplemented virtual methods:
730 virtual void update(UpdatePhase phase);
731 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
733 // introduced virtual methods:
734 virtual int elementCount() const = 0;
735 virtual QCPLayoutElement* elementAt(int index) const = 0;
736 virtual QCPLayoutElement* takeAt(int index) = 0;
737 virtual bool take(QCPLayoutElement* element) = 0;
738 virtual void simplify();
740 // non-virtual methods:
741 bool removeAt(int index);
742 bool remove(QCPLayoutElement* element);
746 // introduced virtual methods:
747 virtual void updateLayout();
749 // non-virtual methods:
750 void sizeConstraintsChanged() const;
751 void adoptElement(QCPLayoutElement *el);
752 void releaseElement(QCPLayoutElement *el);
753 QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
756 Q_DISABLE_COPY(QCPLayout)
757 friend class QCPLayoutElement;
761 class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
764 /// \cond INCLUDE_QPROPERTIES
765 Q_PROPERTY(int rowCount READ rowCount)
766 Q_PROPERTY(int columnCount READ columnCount)
767 Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
768 Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
769 Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
770 Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
773 explicit QCPLayoutGrid();
774 virtual ~QCPLayoutGrid();
777 int rowCount() const;
778 int columnCount() const;
779 QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
780 QList<double> rowStretchFactors() const { return mRowStretchFactors; }
781 int columnSpacing() const { return mColumnSpacing; }
782 int rowSpacing() const { return mRowSpacing; }
785 void setColumnStretchFactor(int column, double factor);
786 void setColumnStretchFactors(const QList<double> &factors);
787 void setRowStretchFactor(int row, double factor);
788 void setRowStretchFactors(const QList<double> &factors);
789 void setColumnSpacing(int pixels);
790 void setRowSpacing(int pixels);
792 // reimplemented virtual methods:
793 virtual void updateLayout();
794 virtual int elementCount() const;
795 virtual QCPLayoutElement* elementAt(int index) const;
796 virtual QCPLayoutElement* takeAt(int index);
797 virtual bool take(QCPLayoutElement* element);
798 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
799 virtual void simplify();
800 virtual QSize minimumSizeHint() const;
801 virtual QSize maximumSizeHint() const;
803 // non-virtual methods:
804 QCPLayoutElement *element(int row, int column) const;
805 bool addElement(int row, int column, QCPLayoutElement *element);
806 bool hasElement(int row, int column);
807 void expandTo(int newRowCount, int newColumnCount);
808 void insertRow(int newIndex);
809 void insertColumn(int newIndex);
813 QList<QList<QCPLayoutElement*> > mElements;
814 QList<double> mColumnStretchFactors;
815 QList<double> mRowStretchFactors;
816 int mColumnSpacing, mRowSpacing;
818 // non-virtual methods:
819 void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
820 void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
823 Q_DISABLE_COPY(QCPLayoutGrid)
827 class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
832 Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
834 enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
835 ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
838 explicit QCPLayoutInset();
839 virtual ~QCPLayoutInset();
842 InsetPlacement insetPlacement(int index) const;
843 Qt::Alignment insetAlignment(int index) const;
844 QRectF insetRect(int index) const;
847 void setInsetPlacement(int index, InsetPlacement placement);
848 void setInsetAlignment(int index, Qt::Alignment alignment);
849 void setInsetRect(int index, const QRectF &rect);
851 // reimplemented virtual methods:
852 virtual void updateLayout();
853 virtual int elementCount() const;
854 virtual QCPLayoutElement* elementAt(int index) const;
855 virtual QCPLayoutElement* takeAt(int index);
856 virtual bool take(QCPLayoutElement* element);
857 virtual void simplify() {}
858 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
860 // non-virtual methods:
861 void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
862 void addElement(QCPLayoutElement *element, const QRectF &rect);
866 QList<QCPLayoutElement*> mElements;
867 QList<InsetPlacement> mInsetPlacement;
868 QList<Qt::Alignment> mInsetAlignment;
869 QList<QRectF> mInsetRect;
872 Q_DISABLE_COPY(QCPLayoutInset)
876 class QCP_LIB_DECL QCPLineEnding
881 Defines the type of ending decoration for line-like items, e.g. an arrow.
883 \image html QCPLineEnding.png
885 The width and length of these decorations can be controlled with the functions \ref setWidth
886 and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
887 support a width, the length property is ignored.
889 \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
892 enum EndingStyle { esNone ///< No ending decoration
893 ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
894 ,esSpikeArrow ///< A filled arrow head with an indented back
895 ,esLineArrow ///< A non-filled arrow head with open back
896 ,esDisc ///< A filled circle
897 ,esSquare ///< A filled square
898 ,esDiamond ///< A filled diamond (45° rotated square)
899 ,esBar ///< A bar perpendicular to the line
900 ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted)
901 ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
905 QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
908 EndingStyle style() const { return mStyle; }
909 double width() const { return mWidth; }
910 double length() const { return mLength; }
911 bool inverted() const { return mInverted; }
914 void setStyle(EndingStyle style);
915 void setWidth(double width);
916 void setLength(double length);
917 void setInverted(bool inverted);
919 // non-property methods:
920 double boundingDistance() const;
921 double realLength() const;
922 void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
923 void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
928 double mWidth, mLength;
931 Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
934 class QCP_LIB_DECL QCPGrid :public QCPLayerable
937 /// \cond INCLUDE_QPROPERTIES
938 Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
939 Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
940 Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
941 Q_PROPERTY(QPen pen READ pen WRITE setPen)
942 Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
943 Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
946 QCPGrid(QCPAxis *parentAxis);
949 bool subGridVisible() const { return mSubGridVisible; }
950 bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
951 bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
952 QPen pen() const { return mPen; }
953 QPen subGridPen() const { return mSubGridPen; }
954 QPen zeroLinePen() const { return mZeroLinePen; }
957 void setSubGridVisible(bool visible);
958 void setAntialiasedSubGrid(bool enabled);
959 void setAntialiasedZeroLine(bool enabled);
960 void setPen(const QPen &pen);
961 void setSubGridPen(const QPen &pen);
962 void setZeroLinePen(const QPen &pen);
966 bool mSubGridVisible;
967 bool mAntialiasedSubGrid, mAntialiasedZeroLine;
968 QPen mPen, mSubGridPen, mZeroLinePen;
969 // non-property members:
970 QCPAxis *mParentAxis;
972 // reimplemented virtual methods:
973 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
974 virtual void draw(QCPPainter *painter);
976 // non-virtual methods:
977 void drawGridLines(QCPPainter *painter) const;
978 void drawSubGridLines(QCPPainter *painter) const;
980 friend class QCPAxis;
984 class QCP_LIB_DECL QCPAxis : public QCPLayerable
987 /// \cond INCLUDE_QPROPERTIES
988 Q_PROPERTY(AxisType axisType READ axisType)
989 Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
990 Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
991 Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
992 Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
993 Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
994 Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
995 Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
996 Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
997 Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
998 Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
999 Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
1000 Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
1001 Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
1002 Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
1003 Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
1004 Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
1005 Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
1006 Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide)
1007 Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
1008 Q_PROPERTY(Qt::TimeSpec dateTimeSpec READ dateTimeSpec WRITE setDateTimeSpec)
1009 Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
1010 Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
1011 Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
1012 Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
1013 Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
1014 Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
1015 Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
1016 Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
1017 Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
1018 Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
1019 Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
1020 Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
1021 Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
1022 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
1023 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
1024 Q_PROPERTY(QString label READ label WRITE setLabel)
1025 Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
1026 Q_PROPERTY(int padding READ padding WRITE setPadding)
1027 Q_PROPERTY(int offset READ offset WRITE setOffset)
1028 Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged)
1029 Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged)
1030 Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
1031 Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
1032 Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
1033 Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
1034 Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
1035 Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
1036 Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
1037 Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
1038 Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
1039 Q_PROPERTY(QCPGrid* grid READ grid)
1043 Defines at which side of the axis rect the axis will appear. This also affects how the tick
1044 marks are drawn, on which side the labels are placed etc.
1046 enum AxisType { atLeft = 0x01 ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect
1047 ,atRight = 0x02 ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect
1048 ,atTop = 0x04 ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect
1049 ,atBottom = 0x08 ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect
1051 Q_FLAGS(AxisType AxisTypes)
1052 Q_DECLARE_FLAGS(AxisTypes, AxisType)
1054 When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the
1055 coordinate of the tick is interpreted, i.e. translated into a string.
1057 \see setTickLabelType
1059 enum LabelType { ltNumber ///< Tick coordinate is regarded as normal number and will be displayed as such. (see \ref setNumberFormat)
1060 ,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)
1064 Defines on which side of the axis the tick labels (numbers) shall appear.
1066 \see setTickLabelSide
1068 enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect
1069 ,lsOutside ///< Tick labels will be displayed outside the axis rect
1073 Defines the scale of an axis.
1076 enum ScaleType { stLinear ///< Linear scaling
1077 ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see \ref setScaleLogBase).
1081 Defines the selectable parts of an axis.
1082 \see setSelectableParts, setSelectedParts
1084 enum SelectablePart { spNone = 0 ///< None of the selectable parts
1085 ,spAxis = 0x001 ///< The axis backbone and tick marks
1086 ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
1087 ,spAxisLabel = 0x004 ///< The axis label
1089 Q_FLAGS(SelectablePart SelectableParts)
1090 Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
1092 explicit QCPAxis(QCPAxisRect *parent, AxisType type);
1096 AxisType axisType() const { return mAxisType; }
1097 QCPAxisRect *axisRect() const { return mAxisRect; }
1098 ScaleType scaleType() const { return mScaleType; }
1099 double scaleLogBase() const { return mScaleLogBase; }
1100 const QCPRange range() const { return mRange; }
1101 bool rangeReversed() const { return mRangeReversed; }
1102 bool autoTicks() const { return mAutoTicks; }
1103 int autoTickCount() const { return mAutoTickCount; }
1104 bool autoTickLabels() const { return mAutoTickLabels; }
1105 bool autoTickStep() const { return mAutoTickStep; }
1106 bool autoSubTicks() const { return mAutoSubTicks; }
1107 bool ticks() const { return mTicks; }
1108 bool tickLabels() const { return mTickLabels; }
1109 int tickLabelPadding() const;
1110 LabelType tickLabelType() const { return mTickLabelType; }
1111 QFont tickLabelFont() const { return mTickLabelFont; }
1112 QColor tickLabelColor() const { return mTickLabelColor; }
1113 double tickLabelRotation() const;
1114 LabelSide tickLabelSide() const;
1115 QString dateTimeFormat() const { return mDateTimeFormat; }
1116 Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
1117 QString numberFormat() const;
1118 int numberPrecision() const { return mNumberPrecision; }
1119 double tickStep() const { return mTickStep; }
1120 QVector<double> tickVector() const { return mTickVector; }
1121 QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
1122 int tickLengthIn() const;
1123 int tickLengthOut() const;
1124 int subTickCount() const { return mSubTickCount; }
1125 int subTickLengthIn() const;
1126 int subTickLengthOut() const;
1127 QPen basePen() const { return mBasePen; }
1128 QPen tickPen() const { return mTickPen; }
1129 QPen subTickPen() const { return mSubTickPen; }
1130 QFont labelFont() const { return mLabelFont; }
1131 QColor labelColor() const { return mLabelColor; }
1132 QString label() const { return mLabel; }
1133 int labelPadding() const;
1134 int padding() const { return mPadding; }
1136 SelectableParts selectedParts() const { return mSelectedParts; }
1137 SelectableParts selectableParts() const { return mSelectableParts; }
1138 QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
1139 QFont selectedLabelFont() const { return mSelectedLabelFont; }
1140 QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
1141 QColor selectedLabelColor() const { return mSelectedLabelColor; }
1142 QPen selectedBasePen() const { return mSelectedBasePen; }
1143 QPen selectedTickPen() const { return mSelectedTickPen; }
1144 QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
1145 QCPLineEnding lowerEnding() const;
1146 QCPLineEnding upperEnding() const;
1147 QCPGrid *grid() const { return mGrid; }
1150 Q_SLOT void setScaleType(QCPAxis::ScaleType type);
1151 void setScaleLogBase(double base);
1152 Q_SLOT void setRange(const QCPRange &range);
1153 void setRange(double lower, double upper);
1154 void setRange(double position, double size, Qt::AlignmentFlag alignment);
1155 void setRangeLower(double lower);
1156 void setRangeUpper(double upper);
1157 void setRangeReversed(bool reversed);
1158 void setAutoTicks(bool on);
1159 void setAutoTickCount(int approximateCount);
1160 void setAutoTickLabels(bool on);
1161 void setAutoTickStep(bool on);
1162 void setAutoSubTicks(bool on);
1163 void setTicks(bool show);
1164 void setTickLabels(bool show);
1165 void setTickLabelPadding(int padding);
1166 void setTickLabelType(LabelType type);
1167 void setTickLabelFont(const QFont &font);
1168 void setTickLabelColor(const QColor &color);
1169 void setTickLabelRotation(double degrees);
1170 void setTickLabelSide(LabelSide side);
1171 void setDateTimeFormat(const QString &format);
1172 void setDateTimeSpec(const Qt::TimeSpec &timeSpec);
1173 void setNumberFormat(const QString &formatCode);
1174 void setNumberPrecision(int precision);
1175 void setTickStep(double step);
1176 void setTickVector(const QVector<double> &vec);
1177 void setTickVectorLabels(const QVector<QString> &vec);
1178 void setTickLength(int inside, int outside=0);
1179 void setTickLengthIn(int inside);
1180 void setTickLengthOut(int outside);
1181 void setSubTickCount(int count);
1182 void setSubTickLength(int inside, int outside=0);
1183 void setSubTickLengthIn(int inside);
1184 void setSubTickLengthOut(int outside);
1185 void setBasePen(const QPen &pen);
1186 void setTickPen(const QPen &pen);
1187 void setSubTickPen(const QPen &pen);
1188 void setLabelFont(const QFont &font);
1189 void setLabelColor(const QColor &color);
1190 void setLabel(const QString &str);
1191 void setLabelPadding(int padding);
1192 void setPadding(int padding);
1193 void setOffset(int offset);
1194 void setSelectedTickLabelFont(const QFont &font);
1195 void setSelectedLabelFont(const QFont &font);
1196 void setSelectedTickLabelColor(const QColor &color);
1197 void setSelectedLabelColor(const QColor &color);
1198 void setSelectedBasePen(const QPen &pen);
1199 void setSelectedTickPen(const QPen &pen);
1200 void setSelectedSubTickPen(const QPen &pen);
1201 Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
1202 Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
1203 void setLowerEnding(const QCPLineEnding &ending);
1204 void setUpperEnding(const QCPLineEnding &ending);
1206 // reimplemented virtual methods:
1207 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1209 // non-property methods:
1210 Qt::Orientation orientation() const { return mOrientation; }
1211 void moveRange(double diff);
1212 void scaleRange(double factor, double center);
1213 void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
1214 void rescale(bool onlyVisiblePlottables=false);
1215 double pixelToCoord(double value) const;
1216 double coordToPixel(double value) const;
1217 SelectablePart getPartAt(const QPointF &pos) const;
1218 QList<QCPAbstractPlottable*> plottables() const;
1219 QList<QCPGraph*> graphs() const;
1220 QList<QCPAbstractItem*> items() const;
1222 static AxisType marginSideToAxisType(QCP::MarginSide side);
1223 static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; }
1224 static AxisType opposite(AxisType type);
1227 void ticksRequest();
1228 void rangeChanged(const QCPRange &newRange);
1229 void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
1230 void scaleTypeChanged(QCPAxis::ScaleType scaleType);
1231 void selectionChanged(const QCPAxis::SelectableParts &parts);
1232 void selectableChanged(const QCPAxis::SelectableParts &parts);
1235 // property members:
1238 QCPAxisRect *mAxisRect;
1239 //int mOffset; // in QCPAxisPainter
1241 Qt::Orientation mOrientation;
1242 SelectableParts mSelectableParts, mSelectedParts;
1243 QPen mBasePen, mSelectedBasePen;
1244 //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter
1246 //int mLabelPadding; // in QCPAxisPainter
1248 QFont mLabelFont, mSelectedLabelFont;
1249 QColor mLabelColor, mSelectedLabelColor;
1251 //int mTickLabelPadding; // in QCPAxisPainter
1252 bool mTickLabels, mAutoTickLabels;
1253 //double mTickLabelRotation; // in QCPAxisPainter
1254 LabelType mTickLabelType;
1255 QFont mTickLabelFont, mSelectedTickLabelFont;
1256 QColor mTickLabelColor, mSelectedTickLabelColor;
1257 QString mDateTimeFormat;
1258 Qt::TimeSpec mDateTimeSpec;
1259 int mNumberPrecision;
1260 QLatin1Char mNumberFormatChar;
1261 bool mNumberBeautifulPowers;
1262 //bool mNumberMultiplyCross; // QCPAxisPainter
1263 // ticks and subticks:
1266 int mSubTickCount, mAutoTickCount;
1267 bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
1268 //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter
1269 QPen mTickPen, mSelectedTickPen;
1270 QPen mSubTickPen, mSelectedSubTickPen;
1273 bool mRangeReversed;
1274 ScaleType mScaleType;
1275 double mScaleLogBase, mScaleLogBaseLogInv;
1277 // non-property members:
1279 QCPAxisPainterPrivate *mAxisPainter;
1280 int mLowestVisibleTick, mHighestVisibleTick;
1281 QVector<double> mTickVector;
1282 QVector<QString> mTickVectorLabels;
1283 QVector<double> mSubTickVector;
1284 bool mCachedMarginValid;
1287 // introduced virtual methods:
1288 virtual void setupTickVectors();
1289 virtual void generateAutoTicks();
1290 virtual int calculateAutoSubTickCount(double tickStep) const;
1291 virtual int calculateMargin();
1293 // reimplemented virtual methods:
1294 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1295 virtual void draw(QCPPainter *painter);
1296 virtual QCP::Interaction selectionCategory() const;
1298 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1299 virtual void deselectEvent(bool *selectionStateChanged);
1301 // non-virtual methods:
1302 void visibleTickBounds(int &lowIndex, int &highIndex) const;
1303 double baseLog(double value) const;
1304 double basePow(double value) const;
1305 QPen getBasePen() const;
1306 QPen getTickPen() const;
1307 QPen getSubTickPen() const;
1308 QFont getTickLabelFont() const;
1309 QFont getLabelFont() const;
1310 QColor getTickLabelColor() const;
1311 QColor getLabelColor() const;
1314 Q_DISABLE_COPY(QCPAxis)
1316 friend class QCustomPlot;
1317 friend class QCPGrid;
1318 friend class QCPAxisRect;
1320 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
1321 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
1322 Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
1325 class QCPAxisPainterPrivate
1328 explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot);
1329 virtual ~QCPAxisPainterPrivate();
1331 virtual void draw(QCPPainter *painter);
1332 virtual int size() const;
1335 QRect axisSelectionBox() const { return mAxisSelectionBox; }
1336 QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; }
1337 QRect labelSelectionBox() const { return mLabelSelectionBox; }
1339 // public property members:
1340 QCPAxis::AxisType type;
1342 QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters
1343 int labelPadding; // directly accessed by QCPAxis setters/getters
1347 int tickLabelPadding; // directly accessed by QCPAxis setters/getters
1348 double tickLabelRotation; // directly accessed by QCPAxis setters/getters
1349 QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters
1350 bool substituteExponent;
1351 bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters
1352 int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters
1353 QPen tickPen, subTickPen;
1354 QFont tickLabelFont;
1355 QColor tickLabelColor;
1356 QRect axisRect, viewportRect;
1357 double offset; // directly accessed by QCPAxis setters/getters
1358 bool abbreviateDecimalPowers;
1359 bool reversedEndings;
1361 QVector<double> subTickPositions;
1362 QVector<double> tickPositions;
1363 QVector<QString> tickLabels;
1371 struct TickLabelData
1373 QString basePart, expPart;
1374 QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
1375 QFont baseFont, expFont;
1377 QCustomPlot *mParentPlot;
1378 QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters
1379 QCache<QString, CachedLabel> mLabelCache;
1380 QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
1382 virtual QByteArray generateLabelParameterHash() const;
1384 virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
1385 virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
1386 virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
1387 virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
1388 virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
1392 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
1395 /// \cond INCLUDE_QPROPERTIES
1396 Q_PROPERTY(QString name READ name WRITE setName)
1397 Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
1398 Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
1399 Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
1400 Q_PROPERTY(QPen pen READ pen WRITE setPen)
1401 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
1402 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
1403 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
1404 Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
1405 Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
1406 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1407 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1410 QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
1413 QString name() const { return mName; }
1414 bool antialiasedFill() const { return mAntialiasedFill; }
1415 bool antialiasedScatters() const { return mAntialiasedScatters; }
1416 bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
1417 QPen pen() const { return mPen; }
1418 QPen selectedPen() const { return mSelectedPen; }
1419 QBrush brush() const { return mBrush; }
1420 QBrush selectedBrush() const { return mSelectedBrush; }
1421 QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1422 QCPAxis *valueAxis() const { return mValueAxis.data(); }
1423 bool selectable() const { return mSelectable; }
1424 bool selected() const { return mSelected; }
1427 void setName(const QString &name);
1428 void setAntialiasedFill(bool enabled);
1429 void setAntialiasedScatters(bool enabled);
1430 void setAntialiasedErrorBars(bool enabled);
1431 void setPen(const QPen &pen);
1432 void setSelectedPen(const QPen &pen);
1433 void setBrush(const QBrush &brush);
1434 void setSelectedBrush(const QBrush &brush);
1435 void setKeyAxis(QCPAxis *axis);
1436 void setValueAxis(QCPAxis *axis);
1437 Q_SLOT void setSelectable(bool selectable);
1438 Q_SLOT void setSelected(bool selected);
1440 // introduced virtual methods:
1441 virtual void clearData() = 0;
1442 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1443 virtual bool addToLegend();
1444 virtual bool removeFromLegend() const;
1446 // non-property methods:
1447 void rescaleAxes(bool onlyEnlarge=false) const;
1448 void rescaleKeyAxis(bool onlyEnlarge=false) const;
1449 void rescaleValueAxis(bool onlyEnlarge=false) const;
1452 void selectionChanged(bool selected);
1453 void selectableChanged(bool selectable);
1457 Represents negative and positive sign domain for passing to \ref getKeyRange and \ref getValueRange.
1459 enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
1460 ,sdBoth ///< Both sign domains, including zero, i.e. all (rational) numbers
1461 ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
1464 // property members:
1466 bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
1467 QPen mPen, mSelectedPen;
1468 QBrush mBrush, mSelectedBrush;
1469 QPointer<QCPAxis> mKeyAxis, mValueAxis;
1470 bool mSelectable, mSelected;
1472 // reimplemented virtual methods:
1473 virtual QRect clipRect() const;
1474 virtual void draw(QCPPainter *painter) = 0;
1475 virtual QCP::Interaction selectionCategory() const;
1476 void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1478 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1479 virtual void deselectEvent(bool *selectionStateChanged);
1481 // introduced virtual methods:
1482 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
1483 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1484 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1486 // non-virtual methods:
1487 void coordsToPixels(double key, double value, double &x, double &y) const;
1488 const QPointF coordsToPixels(double key, double value) const;
1489 void pixelsToCoords(double x, double y, double &key, double &value) const;
1490 void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
1491 QPen mainPen() const;
1492 QBrush mainBrush() const;
1493 void applyFillAntialiasingHint(QCPPainter *painter) const;
1494 void applyScattersAntialiasingHint(QCPPainter *painter) const;
1495 void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
1496 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1499 Q_DISABLE_COPY(QCPAbstractPlottable)
1501 friend class QCustomPlot;
1502 friend class QCPAxis;
1503 friend class QCPPlottableLegendItem;
1507 class QCP_LIB_DECL QCPItemAnchor
1510 QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
1511 virtual ~QCPItemAnchor();
1514 QString name() const { return mName; }
1515 virtual QPointF pixelPoint() const;
1518 // property members:
1521 // non-property members:
1522 QCustomPlot *mParentPlot;
1523 QCPAbstractItem *mParentItem;
1525 QSet<QCPItemPosition*> mChildrenX, mChildrenY;
1527 // introduced virtual methods:
1528 virtual QCPItemPosition *toQCPItemPosition() { return 0; }
1530 // non-virtual methods:
1531 void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1532 void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1533 void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1534 void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1537 Q_DISABLE_COPY(QCPItemAnchor)
1539 friend class QCPItemPosition;
1544 class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
1548 Defines the ways an item position can be specified. Thus it defines what the numbers passed to
1549 \ref setCoords actually mean.
1553 enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget.
1554 ,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
1555 ///< 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
1556 ///< vertically at the top of the viewport/widget, etc.
1557 ,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
1558 ///< 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
1559 ///< 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.
1560 ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes).
1563 QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
1564 virtual ~QCPItemPosition();
1567 PositionType type() const { return typeX(); }
1568 PositionType typeX() const { return mPositionTypeX; }
1569 PositionType typeY() const { return mPositionTypeY; }
1570 QCPItemAnchor *parentAnchor() const { return parentAnchorX(); }
1571 QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; }
1572 QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; }
1573 double key() const { return mKey; }
1574 double value() const { return mValue; }
1575 QPointF coords() const { return QPointF(mKey, mValue); }
1576 QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1577 QCPAxis *valueAxis() const { return mValueAxis.data(); }
1578 QCPAxisRect *axisRect() const;
1579 virtual QPointF pixelPoint() const;
1582 void setType(PositionType type);
1583 void setTypeX(PositionType type);
1584 void setTypeY(PositionType type);
1585 bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1586 bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1587 bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1588 void setCoords(double key, double value);
1589 void setCoords(const QPointF &coords);
1590 void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
1591 void setAxisRect(QCPAxisRect *axisRect);
1592 void setPixelPoint(const QPointF &pixelPoint);
1595 // property members:
1596 PositionType mPositionTypeX, mPositionTypeY;
1597 QPointer<QCPAxis> mKeyAxis, mValueAxis;
1598 QPointer<QCPAxisRect> mAxisRect;
1599 double mKey, mValue;
1600 QCPItemAnchor *mParentAnchorX, *mParentAnchorY;
1602 // reimplemented virtual methods:
1603 virtual QCPItemPosition *toQCPItemPosition() { return this; }
1606 Q_DISABLE_COPY(QCPItemPosition)
1611 class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
1614 /// \cond INCLUDE_QPROPERTIES
1615 Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
1616 Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
1617 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1618 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1621 QCPAbstractItem(QCustomPlot *parentPlot);
1622 virtual ~QCPAbstractItem();
1625 bool clipToAxisRect() const { return mClipToAxisRect; }
1626 QCPAxisRect *clipAxisRect() const;
1627 bool selectable() const { return mSelectable; }
1628 bool selected() const { return mSelected; }
1631 void setClipToAxisRect(bool clip);
1632 void setClipAxisRect(QCPAxisRect *rect);
1633 Q_SLOT void setSelectable(bool selectable);
1634 Q_SLOT void setSelected(bool selected);
1636 // reimplemented virtual methods:
1637 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1639 // non-virtual methods:
1640 QList<QCPItemPosition*> positions() const { return mPositions; }
1641 QList<QCPItemAnchor*> anchors() const { return mAnchors; }
1642 QCPItemPosition *position(const QString &name) const;
1643 QCPItemAnchor *anchor(const QString &name) const;
1644 bool hasAnchor(const QString &name) const;
1647 void selectionChanged(bool selected);
1648 void selectableChanged(bool selectable);
1651 // property members:
1652 bool mClipToAxisRect;
1653 QPointer<QCPAxisRect> mClipAxisRect;
1654 QList<QCPItemPosition*> mPositions;
1655 QList<QCPItemAnchor*> mAnchors;
1656 bool mSelectable, mSelected;
1658 // reimplemented virtual methods:
1659 virtual QCP::Interaction selectionCategory() const;
1660 virtual QRect clipRect() const;
1661 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1662 virtual void draw(QCPPainter *painter) = 0;
1664 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1665 virtual void deselectEvent(bool *selectionStateChanged);
1667 // introduced virtual methods:
1668 virtual QPointF anchorPixelPoint(int anchorId) const;
1670 // non-virtual methods:
1671 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1672 double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
1673 QCPItemPosition *createPosition(const QString &name);
1674 QCPItemAnchor *createAnchor(const QString &name, int anchorId);
1677 Q_DISABLE_COPY(QCPAbstractItem)
1679 friend class QCustomPlot;
1680 friend class QCPItemAnchor;
1684 class QCP_LIB_DECL QCustomPlot : public QWidget
1687 /// \cond INCLUDE_QPROPERTIES
1688 Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
1689 Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1690 Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1691 Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1692 Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
1693 Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
1694 Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
1695 Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
1696 Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
1700 Defines how a layer should be inserted relative to an other layer.
1702 \see addLayer, moveLayer
1704 enum LayerInsertMode { limBelow ///< Layer is inserted below other layer
1705 ,limAbove ///< Layer is inserted above other layer
1707 Q_ENUMS(LayerInsertMode)
1710 Defines with what timing the QCustomPlot surface is refreshed after a replot.
1714 enum RefreshPriority { rpImmediate ///< The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot
1715 ,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
1716 ,rpHint ///< Whether to use immediate repaint or queued update depends on whether the plotting hint \ref QCP::phForceRepaint is set, see \ref setPlottingHints.
1719 explicit QCustomPlot(QWidget *parent = 0);
1720 virtual ~QCustomPlot();
1723 QRect viewport() const { return mViewport; }
1724 QPixmap background() const { return mBackgroundPixmap; }
1725 bool backgroundScaled() const { return mBackgroundScaled; }
1726 Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1727 QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
1728 QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
1729 QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
1730 bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
1731 const QCP::Interactions interactions() const { return mInteractions; }
1732 int selectionTolerance() const { return mSelectionTolerance; }
1733 bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
1734 QCP::PlottingHints plottingHints() const { return mPlottingHints; }
1735 Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
1738 void setViewport(const QRect &rect);
1739 void setBackground(const QPixmap &pm);
1740 void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
1741 void setBackground(const QBrush &brush);
1742 void setBackgroundScaled(bool scaled);
1743 void setBackgroundScaledMode(Qt::AspectRatioMode mode);
1744 void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
1745 void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
1746 void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements);
1747 void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
1748 void setAutoAddPlottableToLegend(bool on);
1749 void setInteractions(const QCP::Interactions &interactions);
1750 void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
1751 void setSelectionTolerance(int pixels);
1752 void setNoAntialiasingOnDrag(bool enabled);
1753 void setPlottingHints(const QCP::PlottingHints &hints);
1754 void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
1755 void setMultiSelectModifier(Qt::KeyboardModifier modifier);
1757 // non-property methods:
1758 // plottable interface:
1759 QCPAbstractPlottable *plottable(int index);
1760 QCPAbstractPlottable *plottable();
1761 bool addPlottable(QCPAbstractPlottable *plottable);
1762 bool removePlottable(QCPAbstractPlottable *plottable);
1763 bool removePlottable(int index);
1764 int clearPlottables();
1765 int plottableCount() const;
1766 QList<QCPAbstractPlottable*> selectedPlottables() const;
1767 QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
1768 bool hasPlottable(QCPAbstractPlottable *plottable) const;
1770 // specialized interface for QCPGraph:
1771 QCPGraph *graph(int index) const;
1772 QCPGraph *graph() const;
1773 QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
1774 bool removeGraph(QCPGraph *graph);
1775 bool removeGraph(int index);
1777 int graphCount() const;
1778 QList<QCPGraph*> selectedGraphs() const;
1781 QCPAbstractItem *item(int index) const;
1782 QCPAbstractItem *item() const;
1783 bool addItem(QCPAbstractItem* item);
1784 bool removeItem(QCPAbstractItem *item);
1785 bool removeItem(int index);
1787 int itemCount() const;
1788 QList<QCPAbstractItem*> selectedItems() const;
1789 QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
1790 bool hasItem(QCPAbstractItem *item) const;
1793 QCPLayer *layer(const QString &name) const;
1794 QCPLayer *layer(int index) const;
1795 QCPLayer *currentLayer() const;
1796 bool setCurrentLayer(const QString &name);
1797 bool setCurrentLayer(QCPLayer *layer);
1798 int layerCount() const;
1799 bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
1800 bool removeLayer(QCPLayer *layer);
1801 bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
1803 // axis rect/layout interface:
1804 int axisRectCount() const;
1805 QCPAxisRect* axisRect(int index=0) const;
1806 QList<QCPAxisRect*> axisRects() const;
1807 QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
1808 Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
1810 QList<QCPAxis*> selectedAxes() const;
1811 QList<QCPLegend*> selectedLegends() const;
1812 Q_SLOT void deselectAll();
1814 bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0, const QString &pdfCreator=QString(), const QString &pdfTitle=QString());
1815 bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1816 bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1817 bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
1818 bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
1819 QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
1820 void toPainter(QCPPainter *painter, int width=0, int height=0);
1821 Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpHint);
1823 QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
1827 void mouseDoubleClick(QMouseEvent *event);
1828 void mousePress(QMouseEvent *event);
1829 void mouseMove(QMouseEvent *event);
1830 void mouseRelease(QMouseEvent *event);
1831 void mouseWheel(QWheelEvent *event);
1833 void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1834 void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1835 void itemClick(QCPAbstractItem *item, QMouseEvent *event);
1836 void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
1837 void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1838 void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1839 void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1840 void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1841 void titleClick(QMouseEvent *event, QCPPlotTitle *title);
1842 void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
1844 void selectionChangedByUser();
1845 void beforeReplot();
1849 // property members:
1851 QCPLayoutGrid *mPlotLayout;
1852 bool mAutoAddPlottableToLegend;
1853 QList<QCPAbstractPlottable*> mPlottables;
1854 QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
1855 QList<QCPAbstractItem*> mItems;
1856 QList<QCPLayer*> mLayers;
1857 QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
1858 QCP::Interactions mInteractions;
1859 int mSelectionTolerance;
1860 bool mNoAntialiasingOnDrag;
1861 QBrush mBackgroundBrush;
1862 QPixmap mBackgroundPixmap;
1863 QPixmap mScaledBackgroundPixmap;
1864 bool mBackgroundScaled;
1865 Qt::AspectRatioMode mBackgroundScaledMode;
1866 QCPLayer *mCurrentLayer;
1867 QCP::PlottingHints mPlottingHints;
1868 Qt::KeyboardModifier mMultiSelectModifier;
1870 // non-property members:
1871 QPixmap mPaintBuffer;
1872 QPoint mMousePressPos;
1873 QPointer<QCPLayoutElement> mMouseEventElement;
1876 // reimplemented virtual methods:
1877 virtual QSize minimumSizeHint() const;
1878 virtual QSize sizeHint() const;
1879 virtual void paintEvent(QPaintEvent *event);
1880 virtual void resizeEvent(QResizeEvent *event);
1881 virtual void mouseDoubleClickEvent(QMouseEvent *event);
1882 virtual void mousePressEvent(QMouseEvent *event);
1883 virtual void mouseMoveEvent(QMouseEvent *event);
1884 virtual void mouseReleaseEvent(QMouseEvent *event);
1885 virtual void wheelEvent(QWheelEvent *event);
1887 // introduced virtual methods:
1888 virtual void draw(QCPPainter *painter);
1889 virtual void axisRemoved(QCPAxis *axis);
1890 virtual void legendRemoved(QCPLegend *legend);
1892 // non-virtual methods:
1893 void updateLayerIndices() const;
1894 QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const;
1895 void drawBackground(QCPPainter *painter);
1897 friend class QCPLegend;
1898 friend class QCPAxis;
1899 friend class QCPLayer;
1900 friend class QCPAxisRect;
1904 class QCP_LIB_DECL QCPColorGradient
1909 Defines the color spaces in which color interpolation between gradient stops can be performed.
1911 \see setColorInterpolation
1913 enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated
1914 ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)
1916 Q_ENUMS(ColorInterpolation)
1919 Defines the available presets that can be loaded with \ref loadPreset. See the documentation
1920 there for an image of the presets.
1922 enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation)
1923 ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation)
1924 ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation)
1925 ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)
1926 ,gpCandy ///< Blue over pink to white
1927 ,gpGeography ///< Colors suitable to represent different elevations on geographical maps
1928 ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)
1929 ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white
1930 ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values
1931 ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)
1932 ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)
1933 ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic)
1935 Q_ENUMS(GradientPreset)
1937 QCPColorGradient(GradientPreset preset=gpCold);
1938 bool operator==(const QCPColorGradient &other) const;
1939 bool operator!=(const QCPColorGradient &other) const { return !(*this == other); }
1942 int levelCount() const { return mLevelCount; }
1943 QMap<double, QColor> colorStops() const { return mColorStops; }
1944 ColorInterpolation colorInterpolation() const { return mColorInterpolation; }
1945 bool periodic() const { return mPeriodic; }
1948 void setLevelCount(int n);
1949 void setColorStops(const QMap<double, QColor> &colorStops);
1950 void setColorStopAt(double position, const QColor &color);
1951 void setColorInterpolation(ColorInterpolation interpolation);
1952 void setPeriodic(bool enabled);
1954 // non-property methods:
1955 void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
1956 QRgb color(double position, const QCPRange &range, bool logarithmic=false);
1957 void loadPreset(GradientPreset preset);
1958 void clearColorStops();
1959 QCPColorGradient inverted() const;
1962 void updateColorBuffer();
1964 // property members:
1966 QMap<double, QColor> mColorStops;
1967 ColorInterpolation mColorInterpolation;
1970 // non-property members:
1971 QVector<QRgb> mColorBuffer;
1972 bool mColorBufferInvalidated;
1976 class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
1979 /// \cond INCLUDE_QPROPERTIES
1980 Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1981 Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1982 Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1983 Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
1984 Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
1987 explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
1988 virtual ~QCPAxisRect();
1991 QPixmap background() const { return mBackgroundPixmap; }
1992 bool backgroundScaled() const { return mBackgroundScaled; }
1993 Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1994 Qt::Orientations rangeDrag() const { return mRangeDrag; }
1995 Qt::Orientations rangeZoom() const { return mRangeZoom; }
1996 QCPAxis *rangeDragAxis(Qt::Orientation orientation);
1997 QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
1998 double rangeZoomFactor(Qt::Orientation orientation);
2001 void setBackground(const QPixmap &pm);
2002 void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
2003 void setBackground(const QBrush &brush);
2004 void setBackgroundScaled(bool scaled);
2005 void setBackgroundScaledMode(Qt::AspectRatioMode mode);
2006 void setRangeDrag(Qt::Orientations orientations);
2007 void setRangeZoom(Qt::Orientations orientations);
2008 void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
2009 void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
2010 void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
2011 void setRangeZoomFactor(double factor);
2013 // non-property methods:
2014 int axisCount(QCPAxis::AxisType type) const;
2015 QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
2016 QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
2017 QList<QCPAxis*> axes() const;
2018 QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0);
2019 QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
2020 bool removeAxis(QCPAxis *axis);
2021 QCPLayoutInset *insetLayout() const { return mInsetLayout; }
2023 void setupFullAxesBox(bool connectRanges=false);
2024 QList<QCPAbstractPlottable*> plottables() const;
2025 QList<QCPGraph*> graphs() const;
2026 QList<QCPAbstractItem*> items() const;
2028 // read-only interface imitating a QRect:
2029 int left() const { return mRect.left(); }
2030 int right() const { return mRect.right(); }
2031 int top() const { return mRect.top(); }
2032 int bottom() const { return mRect.bottom(); }
2033 int width() const { return mRect.width(); }
2034 int height() const { return mRect.height(); }
2035 QSize size() const { return mRect.size(); }
2036 QPoint topLeft() const { return mRect.topLeft(); }
2037 QPoint topRight() const { return mRect.topRight(); }
2038 QPoint bottomLeft() const { return mRect.bottomLeft(); }
2039 QPoint bottomRight() const { return mRect.bottomRight(); }
2040 QPoint center() const { return mRect.center(); }
2042 // reimplemented virtual methods:
2043 virtual void update(UpdatePhase phase);
2044 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
2047 // property members:
2048 QBrush mBackgroundBrush;
2049 QPixmap mBackgroundPixmap;
2050 QPixmap mScaledBackgroundPixmap;
2051 bool mBackgroundScaled;
2052 Qt::AspectRatioMode mBackgroundScaledMode;
2053 QCPLayoutInset *mInsetLayout;
2054 Qt::Orientations mRangeDrag, mRangeZoom;
2055 QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
2056 double mRangeZoomFactorHorz, mRangeZoomFactorVert;
2057 // non-property members:
2058 QCPRange mDragStartHorzRange, mDragStartVertRange;
2059 QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
2062 QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
2064 // reimplemented virtual methods:
2065 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2066 virtual void draw(QCPPainter *painter);
2067 virtual int calculateAutoMargin(QCP::MarginSide side);
2069 virtual void mousePressEvent(QMouseEvent *event);
2070 virtual void mouseMoveEvent(QMouseEvent *event);
2071 virtual void mouseReleaseEvent(QMouseEvent *event);
2072 virtual void wheelEvent(QWheelEvent *event);
2074 // non-property methods:
2075 void drawBackground(QCPPainter *painter);
2076 void updateAxesOffset(QCPAxis::AxisType type);
2079 Q_DISABLE_COPY(QCPAxisRect)
2081 friend class QCustomPlot;
2085 class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
2088 /// \cond INCLUDE_QPROPERTIES
2089 Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
2090 Q_PROPERTY(QFont font READ font WRITE setFont)
2091 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2092 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2093 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2094 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged)
2095 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged)
2098 explicit QCPAbstractLegendItem(QCPLegend *parent);
2101 QCPLegend *parentLegend() const { return mParentLegend; }
2102 QFont font() const { return mFont; }
2103 QColor textColor() const { return mTextColor; }
2104 QFont selectedFont() const { return mSelectedFont; }
2105 QColor selectedTextColor() const { return mSelectedTextColor; }
2106 bool selectable() const { return mSelectable; }
2107 bool selected() const { return mSelected; }
2110 void setFont(const QFont &font);
2111 void setTextColor(const QColor &color);
2112 void setSelectedFont(const QFont &font);
2113 void setSelectedTextColor(const QColor &color);
2114 Q_SLOT void setSelectable(bool selectable);
2115 Q_SLOT void setSelected(bool selected);
2117 // reimplemented virtual methods:
2118 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2121 void selectionChanged(bool selected);
2122 void selectableChanged(bool selectable);
2125 // property members:
2126 QCPLegend *mParentLegend;
2129 QFont mSelectedFont;
2130 QColor mSelectedTextColor;
2131 bool mSelectable, mSelected;
2133 // reimplemented virtual methods:
2134 virtual QCP::Interaction selectionCategory() const;
2135 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2136 virtual QRect clipRect() const;
2137 virtual void draw(QCPPainter *painter) = 0;
2139 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2140 virtual void deselectEvent(bool *selectionStateChanged);
2143 Q_DISABLE_COPY(QCPAbstractLegendItem)
2145 friend class QCPLegend;
2149 class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
2153 QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
2156 QCPAbstractPlottable *plottable() { return mPlottable; }
2159 // property members:
2160 QCPAbstractPlottable *mPlottable;
2162 // reimplemented virtual methods:
2163 virtual void draw(QCPPainter *painter);
2164 virtual QSize minimumSizeHint() const;
2166 // non-virtual methods:
2167 QPen getIconBorderPen() const;
2168 QColor getTextColor() const;
2169 QFont getFont() const;
2173 class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
2176 /// \cond INCLUDE_QPROPERTIES
2177 Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
2178 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2179 Q_PROPERTY(QFont font READ font WRITE setFont)
2180 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2181 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
2182 Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
2183 Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
2184 Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged)
2185 Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged)
2186 Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
2187 Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
2188 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2189 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2190 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2194 Defines the selectable parts of a legend
2196 \see setSelectedParts, setSelectableParts
2198 enum SelectablePart { spNone = 0x000 ///< <tt>0x000</tt> None
2199 ,spLegendBox = 0x001 ///< <tt>0x001</tt> The legend box (frame)
2200 ,spItems = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems)
2202 Q_FLAGS(SelectablePart SelectableParts)
2203 Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
2205 explicit QCPLegend();
2206 virtual ~QCPLegend();
2209 QPen borderPen() const { return mBorderPen; }
2210 QBrush brush() const { return mBrush; }
2211 QFont font() const { return mFont; }
2212 QColor textColor() const { return mTextColor; }
2213 QSize iconSize() const { return mIconSize; }
2214 int iconTextPadding() const { return mIconTextPadding; }
2215 QPen iconBorderPen() const { return mIconBorderPen; }
2216 SelectableParts selectableParts() const { return mSelectableParts; }
2217 SelectableParts selectedParts() const;
2218 QPen selectedBorderPen() const { return mSelectedBorderPen; }
2219 QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
2220 QBrush selectedBrush() const { return mSelectedBrush; }
2221 QFont selectedFont() const { return mSelectedFont; }
2222 QColor selectedTextColor() const { return mSelectedTextColor; }
2225 void setBorderPen(const QPen &pen);
2226 void setBrush(const QBrush &brush);
2227 void setFont(const QFont &font);
2228 void setTextColor(const QColor &color);
2229 void setIconSize(const QSize &size);
2230 void setIconSize(int width, int height);
2231 void setIconTextPadding(int padding);
2232 void setIconBorderPen(const QPen &pen);
2233 Q_SLOT void setSelectableParts(const SelectableParts &selectableParts);
2234 Q_SLOT void setSelectedParts(const SelectableParts &selectedParts);
2235 void setSelectedBorderPen(const QPen &pen);
2236 void setSelectedIconBorderPen(const QPen &pen);
2237 void setSelectedBrush(const QBrush &brush);
2238 void setSelectedFont(const QFont &font);
2239 void setSelectedTextColor(const QColor &color);
2241 // reimplemented virtual methods:
2242 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2244 // non-virtual methods:
2245 QCPAbstractLegendItem *item(int index) const;
2246 QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
2247 int itemCount() const;
2248 bool hasItem(QCPAbstractLegendItem *item) const;
2249 bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
2250 bool addItem(QCPAbstractLegendItem *item);
2251 bool removeItem(int index);
2252 bool removeItem(QCPAbstractLegendItem *item);
2254 QList<QCPAbstractLegendItem*> selectedItems() const;
2257 void selectionChanged(QCPLegend::SelectableParts parts);
2258 void selectableChanged(QCPLegend::SelectableParts parts);
2261 // property members:
2262 QPen mBorderPen, mIconBorderPen;
2267 int mIconTextPadding;
2268 SelectableParts mSelectedParts, mSelectableParts;
2269 QPen mSelectedBorderPen, mSelectedIconBorderPen;
2270 QBrush mSelectedBrush;
2271 QFont mSelectedFont;
2272 QColor mSelectedTextColor;
2274 // reimplemented virtual methods:
2275 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
2276 virtual QCP::Interaction selectionCategory() const;
2277 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2278 virtual void draw(QCPPainter *painter);
2280 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2281 virtual void deselectEvent(bool *selectionStateChanged);
2283 // non-virtual methods:
2284 QPen getBorderPen() const;
2285 QBrush getBrush() const;
2288 Q_DISABLE_COPY(QCPLegend)
2290 friend class QCustomPlot;
2291 friend class QCPAbstractLegendItem;
2293 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
2294 Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
2297 class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
2300 /// \cond INCLUDE_QPROPERTIES
2301 Q_PROPERTY(QString text READ text WRITE setText)
2302 Q_PROPERTY(QFont font READ font WRITE setFont)
2303 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2304 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2305 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2306 Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
2307 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
2310 explicit QCPPlotTitle(QCustomPlot *parentPlot);
2311 explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text);
2314 QString text() const { return mText; }
2315 QFont font() const { return mFont; }
2316 QColor textColor() const { return mTextColor; }
2317 QFont selectedFont() const { return mSelectedFont; }
2318 QColor selectedTextColor() const { return mSelectedTextColor; }
2319 bool selectable() const { return mSelectable; }
2320 bool selected() const { return mSelected; }
2323 void setText(const QString &text);
2324 void setFont(const QFont &font);
2325 void setTextColor(const QColor &color);
2326 void setSelectedFont(const QFont &font);
2327 void setSelectedTextColor(const QColor &color);
2328 Q_SLOT void setSelectable(bool selectable);
2329 Q_SLOT void setSelected(bool selected);
2331 // reimplemented virtual methods:
2332 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2335 void selectionChanged(bool selected);
2336 void selectableChanged(bool selectable);
2339 // property members:
2343 QFont mSelectedFont;
2344 QColor mSelectedTextColor;
2345 QRect mTextBoundingRect;
2346 bool mSelectable, mSelected;
2348 // reimplemented virtual methods:
2349 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2350 virtual void draw(QCPPainter *painter);
2351 virtual QSize minimumSizeHint() const;
2352 virtual QSize maximumSizeHint() const;
2354 virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2355 virtual void deselectEvent(bool *selectionStateChanged);
2357 // non-virtual methods:
2358 QFont mainFont() const;
2359 QColor mainTextColor() const;
2362 Q_DISABLE_COPY(QCPPlotTitle)
2366 class QCPColorScaleAxisRectPrivate : public QCPAxisRect
2370 explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale);
2372 QCPColorScale *mParentColorScale;
2373 QImage mGradientImage;
2374 bool mGradientImageInvalidated;
2375 // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
2376 using QCPAxisRect::calculateAutoMargin;
2377 using QCPAxisRect::mousePressEvent;
2378 using QCPAxisRect::mouseMoveEvent;
2379 using QCPAxisRect::mouseReleaseEvent;
2380 using QCPAxisRect::wheelEvent;
2381 using QCPAxisRect::update;
2382 virtual void draw(QCPPainter *painter);
2383 void updateGradientImage();
2384 Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
2385 Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
2386 friend class QCPColorScale;
2390 class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
2393 /// \cond INCLUDE_QPROPERTIES
2394 Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
2395 Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
2396 Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
2397 Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
2398 Q_PROPERTY(QString label READ label WRITE setLabel)
2399 Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
2400 Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
2401 Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
2404 explicit QCPColorScale(QCustomPlot *parentPlot);
2405 virtual ~QCPColorScale();
2408 QCPAxis *axis() const { return mColorAxis.data(); }
2409 QCPAxis::AxisType type() const { return mType; }
2410 QCPRange dataRange() const { return mDataRange; }
2411 QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
2412 QCPColorGradient gradient() const { return mGradient; }
2413 QString label() const;
2414 int barWidth () const { return mBarWidth; }
2415 bool rangeDrag() const;
2416 bool rangeZoom() const;
2419 void setType(QCPAxis::AxisType type);
2420 Q_SLOT void setDataRange(const QCPRange &dataRange);
2421 Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
2422 Q_SLOT void setGradient(const QCPColorGradient &gradient);
2423 void setLabel(const QString &str);
2424 void setBarWidth(int width);
2425 void setRangeDrag(bool enabled);
2426 void setRangeZoom(bool enabled);
2428 // non-property methods:
2429 QList<QCPColorMap*> colorMaps() const;
2430 void rescaleDataRange(bool onlyVisibleMaps);
2432 // reimplemented virtual methods:
2433 virtual void update(UpdatePhase phase);
2436 void dataRangeChanged(QCPRange newRange);
2437 void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
2438 void gradientChanged(QCPColorGradient newGradient);
2441 // property members:
2442 QCPAxis::AxisType mType;
2443 QCPRange mDataRange;
2444 QCPAxis::ScaleType mDataScaleType;
2445 QCPColorGradient mGradient;
2448 // non-property members:
2449 QPointer<QCPColorScaleAxisRectPrivate> mAxisRect;
2450 QPointer<QCPAxis> mColorAxis;
2452 // reimplemented virtual methods:
2453 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2455 virtual void mousePressEvent(QMouseEvent *event);
2456 virtual void mouseMoveEvent(QMouseEvent *event);
2457 virtual void mouseReleaseEvent(QMouseEvent *event);
2458 virtual void wheelEvent(QWheelEvent *event);
2461 Q_DISABLE_COPY(QCPColorScale)
2463 friend class QCPColorScaleAxisRectPrivate;
2471 class QCP_LIB_DECL QCPData
2475 QCPData(double key, double value);
2477 double keyErrorPlus, keyErrorMinus;
2478 double valueErrorPlus, valueErrorMinus;
2480 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
2482 /*! \typedef QCPDataMap
2483 Container for storing \ref QCPData items in a sorted fashion. The key of the map
2484 is the key member of the QCPData instance.
2486 This is the container in which QCPGraph holds its data.
2487 \see QCPData, QCPGraph::setData
2489 typedef QMap<double, QCPData> QCPDataMap;
2490 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
2491 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
2494 class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
2497 /// \cond INCLUDE_QPROPERTIES
2498 Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2499 Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2500 Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
2501 Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
2502 Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
2503 Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
2504 Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
2505 Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling)
2509 Defines how the graph's line is represented visually in the plot. The line is drawn with the
2510 current pen of the graph (\ref setPen).
2513 enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented
2514 ///< with symbols according to the scatter style, see \ref setScatterStyle)
2515 ,lsLine ///< data points are connected by a straight line
2516 ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point
2517 ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point
2518 ,lsStepCenter ///< line is drawn as steps where the step is in between two data points
2519 ,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
2523 Defines what kind of error bars are drawn for each data point
2525 enum ErrorType { etNone ///< No error bars are shown
2526 ,etKey ///< Error bars for the key dimension of the data point are shown
2527 ,etValue ///< Error bars for the value dimension of the data point are shown
2528 ,etBoth ///< Error bars for both key and value dimensions of the data point are shown
2532 explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
2533 virtual ~QCPGraph();
2536 QCPDataMap *data() const { return mData; }
2537 LineStyle lineStyle() const { return mLineStyle; }
2538 QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2539 ErrorType errorType() const { return mErrorType; }
2540 QPen errorPen() const { return mErrorPen; }
2541 double errorBarSize() const { return mErrorBarSize; }
2542 bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
2543 QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
2544 bool adaptiveSampling() const { return mAdaptiveSampling; }
2547 void setData(QCPDataMap *data, bool copy=false);
2548 void setData(const QVector<double> &key, const QVector<double> &value);
2549 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
2550 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
2551 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
2552 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
2553 void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
2554 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);
2555 void setLineStyle(LineStyle ls);
2556 void setScatterStyle(const QCPScatterStyle &style);
2557 void setErrorType(ErrorType errorType);
2558 void setErrorPen(const QPen &pen);
2559 void setErrorBarSize(double size);
2560 void setErrorBarSkipSymbol(bool enabled);
2561 void setChannelFillGraph(QCPGraph *targetGraph);
2562 void setAdaptiveSampling(bool enabled);
2564 // non-property methods:
2565 void addData(const QCPDataMap &dataMap);
2566 void addData(const QCPData &data);
2567 void addData(double key, double value);
2568 void addData(const QVector<double> &keys, const QVector<double> &values);
2569 void removeDataBefore(double key);
2570 void removeDataAfter(double key);
2571 void removeData(double fromKey, double toKey);
2572 void removeData(double key);
2574 // reimplemented virtual methods:
2575 virtual void clearData();
2576 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2577 using QCPAbstractPlottable::rescaleAxes;
2578 using QCPAbstractPlottable::rescaleKeyAxis;
2579 using QCPAbstractPlottable::rescaleValueAxis;
2580 void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2581 void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2582 void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2585 // property members:
2588 LineStyle mLineStyle;
2589 QCPScatterStyle mScatterStyle;
2590 ErrorType mErrorType;
2591 double mErrorBarSize;
2592 bool mErrorBarSkipSymbol;
2593 QPointer<QCPGraph> mChannelFillGraph;
2594 bool mAdaptiveSampling;
2596 // reimplemented virtual methods:
2597 virtual void draw(QCPPainter *painter);
2598 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2599 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2600 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2601 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2602 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2604 // introduced virtual methods:
2605 virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
2606 virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *scatterData) const;
2607 virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
2608 virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
2610 // non-virtual methods:
2611 void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const;
2612 void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const;
2613 void getScatterPlotData(QVector<QCPData> *scatterData) const;
2614 void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2615 void getStepLeftPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2616 void getStepRightPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2617 void getStepCenterPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2618 void getImpulsePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const;
2619 void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
2620 void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper) const;
2621 int countDataInBounds(const QCPDataMap::const_iterator &lower, const QCPDataMap::const_iterator &upper, int maxCount) const;
2622 void addFillBasePoints(QVector<QPointF> *lineData) const;
2623 void removeFillBasePoints(QVector<QPointF> *lineData) const;
2624 QPointF lowerFillBasePoint(double lowerKey) const;
2625 QPointF upperFillBasePoint(double upperKey) const;
2626 const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
2627 int findIndexBelowX(const QVector<QPointF> *data, double x) const;
2628 int findIndexAboveX(const QVector<QPointF> *data, double x) const;
2629 int findIndexBelowY(const QVector<QPointF> *data, double y) const;
2630 int findIndexAboveY(const QVector<QPointF> *data, double y) const;
2631 double pointDistance(const QPointF &pixelPoint) const;
2633 friend class QCustomPlot;
2634 friend class QCPLegend;
2642 class QCP_LIB_DECL QCPCurveData
2646 QCPCurveData(double t, double key, double value);
2647 double t, key, value;
2649 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
2651 /*! \typedef QCPCurveDataMap
2652 Container for storing \ref QCPCurveData items in a sorted fashion. The key of the map
2653 is the t member of the QCPCurveData instance.
2655 This is the container in which QCPCurve holds its data.
2656 \see QCPCurveData, QCPCurve::setData
2659 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
2660 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
2661 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
2664 class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
2667 /// \cond INCLUDE_QPROPERTIES
2668 Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2669 Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2673 Defines how the curve's line is represented visually in the plot. The line is drawn with the
2674 current pen of the curve (\ref setPen).
2677 enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters)
2678 ,lsLine ///< Data points are connected with a straight line
2680 explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
2681 virtual ~QCPCurve();
2684 QCPCurveDataMap *data() const { return mData; }
2685 QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2686 LineStyle lineStyle() const { return mLineStyle; }
2689 void setData(QCPCurveDataMap *data, bool copy=false);
2690 void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
2691 void setData(const QVector<double> &key, const QVector<double> &value);
2692 void setScatterStyle(const QCPScatterStyle &style);
2693 void setLineStyle(LineStyle style);
2695 // non-property methods:
2696 void addData(const QCPCurveDataMap &dataMap);
2697 void addData(const QCPCurveData &data);
2698 void addData(double t, double key, double value);
2699 void addData(double key, double value);
2700 void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
2701 void removeDataBefore(double t);
2702 void removeDataAfter(double t);
2703 void removeData(double fromt, double tot);
2704 void removeData(double t);
2706 // reimplemented virtual methods:
2707 virtual void clearData();
2708 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2711 // property members:
2712 QCPCurveDataMap *mData;
2713 QCPScatterStyle mScatterStyle;
2714 LineStyle mLineStyle;
2716 // reimplemented virtual methods:
2717 virtual void draw(QCPPainter *painter);
2718 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2719 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2720 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2722 // introduced virtual methods:
2723 virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
2725 // non-virtual methods:
2726 void getCurveData(QVector<QPointF> *lineData) const;
2727 int getRegion(double x, double y, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2728 QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2729 QVector<QPointF> getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom) const;
2730 bool mayTraverse(int prevRegion, int currentRegion) const;
2731 bool getTraverse(double prevKey, double prevValue, double key, double value, double rectLeft, double rectTop, double rectRight, double rectBottom, QPointF &crossA, QPointF &crossB) const;
2732 void getTraverseCornerPoints(int prevRegion, int currentRegion, double rectLeft, double rectTop, double rectRight, double rectBottom, QVector<QPointF> &beforeTraverse, QVector<QPointF> &afterTraverse) const;
2733 double pointDistance(const QPointF &pixelPoint) const;
2735 friend class QCustomPlot;
2736 friend class QCPLegend;
2744 class QCP_LIB_DECL QCPBarsGroup : public QObject
2747 /// \cond INCLUDE_QPROPERTIES
2748 Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType)
2749 Q_PROPERTY(double spacing READ spacing WRITE setSpacing)
2753 Defines the ways the spacing between bars in the group can be specified. Thus it defines what
2754 the number passed to \ref setSpacing actually means.
2756 \see setSpacingType, setSpacing
2758 enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels
2759 ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size
2760 ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range
2762 QCPBarsGroup(QCustomPlot *parentPlot);
2766 SpacingType spacingType() const { return mSpacingType; }
2767 double spacing() const { return mSpacing; }
2770 void setSpacingType(SpacingType spacingType);
2771 void setSpacing(double spacing);
2773 // non-virtual methods:
2774 QList<QCPBars*> bars() const { return mBars; }
2775 QCPBars* bars(int index) const;
2776 int size() const { return mBars.size(); }
2777 bool isEmpty() const { return mBars.isEmpty(); }
2779 bool contains(QCPBars *bars) const { return mBars.contains(bars); }
2780 void append(QCPBars *bars);
2781 void insert(int i, QCPBars *bars);
2782 void remove(QCPBars *bars);
2785 // non-property members:
2786 QCustomPlot *mParentPlot;
2787 SpacingType mSpacingType;
2789 QList<QCPBars*> mBars;
2791 // non-virtual methods:
2792 void registerBars(QCPBars *bars);
2793 void unregisterBars(QCPBars *bars);
2796 double keyPixelOffset(const QCPBars *bars, double keyCoord);
2797 double getPixelSpacing(const QCPBars *bars, double keyCoord);
2800 Q_DISABLE_COPY(QCPBarsGroup)
2802 friend class QCPBars;
2806 class QCP_LIB_DECL QCPBarData
2810 QCPBarData(double key, double value);
2813 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
2815 /*! \typedef QCPBarDataMap
2816 Container for storing \ref QCPBarData items in a sorted fashion. The key of the map
2817 is the key member of the QCPBarData instance.
2819 This is the container in which QCPBars holds its data.
2820 \see QCPBarData, QCPBars::setData
2822 typedef QMap<double, QCPBarData> QCPBarDataMap;
2823 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
2824 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
2827 class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
2830 /// \cond INCLUDE_QPROPERTIES
2831 Q_PROPERTY(double width READ width WRITE setWidth)
2832 Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType)
2833 Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup)
2834 Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue)
2835 Q_PROPERTY(QCPBars* barBelow READ barBelow)
2836 Q_PROPERTY(QCPBars* barAbove READ barAbove)
2840 Defines the ways the width of the bar can be specified. Thus it defines what the number passed
2841 to \ref setWidth actually means.
2843 \see setWidthType, setWidth
2845 enum WidthType { wtAbsolute ///< Bar width is in absolute pixels
2846 ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size
2847 ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range
2851 explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
2855 double width() const { return mWidth; }
2856 WidthType widthType() const { return mWidthType; }
2857 QCPBarsGroup *barsGroup() const { return mBarsGroup; }
2858 double baseValue() const { return mBaseValue; }
2859 QCPBars *barBelow() const { return mBarBelow.data(); }
2860 QCPBars *barAbove() const { return mBarAbove.data(); }
2861 QCPBarDataMap *data() const { return mData; }
2864 void setWidth(double width);
2865 void setWidthType(WidthType widthType);
2866 void setBarsGroup(QCPBarsGroup *barsGroup);
2867 void setBaseValue(double baseValue);
2868 void setData(QCPBarDataMap *data, bool copy=false);
2869 void setData(const QVector<double> &key, const QVector<double> &value);
2871 // non-property methods:
2872 void moveBelow(QCPBars *bars);
2873 void moveAbove(QCPBars *bars);
2874 void addData(const QCPBarDataMap &dataMap);
2875 void addData(const QCPBarData &data);
2876 void addData(double key, double value);
2877 void addData(const QVector<double> &keys, const QVector<double> &values);
2878 void removeDataBefore(double key);
2879 void removeDataAfter(double key);
2880 void removeData(double fromKey, double toKey);
2881 void removeData(double key);
2883 // reimplemented virtual methods:
2884 virtual void clearData();
2885 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2888 // property members:
2889 QCPBarDataMap *mData;
2891 WidthType mWidthType;
2892 QCPBarsGroup *mBarsGroup;
2894 QPointer<QCPBars> mBarBelow, mBarAbove;
2896 // reimplemented virtual methods:
2897 virtual void draw(QCPPainter *painter);
2898 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2899 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2900 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2902 // non-virtual methods:
2903 void getVisibleDataBounds(QCPBarDataMap::const_iterator &lower, QCPBarDataMap::const_iterator &upperEnd) const;
2904 QPolygonF getBarPolygon(double key, double value) const;
2905 void getPixelWidth(double key, double &lower, double &upper) const;
2906 double getStackedBaseValue(double key, bool positive) const;
2907 static void connectBars(QCPBars* lower, QCPBars* upper);
2909 friend class QCustomPlot;
2910 friend class QCPLegend;
2911 friend class QCPBarsGroup;
2919 class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
2922 /// \cond INCLUDE_QPROPERTIES
2923 Q_PROPERTY(double key READ key WRITE setKey)
2924 Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
2925 Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
2926 Q_PROPERTY(double median READ median WRITE setMedian)
2927 Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
2928 Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
2929 Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers)
2930 Q_PROPERTY(double width READ width WRITE setWidth)
2931 Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
2932 Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
2933 Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
2934 Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
2935 Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
2938 explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
2941 double key() const { return mKey; }
2942 double minimum() const { return mMinimum; }
2943 double lowerQuartile() const { return mLowerQuartile; }
2944 double median() const { return mMedian; }
2945 double upperQuartile() const { return mUpperQuartile; }
2946 double maximum() const { return mMaximum; }
2947 QVector<double> outliers() const { return mOutliers; }
2948 double width() const { return mWidth; }
2949 double whiskerWidth() const { return mWhiskerWidth; }
2950 QPen whiskerPen() const { return mWhiskerPen; }
2951 QPen whiskerBarPen() const { return mWhiskerBarPen; }
2952 QPen medianPen() const { return mMedianPen; }
2953 QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
2956 void setKey(double key);
2957 void setMinimum(double value);
2958 void setLowerQuartile(double value);
2959 void setMedian(double value);
2960 void setUpperQuartile(double value);
2961 void setMaximum(double value);
2962 void setOutliers(const QVector<double> &values);
2963 void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
2964 void setWidth(double width);
2965 void setWhiskerWidth(double width);
2966 void setWhiskerPen(const QPen &pen);
2967 void setWhiskerBarPen(const QPen &pen);
2968 void setMedianPen(const QPen &pen);
2969 void setOutlierStyle(const QCPScatterStyle &style);
2971 // non-property methods:
2972 virtual void clearData();
2973 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2976 // property members:
2977 QVector<double> mOutliers;
2978 double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
2980 double mWhiskerWidth;
2981 QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
2982 QCPScatterStyle mOutlierStyle;
2984 // reimplemented virtual methods:
2985 virtual void draw(QCPPainter *painter);
2986 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2987 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2988 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2990 // introduced virtual methods:
2991 virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
2992 virtual void drawMedian(QCPPainter *painter) const;
2993 virtual void drawWhiskers(QCPPainter *painter) const;
2994 virtual void drawOutliers(QCPPainter *painter) const;
2996 friend class QCustomPlot;
2997 friend class QCPLegend;
3001 class QCP_LIB_DECL QCPColorMapData
3004 QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange);
3006 QCPColorMapData(const QCPColorMapData &other);
3007 QCPColorMapData &operator=(const QCPColorMapData &other);
3010 int keySize() const { return mKeySize; }
3011 int valueSize() const { return mValueSize; }
3012 QCPRange keyRange() const { return mKeyRange; }
3013 QCPRange valueRange() const { return mValueRange; }
3014 QCPRange dataBounds() const { return mDataBounds; }
3015 double data(double key, double value);
3016 double cell(int keyIndex, int valueIndex);
3019 void setSize(int keySize, int valueSize);
3020 void setKeySize(int keySize);
3021 void setValueSize(int valueSize);
3022 void setRange(const QCPRange &keyRange, const QCPRange &valueRange);
3023 void setKeyRange(const QCPRange &keyRange);
3024 void setValueRange(const QCPRange &valueRange);
3025 void setData(double key, double value, double z);
3026 void setCell(int keyIndex, int valueIndex, double z);
3028 // non-property methods:
3029 void recalculateDataBounds();
3031 void fill(double z);
3032 bool isEmpty() const { return mIsEmpty; }
3033 void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const;
3034 void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const;
3037 // property members:
3038 int mKeySize, mValueSize;
3039 QCPRange mKeyRange, mValueRange;
3041 // non-property members:
3043 QCPRange mDataBounds;
3046 friend class QCPColorMap;
3050 class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
3053 /// \cond INCLUDE_QPROPERTIES
3054 Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
3055 Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
3056 Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
3057 Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
3058 Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
3059 Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
3062 explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis);
3063 virtual ~QCPColorMap();
3066 QCPColorMapData *data() const { return mMapData; }
3067 QCPRange dataRange() const { return mDataRange; }
3068 QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
3069 bool interpolate() const { return mInterpolate; }
3070 bool tightBoundary() const { return mTightBoundary; }
3071 QCPColorGradient gradient() const { return mGradient; }
3072 QCPColorScale *colorScale() const { return mColorScale.data(); }
3075 void setData(QCPColorMapData *data, bool copy=false);
3076 Q_SLOT void setDataRange(const QCPRange &dataRange);
3077 Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
3078 Q_SLOT void setGradient(const QCPColorGradient &gradient);
3079 void setInterpolate(bool enabled);
3080 void setTightBoundary(bool enabled);
3081 void setColorScale(QCPColorScale *colorScale);
3083 // non-property methods:
3084 void rescaleDataRange(bool recalculateDataBounds=false);
3085 Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18));
3087 // reimplemented virtual methods:
3088 virtual void clearData();
3089 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3092 void dataRangeChanged(QCPRange newRange);
3093 void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
3094 void gradientChanged(QCPColorGradient newGradient);
3097 // property members:
3098 QCPRange mDataRange;
3099 QCPAxis::ScaleType mDataScaleType;
3100 QCPColorMapData *mMapData;
3101 QCPColorGradient mGradient;
3103 bool mTightBoundary;
3104 QPointer<QCPColorScale> mColorScale;
3105 // non-property members:
3106 QImage mMapImage, mUndersampledMapImage;
3107 QPixmap mLegendIcon;
3108 bool mMapImageInvalidated;
3110 // introduced virtual methods:
3111 virtual void updateMapImage();
3113 // reimplemented virtual methods:
3114 virtual void draw(QCPPainter *painter);
3115 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
3116 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3117 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3119 friend class QCustomPlot;
3120 friend class QCPLegend;
3128 class QCP_LIB_DECL QCPFinancialData
3132 QCPFinancialData(double key, double open, double high, double low, double close);
3133 double key, open, high, low, close;
3135 Q_DECLARE_TYPEINFO(QCPFinancialData, Q_MOVABLE_TYPE);
3137 /*! \typedef QCPFinancialDataMap
3138 Container for storing \ref QCPFinancialData items in a sorted fashion. The key of the map
3139 is the key member of the QCPFinancialData instance.
3141 This is the container in which QCPFinancial holds its data.
3142 \see QCPFinancial, QCPFinancial::setData
3144 typedef QMap<double, QCPFinancialData> QCPFinancialDataMap;
3145 typedef QMapIterator<double, QCPFinancialData> QCPFinancialDataMapIterator;
3146 typedef QMutableMapIterator<double, QCPFinancialData> QCPFinancialDataMutableMapIterator;
3149 class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable
3152 /// \cond INCLUDE_QPROPERTIES
3153 Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle)
3154 Q_PROPERTY(double width READ width WRITE setWidth)
3155 Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored)
3156 Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive)
3157 Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative)
3158 Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive)
3159 Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative)
3163 Defines the possible representations of OHLC data in the plot.
3167 enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation
3168 ,csCandlestick ///< Candlestick representation
3172 explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis);
3173 virtual ~QCPFinancial();
3176 QCPFinancialDataMap *data() const { return mData; }
3177 ChartStyle chartStyle() const { return mChartStyle; }
3178 double width() const { return mWidth; }
3179 bool twoColored() const { return mTwoColored; }
3180 QBrush brushPositive() const { return mBrushPositive; }
3181 QBrush brushNegative() const { return mBrushNegative; }
3182 QPen penPositive() const { return mPenPositive; }
3183 QPen penNegative() const { return mPenNegative; }
3187 void setData(QCPFinancialDataMap *data, bool copy=false);
3188 void setData(const QVector<double> &key, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close);
3189 void setChartStyle(ChartStyle style);
3190 void setWidth(double width);
3191 void setTwoColored(bool twoColored);
3192 void setBrushPositive(const QBrush &brush);
3193 void setBrushNegative(const QBrush &brush);
3194 void setPenPositive(const QPen &pen);
3195 void setPenNegative(const QPen &pen);
3197 // non-property methods:
3198 void addData(const QCPFinancialDataMap &dataMap);
3199 void addData(const QCPFinancialData &data);
3200 void addData(double key, double open, double high, double low, double close);
3201 void addData(const QVector<double> &key, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close);
3202 void removeDataBefore(double key);
3203 void removeDataAfter(double key);
3204 void removeData(double fromKey, double toKey);
3205 void removeData(double key);
3207 // reimplemented virtual methods:
3208 virtual void clearData();
3209 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3212 static QCPFinancialDataMap timeSeriesToOhlc(const QVector<double> &time, const QVector<double> &value, double timeBinSize, double timeBinOffset = 0);
3215 // property members:
3216 QCPFinancialDataMap *mData;
3217 ChartStyle mChartStyle;
3220 QBrush mBrushPositive, mBrushNegative;
3221 QPen mPenPositive, mPenNegative;
3223 // reimplemented virtual methods:
3224 virtual void draw(QCPPainter *painter);
3225 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
3226 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3227 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
3229 // non-virtual methods:
3230 void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end);
3231 void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end);
3232 double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end) const;
3233 double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataMap::const_iterator &begin, const QCPFinancialDataMap::const_iterator &end) const;
3234 void getVisibleDataBounds(QCPFinancialDataMap::const_iterator &lower, QCPFinancialDataMap::const_iterator &upper) const;
3236 friend class QCustomPlot;
3237 friend class QCPLegend;
3241 class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
3244 /// \cond INCLUDE_QPROPERTIES
3245 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3246 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3249 QCPItemStraightLine(QCustomPlot *parentPlot);
3250 virtual ~QCPItemStraightLine();
3253 QPen pen() const { return mPen; }
3254 QPen selectedPen() const { return mSelectedPen; }
3257 void setPen(const QPen &pen);
3258 void setSelectedPen(const QPen &pen);
3260 // reimplemented virtual methods:
3261 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3263 QCPItemPosition * const point1;
3264 QCPItemPosition * const point2;
3267 // property members:
3268 QPen mPen, mSelectedPen;
3270 // reimplemented virtual methods:
3271 virtual void draw(QCPPainter *painter);
3273 // non-virtual methods:
3274 double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
3275 QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
3276 QPen mainPen() const;
3280 class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
3283 /// \cond INCLUDE_QPROPERTIES
3284 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3285 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3286 Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3287 Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3290 QCPItemLine(QCustomPlot *parentPlot);
3291 virtual ~QCPItemLine();
3294 QPen pen() const { return mPen; }
3295 QPen selectedPen() const { return mSelectedPen; }
3296 QCPLineEnding head() const { return mHead; }
3297 QCPLineEnding tail() const { return mTail; }
3300 void setPen(const QPen &pen);
3301 void setSelectedPen(const QPen &pen);
3302 void setHead(const QCPLineEnding &head);
3303 void setTail(const QCPLineEnding &tail);
3305 // reimplemented virtual methods:
3306 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3308 QCPItemPosition * const start;
3309 QCPItemPosition * const end;
3312 // property members:
3313 QPen mPen, mSelectedPen;
3314 QCPLineEnding mHead, mTail;
3316 // reimplemented virtual methods:
3317 virtual void draw(QCPPainter *painter);
3319 // non-virtual methods:
3320 QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
3321 QPen mainPen() const;
3325 class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
3328 /// \cond INCLUDE_QPROPERTIES
3329 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3330 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3331 Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3332 Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3335 QCPItemCurve(QCustomPlot *parentPlot);
3336 virtual ~QCPItemCurve();
3339 QPen pen() const { return mPen; }
3340 QPen selectedPen() const { return mSelectedPen; }
3341 QCPLineEnding head() const { return mHead; }
3342 QCPLineEnding tail() const { return mTail; }
3345 void setPen(const QPen &pen);
3346 void setSelectedPen(const QPen &pen);
3347 void setHead(const QCPLineEnding &head);
3348 void setTail(const QCPLineEnding &tail);
3350 // reimplemented virtual methods:
3351 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3353 QCPItemPosition * const start;
3354 QCPItemPosition * const startDir;
3355 QCPItemPosition * const endDir;
3356 QCPItemPosition * const end;
3359 // property members:
3360 QPen mPen, mSelectedPen;
3361 QCPLineEnding mHead, mTail;
3363 // reimplemented virtual methods:
3364 virtual void draw(QCPPainter *painter);
3366 // non-virtual methods:
3367 QPen mainPen() const;
3371 class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
3374 /// \cond INCLUDE_QPROPERTIES
3375 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3376 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3377 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3378 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3381 QCPItemRect(QCustomPlot *parentPlot);
3382 virtual ~QCPItemRect();
3385 QPen pen() const { return mPen; }
3386 QPen selectedPen() const { return mSelectedPen; }
3387 QBrush brush() const { return mBrush; }
3388 QBrush selectedBrush() const { return mSelectedBrush; }
3391 void setPen(const QPen &pen);
3392 void setSelectedPen(const QPen &pen);
3393 void setBrush(const QBrush &brush);
3394 void setSelectedBrush(const QBrush &brush);
3396 // reimplemented virtual methods:
3397 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3399 QCPItemPosition * const topLeft;
3400 QCPItemPosition * const bottomRight;
3401 QCPItemAnchor * const top;
3402 QCPItemAnchor * const topRight;
3403 QCPItemAnchor * const right;
3404 QCPItemAnchor * const bottom;
3405 QCPItemAnchor * const bottomLeft;
3406 QCPItemAnchor * const left;
3409 enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3411 // property members:
3412 QPen mPen, mSelectedPen;
3413 QBrush mBrush, mSelectedBrush;
3415 // reimplemented virtual methods:
3416 virtual void draw(QCPPainter *painter);
3417 virtual QPointF anchorPixelPoint(int anchorId) const;
3419 // non-virtual methods:
3420 QPen mainPen() const;
3421 QBrush mainBrush() const;
3425 class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
3428 /// \cond INCLUDE_QPROPERTIES
3429 Q_PROPERTY(QColor color READ color WRITE setColor)
3430 Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
3431 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3432 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3433 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3434 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3435 Q_PROPERTY(QFont font READ font WRITE setFont)
3436 Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
3437 Q_PROPERTY(QString text READ text WRITE setText)
3438 Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
3439 Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
3440 Q_PROPERTY(double rotation READ rotation WRITE setRotation)
3441 Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
3444 QCPItemText(QCustomPlot *parentPlot);
3445 virtual ~QCPItemText();
3448 QColor color() const { return mColor; }
3449 QColor selectedColor() const { return mSelectedColor; }
3450 QPen pen() const { return mPen; }
3451 QPen selectedPen() const { return mSelectedPen; }
3452 QBrush brush() const { return mBrush; }
3453 QBrush selectedBrush() const { return mSelectedBrush; }
3454 QFont font() const { return mFont; }
3455 QFont selectedFont() const { return mSelectedFont; }
3456 QString text() const { return mText; }
3457 Qt::Alignment positionAlignment() const { return mPositionAlignment; }
3458 Qt::Alignment textAlignment() const { return mTextAlignment; }
3459 double rotation() const { return mRotation; }
3460 QMargins padding() const { return mPadding; }
3463 void setColor(const QColor &color);
3464 void setSelectedColor(const QColor &color);
3465 void setPen(const QPen &pen);
3466 void setSelectedPen(const QPen &pen);
3467 void setBrush(const QBrush &brush);
3468 void setSelectedBrush(const QBrush &brush);
3469 void setFont(const QFont &font);
3470 void setSelectedFont(const QFont &font);
3471 void setText(const QString &text);
3472 void setPositionAlignment(Qt::Alignment alignment);
3473 void setTextAlignment(Qt::Alignment alignment);
3474 void setRotation(double degrees);
3475 void setPadding(const QMargins &padding);
3477 // reimplemented virtual methods:
3478 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3480 QCPItemPosition * const position;
3481 QCPItemAnchor * const topLeft;
3482 QCPItemAnchor * const top;
3483 QCPItemAnchor * const topRight;
3484 QCPItemAnchor * const right;
3485 QCPItemAnchor * const bottomRight;
3486 QCPItemAnchor * const bottom;
3487 QCPItemAnchor * const bottomLeft;
3488 QCPItemAnchor * const left;
3491 enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
3493 // property members:
3494 QColor mColor, mSelectedColor;
3495 QPen mPen, mSelectedPen;
3496 QBrush mBrush, mSelectedBrush;
3497 QFont mFont, mSelectedFont;
3499 Qt::Alignment mPositionAlignment;
3500 Qt::Alignment mTextAlignment;
3504 // reimplemented virtual methods:
3505 virtual void draw(QCPPainter *painter);
3506 virtual QPointF anchorPixelPoint(int anchorId) const;
3508 // non-virtual methods:
3509 QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
3510 QFont mainFont() const;
3511 QColor mainColor() const;
3512 QPen mainPen() const;
3513 QBrush mainBrush() const;
3517 class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
3520 /// \cond INCLUDE_QPROPERTIES
3521 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3522 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3523 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3524 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3527 QCPItemEllipse(QCustomPlot *parentPlot);
3528 virtual ~QCPItemEllipse();
3531 QPen pen() const { return mPen; }
3532 QPen selectedPen() const { return mSelectedPen; }
3533 QBrush brush() const { return mBrush; }
3534 QBrush selectedBrush() const { return mSelectedBrush; }
3537 void setPen(const QPen &pen);
3538 void setSelectedPen(const QPen &pen);
3539 void setBrush(const QBrush &brush);
3540 void setSelectedBrush(const QBrush &brush);
3542 // reimplemented virtual methods:
3543 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3545 QCPItemPosition * const topLeft;
3546 QCPItemPosition * const bottomRight;
3547 QCPItemAnchor * const topLeftRim;
3548 QCPItemAnchor * const top;
3549 QCPItemAnchor * const topRightRim;
3550 QCPItemAnchor * const right;
3551 QCPItemAnchor * const bottomRightRim;
3552 QCPItemAnchor * const bottom;
3553 QCPItemAnchor * const bottomLeftRim;
3554 QCPItemAnchor * const left;
3555 QCPItemAnchor * const center;
3558 enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
3560 // property members:
3561 QPen mPen, mSelectedPen;
3562 QBrush mBrush, mSelectedBrush;
3564 // reimplemented virtual methods:
3565 virtual void draw(QCPPainter *painter);
3566 virtual QPointF anchorPixelPoint(int anchorId) const;
3568 // non-virtual methods:
3569 QPen mainPen() const;
3570 QBrush mainBrush() const;
3574 class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
3577 /// \cond INCLUDE_QPROPERTIES
3578 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
3579 Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
3580 Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
3581 Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode)
3582 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3583 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3586 QCPItemPixmap(QCustomPlot *parentPlot);
3587 virtual ~QCPItemPixmap();
3590 QPixmap pixmap() const { return mPixmap; }
3591 bool scaled() const { return mScaled; }
3592 Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
3593 Qt::TransformationMode transformationMode() const { return mTransformationMode; }
3594 QPen pen() const { return mPen; }
3595 QPen selectedPen() const { return mSelectedPen; }
3598 void setPixmap(const QPixmap &pixmap);
3599 void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation);
3600 void setPen(const QPen &pen);
3601 void setSelectedPen(const QPen &pen);
3603 // reimplemented virtual methods:
3604 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3606 QCPItemPosition * const topLeft;
3607 QCPItemPosition * const bottomRight;
3608 QCPItemAnchor * const top;
3609 QCPItemAnchor * const topRight;
3610 QCPItemAnchor * const right;
3611 QCPItemAnchor * const bottom;
3612 QCPItemAnchor * const bottomLeft;
3613 QCPItemAnchor * const left;
3616 enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3618 // property members:
3620 QPixmap mScaledPixmap;
3622 bool mScaledPixmapInvalidated;
3623 Qt::AspectRatioMode mAspectRatioMode;
3624 Qt::TransformationMode mTransformationMode;
3625 QPen mPen, mSelectedPen;
3627 // reimplemented virtual methods:
3628 virtual void draw(QCPPainter *painter);
3629 virtual QPointF anchorPixelPoint(int anchorId) const;
3631 // non-virtual methods:
3632 void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
3633 QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
3634 QPen mainPen() const;
3638 class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
3641 /// \cond INCLUDE_QPROPERTIES
3642 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3643 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3644 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3645 Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3646 Q_PROPERTY(double size READ size WRITE setSize)
3647 Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
3648 Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
3649 Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
3650 Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
3654 The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize.
3658 enum TracerStyle { tsNone ///< The tracer is not visible
3659 ,tsPlus ///< A plus shaped crosshair with limited size
3660 ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect
3661 ,tsCircle ///< A circle
3662 ,tsSquare ///< A square
3664 Q_ENUMS(TracerStyle)
3666 QCPItemTracer(QCustomPlot *parentPlot);
3667 virtual ~QCPItemTracer();
3670 QPen pen() const { return mPen; }
3671 QPen selectedPen() const { return mSelectedPen; }
3672 QBrush brush() const { return mBrush; }
3673 QBrush selectedBrush() const { return mSelectedBrush; }
3674 double size() const { return mSize; }
3675 TracerStyle style() const { return mStyle; }
3676 QCPGraph *graph() const { return mGraph; }
3677 double graphKey() const { return mGraphKey; }
3678 bool interpolating() const { return mInterpolating; }
3681 void setPen(const QPen &pen);
3682 void setSelectedPen(const QPen &pen);
3683 void setBrush(const QBrush &brush);
3684 void setSelectedBrush(const QBrush &brush);
3685 void setSize(double size);
3686 void setStyle(TracerStyle style);
3687 void setGraph(QCPGraph *graph);
3688 void setGraphKey(double key);
3689 void setInterpolating(bool enabled);
3691 // reimplemented virtual methods:
3692 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3694 // non-virtual methods:
3695 void updatePosition();
3697 QCPItemPosition * const position;
3700 // property members:
3701 QPen mPen, mSelectedPen;
3702 QBrush mBrush, mSelectedBrush;
3707 bool mInterpolating;
3709 // reimplemented virtual methods:
3710 virtual void draw(QCPPainter *painter);
3712 // non-virtual methods:
3713 QPen mainPen() const;
3714 QBrush mainBrush() const;
3718 class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
3721 /// \cond INCLUDE_QPROPERTIES
3722 Q_PROPERTY(QPen pen READ pen WRITE setPen)
3723 Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3724 Q_PROPERTY(double length READ length WRITE setLength)
3725 Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
3728 enum BracketStyle { bsSquare ///< A brace with angled edges
3729 ,bsRound ///< A brace with round edges
3730 ,bsCurly ///< A curly brace
3731 ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
3734 QCPItemBracket(QCustomPlot *parentPlot);
3735 virtual ~QCPItemBracket();
3738 QPen pen() const { return mPen; }
3739 QPen selectedPen() const { return mSelectedPen; }
3740 double length() const { return mLength; }
3741 BracketStyle style() const { return mStyle; }
3744 void setPen(const QPen &pen);
3745 void setSelectedPen(const QPen &pen);
3746 void setLength(double length);
3747 void setStyle(BracketStyle style);
3749 // reimplemented virtual methods:
3750 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3752 QCPItemPosition * const left;
3753 QCPItemPosition * const right;
3754 QCPItemAnchor * const center;
3757 // property members:
3758 enum AnchorIndex {aiCenter};
3759 QPen mPen, mSelectedPen;
3761 BracketStyle mStyle;
3763 // reimplemented virtual methods:
3764 virtual void draw(QCPPainter *painter);
3765 virtual QPointF anchorPixelPoint(int anchorId) const;
3767 // non-virtual methods:
3768 QPen mainPen() const;
3771 #endif // QCUSTOMPLOT_H