-
Notifications
You must be signed in to change notification settings - Fork 0
/
qcustomplot.h
3767 lines (3227 loc) · 146 KB
/
qcustomplot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
** **
** QCustomPlot, an easy to use, modern plotting widget for Qt **
** Copyright (C) 2011-2015 Emanuel Eichhammer **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU General Public License as published by **
** the Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see http://www.gnu.org/licenses/. **
** **
****************************************************************************
** Author: Emanuel Eichhammer **
** Website/Contact: http://www.qcustomplot.com/ **
** Date: 25.04.15 **
** Version: 1.3.1 **
****************************************************************************/
#ifndef QCUSTOMPLOT_H
#define QCUSTOMPLOT_H
#include <QObject>
#include <QPointer>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QMouseEvent>
#include <QPixmap>
#include <QVector>
#include <QString>
#include <QDateTime>
#include <QMultiMap>
#include <QFlags>
#include <QDebug>
#include <QVector2D>
#include <QStack>
#include <QCache>
#include <QMargins>
#include <qmath.h>
#include <limits>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
# include <qnumeric.h>
# include <QPrinter>
# include <QPrintEngine>
#else
# include <QtCore/QtNumeric>
# include <QtPrintSupport>
#endif
class QCPPainter;
class QCustomPlot;
class QCPLayerable;
class QCPLayoutElement;
class QCPLayout;
class QCPAxis;
class QCPAxisRect;
class QCPAxisPainterPrivate;
class QCPAbstractPlottable;
class QCPGraph;
class QCPAbstractItem;
class QCPItemPosition;
class QCPLayer;
class QCPPlotTitle;
class QCPLegend;
class QCPAbstractLegendItem;
class QCPColorMap;
class QCPColorScale;
class QCPBars;
/*! \file */
// decl definitions for shared library compilation/usage:
#if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
# define QCP_LIB_DECL Q_DECL_EXPORT
#elif defined(QCUSTOMPLOT_USE_LIBRARY)
# define QCP_LIB_DECL Q_DECL_IMPORT
#else
# define QCP_LIB_DECL
#endif
/*!
The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
*/
namespace QCP
{
/*!
Defines the sides of a rectangular entity to which margins can be applied.
\see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
*/
enum MarginSide { msLeft = 0x01 ///< <tt>0x01</tt> left margin
,msRight = 0x02 ///< <tt>0x02</tt> right margin
,msTop = 0x04 ///< <tt>0x04</tt> top margin
,msBottom = 0x08 ///< <tt>0x08</tt> bottom margin
,msAll = 0xFF ///< <tt>0xFF</tt> all margins
,msNone = 0x00 ///< <tt>0x00</tt> no margin
};
Q_DECLARE_FLAGS(MarginSides, MarginSide)
/*!
Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
element how it is drawn. Typically it provides a \a setAntialiased function for this.
\c AntialiasedElements is a flag of or-combined elements of this enum type.
\see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
*/
enum AntialiasedElement { aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
,aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines
,aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
,aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box
,aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items
,aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see element \ref aeErrorBars)
,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
,aeErrorBars = 0x0100 ///< <tt>0x0100</tt> Error bars
,aeFills = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs)
,aeZeroLine = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
,aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements
,aeNone = 0x0000 ///< <tt>0x0000</tt> No elements
};
Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
/*!
Defines plotting hints that control various aspects of the quality and speed of plotting.
\see QCustomPlot::setPlottingHints
*/
enum PlottingHint { phNone = 0x000 ///< <tt>0x000</tt> No hints are set
,phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality
///< especially of the line segment joins. (Only relevant for solid line pens.)
,phForceRepaint = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint.
///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
,phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance.
};
Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
/*!
Defines the mouse interactions possible with QCustomPlot.
\c Interactions is a flag of or-combined elements of this enum type.
\see QCustomPlot::setInteractions
*/
enum Interaction { iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
,iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
,iMultiSelect = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
,iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
,iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
,iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
,iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...)
};
Q_DECLARE_FLAGS(Interactions, Interaction)
/*! \internal
Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
*/
inline bool isInvalidData(double value)
{
return qIsNaN(value) || qIsInf(value);
}
/*! \internal
\overload
Checks two arguments instead of one.
*/
inline bool isInvalidData(double value1, double value2)
{
return isInvalidData(value1) || isInvalidData(value2);
}
/*! \internal
Sets the specified \a side of \a margins to \a value
\see getMarginValue
*/
inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
{
switch (side)
{
case QCP::msLeft: margins.setLeft(value); break;
case QCP::msRight: margins.setRight(value); break;
case QCP::msTop: margins.setTop(value); break;
case QCP::msBottom: margins.setBottom(value); break;
case QCP::msAll: margins = QMargins(value, value, value, value); break;
default: break;
}
}
/*! \internal
Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
\ref QCP::msAll, returns 0.
\see setMarginValue
*/
inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
{
switch (side)
{
case QCP::msLeft: return margins.left();
case QCP::msRight: return margins.right();
case QCP::msTop: return margins.top();
case QCP::msBottom: return margins.bottom();
default: break;
}
return 0;
}
} // end of namespace QCP
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
class QCP_LIB_DECL QCPScatterStyle
{
Q_GADGET
public:
/*!
Defines the shape used for scatter points.
On plottables/items that draw scatters, the sizes of these visualizations (with exception of
\ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
drawn with the pen and brush specified with \ref setPen and \ref setBrush.
*/
Q_ENUMS(ScatterShape)
enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
,ssCross ///< \enumimage{ssCross.png} a cross
,ssPlus ///< \enumimage{ssPlus.png} a plus
,ssCircle ///< \enumimage{ssCircle.png} a circle
,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
,ssSquare ///< \enumimage{ssSquare.png} a square
,ssDiamond ///< \enumimage{ssDiamond.png} a diamond
,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
};
QCPScatterStyle();
QCPScatterStyle(ScatterShape shape, double size=6);
QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
QCPScatterStyle(const QPixmap &pixmap);
QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
// getters:
double size() const { return mSize; }
ScatterShape shape() const { return mShape; }
QPen pen() const { return mPen; }
QBrush brush() const { return mBrush; }
QPixmap pixmap() const { return mPixmap; }
QPainterPath customPath() const { return mCustomPath; }
// setters:
void setSize(double size);
void setShape(ScatterShape shape);
void setPen(const QPen &pen);
void setBrush(const QBrush &brush);
void setPixmap(const QPixmap &pixmap);
void setCustomPath(const QPainterPath &customPath);
// non-property methods:
bool isNone() const { return mShape == ssNone; }
bool isPenDefined() const { return mPenDefined; }
void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
void drawShape(QCPPainter *painter, QPointF pos) const;
void drawShape(QCPPainter *painter, double x, double y) const;
protected:
// property members:
double mSize;
ScatterShape mShape;
QPen mPen;
QBrush mBrush;
QPixmap mPixmap;
QPainterPath mCustomPath;
// non-property members:
bool mPenDefined;
};
Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
class QCP_LIB_DECL QCPPainter : public QPainter
{
Q_GADGET
public:
/*!
Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
depending on whether they are wanted on the respective output device.
*/
enum PainterMode { pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices
,pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
,pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
,pmNonCosmetic = 0x04 ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)
};
Q_FLAGS(PainterMode PainterModes)
Q_DECLARE_FLAGS(PainterModes, PainterMode)
QCPPainter();
QCPPainter(QPaintDevice *device);
~QCPPainter();
// getters:
bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
PainterModes modes() const { return mModes; }
// setters:
void setAntialiasing(bool enabled);
void setMode(PainterMode mode, bool enabled=true);
void setModes(PainterModes modes);
// methods hiding non-virtual base class functions (QPainter bug workarounds):
bool begin(QPaintDevice *device);
void setPen(const QPen &pen);
void setPen(const QColor &color);
void setPen(Qt::PenStyle penStyle);
void drawLine(const QLineF &line);
void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
void save();
void restore();
// non-virtual methods:
void makeNonCosmetic();
protected:
// property members:
PainterModes mModes;
bool mIsAntialiasing;
// non-property members:
QStack<bool> mAntialiasingStack;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
class QCP_LIB_DECL QCPLayer : public QObject
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
Q_PROPERTY(QString name READ name)
Q_PROPERTY(int index READ index)
Q_PROPERTY(QList<QCPLayerable*> children READ children)
Q_PROPERTY(bool visible READ visible WRITE setVisible)
/// \endcond
public:
QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
~QCPLayer();
// getters:
QCustomPlot *parentPlot() const { return mParentPlot; }
QString name() const { return mName; }
int index() const { return mIndex; }
QList<QCPLayerable*> children() const { return mChildren; }
bool visible() const { return mVisible; }
// setters:
void setVisible(bool visible);
protected:
// property members:
QCustomPlot *mParentPlot;
QString mName;
int mIndex;
QList<QCPLayerable*> mChildren;
bool mVisible;
// non-virtual methods:
void addChild(QCPLayerable *layerable, bool prepend);
void removeChild(QCPLayerable *layerable);
private:
Q_DISABLE_COPY(QCPLayer)
friend class QCustomPlot;
friend class QCPLayerable;
};
class QCP_LIB_DECL QCPLayerable : public QObject
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(bool visible READ visible WRITE setVisible)
Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
/// \endcond
public:
QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0);
~QCPLayerable();
// getters:
bool visible() const { return mVisible; }
QCustomPlot *parentPlot() const { return mParentPlot; }
QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
QCPLayer *layer() const { return mLayer; }
bool antialiased() const { return mAntialiased; }
// setters:
void setVisible(bool on);
Q_SLOT bool setLayer(QCPLayer *layer);
bool setLayer(const QString &layerName);
void setAntialiased(bool enabled);
// introduced virtual methods:
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
// non-property methods:
bool realVisibility() const;
signals:
void layerChanged(QCPLayer *newLayer);
protected:
// property members:
bool mVisible;
QCustomPlot *mParentPlot;
QPointer<QCPLayerable> mParentLayerable;
QCPLayer *mLayer;
bool mAntialiased;
// introduced virtual methods:
virtual void parentPlotInitialized(QCustomPlot *parentPlot);
virtual QCP::Interaction selectionCategory() const;
virtual QRect clipRect() const;
virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
virtual void draw(QCPPainter *painter) = 0;
// events:
virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
virtual void deselectEvent(bool *selectionStateChanged);
// non-property methods:
void initializeParentPlot(QCustomPlot *parentPlot);
void setParentLayerable(QCPLayerable* parentLayerable);
bool moveToLayer(QCPLayer *layer, bool prepend);
void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
private:
Q_DISABLE_COPY(QCPLayerable)
friend class QCustomPlot;
friend class QCPAxisRect;
};
class QCP_LIB_DECL QCPRange
{
public:
double lower, upper;
QCPRange();
QCPRange(double lower, double upper);
bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; }
bool operator!=(const QCPRange& other) const { return !(*this == other); }
QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; }
QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; }
QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; }
QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
friend inline const QCPRange operator+(const QCPRange&, double);
friend inline const QCPRange operator+(double, const QCPRange&);
friend inline const QCPRange operator-(const QCPRange& range, double value);
friend inline const QCPRange operator*(const QCPRange& range, double value);
friend inline const QCPRange operator*(double value, const QCPRange& range);
friend inline const QCPRange operator/(const QCPRange& range, double value);
double size() const;
double center() const;
void normalize();
void expand(const QCPRange &otherRange);
QCPRange expanded(const QCPRange &otherRange) const;
QCPRange sanitizedForLogScale() const;
QCPRange sanitizedForLinScale() const;
bool contains(double value) const;
static bool validRange(double lower, double upper);
static bool validRange(const QCPRange &range);
static const double minRange; //1e-280;
static const double maxRange; //1e280;
};
Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
/* documentation of inline functions */
/*! \fn QCPRange &QCPRange::operator+=(const double& value)
Adds \a value to both boundaries of the range.
*/
/*! \fn QCPRange &QCPRange::operator-=(const double& value)
Subtracts \a value from both boundaries of the range.
*/
/*! \fn QCPRange &QCPRange::operator*=(const double& value)
Multiplies both boundaries of the range by \a value.
*/
/*! \fn QCPRange &QCPRange::operator/=(const double& value)
Divides both boundaries of the range by \a value.
*/
/* end documentation of inline functions */
/*!
Adds \a value to both boundaries of the range.
*/
inline const QCPRange operator+(const QCPRange& range, double value)
{
QCPRange result(range);
result += value;
return result;
}
/*!
Adds \a value to both boundaries of the range.
*/
inline const QCPRange operator+(double value, const QCPRange& range)
{
QCPRange result(range);
result += value;
return result;
}
/*!
Subtracts \a value from both boundaries of the range.
*/
inline const QCPRange operator-(const QCPRange& range, double value)
{
QCPRange result(range);
result -= value;
return result;
}
/*!
Multiplies both boundaries of the range by \a value.
*/
inline const QCPRange operator*(const QCPRange& range, double value)
{
QCPRange result(range);
result *= value;
return result;
}
/*!
Multiplies both boundaries of the range by \a value.
*/
inline const QCPRange operator*(double value, const QCPRange& range)
{
QCPRange result(range);
result *= value;
return result;
}
/*!
Divides both boundaries of the range by \a value.
*/
inline const QCPRange operator/(const QCPRange& range, double value)
{
QCPRange result(range);
result /= value;
return result;
}
class QCP_LIB_DECL QCPMarginGroup : public QObject
{
Q_OBJECT
public:
QCPMarginGroup(QCustomPlot *parentPlot);
~QCPMarginGroup();
// non-virtual methods:
QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
bool isEmpty() const;
void clear();
protected:
// non-property members:
QCustomPlot *mParentPlot;
QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
// non-virtual methods:
int commonMargin(QCP::MarginSide side) const;
void addChild(QCP::MarginSide side, QCPLayoutElement *element);
void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
private:
Q_DISABLE_COPY(QCPMarginGroup)
friend class QCPLayoutElement;
};
class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(QCPLayout* layout READ layout)
Q_PROPERTY(QRect rect READ rect)
Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
/// \endcond
public:
/*!
Defines the phases of the update process, that happens just before a replot. At each phase,
\ref update is called with the according UpdatePhase value.
*/
enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout
,upMargins ///< Phase in which the margins are calculated and set
,upLayout ///< Final phase in which the layout system places the rects of the elements
};
Q_ENUMS(UpdatePhase)
explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
virtual ~QCPLayoutElement();
// getters:
QCPLayout *layout() const { return mParentLayout; }
QRect rect() const { return mRect; }
QRect outerRect() const { return mOuterRect; }
QMargins margins() const { return mMargins; }
QMargins minimumMargins() const { return mMinimumMargins; }
QCP::MarginSides autoMargins() const { return mAutoMargins; }
QSize minimumSize() const { return mMinimumSize; }
QSize maximumSize() const { return mMaximumSize; }
QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
// setters:
void setOuterRect(const QRect &rect);
void setMargins(const QMargins &margins);
void setMinimumMargins(const QMargins &margins);
void setAutoMargins(QCP::MarginSides sides);
void setMinimumSize(const QSize &size);
void setMinimumSize(int width, int height);
void setMaximumSize(const QSize &size);
void setMaximumSize(int width, int height);
void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
// introduced virtual methods:
virtual void update(UpdatePhase phase);
virtual QSize minimumSizeHint() const;
virtual QSize maximumSizeHint() const;
virtual QList<QCPLayoutElement*> elements(bool recursive) const;
// reimplemented virtual methods:
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
protected:
// property members:
QCPLayout *mParentLayout;
QSize mMinimumSize, mMaximumSize;
QRect mRect, mOuterRect;
QMargins mMargins, mMinimumMargins;
QCP::MarginSides mAutoMargins;
QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
// introduced virtual methods:
virtual int calculateAutoMargin(QCP::MarginSide side);
// events:
virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
// reimplemented virtual methods:
virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
virtual void parentPlotInitialized(QCustomPlot *parentPlot);
private:
Q_DISABLE_COPY(QCPLayoutElement)
friend class QCustomPlot;
friend class QCPLayout;
friend class QCPMarginGroup;
};
class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
{
Q_OBJECT
public:
explicit QCPLayout();
// reimplemented virtual methods:
virtual void update(UpdatePhase phase);
virtual QList<QCPLayoutElement*> elements(bool recursive) const;
// introduced virtual methods:
virtual int elementCount() const = 0;
virtual QCPLayoutElement* elementAt(int index) const = 0;
virtual QCPLayoutElement* takeAt(int index) = 0;
virtual bool take(QCPLayoutElement* element) = 0;
virtual void simplify();
// non-virtual methods:
bool removeAt(int index);
bool remove(QCPLayoutElement* element);
void clear();
protected:
// introduced virtual methods:
virtual void updateLayout();
// non-virtual methods:
void sizeConstraintsChanged() const;
void adoptElement(QCPLayoutElement *el);
void releaseElement(QCPLayoutElement *el);
QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
private:
Q_DISABLE_COPY(QCPLayout)
friend class QCPLayoutElement;
};
class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(int rowCount READ rowCount)
Q_PROPERTY(int columnCount READ columnCount)
Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
/// \endcond
public:
explicit QCPLayoutGrid();
virtual ~QCPLayoutGrid();
// getters:
int rowCount() const;
int columnCount() const;
QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
QList<double> rowStretchFactors() const { return mRowStretchFactors; }
int columnSpacing() const { return mColumnSpacing; }
int rowSpacing() const { return mRowSpacing; }
// setters:
void setColumnStretchFactor(int column, double factor);
void setColumnStretchFactors(const QList<double> &factors);
void setRowStretchFactor(int row, double factor);
void setRowStretchFactors(const QList<double> &factors);
void setColumnSpacing(int pixels);
void setRowSpacing(int pixels);
// reimplemented virtual methods:
virtual void updateLayout();
virtual int elementCount() const;
virtual QCPLayoutElement* elementAt(int index) const;
virtual QCPLayoutElement* takeAt(int index);
virtual bool take(QCPLayoutElement* element);
virtual QList<QCPLayoutElement*> elements(bool recursive) const;
virtual void simplify();
virtual QSize minimumSizeHint() const;
virtual QSize maximumSizeHint() const;
// non-virtual methods:
QCPLayoutElement *element(int row, int column) const;
bool addElement(int row, int column, QCPLayoutElement *element);
bool hasElement(int row, int column);
void expandTo(int newRowCount, int newColumnCount);
void insertRow(int newIndex);
void insertColumn(int newIndex);
protected:
// property members:
QList<QList<QCPLayoutElement*> > mElements;
QList<double> mColumnStretchFactors;
QList<double> mRowStretchFactors;
int mColumnSpacing, mRowSpacing;
// non-virtual methods:
void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
private:
Q_DISABLE_COPY(QCPLayoutGrid)
};
class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
{
Q_OBJECT
public:
/*!
Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
*/
enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
};
explicit QCPLayoutInset();
virtual ~QCPLayoutInset();
// getters:
InsetPlacement insetPlacement(int index) const;
Qt::Alignment insetAlignment(int index) const;
QRectF insetRect(int index) const;
// setters:
void setInsetPlacement(int index, InsetPlacement placement);
void setInsetAlignment(int index, Qt::Alignment alignment);
void setInsetRect(int index, const QRectF &rect);
// reimplemented virtual methods:
virtual void updateLayout();
virtual int elementCount() const;
virtual QCPLayoutElement* elementAt(int index) const;
virtual QCPLayoutElement* takeAt(int index);
virtual bool take(QCPLayoutElement* element);
virtual void simplify() {}
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
// non-virtual methods:
void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
void addElement(QCPLayoutElement *element, const QRectF &rect);
protected:
// property members:
QList<QCPLayoutElement*> mElements;
QList<InsetPlacement> mInsetPlacement;
QList<Qt::Alignment> mInsetAlignment;
QList<QRectF> mInsetRect;
private:
Q_DISABLE_COPY(QCPLayoutInset)
};
class QCP_LIB_DECL QCPLineEnding
{
Q_GADGET
public:
/*!
Defines the type of ending decoration for line-like items, e.g. an arrow.
\image html QCPLineEnding.png
The width and length of these decorations can be controlled with the functions \ref setWidth
and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
support a width, the length property is ignored.
\see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
*/
Q_ENUMS(EndingStyle)
enum EndingStyle { esNone ///< No ending decoration
,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
,esSpikeArrow ///< A filled arrow head with an indented back
,esLineArrow ///< A non-filled arrow head with open back
,esDisc ///< A filled circle
,esSquare ///< A filled square
,esDiamond ///< A filled diamond (45° rotated square)
,esBar ///< A bar perpendicular to the line
,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted)
,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
};
QCPLineEnding();
QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
// getters:
EndingStyle style() const { return mStyle; }
double width() const { return mWidth; }
double length() const { return mLength; }
bool inverted() const { return mInverted; }
// setters:
void setStyle(EndingStyle style);
void setWidth(double width);
void setLength(double length);
void setInverted(bool inverted);
// non-property methods:
double boundingDistance() const;
double realLength() const;
void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
protected:
// property members:
EndingStyle mStyle;
double mWidth, mLength;
bool mInverted;
};
Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
class QCP_LIB_DECL QCPGrid :public QCPLayerable
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
Q_PROPERTY(QPen pen READ pen WRITE setPen)
Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
/// \endcond
public:
QCPGrid(QCPAxis *parentAxis);
// getters:
bool subGridVisible() const { return mSubGridVisible; }
bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
QPen pen() const { return mPen; }
QPen subGridPen() const { return mSubGridPen; }
QPen zeroLinePen() const { return mZeroLinePen; }
// setters:
void setSubGridVisible(bool visible);
void setAntialiasedSubGrid(bool enabled);
void setAntialiasedZeroLine(bool enabled);
void setPen(const QPen &pen);
void setSubGridPen(const QPen &pen);
void setZeroLinePen(const QPen &pen);
protected:
// property members:
bool mSubGridVisible;
bool mAntialiasedSubGrid, mAntialiasedZeroLine;
QPen mPen, mSubGridPen, mZeroLinePen;
// non-property members:
QCPAxis *mParentAxis;
// reimplemented virtual methods:
virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
virtual void draw(QCPPainter *painter);
// non-virtual methods:
void drawGridLines(QCPPainter *painter) const;
void drawSubGridLines(QCPPainter *painter) const;
friend class QCPAxis;
};
class QCP_LIB_DECL QCPAxis : public QCPLayerable
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(AxisType axisType READ axisType)
Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)