00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #ifndef QCUSTOMPLOT_H
00028 #define QCUSTOMPLOT_H
00029
00030 #include <QObject>
00031 #include <QWidget>
00032 #include <QPainter>
00033 #include <QPaintEvent>
00034 #include <QPixmap>
00035 #include <QVector>
00036 #include <QString>
00037 #include <QPrinter>
00038 #include <QDateTime>
00039 #include <QMultiMap>
00040 #include <QFlags>
00041 #include <QDebug>
00042 #include <QVector2D>
00043 #include <QStack>
00044 #include <qmath.h>
00045 #include <limits>
00046
00047
00048 #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
00049 # define QCP_LIB_DECL Q_DECL_EXPORT
00050 #elif defined(QCUSTOMPLOT_USE_LIBRARY)
00051 # define QCP_LIB_DECL Q_DECL_IMPORT
00052 #else
00053 # define QCP_LIB_DECL
00054 #endif
00055
00056 class QCustomPlot;
00057 class QCPLegend;
00058 class QCPRange;
00059 class QCPLayerable;
00060 class QCPAbstractItem;
00061 class QCPItemPosition;
00062 class QCPAxis;
00063 class QCPData;
00064
00068 namespace QCP
00069 {
00079 enum ScatterStyle { ssNone
00080 ,ssDot
00081 ,ssCross
00082 ,ssPlus
00083 ,ssCircle
00084 ,ssDisc
00085 ,ssSquare
00086 ,ssDiamond
00087 ,ssStar
00088 ,ssTriangle
00089 ,ssTriangleInverted
00090 ,ssCrossSquare
00091 ,ssPlusSquare
00092 ,ssCrossCircle
00093 ,ssPlusCircle
00094 ,ssPeace
00095 ,ssPixmap
00096 };
00097
00108 enum AntialiasedElement { aeAxes = 0x0001
00109 ,aeGrid = 0x0002
00110 ,aeSubGrid = 0x0004
00111 ,aeLegend = 0x0008
00112 ,aeLegendItems = 0x0010
00113 ,aePlottables = 0x0020
00114 ,aeItems = 0x0040
00115 ,aeScatters = 0x0080
00116 ,aeErrorBars = 0x0100
00117 ,aeFills = 0x0200
00118 ,aeZeroLine = 0x0400
00119 ,aeAll = 0xFFFF
00120 ,aeNone = 0x0000
00121 };
00122 Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
00123
00124
00128 enum PlottingHint { phNone = 0x000
00129 ,phFastPolylines = 0x001
00130
00131 ,phForceRepaint = 0x002
00132
00133 };
00134 Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
00135 }
00136
00137 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
00138 Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
00139
00140 class QCP_LIB_DECL QCPData
00141 {
00142 public:
00143 QCPData();
00144 QCPData(double key, double value);
00145 double key, value;
00146 double keyErrorPlus, keyErrorMinus;
00147 double valueErrorPlus, valueErrorMinus;
00148 };
00149 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
00150
00158 typedef QMap<double, QCPData> QCPDataMap;
00159 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
00160 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
00161
00162 class QCP_LIB_DECL QCPCurveData
00163 {
00164 public:
00165 QCPCurveData();
00166 QCPCurveData(double t, double key, double value);
00167 double t, key, value;
00168 };
00169 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
00170
00179 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
00180 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
00181 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
00182
00183 class QCP_LIB_DECL QCPBarData
00184 {
00185 public:
00186 QCPBarData();
00187 QCPBarData(double key, double value);
00188 double key, value;
00189 };
00190 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
00191
00199 typedef QMap<double, QCPBarData> QCPBarDataMap;
00200 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
00201 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
00202
00203 class QCP_LIB_DECL QCPPainter : public QPainter
00204 {
00205 public:
00206 QCPPainter();
00207 QCPPainter(QPaintDevice *device);
00208 ~QCPPainter();
00209
00210
00211 QPixmap scatterPixmap() const { return mScatterPixmap; }
00212 bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
00213 bool pdfExportMode() const { return mPdfExportMode; }
00214 bool scaledExportMode() const { return mScaledExportMode; }
00215
00216
00217 void setScatterPixmap(const QPixmap pm);
00218 void setAntialiasing(bool enabled);
00219 void setPdfExportMode(bool enabled);
00220 void setScaledExportMode(bool enabled);
00221
00222
00223 void setPen(const QPen &pen);
00224 void setPen(const QColor &color);
00225 void setPen(Qt::PenStyle penStyle);
00226 void drawLine(const QLineF &line);
00227 void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
00228 void save();
00229 void restore();
00230
00231
00232 void fixScaledPen();
00233 void drawScatter(double x, double y, double size, QCP::ScatterStyle style);
00234
00235 protected:
00236 QPixmap mScatterPixmap;
00237 bool mScaledExportMode;
00238 bool mPdfExportMode;
00239 bool mIsAntialiasing;
00240 QStack<bool> mAntialiasingStack;
00241 };
00242
00243 class QCP_LIB_DECL QCPLineEnding
00244 {
00245 public:
00257 enum EndingStyle { esNone
00258 ,esFlatArrow
00259 ,esSpikeArrow
00260 ,esLineArrow
00261 ,esDisc
00262 ,esSquare
00263 ,esDiamond
00264 ,esBar
00265 };
00266
00267 QCPLineEnding();
00268 QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
00269
00270
00271 EndingStyle style() const { return mStyle; }
00272 double width() const { return mWidth; }
00273 double length() const { return mLength; }
00274 bool inverted() const { return mInverted; }
00275
00276
00277 void setStyle(EndingStyle style);
00278 void setWidth(double width);
00279 void setLength(double length);
00280 void setInverted(bool inverted);
00281
00282
00283 double boundingDistance() const;
00284 void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
00285 void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
00286
00287 protected:
00288 EndingStyle mStyle;
00289 double mWidth, mLength;
00290 bool mInverted;
00291 };
00292 Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
00293
00294 class QCP_LIB_DECL QCPLayer
00295 {
00296 public:
00297 QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
00298 ~QCPLayer();
00299
00300
00301 QCustomPlot *parentPlot() const { return mParentPlot; }
00302 QString name() const { return mName; }
00303 int index() const;
00304 QList<QCPLayerable*> children() const { return mChildren; }
00305
00306 protected:
00307 QCustomPlot *mParentPlot;
00308 QString mName;
00309 QList<QCPLayerable*> mChildren;
00310
00311 void addChild(QCPLayerable *layerable, bool prepend);
00312 void removeChild(QCPLayerable *layerable);
00313
00314 private:
00315 Q_DISABLE_COPY(QCPLayer)
00316
00317 friend class QCPLayerable;
00318 };
00319
00320 class QCP_LIB_DECL QCPLayerable : public QObject
00321 {
00322 Q_OBJECT
00323 public:
00324 QCPLayerable(QCustomPlot *parentPlot);
00325 ~QCPLayerable();
00326
00327
00328 bool visible() const { return mVisible; }
00329 QCustomPlot *parentPlot() const { return mParentPlot; }
00330 QCPLayer *layer() const { return mLayer; }
00331 bool antialiased() const { return mAntialiased; }
00332
00333
00334 void setVisible(bool on);
00335 bool setLayer(QCPLayer *layer);
00336 bool setLayer(const QString &layerName);
00337 void setAntialiased(bool enabled);
00338
00339 protected:
00340 bool mVisible;
00341 QCustomPlot *mParentPlot;
00342 QCPLayer *mLayer;
00343 bool mAntialiased;
00344
00345
00346 bool moveToLayer(QCPLayer *layer, bool prepend);
00347
00348 void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
00349 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
00350 virtual QRect clipRect() const;
00351 virtual void draw(QCPPainter *painter) = 0;
00352
00353 private:
00354 Q_DISABLE_COPY(QCPLayerable)
00355
00356 friend class QCustomPlot;
00357 };
00358
00359 class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
00360 {
00361 Q_OBJECT
00362 public:
00363 QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
00364 virtual ~QCPAbstractPlottable() {}
00365
00366
00367 QString name() const { return mName; }
00368 bool antialiasedFill() const { return mAntialiasedFill; }
00369 bool antialiasedScatters() const { return mAntialiasedScatters; }
00370 bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
00371 QPen pen() const { return mPen; }
00372 QPen selectedPen() const { return mSelectedPen; }
00373 QBrush brush() const { return mBrush; }
00374 QBrush selectedBrush() const { return mSelectedBrush; }
00375 QCPAxis *keyAxis() const { return mKeyAxis; }
00376 QCPAxis *valueAxis() const { return mValueAxis; }
00377 bool selectable() const { return mSelectable; }
00378 bool selected() const { return mSelected; }
00379
00380
00381 void setName(const QString &name);
00382 void setAntialiasedFill(bool enabled);
00383 void setAntialiasedScatters(bool enabled);
00384 void setAntialiasedErrorBars(bool enabled);
00385 void setPen(const QPen &pen);
00386 void setSelectedPen(const QPen &pen);
00387 void setBrush(const QBrush &brush);
00388 void setSelectedBrush(const QBrush &brush);
00389 void setKeyAxis(QCPAxis *axis);
00390 void setValueAxis(QCPAxis *axis);
00391 void setSelectable(bool selectable);
00392 void setSelected(bool selected);
00393
00394
00395 void rescaleAxes(bool onlyEnlarge=false) const;
00396 void rescaleKeyAxis(bool onlyEnlarge=false) const;
00397 void rescaleValueAxis(bool onlyEnlarge=false) const;
00398 virtual void clearData() = 0;
00399 virtual double selectTest(const QPointF &pos) const = 0;
00400 virtual bool addToLegend();
00401 virtual bool removeFromLegend() const;
00402
00403 signals:
00404 void selectionChanged(bool selected);
00405
00406 protected:
00410 enum SignDomain { sdNegative
00411 ,sdBoth
00412 ,sdPositive
00413 };
00414 QString mName;
00415 bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
00416 QPen mPen, mSelectedPen;
00417 QBrush mBrush, mSelectedBrush;
00418 QCPAxis *mKeyAxis, *mValueAxis;
00419 bool mSelected, mSelectable;
00420
00421 virtual QRect clipRect() const;
00422 virtual void draw(QCPPainter *painter) = 0;
00423 virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0;
00424 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
00425 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
00426
00427
00428 void coordsToPixels(double key, double value, double &x, double &y) const;
00429 const QPointF coordsToPixels(double key, double value) const;
00430 void pixelsToCoords(double x, double y, double &key, double &value) const;
00431 void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
00432 QPen mainPen() const;
00433 QBrush mainBrush() const;
00434 void applyDefaultAntialiasingHint(QCPPainter *painter) const;
00435 void applyFillAntialiasingHint(QCPPainter *painter) const;
00436 void applyScattersAntialiasingHint(QCPPainter *painter) const;
00437 void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
00438
00439
00440 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
00441
00442 private:
00443 Q_DISABLE_COPY(QCPAbstractPlottable)
00444
00445 friend class QCustomPlot;
00446 friend class QCPPlottableLegendItem;
00447 };
00448
00449 class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
00450 {
00451 Q_OBJECT
00452 public:
00458 enum LineStyle { lsNone
00459
00460 ,lsLine
00461 ,lsStepLeft
00462 ,lsStepRight
00463 ,lsStepCenter
00464 ,lsImpulse
00465 };
00466 Q_ENUMS(LineStyle)
00470 enum ErrorType { etNone
00471 ,etKey
00472 ,etValue
00473 ,etBoth
00474 };
00475 Q_ENUMS(ErrorType)
00476
00477 explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
00478 virtual ~QCPGraph();
00479
00480
00481 const QCPDataMap *data() const { return mData; }
00482 LineStyle lineStyle() const { return mLineStyle; }
00483 QCP::ScatterStyle scatterStyle() const { return mScatterStyle; }
00484 double scatterSize() const { return mScatterSize; }
00485 const QPixmap scatterPixmap() const { return mScatterPixmap; }
00486 ErrorType errorType() const { return mErrorType; }
00487 QPen errorPen() const { return mErrorPen; }
00488 double errorBarSize() const { return mErrorBarSize; }
00489 bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
00490 QCPGraph *channelFillGraph() const { return mChannelFillGraph; }
00491
00492
00493 void setData(QCPDataMap *data, bool copy=false);
00494 void setData(const QVector<double> &key, const QVector<double> &value);
00495 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
00496 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
00497 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
00498 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
00499 void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
00500 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);
00501 void setLineStyle(LineStyle ls);
00502 void setScatterStyle(QCP::ScatterStyle ss);
00503 void setScatterSize(double size);
00504 void setScatterPixmap(const QPixmap &pixmap);
00505 void setErrorType(ErrorType errorType);
00506 void setErrorPen(const QPen &pen);
00507 void setErrorBarSize(double size);
00508 void setErrorBarSkipSymbol(bool enabled);
00509 void setChannelFillGraph(QCPGraph *targetGraph);
00510
00511
00512 void addData(const QCPDataMap &dataMap);
00513 void addData(const QCPData &data);
00514 void addData(double key, double value);
00515 void addData(const QVector<double> &keys, const QVector<double> &values);
00516 void removeDataBefore(double key);
00517 void removeDataAfter(double key);
00518 void removeData(double fromKey, double toKey);
00519 void removeData(double key);
00520 virtual void clearData();
00521 virtual double selectTest(const QPointF &pos) const;
00522 using QCPAbstractPlottable::rescaleAxes;
00523 using QCPAbstractPlottable::rescaleKeyAxis;
00524 using QCPAbstractPlottable::rescaleValueAxis;
00525 virtual void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const;
00526 virtual void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const;
00527 virtual void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const;
00528
00529 protected:
00530 QCPDataMap *mData;
00531 QPen mErrorPen;
00532 LineStyle mLineStyle;
00533 QCP::ScatterStyle mScatterStyle;
00534 double mScatterSize;
00535 QPixmap mScatterPixmap;
00536 ErrorType mErrorType;
00537 double mErrorBarSize;
00538 bool mErrorBarSkipSymbol;
00539 QCPGraph *mChannelFillGraph;
00540
00541 virtual void draw(QCPPainter *painter);
00542 virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
00543
00544
00545 void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
00546
00547 void getScatterPlotData(QVector<QCPData> *pointData) const;
00548 void getLinePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
00549 void getStepLeftPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
00550 void getStepRightPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
00551 void getStepCenterPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
00552 void getImpulsePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
00553
00554
00555 void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
00556 void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *pointData) const;
00557 void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
00558 void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
00559 void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
00560
00561
00562 void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const;
00563 void addFillBasePoints(QVector<QPointF> *lineData) const;
00564 void removeFillBasePoints(QVector<QPointF> *lineData) const;
00565 QPointF lowerFillBasePoint(double lowerKey) const;
00566 QPointF upperFillBasePoint(double upperKey) const;
00567 const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
00568 int findIndexBelowX(const QVector<QPointF> *data, double x) const;
00569 int findIndexAboveX(const QVector<QPointF> *data, double x) const;
00570 int findIndexBelowY(const QVector<QPointF> *data, double y) const;
00571 int findIndexAboveY(const QVector<QPointF> *data, double y) const;
00572 double pointDistance(const QPointF &pixelPoint) const;
00573 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00574 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00575 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const;
00576 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const;
00577
00578 friend class QCustomPlot;
00579 friend class QCPLegend;
00580 };
00581
00582 class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
00583 {
00584 Q_OBJECT
00585 public:
00591 enum LineStyle { lsNone,
00592 lsLine
00593 };
00594 explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
00595 virtual ~QCPCurve();
00596
00597
00598 const QCPCurveDataMap *data() const { return mData; }
00599 QCP::ScatterStyle scatterStyle() const { return mScatterStyle; }
00600 double scatterSize() const { return mScatterSize; }
00601 QPixmap scatterPixmap() const { return mScatterPixmap; }
00602 LineStyle lineStyle() const { return mLineStyle; }
00603
00604
00605 void setData(QCPCurveDataMap *data, bool copy=false);
00606 void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
00607 void setData(const QVector<double> &key, const QVector<double> &value);
00608 void setScatterStyle(QCP::ScatterStyle style);
00609 void setScatterSize(double size);
00610 void setScatterPixmap(const QPixmap &pixmap);
00611 void setLineStyle(LineStyle style);
00612
00613
00614 void addData(const QCPCurveDataMap &dataMap);
00615 void addData(const QCPCurveData &data);
00616 void addData(double t, double key, double value);
00617 void addData(double key, double value);
00618 void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
00619 void removeDataBefore(double t);
00620 void removeDataAfter(double t);
00621 void removeData(double fromt, double tot);
00622 void removeData(double t);
00623 virtual void clearData();
00624 virtual double selectTest(const QPointF &pos) const;
00625
00626 protected:
00627 QCPCurveDataMap *mData;
00628 QCP::ScatterStyle mScatterStyle;
00629 double mScatterSize;
00630 QPixmap mScatterPixmap;
00631 LineStyle mLineStyle;
00632
00633 virtual void draw(QCPPainter *painter);
00634 virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
00635
00636 virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
00637
00638
00639 void getCurveData(QVector<QPointF> *lineData) const;
00640 double pointDistance(const QPointF &pixelPoint) const;
00641
00642 QPointF outsideCoordsToPixels(double key, double value, int region) const;
00643 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00644 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00645
00646 friend class QCustomPlot;
00647 friend class QCPLegend;
00648 };
00649
00650 class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
00651 {
00652 Q_OBJECT
00653 public:
00654 explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
00655 virtual ~QCPBars();
00656
00657
00658 double width() const { return mWidth; }
00659 QCPBars *barBelow() const { return mBarBelow; }
00660 QCPBars *barAbove() const { return mBarAbove; }
00661 const QCPBarDataMap *data() const { return mData; }
00662
00663
00664 void setWidth(double width);
00665 void setData(QCPBarDataMap *data, bool copy=false);
00666 void setData(const QVector<double> &key, const QVector<double> &value);
00667
00668
00669 void moveBelow(QCPBars *bars);
00670 void moveAbove(QCPBars *bars);
00671 void addData(const QCPBarDataMap &dataMap);
00672 void addData(const QCPBarData &data);
00673 void addData(double key, double value);
00674 void addData(const QVector<double> &keys, const QVector<double> &values);
00675 void removeDataBefore(double key);
00676 void removeDataAfter(double key);
00677 void removeData(double fromKey, double toKey);
00678 void removeData(double key);
00679 virtual void clearData();
00680 virtual double selectTest(const QPointF &pos) const;
00681
00682 protected:
00683 QCPBarDataMap *mData;
00684 double mWidth;
00685 QCPBars *mBarBelow, *mBarAbove;
00686
00687 virtual void draw(QCPPainter *painter);
00688 virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
00689
00690 QPolygonF getBarPolygon(double key, double value) const;
00691 double getBaseValue(double key, bool positive) const;
00692 static void connectBars(QCPBars* lower, QCPBars* upper);
00693 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00694 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00695
00696 friend class QCustomPlot;
00697 friend class QCPLegend;
00698 };
00699
00700 class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
00701 {
00702 Q_OBJECT
00703 public:
00704 explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
00705 virtual ~QCPStatisticalBox();
00706
00707
00708 double key() const { return mKey; }
00709 double minimum() const { return mMinimum; }
00710 double lowerQuartile() const { return mLowerQuartile; }
00711 double median() const { return mMedian; }
00712 double upperQuartile() const { return mUpperQuartile; }
00713 double maximum() const { return mMaximum; }
00714 QVector<double> outliers() const { return mOutliers; }
00715 double width() const { return mWidth; }
00716 double whiskerWidth() const { return mWhiskerWidth; }
00717 QPen whiskerPen() const { return mWhiskerPen; }
00718 QPen whiskerBarPen() const { return mWhiskerBarPen; }
00719 QPen medianPen() const { return mMedianPen; }
00720 double outlierSize() const { return mOutlierSize; }
00721 QPen outlierPen() const { return mOutlierPen; }
00722 QCP::ScatterStyle outlierStyle() const { return mOutlierStyle; }
00723
00724
00725 void setKey(double key);
00726 void setMinimum(double value);
00727 void setLowerQuartile(double value);
00728 void setMedian(double value);
00729 void setUpperQuartile(double value);
00730 void setMaximum(double value);
00731 void setOutliers(const QVector<double> &values);
00732 void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
00733 void setWidth(double width);
00734 void setWhiskerWidth(double width);
00735 void setWhiskerPen(const QPen &pen);
00736 void setWhiskerBarPen(const QPen &pen);
00737 void setMedianPen(const QPen &pen);
00738 void setOutlierSize(double pixels);
00739 void setOutlierPen(const QPen &pen);
00740 void setOutlierStyle(QCP::ScatterStyle style);
00741
00742
00743 virtual void clearData();
00744 virtual double selectTest(const QPointF &pos) const;
00745
00746 protected:
00747 QVector<double> mOutliers;
00748 double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
00749 double mWidth;
00750 double mWhiskerWidth;
00751 double mOutlierSize;
00752 QPen mWhiskerPen, mWhiskerBarPen, mOutlierPen, mMedianPen;
00753 QCP::ScatterStyle mOutlierStyle;
00754
00755 virtual void draw(QCPPainter *painter);
00756 virtual void drawLegendIcon(QCPPainter *painter, const QRect &rect) const;
00757
00758 virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
00759 virtual void drawMedian(QCPPainter *painter) const;
00760 virtual void drawWhiskers(QCPPainter *painter) const;
00761 virtual void drawOutliers(QCPPainter *painter) const;
00762 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00763 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
00764
00765 friend class QCustomPlot;
00766 friend class QCPLegend;
00767 };
00768
00769 class QCP_LIB_DECL QCPItemAnchor
00770 {
00771 public:
00772 QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
00773 virtual ~QCPItemAnchor();
00774
00775 QString name() const { return mName; }
00776 virtual QPointF pixelPoint() const;
00777
00778 protected:
00779 QCustomPlot *mParentPlot;
00780 QCPAbstractItem *mParentItem;
00781 int mAnchorId;
00782 QString mName;
00783
00784 QSet<QCPItemPosition*> mChildren;
00785
00786 void addChild(QCPItemPosition* pos);
00787 void removeChild(QCPItemPosition *pos);
00788
00789 private:
00790 Q_DISABLE_COPY(QCPItemAnchor)
00791
00792 friend class QCPItemPosition;
00793 };
00794
00795 class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
00796 {
00797 public:
00804 enum PositionType { ptAbsolute
00805 ,ptViewportRatio
00806 ,ptAxisRectRatio
00807 ,ptPlotCoords
00808 };
00809
00810 QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
00811 virtual ~QCPItemPosition();
00812
00813
00814 PositionType type() const { return mPositionType; }
00815 QCPItemAnchor *parentAnchor() const { return mParentAnchor; }
00816 double key() const { return mKey; }
00817 double value() const { return mValue; }
00818 QPointF coords() const { return QPointF(mKey, mValue); }
00819 QCPAxis *keyAxis() const { return mKeyAxis; }
00820 QCPAxis *valueAxis() const { return mValueAxis; }
00821 virtual QPointF pixelPoint() const;
00822
00823
00824 void setType(PositionType type);
00825 bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
00826 void setCoords(double key, double value);
00827 void setCoords(const QPointF &coords);
00828 void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
00829 void setPixelPoint(const QPointF &pixelPoint);
00830
00831 protected:
00832 PositionType mPositionType;
00833 QCPAxis *mKeyAxis, *mValueAxis;
00834 double mKey, mValue;
00835 QCPItemAnchor *mParentAnchor;
00836
00837 private:
00838 Q_DISABLE_COPY(QCPItemPosition)
00839
00840 };
00841
00842 class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
00843 {
00844 Q_OBJECT
00845 public:
00846 QCPAbstractItem(QCustomPlot *parentPlot);
00847 virtual ~QCPAbstractItem();
00848
00849
00850 bool clipToAxisRect() const { return mClipToAxisRect; }
00851 QCPAxis *clipKeyAxis() const { return mClipKeyAxis; }
00852 QCPAxis *clipValueAxis() const { return mClipValueAxis; }
00853 bool selectable() const { return mSelectable; }
00854 bool selected() const { return mSelected; }
00855
00856
00857 void setClipToAxisRect(bool clip);
00858 void setClipAxes(QCPAxis *keyAxis, QCPAxis *valueAxis);
00859 void setClipKeyAxis(QCPAxis *axis);
00860 void setClipValueAxis(QCPAxis *axis);
00861 void setSelectable(bool selectable);
00862 void setSelected(bool selected);
00863
00864
00865 virtual double selectTest(const QPointF &pos) const = 0;
00866 QList<QCPItemPosition*> positions() const { return mPositions; }
00867 QList<QCPItemAnchor*> anchors() const { return mAnchors; }
00868 QCPItemPosition *position(const QString &name) const;
00869 QCPItemAnchor *anchor(const QString &name) const;
00870 bool hasAnchor(const QString &name) const;
00871
00872 protected:
00873 bool mClipToAxisRect;
00874 QCPAxis *mClipKeyAxis, *mClipValueAxis;
00875 bool mSelectable, mSelected;
00876 QList<QCPItemPosition*> mPositions;
00877 QList<QCPItemAnchor*> mAnchors;
00878
00879 virtual QRect clipRect() const;
00880 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
00881 virtual void draw(QCPPainter *painter) = 0;
00882
00883
00884 double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
00885 double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
00886
00887
00888 virtual QPointF anchorPixelPoint(int anchorId) const;
00889 QCPItemPosition *createPosition(const QString &name);
00890 QCPItemAnchor *createAnchor(const QString &name, int anchorId);
00891
00892 signals:
00893 void selectionChanged(bool selected);
00894
00895 private:
00896 Q_DISABLE_COPY(QCPAbstractItem)
00897
00898 friend class QCustomPlot;
00899 friend class QCPItemAnchor;
00900 };
00901
00902 class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
00903 {
00904 Q_OBJECT
00905 public:
00906 QCPItemStraightLine(QCustomPlot *parentPlot);
00907 virtual ~QCPItemStraightLine();
00908
00909
00910 QPen pen() const { return mPen; }
00911 QPen selectedPen() const { return mSelectedPen; }
00912
00913
00914 void setPen(const QPen &pen);
00915 void setSelectedPen(const QPen &pen);
00916
00917
00918 virtual double selectTest(const QPointF &pos) const;
00919
00920 QCPItemPosition * const point1;
00921 QCPItemPosition * const point2;
00922
00923 protected:
00924 QPen mPen, mSelectedPen;
00925
00926 virtual void draw(QCPPainter *painter);
00927
00928
00929 double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
00930 QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
00931 QPen mainPen() const;
00932 };
00933
00934 class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
00935 {
00936 Q_OBJECT
00937 public:
00938 QCPItemLine(QCustomPlot *parentPlot);
00939 virtual ~QCPItemLine();
00940
00941
00942 QPen pen() const { return mPen; }
00943 QPen selectedPen() const { return mSelectedPen; }
00944 QCPLineEnding head() const { return mHead; }
00945 QCPLineEnding tail() const { return mTail; }
00946
00947
00948 void setPen(const QPen &pen);
00949 void setSelectedPen(const QPen &pen);
00950 void setHead(const QCPLineEnding &head);
00951 void setTail(const QCPLineEnding &tail);
00952
00953
00954 virtual double selectTest(const QPointF &pos) const;
00955
00956 QCPItemPosition * const start;
00957 QCPItemPosition * const end;
00958
00959 protected:
00960 QPen mPen, mSelectedPen;
00961 QCPLineEnding mHead, mTail;
00962
00963 virtual void draw(QCPPainter *painter);
00964
00965
00966 QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
00967 QPen mainPen() const;
00968 };
00969
00970 class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
00971 {
00972 Q_OBJECT
00973 public:
00974 QCPItemEllipse(QCustomPlot *parentPlot);
00975 virtual ~QCPItemEllipse();
00976
00977
00978 QPen pen() const { return mPen; }
00979 QPen selectedPen() const { return mSelectedPen; }
00980 QBrush brush() const { return mBrush; }
00981 QBrush selectedBrush() const { return mSelectedBrush; }
00982
00983
00984 void setPen(const QPen &pen);
00985 void setSelectedPen(const QPen &pen);
00986 void setBrush(const QBrush &brush);
00987 void setSelectedBrush(const QBrush &brush);
00988
00989
00990 virtual double selectTest(const QPointF &pos) const;
00991
00992 QCPItemPosition * const topLeft;
00993 QCPItemPosition * const bottomRight;
00994 QCPItemAnchor * const topLeftRim;
00995 QCPItemAnchor * const top;
00996 QCPItemAnchor * const topRightRim;
00997 QCPItemAnchor * const right;
00998 QCPItemAnchor * const bottomRightRim;
00999 QCPItemAnchor * const bottom;
01000 QCPItemAnchor * const bottomLeftRim;
01001 QCPItemAnchor * const left;
01002
01003 protected:
01004 enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft};
01005 QPen mPen, mSelectedPen;
01006 QBrush mBrush, mSelectedBrush;
01007
01008 virtual void draw(QCPPainter *painter);
01009 virtual QPointF anchorPixelPoint(int anchorId) const;
01010
01011
01012 QPen mainPen() const;
01013 QBrush mainBrush() const;
01014 };
01015
01016 class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
01017 {
01018 Q_OBJECT
01019 public:
01020 QCPItemRect(QCustomPlot *parentPlot);
01021 virtual ~QCPItemRect();
01022
01023
01024 QPen pen() const { return mPen; }
01025 QPen selectedPen() const { return mSelectedPen; }
01026 QBrush brush() const { return mBrush; }
01027 QBrush selectedBrush() const { return mSelectedBrush; }
01028
01029
01030 void setPen(const QPen &pen);
01031 void setSelectedPen(const QPen &pen);
01032 void setBrush(const QBrush &brush);
01033 void setSelectedBrush(const QBrush &brush);
01034
01035
01036 virtual double selectTest(const QPointF &pos) const;
01037
01038 QCPItemPosition * const topLeft;
01039 QCPItemPosition * const bottomRight;
01040 QCPItemAnchor * const top;
01041 QCPItemAnchor * const topRight;
01042 QCPItemAnchor * const right;
01043 QCPItemAnchor * const bottom;
01044 QCPItemAnchor * const bottomLeft;
01045 QCPItemAnchor * const left;
01046
01047 protected:
01048 enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
01049 QPen mPen, mSelectedPen;
01050 QBrush mBrush, mSelectedBrush;
01051
01052 virtual void draw(QCPPainter *painter);
01053 virtual QPointF anchorPixelPoint(int anchorId) const;
01054
01055
01056 QPen mainPen() const;
01057 QBrush mainBrush() const;
01058 };
01059
01060 class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
01061 {
01062 Q_OBJECT
01063 public:
01064 QCPItemPixmap(QCustomPlot *parentPlot);
01065 virtual ~QCPItemPixmap();
01066
01067
01068 QPixmap pixmap() const { return mPixmap; }
01069 bool scaled() const { return mScaled; }
01070 Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
01071 QPen pen() const { return mPen; }
01072 QPen selectedPen() const { return mSelectedPen; }
01073
01074
01075 void setPixmap(const QPixmap &pixmap);
01076 void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);
01077 void setPen(const QPen &pen);
01078 void setSelectedPen(const QPen &pen);
01079
01080
01081 virtual double selectTest(const QPointF &pos) const;
01082
01083 QCPItemPosition * const topLeft;
01084 QCPItemPosition * const bottomRight;
01085 QCPItemAnchor * const top;
01086 QCPItemAnchor * const topRight;
01087 QCPItemAnchor * const right;
01088 QCPItemAnchor * const bottom;
01089 QCPItemAnchor * const bottomLeft;
01090 QCPItemAnchor * const left;
01091
01092 protected:
01093 enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
01094 QPixmap mPixmap;
01095 QPixmap mScaledPixmap;
01096 bool mScaled;
01097 Qt::AspectRatioMode mAspectRatioMode;
01098 QPen mPen, mSelectedPen;
01099
01100 virtual void draw(QCPPainter *painter);
01101 virtual QPointF anchorPixelPoint(int anchorId) const;
01102
01103
01104 void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
01105 QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
01106 QPen mainPen() const;
01107 };
01108
01109 class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
01110 {
01111 Q_OBJECT
01112 public:
01113 QCPItemText(QCustomPlot *parentPlot);
01114 virtual ~QCPItemText();
01115
01116
01117 QColor color() const { return mColor; }
01118 QColor selectedColor() const { return mSelectedColor; }
01119 QPen pen() const { return mPen; }
01120 QPen selectedPen() const { return mSelectedPen; }
01121 QBrush brush() const { return mBrush; }
01122 QBrush selectedBrush() const { return mSelectedBrush; }
01123 QFont font() const { return mFont; }
01124 QFont selectedFont() const { return mSelectedFont; }
01125 QString text() const { return mText; }
01126 Qt::Alignment positionAlignment() const { return mPositionAlignment; }
01127 Qt::Alignment textAlignment() const { return mTextAlignment; }
01128 double rotation() const { return mRotation; }
01129 QMargins padding() const { return mPadding; }
01130
01131
01132 void setColor(const QColor &color);
01133 void setSelectedColor(const QColor &color);
01134 void setPen(const QPen &pen);
01135 void setSelectedPen(const QPen &pen);
01136 void setBrush(const QBrush &brush);
01137 void setSelectedBrush(const QBrush &brush);
01138 void setFont(const QFont &font);
01139 void setSelectedFont(const QFont &font);
01140 void setText(const QString &text);
01141 void setPositionAlignment(Qt::Alignment alignment);
01142 void setTextAlignment(Qt::Alignment alignment);
01143 void setRotation(double degrees);
01144 void setPadding(const QMargins &padding);
01145
01146
01147 virtual double selectTest(const QPointF &pos) const;
01148
01149 QCPItemPosition * const position;
01150 QCPItemAnchor * const topLeft;
01151 QCPItemAnchor * const top;
01152 QCPItemAnchor * const topRight;
01153 QCPItemAnchor * const right;
01154 QCPItemAnchor * const bottomRight;
01155 QCPItemAnchor * const bottom;
01156 QCPItemAnchor * const bottomLeft;
01157 QCPItemAnchor * const left;
01158
01159 protected:
01160 enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
01161 QColor mColor, mSelectedColor;
01162 QPen mPen, mSelectedPen;
01163 QBrush mBrush, mSelectedBrush;
01164 QFont mFont, mSelectedFont;
01165 QString mText;
01166 Qt::Alignment mPositionAlignment;
01167 Qt::Alignment mTextAlignment;
01168 double mRotation;
01169 QMargins mPadding;
01170
01171 virtual void draw(QCPPainter *painter);
01172 virtual QPointF anchorPixelPoint(int anchorId) const;
01173
01174
01175 QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
01176 QFont mainFont() const;
01177 QColor mainColor() const;
01178 QPen mainPen() const;
01179 QBrush mainBrush() const;
01180 };
01181
01182 class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
01183 {
01184 Q_OBJECT
01185 public:
01186 QCPItemCurve(QCustomPlot *parentPlot);
01187 virtual ~QCPItemCurve();
01188
01189
01190 QPen pen() const { return mPen; }
01191 QPen selectedPen() const { return mSelectedPen; }
01192 QCPLineEnding head() const { return mHead; }
01193 QCPLineEnding tail() const { return mTail; }
01194
01195
01196 void setPen(const QPen &pen);
01197 void setSelectedPen(const QPen &pen);
01198 void setHead(const QCPLineEnding &head);
01199 void setTail(const QCPLineEnding &tail);
01200
01201
01202 virtual double selectTest(const QPointF &pos) const;
01203
01204 QCPItemPosition * const start;
01205 QCPItemPosition * const startDir;
01206 QCPItemPosition * const endDir;
01207 QCPItemPosition * const end;
01208
01209 protected:
01210 QPen mPen, mSelectedPen;
01211 QCPLineEnding mHead, mTail;
01212
01213 virtual void draw(QCPPainter *painter);
01214
01215
01216 QPen mainPen() const;
01217 };
01218
01219 class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
01220 {
01221 Q_OBJECT
01222 public:
01223 enum BracketStyle { bsSquare
01224 ,bsRound
01225 ,bsCurly
01226 ,bsCalligraphic
01227 };
01228
01229 QCPItemBracket(QCustomPlot *parentPlot);
01230 virtual ~QCPItemBracket();
01231
01232
01233 QPen pen() const { return mPen; }
01234 QPen selectedPen() const { return mSelectedPen; }
01235 double length() const { return mLength; }
01236 BracketStyle style() const { return mStyle; }
01237
01238
01239 void setPen(const QPen &pen);
01240 void setSelectedPen(const QPen &pen);
01241 void setLength(double length);
01242 void setStyle(BracketStyle style);
01243
01244
01245 virtual double selectTest(const QPointF &pos) const;
01246
01247 QCPItemPosition * const left;
01248 QCPItemPosition * const right;
01249 QCPItemAnchor * const center;
01250
01251 protected:
01252 enum AnchorIndex {aiCenter};
01253 QPen mPen, mSelectedPen;
01254 double mLength;
01255 BracketStyle mStyle;
01256
01257 virtual void draw(QCPPainter *painter);
01258 virtual QPointF anchorPixelPoint(int anchorId) const;
01259
01260
01261 QPen mainPen() const;
01262 };
01263
01264 class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
01265 {
01266 Q_OBJECT
01267 public:
01273 enum TracerStyle { tsNone
01274 ,tsPlus
01275 ,tsCrosshair
01276 ,tsCircle
01277 ,tsSquare
01278 };
01279 Q_ENUMS(TracerStyle)
01280
01281 QCPItemTracer(QCustomPlot *parentPlot);
01282 virtual ~QCPItemTracer();
01283
01284
01285 QPen pen() const { return mPen; }
01286 QPen selectedPen() const { return mSelectedPen; }
01287 QBrush brush() const { return mBrush; }
01288 QBrush selectedBrush() const { return mSelectedBrush; }
01289 double size() const { return mSize; }
01290 TracerStyle style() const { return mStyle; }
01291 QCPGraph *graph() const { return mGraph; }
01292 double graphKey() const { return mGraphKey; }
01293 bool interpolating() const { return mInterpolating; }
01294
01295
01296 void setPen(const QPen &pen);
01297 void setSelectedPen(const QPen &pen);
01298 void setBrush(const QBrush &brush);
01299 void setSelectedBrush(const QBrush &brush);
01300 void setSize(double size);
01301 void setStyle(TracerStyle style);
01302 void setGraph(QCPGraph *graph);
01303 void setGraphKey(double key);
01304 void setInterpolating(bool enabled);
01305
01306
01307 virtual double selectTest(const QPointF &pos) const;
01308 void updatePosition();
01309
01310 QCPItemPosition * const position;
01311
01312 protected:
01313 QPen mPen, mSelectedPen;
01314 QBrush mBrush, mSelectedBrush;
01315 double mSize;
01316 TracerStyle mStyle;
01317 QCPGraph *mGraph;
01318 double mGraphKey;
01319 bool mInterpolating;
01320
01321 virtual void draw(QCPPainter *painter);
01322
01323
01324 QPen mainPen() const;
01325 QBrush mainBrush() const;
01326 };
01327
01328 class QCP_LIB_DECL QCPRange
01329 {
01330 public:
01331 double lower, upper;
01332 QCPRange();
01333 QCPRange(double lower, double upper);
01334 double size() const;
01335 double center() const;
01336 void normalize();
01337 QCPRange sanitizedForLogScale() const;
01338 QCPRange sanitizedForLinScale() const;
01339 bool contains(double value) const;
01340
01341 static bool validRange(double lower, double upper);
01342 static bool validRange(const QCPRange &range);
01343 static const double minRange;
01344 static const double maxRange;
01345 };
01346 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
01347
01348 class QCP_LIB_DECL QCPAbstractLegendItem : public QObject
01349 {
01350 Q_OBJECT
01351 public:
01352 QCPAbstractLegendItem(QCPLegend *parent);
01353 virtual ~QCPAbstractLegendItem() {}
01354
01355
01356 bool antialiased() const { return mAntialiased; }
01357 QFont font() const { return mFont; }
01358 QColor textColor() const { return mTextColor; }
01359 QFont selectedFont() const { return mSelectedFont; }
01360 QColor selectedTextColor() const { return mSelectedTextColor; }
01361 bool selectable() const { return mSelectable; }
01362 bool selected() const { return mSelected; }
01363
01364
01365 void setAntialiased(bool enabled);
01366 void setFont(const QFont &font);
01367 void setTextColor(const QColor &color);
01368 void setSelectedFont(const QFont &font);
01369 void setSelectedTextColor(const QColor &color);
01370 void setSelectable(bool selectable);
01371 void setSelected(bool selected);
01372
01373 signals:
01374 void selectionChanged(bool selected);
01375
01376 protected:
01377 QCPLegend *mParentLegend;
01378 bool mAntialiased;
01379 QFont mFont;
01380 QColor mTextColor;
01381 QFont mSelectedFont;
01382 QColor mSelectedTextColor;
01383 bool mSelectable, mSelected;
01384
01385 virtual void draw(QCPPainter *painter, const QRect &rect) const = 0;
01386 virtual QSize size(const QSize &targetSize) const = 0;
01387 void applyAntialiasingHint(QCPPainter *painter) const;
01388
01389 private:
01390 Q_DISABLE_COPY(QCPAbstractLegendItem)
01391
01392 friend class QCPLegend;
01393 };
01394
01395 class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
01396 {
01397 Q_OBJECT
01398 public:
01399 QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
01400 virtual ~QCPPlottableLegendItem() {}
01401
01402
01403 QCPAbstractPlottable *plottable() { return mPlottable; }
01404 bool textWrap() const { return mTextWrap; }
01405
01406
01407 void setTextWrap(bool wrap);
01408
01409 protected:
01410 QCPAbstractPlottable *mPlottable;
01411 bool mTextWrap;
01412
01413 QPen getIconBorderPen() const;
01414 QColor getTextColor() const;
01415 QFont getFont() const;
01416
01417 virtual void draw(QCPPainter *painter, const QRect &rect) const;
01418 virtual QSize size(const QSize &targetSize) const;
01419 };
01420
01421 class QCP_LIB_DECL QCPLegend : public QCPLayerable
01422 {
01423 Q_OBJECT
01424 public:
01428 enum PositionStyle { psManual
01429 ,psTopLeft
01430 ,psTop
01431 ,psTopRight
01432 ,psRight
01433 ,psBottomRight
01434 ,psBottom
01435 ,psBottomLeft
01436 ,psLeft
01437 };
01438 Q_ENUMS(PositionStyle)
01439
01440
01443 enum SelectablePart { spNone = 0
01444 ,spLegendBox = 0x001
01445 ,spItems = 0x002
01446 };
01447 Q_ENUMS(SelectablePart)
01448 Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
01449
01450 explicit QCPLegend(QCustomPlot *parentPlot);
01451 virtual ~QCPLegend();
01452
01453
01454 QPen borderPen() const { return mBorderPen; }
01455 QBrush brush() const { return mBrush; }
01456 QFont font() const { return mFont; }
01457 QColor textColor() const { return mTextColor; }
01458 PositionStyle positionStyle() const { return mPositionStyle; }
01459 QPoint position() const { return mPosition; }
01460 bool autoSize() const { return mAutoSize; }
01461 QSize size() const { return mSize; }
01462 QSize minimumSize() const { return mMinimumSize; }
01463 int paddingLeft() const { return mPaddingLeft; }
01464 int paddingRight() const { return mPaddingRight; }
01465 int paddingTop() const { return mPaddingTop; }
01466 int paddingBottom() const { return mPaddingBottom; }
01467 int marginLeft() const { return mMarginLeft; }
01468 int marginRight() const { return mMarginRight; }
01469 int marginTop() const { return mMarginTop; }
01470 int marginBottom() const { return mMarginBottom; }
01471 int itemSpacing() const { return mItemSpacing; }
01472 QSize iconSize() const { return mIconSize; }
01473 int iconTextPadding() const { return mIconTextPadding; }
01474 QPen iconBorderPen() const { return mIconBorderPen; }
01475 SelectableParts selectable() const { return mSelectable; }
01476 SelectableParts selected() const { return mSelected; }
01477 QPen selectedBorderPen() const { return mSelectedBorderPen; }
01478 QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
01479 QBrush selectedBrush() const { return mSelectedBrush; }
01480 QFont selectedFont() const { return mSelectedFont; }
01481 QColor selectedTextColor() const { return mSelectedTextColor; }
01482
01483
01484 void setBorderPen(const QPen &pen);
01485 void setBrush(const QBrush &brush);
01486 void setFont(const QFont &font);
01487 void setTextColor(const QColor &color);
01488 void setPositionStyle(PositionStyle legendPositionStyle);
01489 void setPosition(const QPoint &pixelPosition);
01490 void setAutoSize(bool on);
01491 void setSize(const QSize &size);
01492 void setSize(int width, int height);
01493 void setMinimumSize(const QSize &size);
01494 void setMinimumSize(int width, int height);
01495 void setPaddingLeft(int padding);
01496 void setPaddingRight(int padding);
01497 void setPaddingTop(int padding);
01498 void setPaddingBottom(int padding);
01499 void setPadding(int left, int right, int top, int bottom);
01500 void setMarginLeft(int margin);
01501 void setMarginRight(int margin);
01502 void setMarginTop(int margin);
01503 void setMarginBottom(int margin);
01504 void setMargin(int left, int right, int top, int bottom);
01505 void setItemSpacing(int spacing);
01506 void setIconSize(const QSize &size);
01507 void setIconSize(int width, int height);
01508 void setIconTextPadding(int padding);
01509 void setIconBorderPen(const QPen &pen);
01510 void setSelectable(const SelectableParts &selectable);
01511 void setSelected(const SelectableParts &selected);
01512 void setSelectedBorderPen(const QPen &pen);
01513 void setSelectedIconBorderPen(const QPen &pen);
01514 void setSelectedBrush(const QBrush &brush);
01515 void setSelectedFont(const QFont &font);
01516 void setSelectedTextColor(const QColor &color);
01517
01518
01519 QCPAbstractLegendItem *item(int index) const;
01520 QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
01521 int itemCount() const;
01522 bool hasItem(QCPAbstractLegendItem *item) const;
01523 bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
01524 bool addItem(QCPAbstractLegendItem *item);
01525 bool removeItem(int index);
01526 bool removeItem(QCPAbstractLegendItem *item);
01527 void clearItems();
01528 QList<QCPAbstractLegendItem*> selectedItems() const;
01529 void reArrange();
01530
01531 bool selectTestLegend(const QPointF &pos) const;
01532 QCPAbstractLegendItem *selectTestItem(const QPoint pos) const;
01533
01534 signals:
01535 void selectionChanged(QCPLegend::SelectableParts selection);
01536
01537 protected:
01538
01539 QPen mBorderPen, mIconBorderPen;
01540 QBrush mBrush;
01541 QFont mFont;
01542 QColor mTextColor;
01543 QPoint mPosition;
01544 QSize mSize, mMinimumSize, mIconSize;
01545 PositionStyle mPositionStyle;
01546 bool mAutoSize;
01547 int mPaddingLeft, mPaddingRight, mPaddingTop, mPaddingBottom;
01548 int mMarginLeft, mMarginRight, mMarginTop, mMarginBottom;
01549 int mItemSpacing, mIconTextPadding;
01550 SelectableParts mSelected, mSelectable;
01551 QPen mSelectedBorderPen, mSelectedIconBorderPen;
01552 QBrush mSelectedBrush;
01553 QFont mSelectedFont;
01554 QColor mSelectedTextColor;
01555
01556
01557 QList<QCPAbstractLegendItem*> mItems;
01558 QMap<QCPAbstractLegendItem*, QRect> mItemBoundingBoxes;
01559
01560 virtual void updateSelectionState();
01561 virtual bool handleLegendSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
01562
01563 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
01564 virtual void draw(QCPPainter *painter);
01565 virtual void calculateAutoSize();
01566 virtual void calculateAutoPosition();
01567
01568
01569 QPen getBorderPen() const;
01570 QBrush getBrush() const;
01571
01572 private:
01573 Q_DISABLE_COPY(QCPLegend)
01574
01575 friend class QCustomPlot;
01576 friend class QCPAbstractLegendItem;
01577 };
01578 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
01579
01580 class QCP_LIB_DECL QCPGrid : public QCPLayerable
01581 {
01582 Q_OBJECT
01583 public:
01584 QCPGrid(QCPAxis *parentAxis);
01585 ~QCPGrid();
01586
01587
01588 bool subGridVisible() const { return mSubGridVisible; }
01589 bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
01590 bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
01591 QPen pen() const { return mPen; }
01592 QPen subGridPen() const { return mSubGridPen; }
01593 QPen zeroLinePen() const { return mZeroLinePen; }
01594
01595
01596 void setSubGridVisible(bool visible);
01597 void setAntialiasedSubGrid(bool enabled);
01598 void setAntialiasedZeroLine(bool enabled);
01599 void setPen(const QPen &pen);
01600 void setSubGridPen(const QPen &pen);
01601 void setZeroLinePen(const QPen &pen);
01602
01603 protected:
01604 QCPAxis *mParentAxis;
01605 bool mSubGridVisible;
01606 bool mAntialiasedSubGrid, mAntialiasedZeroLine;
01607 QPen mPen, mSubGridPen, mZeroLinePen;
01608
01609 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
01610 virtual void draw(QCPPainter *painter);
01611
01612 void drawGridLines(QCPPainter *painter) const;
01613 void drawSubGridLines(QCPPainter *painter) const;
01614
01615 friend class QCPAxis;
01616 };
01617
01618 class QCP_LIB_DECL QCPAxis : public QCPLayerable
01619 {
01620 Q_OBJECT
01622 Q_PROPERTY(AxisType axisType READ axisType WRITE setAxisType)
01623 Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType)
01624 Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
01625 Q_PROPERTY(QRect axisRect READ axisRect WRITE setAxisRect)
01626 Q_PROPERTY(QCPRange range READ range WRITE setRange)
01627 Q_PROPERTY(bool grid READ grid WRITE setGrid)
01628 Q_PROPERTY(bool subGrid READ subGrid WRITE setSubGrid)
01629 Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
01630 Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
01631 Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
01632 Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
01633 Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
01634 Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
01635 Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
01636 Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
01637 Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
01638 Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
01639 Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
01640 Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
01641 Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
01642 Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
01643 Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
01644 Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
01645 Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
01646 Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
01647 Q_PROPERTY(QPen gridPen READ gridPen WRITE setGridPen)
01648 Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
01649 Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
01650 Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
01651 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
01652 Q_PROPERTY(QString label READ label WRITE setLabel)
01653 Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
01655 public:
01661 enum AxisType { atLeft
01662 ,atRight
01663 ,atTop
01664 ,atBottom
01665 };
01666 Q_ENUMS(AxisType)
01673 enum LabelType { ltNumber
01674 ,ltDateTime
01675 };
01676 Q_ENUMS(LabelType)
01681 enum ScaleType { stLinear
01682 ,stLogarithmic
01683 };
01684 Q_ENUMS(ScaleType)
01689 enum SelectablePart { spNone = 0
01690 ,spAxis = 0x001
01691 ,spTickLabels = 0x002
01692 ,spAxisLabel = 0x004
01693 };
01694 Q_ENUMS(SelectablePart)
01695 Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
01696
01697 explicit QCPAxis(QCustomPlot *parentPlot, AxisType type);
01698 virtual ~QCPAxis();
01699
01700
01701 AxisType axisType() const { return mAxisType; }
01702 QRect axisRect() const { return mAxisRect; }
01703 ScaleType scaleType() const { return mScaleType; }
01704 double scaleLogBase() const { return mScaleLogBase; }
01705 const QCPRange range() const { return mRange; }
01706 bool rangeReversed() const { return mRangeReversed; }
01707 bool antialiasedGrid() const { return mGrid->antialiased(); }
01708 bool antialiasedSubGrid() const { return mGrid->antialiasedSubGrid(); }
01709 bool antialiasedZeroLine() const { return mGrid->antialiasedZeroLine(); }
01710 bool grid() const { return mGrid->visible(); }
01711 bool subGrid() const { return mGrid->subGridVisible(); }
01712 bool autoTicks() const { return mAutoTicks; }
01713 int autoTickCount() const { return mAutoTickCount; }
01714 bool autoTickLabels() const { return mAutoTickLabels; }
01715 bool autoTickStep() const { return mAutoTickStep; }
01716 bool autoSubTicks() const { return mAutoSubTicks; }
01717 bool ticks() const { return mTicks; }
01718 bool tickLabels() const { return mTickLabels; }
01719 int tickLabelPadding() const { return mTickLabelPadding; }
01720 LabelType tickLabelType() const { return mTickLabelType; }
01721 QFont tickLabelFont() const { return mTickLabelFont; }
01722 QColor tickLabelColor() const { return mTickLabelColor; }
01723 double tickLabelRotation() const { return mTickLabelRotation; }
01724 QString dateTimeFormat() const { return mDateTimeFormat; }
01725 QString numberFormat() const;
01726 int numberPrecision() const { return mNumberPrecision; }
01727 double tickStep() const { return mTickStep; }
01728 QVector<double> tickVector() const { return mTickVector; }
01729 QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
01730 int tickLengthIn() const { return mTickLengthIn; }
01731 int tickLengthOut() const { return mTickLengthOut; }
01732 int subTickCount() const { return mSubTickCount; }
01733 int subTickLengthIn() const { return mSubTickLengthIn; }
01734 int subTickLengthOut() const { return mSubTickLengthOut; }
01735 QPen basePen() const { return mBasePen; }
01736 QPen gridPen() const { return mGrid->pen(); }
01737 QPen subGridPen() const { return mGrid->subGridPen(); }
01738 QPen zeroLinePen() const { return mGrid->zeroLinePen(); }
01739 QPen tickPen() const { return mTickPen; }
01740 QPen subTickPen() const { return mSubTickPen; }
01741 QFont labelFont() const { return mLabelFont; }
01742 QColor labelColor() const { return mLabelColor; }
01743 QString label() const { return mLabel; }
01744 int labelPadding() const { return mLabelPadding; }
01745 int padding() const { return mPadding; }
01746 SelectableParts selected() const { return mSelected; }
01747 SelectableParts selectable() const { return mSelectable; }
01748 QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
01749 QFont selectedLabelFont() const { return mSelectedLabelFont; }
01750 QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
01751 QColor selectedLabelColor() const { return mSelectedLabelColor; }
01752 QPen selectedBasePen() const { return mSelectedBasePen; }
01753 QPen selectedTickPen() const { return mSelectedTickPen; }
01754 QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
01755
01756
01757 void setScaleType(ScaleType type);
01758 void setScaleLogBase(double base);
01759 void setRange(double lower, double upper);
01760 void setRange(double position, double size, Qt::AlignmentFlag alignment);
01761 void setRangeLower(double lower);
01762 void setRangeUpper(double upper);
01763 void setRangeReversed(bool reversed);
01764 void setAntialiasedGrid(bool enabled);
01765 void setAntialiasedSubGrid(bool enabled);
01766 void setAntialiasedZeroLine(bool enabled);
01767 void setGrid(bool show);
01768 void setSubGrid(bool show);
01769 void setAutoTicks(bool on);
01770 void setAutoTickCount(int approximateCount);
01771 void setAutoTickLabels(bool on);
01772 void setAutoTickStep(bool on);
01773 void setAutoSubTicks(bool on);
01774 void setTicks(bool show);
01775 void setTickLabels(bool show);
01776 void setTickLabelPadding(int padding);
01777 void setTickLabelType(LabelType type);
01778 void setTickLabelFont(const QFont &font);
01779 void setTickLabelColor(const QColor &color);
01780 void setTickLabelRotation(double degrees);
01781 void setDateTimeFormat(const QString &format);
01782 void setNumberFormat(const QString &formatCode);
01783 void setNumberPrecision(int precision);
01784 void setTickStep(double step);
01785 void setTickVector(const QVector<double> &vec);
01786 void setTickVectorLabels(const QVector<QString> &vec);
01787 void setTickLength(int inside, int outside=0);
01788 void setSubTickCount(int count);
01789 void setSubTickLength(int inside, int outside=0);
01790 void setBasePen(const QPen &pen);
01791 void setGridPen(const QPen &pen);
01792 void setSubGridPen(const QPen &pen);
01793 void setZeroLinePen(const QPen &pen);
01794 void setTickPen(const QPen &pen);
01795 void setSubTickPen(const QPen &pen);
01796 void setLabelFont(const QFont &font);
01797 void setLabelColor(const QColor &color);
01798 void setLabel(const QString &str);
01799 void setLabelPadding(int padding);
01800 void setPadding(int padding);
01801 void setSelectedTickLabelFont(const QFont &font);
01802 void setSelectedLabelFont(const QFont &font);
01803 void setSelectedTickLabelColor(const QColor &color);
01804 void setSelectedLabelColor(const QColor &color);
01805 void setSelectedBasePen(const QPen &pen);
01806 void setSelectedTickPen(const QPen &pen);
01807 void setSelectedSubTickPen(const QPen &pen);
01808
01809
01810 Qt::Orientation orientation() const { return mOrientation; }
01811 void moveRange(double diff);
01812 void scaleRange(double factor, double center);
01813 void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
01814 double pixelToCoord(double value) const;
01815 double coordToPixel(double value) const;
01816 SelectablePart selectTest(const QPointF &pos) const;
01817
01818 public slots:
01819
01820 void setRange(const QCPRange &range);
01821 void setSelectable(const QCPAxis::SelectableParts &selectable);
01822 void setSelected(const QCPAxis::SelectableParts &selected);
01823
01824 signals:
01825 void ticksRequest();
01826 void rangeChanged(const QCPRange &newRange);
01827 void selectionChanged(QCPAxis::SelectableParts selection);
01828
01829 protected:
01830
01831 QVector<double> mTickVector;
01832 QVector<QString> mTickVectorLabels;
01833 QCPRange mRange;
01834 QString mDateTimeFormat;
01835 QString mLabel;
01836 QRect mAxisRect;
01837 QPen mBasePen, mTickPen, mSubTickPen;
01838 QFont mTickLabelFont, mLabelFont;
01839 QColor mTickLabelColor, mLabelColor;
01840 LabelType mTickLabelType;
01841 ScaleType mScaleType;
01842 AxisType mAxisType;
01843 double mTickStep;
01844 double mScaleLogBase, mScaleLogBaseLogInv;
01845 int mSubTickCount, mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut;
01846 int mAutoTickCount;
01847 int mTickLabelPadding, mLabelPadding, mPadding;
01848 double mTickLabelRotation;
01849 bool mTicks, mTickLabels, mAutoTicks, mAutoTickLabels, mAutoTickStep, mAutoSubTicks;
01850 bool mRangeReversed;
01851 SelectableParts mSelectable, mSelected;
01852 QFont mSelectedTickLabelFont, mSelectedLabelFont;
01853 QColor mSelectedTickLabelColor, mSelectedLabelColor;
01854 QPen mSelectedBasePen, mSelectedTickPen, mSelectedSubTickPen;
01855 QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
01856
01857
01858 QCPGrid *mGrid;
01859 QVector<double> mSubTickVector;
01860 QChar mExponentialChar, mPositiveSignChar;
01861 int mNumberPrecision;
01862 char mNumberFormatChar;
01863 bool mNumberBeautifulPowers, mNumberMultiplyCross;
01864 Qt::Orientation mOrientation;
01865 int mLowestVisibleTick, mHighestVisibleTick;
01866
01867
01868 void setAxisType(AxisType type);
01869 void setAxisRect(const QRect &rect);
01870
01871
01872 virtual void setupTickVectors();
01873 virtual void generateAutoTicks();
01874 virtual int calculateAutoSubTickCount(double tickStep) const;
01875 virtual int calculateMargin() const;
01876 virtual bool handleAxisSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
01877
01878
01879 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
01880 virtual void draw(QCPPainter *painter);
01881 virtual void drawTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
01882 virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
01883
01884
01885 void visibleTickBounds(int &lowIndex, int &highIndex) const;
01886 double baseLog(double value) const;
01887 double basePow(double value) const;
01888
01889
01890 QPen getBasePen() const;
01891 QPen getTickPen() const;
01892 QPen getSubTickPen() const;
01893 QFont getTickLabelFont() const;
01894 QFont getLabelFont() const;
01895 QColor getTickLabelColor() const;
01896 QColor getLabelColor() const;
01897
01898 private:
01899 Q_DISABLE_COPY(QCPAxis)
01900
01901 friend class QCustomPlot;
01902 friend class QCPGrid;
01903 };
01904 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
01905
01906 class QCP_LIB_DECL QCustomPlot : public QWidget
01907 {
01908 Q_OBJECT
01910 Q_PROPERTY(QString title READ title WRITE setTitle)
01911 Q_PROPERTY(QRect axisRect READ axisRect WRITE setAxisRect)
01912 Q_PROPERTY(int marginLeft READ marginLeft WRITE setMarginLeft)
01913 Q_PROPERTY(int marginRight READ marginRight WRITE setMarginRight)
01914 Q_PROPERTY(int marginTop READ marginTop WRITE setMarginTop)
01915 Q_PROPERTY(int marginBottom READ marginBottom WRITE setMarginBottom)
01916 Q_PROPERTY(int autoMargin READ autoMargin WRITE setAutoMargin)
01917 Q_PROPERTY(QColor color READ color WRITE setColor)
01918 Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
01919 Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
01921 public:
01928 enum Interaction { iRangeDrag = 0x001
01929 ,iRangeZoom = 0x002
01930 ,iMultiSelect = 0x004
01931 ,iSelectTitle = 0x008
01932 ,iSelectPlottables = 0x010
01933 ,iSelectAxes = 0x020
01934 ,iSelectLegend = 0x040
01935 ,iSelectItems = 0x080
01936 };
01937 Q_ENUMS(Interaction)
01938 Q_DECLARE_FLAGS(Interactions, Interaction)
01944 enum LayerInsertMode { limBelow
01945 ,limAbove
01946 };
01947 Q_ENUMS(LayerInsertMode)
01948
01949 explicit QCustomPlot(QWidget *parent = 0);
01950 virtual ~QCustomPlot();
01951
01952
01953 QString title() const { return mTitle; }
01954 QFont titleFont() const { return mTitleFont; }
01955 QColor titleColor() const { return mTitleColor; }
01956 QRect axisRect() const { return mAxisRect; }
01957 QRect viewport() const { return mViewport; }
01958 int marginLeft() const { return mMarginLeft; }
01959 int marginRight() const { return mMarginRight; }
01960 int marginTop() const { return mMarginTop; }
01961 int marginBottom() const { return mMarginBottom; }
01962 bool autoMargin() const { return mAutoMargin; }
01963 QColor color() const { return mColor; }
01964 Qt::Orientations rangeDrag() const { return mRangeDrag; }
01965 Qt::Orientations rangeZoom() const { return mRangeZoom; }
01966 QCPAxis *rangeDragAxis(Qt::Orientation orientation);
01967 QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
01968 double rangeZoomFactor(Qt::Orientation orientation);
01969 QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
01970 QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
01971 bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
01972 QPixmap axisBackground() const { return mAxisBackground; }
01973 bool axisBackgroundScaled() const { return mAxisBackgroundScaled; }
01974 Qt::AspectRatioMode axisBackgroundScaledMode() const { return mAxisBackgroundScaledMode; }
01975 const Interactions interactions() const { return mInteractions; }
01976 int selectionTolerance() const { return mSelectionTolerance; }
01977 QFont selectedTitleFont() const { return mSelectedTitleFont; }
01978 QColor selectedTitleColor() const { return mSelectedTitleColor; }
01979 bool titleSelected() const { return mTitleSelected; }
01980 bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
01981 QCP::PlottingHints plottingHints() const { return mPlottingHints; }
01982 Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
01983
01984
01985 void setTitle(const QString &title);
01986 void setTitleFont(const QFont &font);
01987 void setTitleColor(const QColor &color);
01988 void setAxisRect(const QRect &arect);
01989 void setMarginLeft(int margin);
01990 void setMarginRight(int margin);
01991 void setMarginTop(int margin);
01992 void setMarginBottom(int margin);
01993 void setMargin(int left, int right, int top, int bottom);
01994 void setAutoMargin(bool enabled);
01995 void setColor(const QColor &color);
01996 void setRangeDrag(Qt::Orientations orientations);
01997 void setRangeZoom(Qt::Orientations orientations);
01998 void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
01999 void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
02000 void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
02001 void setRangeZoomFactor(double factor);
02002 void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
02003 void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
02004 void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements);
02005 void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
02006 void setAutoAddPlottableToLegend(bool on);
02007 void setAxisBackground(const QPixmap &pm);
02008 void setAxisBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
02009 void setAxisBackgroundScaled(bool scaled);
02010 void setAxisBackgroundScaledMode(Qt::AspectRatioMode mode);
02011 void setInteractions(const Interactions &interactions);
02012 void setInteraction(const Interaction &interaction, bool enabled=true);
02013 void setSelectionTolerance(int pixels);
02014 void setSelectedTitleFont(const QFont &font);
02015 void setSelectedTitleColor(const QColor &color);
02016 void setTitleSelected(bool selected);
02017 void setNoAntialiasingOnDrag(bool enabled);
02018 void setPlottingHints(const QCP::PlottingHints &hints);
02019 void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
02020 void setMultiSelectModifier(Qt::KeyboardModifier modifier);
02021
02022
02023
02024 QCPAbstractPlottable *plottable(int index);
02025 QCPAbstractPlottable *plottable();
02026 bool addPlottable(QCPAbstractPlottable *plottable);
02027 bool removePlottable(QCPAbstractPlottable *plottable);
02028 bool removePlottable(int index);
02029 int clearPlottables();
02030 int plottableCount() const;
02031 QList<QCPAbstractPlottable*> selectedPlottables() const;
02032 QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
02033 bool hasPlottable(QCPAbstractPlottable *plottable) const;
02034
02035
02036 QCPGraph *graph(int index) const;
02037 QCPGraph *graph() const;
02038 QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
02039 bool removeGraph(QCPGraph *graph);
02040 bool removeGraph(int index);
02041 int clearGraphs();
02042 int graphCount() const;
02043 QList<QCPGraph*> selectedGraphs() const;
02044
02045
02046 QCPAbstractItem *item(int index) const;
02047 QCPAbstractItem *item() const;
02048 bool addItem(QCPAbstractItem* item);
02049 bool removeItem(QCPAbstractItem *item);
02050 bool removeItem(int index);
02051 int clearItems();
02052 int itemCount() const;
02053 QList<QCPAbstractItem*> selectedItems() const;
02054 QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
02055
02056
02057 QCPLayer *layer(const QString &name) const;
02058 QCPLayer *layer(int index) const;
02059 QCPLayer *currentLayer() const;
02060 bool setCurrentLayer(const QString &name);
02061 bool setCurrentLayer(QCPLayer *layer);
02062 int layerCount() const;
02063 bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
02064 bool removeLayer(QCPLayer *layer);
02065 bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
02066
02067 QList<QCPAxis*> selectedAxes() const;
02068 QList<QCPLegend*> selectedLegends() const;
02069 void setupFullAxesBox();
02070 bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0);
02071 bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
02072 bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
02073 bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
02074 bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
02075
02076 QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
02077 QCPLegend *legend;
02078
02079 public slots:
02080 void deselectAll();
02081 void replot();
02082 void rescaleAxes();
02083
02084 signals:
02085 void mouseDoubleClick(QMouseEvent *event);
02086 void mousePress(QMouseEvent *event);
02087 void mouseMove(QMouseEvent *event);
02088 void mouseRelease(QMouseEvent *event);
02089 void mouseWheel(QWheelEvent *event);
02090
02091 void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
02092 void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
02093 void itemClick(QCPAbstractItem *item, QMouseEvent *event);
02094 void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
02095 void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
02096 void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
02097 void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
02098 void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
02099 void titleClick(QMouseEvent *event);
02100 void titleDoubleClick(QMouseEvent *event);
02101
02102 void selectionChangedByUser();
02103 void beforeReplot();
02104 void afterReplot();
02105
02106 protected:
02107 QString mTitle;
02108 QFont mTitleFont, mSelectedTitleFont;
02109 QColor mTitleColor, mSelectedTitleColor;
02110 QRect mViewport;
02111 QRect mAxisRect;
02112 int mMarginLeft, mMarginRight, mMarginTop, mMarginBottom;
02113 bool mAutoMargin, mAutoAddPlottableToLegend;
02114 QColor mColor;
02115 QList<QCPAbstractPlottable*> mPlottables;
02116 QList<QCPGraph*> mGraphs;
02117 QList<QCPAbstractItem*> mItems;
02118 QList<QCPLayer*> mLayers;
02119 Qt::Orientations mRangeDrag, mRangeZoom;
02120 QCPAxis *mRangeDragHorzAxis, *mRangeDragVertAxis, *mRangeZoomHorzAxis, *mRangeZoomVertAxis;
02121 double mRangeZoomFactorHorz, mRangeZoomFactorVert;
02122 bool mDragging;
02123 QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
02124 QPixmap mAxisBackground;
02125 bool mAxisBackgroundScaled;
02126 Qt::AspectRatioMode mAxisBackgroundScaledMode;
02127 Interactions mInteractions;
02128 int mSelectionTolerance;
02129 bool mTitleSelected;
02130 QRect mTitleBoundingBox;
02131 bool mNoAntialiasingOnDrag;
02132
02133 QPixmap mPaintBuffer;
02134 QPoint mDragStart;
02135 QCPRange mDragStartHorzRange, mDragStartVertRange;
02136 QPixmap mScaledAxisBackground;
02137 bool mReplotting;
02138 QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
02139 QCPLayer *mCurrentLayer;
02140 QCP::PlottingHints mPlottingHints;
02141 Qt::KeyboardModifier mMultiSelectModifier;
02142
02143
02144 virtual QSize minimumSizeHint() const;
02145 virtual void paintEvent(QPaintEvent *event);
02146 virtual void resizeEvent(QResizeEvent *event);
02147 virtual void mouseDoubleClickEvent(QMouseEvent *event);
02148 virtual void mousePressEvent(QMouseEvent *event);
02149 virtual void mouseMoveEvent(QMouseEvent *event);
02150 virtual void mouseReleaseEvent(QMouseEvent *event);
02151 virtual void wheelEvent(QWheelEvent *event);
02152
02153 virtual bool handlePlottableSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
02154 virtual bool handleItemSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
02155 virtual bool handleAxisSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
02156 virtual bool handleTitleSelection(QMouseEvent *event, bool additiveSelection, bool &modified);
02157
02158
02159 virtual void draw(QCPPainter *painter);
02160 virtual void drawAxisBackground(QCPPainter *painter);
02161
02162
02163 void updateAxisRect();
02164 bool selectTestTitle(const QPointF &pos) const;
02165 friend class QCPLegend;
02166 friend class QCPAxis;
02167 friend class QCPLayer;
02168 };
02169 Q_DECLARE_OPERATORS_FOR_FLAGS(QCustomPlot::Interactions)
02170
02171 #endif // QCUSTOMPLOT_H