Guest User

Untitled

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