forked from collin80/SavvyCAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qcustomplot.h
6673 lines (5585 loc) · 261 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-2018 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.06.18 **
** Version: 2.0.1 **
****************************************************************************/
#ifndef QCUSTOMPLOT_H
#define QCUSTOMPLOT_H
#include <QtCore/qglobal.h>
// some Qt version/configuration dependent macros to include or exclude certain code paths:
#ifdef QCUSTOMPLOT_USE_OPENGL
# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
# define QCP_OPENGL_PBUFFER
# else
# define QCP_OPENGL_FBO
# endif
# if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
# define QCP_OPENGL_OFFSCREENSURFACE
# endif
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
# define QCP_DEVICEPIXELRATIO_SUPPORTED
# if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
# define QCP_DEVICEPIXELRATIO_FLOAT
# endif
#endif
#include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtCore/QSharedPointer>
#include <QtCore/QTimer>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QWheelEvent>
#include <QtGui/QPixmap>
#include <QtCore/QVector>
#include <QtCore/QString>
#include <QtCore/QDateTime>
#include <QtCore/QMultiMap>
#include <QtCore/QFlags>
#include <QtCore/QDebug>
#include <QtCore/QStack>
#include <QtCore/QCache>
#include <QtCore/QMargins>
#include <qmath.h>
#include <limits>
#include <algorithm>
#ifdef QCP_OPENGL_FBO
# include <QtGui/QOpenGLContext>
# include <QtGui/QOpenGLFramebufferObject>
# ifdef QCP_OPENGL_OFFSCREENSURFACE
# include <QtGui/QOffscreenSurface>
# else
# include <QtGui/QWindow>
# endif
#endif
#ifdef QCP_OPENGL_PBUFFER
# include <QtOpenGL/QGLPixelBuffer>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
# include <qnumeric.h>
# include <QtGui/QWidget>
# include <QtGui/QPrinter>
# include <QtGui/QPrintEngine>
#else
# include <QtNumeric>
# include <QtWidgets/QWidget>
# include <QtPrintSupport/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 QCPPlottableInterface1D;
class QCPLegend;
class QCPItemPosition;
class QCPLayer;
class QCPAbstractLegendItem;
class QCPSelectionRect;
class QCPColorMap;
class QCPColorScale;
class QCPBars;
/* including file 'src/global.h', size 16357 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
#define QCUSTOMPLOT_VERSION_STR "2.0.1"
#define QCUSTOMPLOT_VERSION 0x020001
// decl definitions for shared library compilation/usage:
#if defined(QT_STATIC_BUILD)
# define QCP_LIB_DECL
#elif 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
// define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5)
#ifndef Q_DECL_OVERRIDE
# define Q_DECL_OVERRIDE
#endif
/*!
The QCP Namespace contains general enums, QFlags and functions used throughout the QCustomPlot
library.
It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject.
*/
#ifndef Q_MOC_RUN
namespace QCP {
#else
class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace
Q_GADGET
Q_ENUMS(ExportPen)
Q_ENUMS(ResolutionUnit)
Q_ENUMS(SignDomain)
Q_ENUMS(MarginSide)
Q_FLAGS(MarginSides)
Q_ENUMS(AntialiasedElement)
Q_FLAGS(AntialiasedElements)
Q_ENUMS(PlottingHint)
Q_FLAGS(PlottingHints)
Q_ENUMS(Interaction)
Q_FLAGS(Interactions)
Q_ENUMS(SelectionRectMode)
Q_ENUMS(SelectionType)
public:
#endif
/*!
Defines the different units in which the image resolution can be specified in the export
functions.
\see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered
*/
enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm)
,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm)
,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI)
};
/*!
Defines how cosmetic pens (pens with numerical width 0) are handled during export.
\see QCustomPlot::savePdf
*/
enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting
,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level)
};
/*!
Represents negative and positive sign domain, e.g. for passing to \ref
QCPAbstractPlottable::getKeyRange and \ref QCPAbstractPlottable::getValueRange.
This is primarily needed when working with logarithmic axis scales, since only one of the sign
domains can be visible at a time.
*/
enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
,sdBoth ///< Both sign domains, including zero, i.e. all numbers
,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
};
/*!
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
,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
,aeFills = 0x0100 ///< <tt>0x0100</tt> Borders of fills (e.g. under or between graphs)
,aeZeroLine = 0x0200 ///< <tt>0x0200</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
,aeOther = 0x8000 ///< <tt>0x8000</tt> Other elements that don't fit into any of the existing categories
,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, thus is most effective for pen sizes larger than 1. It is only used for solid line pens.
,phImmediateRefresh = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint.
///< 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, other layout elements,...)
};
Q_DECLARE_FLAGS(Interactions, Interaction)
/*!
Defines the behaviour of the selection rect.
\see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect
*/
enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging
,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly.
,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.)
,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction.
};
/*!
Defines the different ways a plottable can be selected. These images show the effect of the
different selection types, when the indicated selection rect was dragged:
<center>
<table>
<tr>
<td>\image html selectiontype-none.png stNone</td>
<td>\image html selectiontype-whole.png stWhole</td>
<td>\image html selectiontype-singledata.png stSingleData</td>
<td>\image html selectiontype-datarange.png stDataRange</td>
<td>\image html selectiontype-multipledataranges.png stMultipleDataRanges</td>
</tr>
</table>
</center>
\see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType
*/
enum SelectionType { stNone ///< The plottable is not selectable
,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected.
,stSingleData ///< One individual data point can be selected at a time
,stDataRange ///< Multiple contiguous data points (a data range) can be selected
,stMultipleDataRanges ///< Any combination of data points/ranges can be selected
};
/*! \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;
}
extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace
} // 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)
Q_DECLARE_METATYPE(QCP::ExportPen)
Q_DECLARE_METATYPE(QCP::ResolutionUnit)
Q_DECLARE_METATYPE(QCP::SignDomain)
Q_DECLARE_METATYPE(QCP::MarginSide)
Q_DECLARE_METATYPE(QCP::AntialiasedElement)
Q_DECLARE_METATYPE(QCP::PlottingHint)
Q_DECLARE_METATYPE(QCP::Interaction)
Q_DECLARE_METATYPE(QCP::SelectionRectMode)
Q_DECLARE_METATYPE(QCP::SelectionType)
/* end of 'src/global.h' */
/* including file 'src/vector2d.h', size 4928 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
class QCP_LIB_DECL QCPVector2D
{
public:
QCPVector2D();
QCPVector2D(double x, double y);
QCPVector2D(const QPoint &point);
QCPVector2D(const QPointF &point);
// getters:
double x() const { return mX; }
double y() const { return mY; }
double &rx() { return mX; }
double &ry() { return mY; }
// setters:
void setX(double x) { mX = x; }
void setY(double y) { mY = y; }
// non-virtual methods:
double length() const { return qSqrt(mX*mX+mY*mY); }
double lengthSquared() const { return mX*mX+mY*mY; }
QPoint toPoint() const { return QPoint(mX, mY); }
QPointF toPointF() const { return QPointF(mX, mY); }
bool isNull() const { return qIsNull(mX) && qIsNull(mY); }
void normalize();
QCPVector2D normalized() const;
QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); }
double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; }
double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const;
double distanceSquaredToLine(const QLineF &line) const;
double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const;
QCPVector2D &operator*=(double factor);
QCPVector2D &operator/=(double divisor);
QCPVector2D &operator+=(const QCPVector2D &vector);
QCPVector2D &operator-=(const QCPVector2D &vector);
private:
// property members:
double mX, mY;
friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec);
friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor);
friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor);
friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2);
friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2);
friend inline const QCPVector2D operator-(const QCPVector2D &vec);
};
Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE);
inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); }
inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); }
inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); }
inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); }
inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); }
inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); }
/*! \relates QCPVector2D
Prints \a vec in a human readable format to the qDebug output.
*/
inline QDebug operator<< (QDebug d, const QCPVector2D &vec)
{
d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")";
return d.space();
}
/* end of 'src/vector2d.h' */
/* including file 'src/painter.h', size 4035 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
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_ENUMS(PainterMode)
Q_FLAGS(PainterModes)
Q_DECLARE_FLAGS(PainterModes, PainterMode)
QCPPainter();
explicit QCPPainter(QPaintDevice *device);
// 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)
Q_DECLARE_METATYPE(QCPPainter::PainterMode)
/* end of 'src/painter.h' */
/* including file 'src/paintbuffer.h', size 4958 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
class QCP_LIB_DECL QCPAbstractPaintBuffer
{
public:
explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio);
virtual ~QCPAbstractPaintBuffer();
// getters:
QSize size() const { return mSize; }
bool invalidated() const { return mInvalidated; }
double devicePixelRatio() const { return mDevicePixelRatio; }
// setters:
void setSize(const QSize &size);
void setInvalidated(bool invalidated=true);
void setDevicePixelRatio(double ratio);
// introduced virtual methods:
virtual QCPPainter *startPainting() = 0;
virtual void donePainting() {}
virtual void draw(QCPPainter *painter) const = 0;
virtual void clear(const QColor &color) = 0;
protected:
// property members:
QSize mSize;
double mDevicePixelRatio;
// non-property members:
bool mInvalidated;
// introduced virtual methods:
virtual void reallocateBuffer() = 0;
};
class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer
{
public:
explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio);
virtual ~QCPPaintBufferPixmap();
// reimplemented virtual methods:
virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
void clear(const QColor &color) Q_DECL_OVERRIDE;
protected:
// non-property members:
QPixmap mBuffer;
// reimplemented virtual methods:
virtual void reallocateBuffer() Q_DECL_OVERRIDE;
};
#ifdef QCP_OPENGL_PBUFFER
class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer
{
public:
explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples);
virtual ~QCPPaintBufferGlPbuffer();
// reimplemented virtual methods:
virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
void clear(const QColor &color) Q_DECL_OVERRIDE;
protected:
// non-property members:
QGLPixelBuffer *mGlPBuffer;
int mMultisamples;
// reimplemented virtual methods:
virtual void reallocateBuffer() Q_DECL_OVERRIDE;
};
#endif // QCP_OPENGL_PBUFFER
#ifdef QCP_OPENGL_FBO
class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer
{
public:
explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer<QOpenGLContext> glContext, QWeakPointer<QOpenGLPaintDevice> glPaintDevice);
virtual ~QCPPaintBufferGlFbo();
// reimplemented virtual methods:
virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
virtual void donePainting() Q_DECL_OVERRIDE;
virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
void clear(const QColor &color) Q_DECL_OVERRIDE;
protected:
// non-property members:
QWeakPointer<QOpenGLContext> mGlContext;
QWeakPointer<QOpenGLPaintDevice> mGlPaintDevice;
QOpenGLFramebufferObject *mGlFrameBuffer;
// reimplemented virtual methods:
virtual void reallocateBuffer() Q_DECL_OVERRIDE;
};
#endif // QCP_OPENGL_FBO
/* end of 'src/paintbuffer.h' */
/* including file 'src/layer.h', size 6885 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
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)
Q_PROPERTY(LayerMode mode READ mode WRITE setMode)
/// \endcond
public:
/*!
Defines the different rendering modes of a layer. Depending on the mode, certain layers can be
replotted individually, without the need to replot (possibly complex) layerables on other
layers.
\see setMode
*/
enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers.
,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot).
};
Q_ENUMS(LayerMode)
QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
virtual ~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; }
LayerMode mode() const { return mMode; }
// setters:
void setVisible(bool visible);
void setMode(LayerMode mode);
// non-virtual methods:
void replot();
protected:
// property members:
QCustomPlot *mParentPlot;
QString mName;
int mIndex;
QList<QCPLayerable*> mChildren;
bool mVisible;
LayerMode mMode;
// non-property members:
QWeakPointer<QCPAbstractPaintBuffer> mPaintBuffer;
// non-virtual methods:
void draw(QCPPainter *painter);
void drawToPaintBuffer();
void addChild(QCPLayerable *layerable, bool prepend);
void removeChild(QCPLayerable *layerable);
private:
Q_DISABLE_COPY(QCPLayer)
friend class QCustomPlot;
friend class QCPLayerable;
};
Q_DECLARE_METATYPE(QCPLayer::LayerMode)
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);
virtual ~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;
// selection events:
virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
virtual void deselectEvent(bool *selectionStateChanged);
// low-level mouse events:
virtual void mousePressEvent(QMouseEvent *event, const QVariant &details);
virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos);
virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos);
virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details);
virtual void wheelEvent(QWheelEvent *event);
// 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 QCPLayer;
friend class QCPAxisRect;
};
/* end of 'src/layer.h' */
/* including file 'src/axis/range.h', size 5280 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
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 { return upper-lower; }
double center() const { return (upper+lower)*0.5; }
void normalize() { if (lower > upper) qSwap(lower, upper); }
void expand(const QCPRange &otherRange);
void expand(double includeCoord);
QCPRange expanded(const QCPRange &otherRange) const;
QCPRange expanded(double includeCoord) const;
QCPRange bounded(double lowerBound, double upperBound) const;
QCPRange sanitizedForLogScale() const;
QCPRange sanitizedForLinScale() const;
bool contains(double value) const { return value >= lower && value <= upper; }
static bool validRange(double lower, double upper);
static bool validRange(const QCPRange &range);
static const double minRange;
static const double maxRange;
};
Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
/*! \relates QCPRange
Prints \a range in a human readable format to the qDebug output.
*/
inline QDebug operator<< (QDebug d, const QCPRange &range)
{
d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")";
return d.space();
}
/*!
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;
}
/* end of 'src/axis/range.h' */
/* including file 'src/selection.h', size 8569 */
/* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */
class QCP_LIB_DECL QCPDataRange
{
public:
QCPDataRange();
QCPDataRange(int begin, int end);
bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; }
bool operator!=(const QCPDataRange& other) const { return !(*this == other); }
// getters:
int begin() const { return mBegin; }
int end() const { return mEnd; }
int size() const { return mEnd-mBegin; }
int length() const { return size(); }
// setters:
void setBegin(int begin) { mBegin = begin; }
void setEnd(int end) { mEnd = end; }
// non-property methods:
bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); }
bool isEmpty() const { return length() == 0; }
QCPDataRange bounded(const QCPDataRange &other) const;
QCPDataRange expanded(const QCPDataRange &other) const;
QCPDataRange intersection(const QCPDataRange &other) const;
QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); }
bool intersects(const QCPDataRange &other) const;
bool contains(const QCPDataRange &other) const;
private:
// property members:
int mBegin, mEnd;
};
Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE);
class QCP_LIB_DECL QCPDataSelection
{
public:
explicit QCPDataSelection();
explicit QCPDataSelection(const QCPDataRange &range);
bool operator==(const QCPDataSelection& other) const;
bool operator!=(const QCPDataSelection& other) const { return !(*this == other); }
QCPDataSelection &operator+=(const QCPDataSelection& other);
QCPDataSelection &operator+=(const QCPDataRange& other);
QCPDataSelection &operator-=(const QCPDataSelection& other);
QCPDataSelection &operator-=(const QCPDataRange& other);
friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b);
friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b);
friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b);
friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b);
friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b);
friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b);
friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b);
friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b);
// getters:
int dataRangeCount() const { return mDataRanges.size(); }
int dataPointCount() const;
QCPDataRange dataRange(int index=0) const;
QList<QCPDataRange> dataRanges() const { return mDataRanges; }
QCPDataRange span() const;
// non-property methods:
void addDataRange(const QCPDataRange &dataRange, bool simplify=true);
void clear();
bool isEmpty() const { return mDataRanges.isEmpty(); }
void simplify();
void enforceType(QCP::SelectionType type);
bool contains(const QCPDataSelection &other) const;
QCPDataSelection intersection(const QCPDataRange &other) const;
QCPDataSelection intersection(const QCPDataSelection &other) const;
QCPDataSelection inverse(const QCPDataRange &outerRange) const;
private:
// property members:
QList<QCPDataRange> mDataRanges;
inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); }
};
Q_DECLARE_METATYPE(QCPDataSelection)
/*!
Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b.
The resulting data selection is already simplified (see \ref QCPDataSelection::simplify).
*/
inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b)
{
QCPDataSelection result(a);
result += b;
return result;
}
/*!
Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b.
The resulting data selection is already simplified (see \ref QCPDataSelection::simplify).
*/
inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b)
{
QCPDataSelection result(a);
result += b;
return result;
}