-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjkqtfastplotter.h
More file actions
executable file
·2180 lines (1917 loc) · 82.7 KB
/
Copy pathjkqtfastplotter.h
File metadata and controls
executable file
·2180 lines (1917 loc) · 82.7 KB
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
/*
Copyright (c) 2008-2015 Jan W. Krieger (<jan@jkrieger.de>, <j.krieger@dkfz.de>), German Cancer Research Center (DKFZ) & IWR, University of Heidelberg
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2 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 Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Name: jkqtpfastplotter.h
Copyright: (c) 2010
Author: Jan krieger <jan@jkrieger.de>, http://www.jkrieger.de/
*/
/**
* \defgroup jkqtfastplotter Speed-Optimized Plotter class
* \ingroup tools_qt
*/
/** \file jkqtpfastplotter.h
* \ingroup jkqtfastplotter
*/
#ifndef JKQTFASTPLOTTER_H
#define JKQTFASTPLOTTER_H
#include "jkqtp_imexport.h"
#include <QWidget>
#include <QVector>
#include <QSettings>
#include <QColor>
#include <QVector>
#include <QPair>
#include <QStringList>
#include <QIcon>
#include <cmath>
#include <iostream>
#include <QMutex>
#include <QGLWidget>
#include "jkqtptools.h"
#ifdef DEBUG_TIMING
# include "jkqtphighrestimer.h"
#endif
#define JKQTFASTPLOTTER_ABS_MIN_LINEWIDTH 0.05
// forward declaration
class JKQTFPPlot;
#ifndef JKQTFASTPLOTTER_NOOPENGL
# define JKQTFASTPLOTTER_BASEWIDGET QGLWidget
# define JKQTFASTPLOTTER_BASEWIDGET_CONSTRUCTOR(parent) QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel | QGL::Rgba), parent)
#else
# define JKQTFASTPLOTTER_BASEWIDGET QWidget
# define JKQTFASTPLOTTER_BASEWIDGET_CONSTRUCTOR(parent) QWidget(parent)
#endif
/**
* \brief create a property variable and a default variable for it. Also creates a doxygen comment for the default variable
* \ingroup jkqtfastplotter
*/
#define JKQTFPPROPERTY(type,varname) \
type varname; \
/** \brief default value for property property varname. \see varname for more information */ \
type def_##varname;
/**
* \brief saves the given property (for which also a def_property exists) into the given settings object
* \ingroup jkqtfastplotter
*/
#define JKQTFPPROPERTYsave(settings, group, var, varname) \
if (var!=def_##var) settings.setValue(group+varname, var);
/**
* \brief loads the given property from the given settings object
* \ingroup jkqtfastplotter
*/
#define JKQTFPPROPERTYload(settings, group, var, varname, varconvert) \
var=settings.value(group+varname, var).varconvert;
/*! \brief a speed optimized plotter class
\ingroup jkqtfastplotter
This plotter class is (in contrast to JKQTPlotter) optimized for speed. It allows to plot function graphs/data in
a simple manner. The focus of design was not on a nice output (athough this is not unimportant), but on the speed
of the output. So the class may be used to di quick plotting of data, i.e. in fast image sequence applications.
These measures were taken to increase speed:
- The coordinate system is drawn onto an internal image which is only updated, when the size of the widget
or a property of the coordinate system changes. When only the data changes, just the data plot has to be
updated.
- The class uses an internal buffer with the complete image, so a repaint does not always trigger a complete
repaint of all elements, but just measns painting the internal image to the screen. This also allows to
plot selections ... over the plot, without having to replot the plots.
- The definition of the coordinate system as well as the definition the system ticks ... is reduced to the absolute
minimum.
- The method set_doDrawing() allows to prevent replotting of the class contents, e.g. when you want to set
a multitude of parameters without triggering a replot every time.
.
The class supports these features:
- coordinate axes may be linear or logarithmic.
- ticks and tick labels are drawn by a simple algorithm: The user has to supply two values:
\c zeroTick is a tick value that exists in any case (i.e. 0) and \c tickDistance which contains the distance
between two ticks (only applicable to linear axes). Then the class starts to draw at zeroTick and move on to
\c zeroTick+tickDistance and \c zeroTick-tickDistance until \c min / \c max of the axis is reached. For logarithmic axes
the class uses \c zeroTick*10 and \c zeroTick/10
- plot may contain a grid (x and y grid may be switched on/off separately).
- plots are represented by descendents of JKQTFPPlot and the plotting code is completely
contained therein (and should be speed optimized).
- it is possible to keep a specified aspect ration
- it is possible to couple different plots in a way, that they are plottetd with the same width/height
both in pixel and world coordinates by using plotterSizesChanged() and synchronizeX() / synchronizeY().
.
*/
class LIB_EXPORT JKQTFastPlotter : public JKQTFASTPLOTTER_BASEWIDGET {
Q_OBJECT
protected:
/** \brief indicates whether to do full repaint (system and data) at the next repaint (any of the repaint meothods) */
bool doFullRepaint;
/** \brief this stores the currently displayed coordinate system */
QImage systemImage;
/** \brief this stores the currently displayed plot */
QImage image;
/** \brief this can be used when drawing a zoom rectangle to store an unchanged
* copy of the currently displayed image.
*/
QImage oldImage;
/** \brief if \c false the plotting won't be performed (may be used to set more than one parameter without replot */
bool doDrawing;
/** \brief list of plots in this graph */
QVector<JKQTFPPlot*> plots;
/** \brief free space between widget left border and plot left border */
JKQTFPPROPERTY(int, plotBorderLeft);
/** \brief free space between widget bottom border and plot bottom border */
JKQTFPPROPERTY(int, plotBorderBottom);
/** \brief free space between widget right border and plot left border */
JKQTFPPROPERTY(int, plotBorderRight);
/** \brief free space between widget top border and plot bottom border */
JKQTFPPROPERTY(int, plotBorderTop);
/** \brief internally calculated: free space between widget left border and plot left border
*
* \note This is the actual border used for plotting, as it may be different from what the user supplied.
* Note also that this is at least as huge as the suer supplied border value!
*/
int internalPlotBorderLeft;
/** \brief internally calculated: free space between widget bottom border and plot bottom border
*
* \note This is the actual border used for plotting, as it may be different from what the user supplied.
* Note also that this is at least as huge as the suer supplied border value!
*/
int internalPlotBorderBottom;
/** \brief internally calculated: free space between widget right border and plot left border
*
* \note This is the actual border used for plotting, as it may be different from what the user supplied.
* Note also that this is at least as huge as the suer supplied border value!
*/
int internalPlotBorderRight;
/** \brief internally calculated: free space between widget top border and plot bottom border
*
* \note This is the actual border used for plotting, as it may be different from what the user supplied.
* Note also that this is at least as huge as the suer supplied border value!
*/
int internalPlotBorderTop;
/** \brief plot width in pixels inside the widget (calculated by calcPlotScaling() from plotBorderLeft, plotBorderRight and widgetWidth) */
int plotWidth;
/** \brief plot height in pixels inside the widget (calculated by calcPlotScaling() from plotBorderTop, plotBorderBottom and widgetHeight) */
int plotHeight;
/** \brief color of the coordinate system */
JKQTFPPROPERTY(QColor, systemColor);
/** \brief width of the coordinate (in pixel) */
JKQTFPPROPERTY(double, systemWidth);
/** \brief color of the background*/
JKQTFPPROPERTY(QColor, backgroundColor);
/** \brief color of the plot's background
*
* \note the background is not drawn if this color is set to \c QColor(Qt::transparent) !
*/
JKQTFPPROPERTY(QColor, plotBackgroundColor);
/** \brief indicates whether to draw a system box */
JKQTFPPROPERTY(bool, drawSystemBox);
/** \brief indicates whether to draw axes at x=0/y=0 */
JKQTFPPROPERTY(bool, drawZeroAxes);
/** \brief indicates whether to draw a grid */
JKQTFPPROPERTY(bool, drawGrid);
/** \brief color of the coordinate grid */
JKQTFPPROPERTY(QColor, gridColor);
/** \brief style of the coordinate grid */
JKQTFPPROPERTY(Qt::PenStyle, gridStyle);
/** \brief width of the coordinate grid (in pixel) */
JKQTFPPROPERTY(double, gridWidth);
/** \brief font size (in points) of the axis labels */
JKQTFPPROPERTY(double, labelFontSize);
/** \brief font name of the axis labels */
JKQTFPPROPERTY(QString, labelFontName);
/** \brief font size (in points) of the tick labels */
JKQTFPPROPERTY(double, tickFontSize);
/** \brief font name of the tick labels */
JKQTFPPROPERTY(QString, tickFontName);
/** \brief length of an axis tick (pixels) */
JKQTFPPROPERTY(double, tickLength);
/** \brief minimum value of x axis */
double xMin;
/** \brief maximum value of x axis */
double xMax;
/** \brief minimum value of y axis */
double yMin;
/** \brief maximum value of y axis */
double yMax;
/** \brief is x axis logarithmic? */
bool xAxisLog;
/** \brief is x axis logarithmic? */
bool yAxisLog;
/** \brief width of plot on x axis (calculated internally) */
double xWidth;
/** \brief x axis scaling factor (calculated internally) */
double xScale;
/** \brief x axis offset (calculated internally) */
double xOffset;
/** \brief width of plot on y axis (calculated internally) */
double yWidth;
/** \brief y axis scaling factor (calculated internally) */
double yScale;
/** \brief y axis offset (calculated internally) */
double yOffset;
/** \brief a label position from which axis label plotting is started for the x axis */
double xZeroTick;
/** \brief a label position from which axis label plotting is started for the y axis */
double yZeroTick;
/** \brief distance between two labels on x axis */
double xTickDistance;
/** \brief distance between two labels on y axis */
double yTickDistance;
/** \brief label of x axis */
QString xAxisLabel;
/** \brief label of y axis */
QString yAxisLabel;
/** \brief plot y axis label */
bool yAxisLabelVisible;
/** \brief plot x axis label */
bool xAxisLabelVisible;
/** \brief synchronize x-axis settings to this plotter */
JKQTFastPlotter* synchronizeX;
/** \brief synchronize y-axis settings to this plotter */
JKQTFastPlotter* synchronizeY;
/** \brief aspect ration of the plot, only used when maintainAspectRation is \c true
*
* The aspect ratio is defined as \c width/height of the plot in pixels.
* So if you want to have a plot spanning \c x=0..20 and \c y=0..10 where each 1x1 square should be
* as wide as high you will have to set aspectRatio to \c 2 .
*
* \note Note that aspect ratios only make sense for linear-linear plots. This will be ignored
* if any one axis is logarithmic.
*/
double aspectRatio;
/** \brief indicates whether to maintain a specific aspect ratio */
bool maintainAspectRatio;
QPoint mouseDragStart;
QPoint mouseDragEnd;
bool dragging;
QPen dragShapePen;
bool dragLine;
QAction* actCopyImage;
/** \brief this simply paints the stored image to the widget's surface */
virtual void paintEvent(QPaintEvent *event);
/** \brief resizes the internal representation (image) of the graphs */
virtual void resizeEvent(QResizeEvent *event);
/** \brief event handler for a double click */
virtual void mouseDoubleClickEvent ( QMouseEvent * event );
/** \brief event handler for a mouse move */
virtual void mouseMoveEvent ( QMouseEvent * event );
/** \brief event handler for a mouse button press */
virtual void mousePressEvent ( QMouseEvent * event );
/** \brief event handler for a mouse button is released */
virtual void mouseReleaseEvent(QMouseEvent* event);
/** \brief paint the coordinate system */
void plotSystem(QPainter& painter);
/** \brief paint the graphs */
void plotGraphs(QPainter& painter);
/** \brief recalculate the scaling of the plot */
void calcPlotScaling();
QSize minimumSizeHint() const;
/** \brief mutex to lock global widget repaint */
QMutex mutexRepaint;
/** \brief mutex to lock data repaint */
QMutex mutexRepaintData;
/** \brief mutex to lock system repaint */
QMutex mutexRepaintSystem;
public:
/** \brief class constructor */
JKQTFastPlotter(QWidget *parent = 0);
/** \brief set the properties of the x axis */
void setXRange(double min, double max, bool logarithmic=false);
/** \brief set the properties of the y axis */
void setYRange(double min, double max, bool logarithmic=false);
/** \brief set the properties of both axes */
void setXYRange(double xmin, double xmax, double ymin, double ymax, bool xlogarithmic=false, bool ylogarithmic=false);
/** \brief clear all plots in the graph
*
* \param remove if \c true the object will also be deleted from memory, not just from the list
*/
void clearPlots(bool remove=false);
/** \brief add a new graph */
void addPlot(JKQTFPPlot* g);
/** \brief return the internal number (0..N-1) of the given plot, or -1*/
int getPlotNum(JKQTFPPlot* g);
/** \brief remove given graph
*
* \param id specifies the graph to delete
* \param remove if \c true the object will also be deleted from memory, not just from the list
*/
void deletePlot(int id, bool remove=false);
/** \brief remove given graph
*
* \param g specifies the graph to delete
* \param remove if \c true the object will also be deleted from memory, not just from the list
*/
void deletePlot(JKQTFPPlot* g, bool remove=false);
/** \brief return x-pixel coordinate from x coordinate */
inline double x2p(double x) {
if (xAxisLog) {
if (x<0) return xOffset+log(xMin/10.0)/log(10.0)*xScale;
return xOffset+log(x)/log(10.0)*xScale;
} else {
return xOffset+x*xScale;
}
};
/** \brief return x coordinate coordinate from x-pixel */
inline double p2x(long x) {
if (xAxisLog) {
return exp(log(10.0)*((double)x-xOffset)/(xScale));
} else {
return ((double)x-xOffset)/(xScale);
}
};
/** \brief return y-pixel coordinate from y coordinate */
inline double y2p(double y) {
if (yAxisLog) {
if (y<0) return yOffset-log(yMin/10.0)/log(10.0)*yScale;
return yOffset-log(y)/log(10.0)*yScale;
} else {
return yOffset-y*yScale;
}
};
/** \brief return y coordinate coordinate from y-pixel */
inline double p2y(long y) {
if (yAxisLog) {
return exp(log(10.0)*((double)y-yOffset)/(-1.0*yScale));
} else {
return ((double)y-yOffset)/(-1.0*yScale);
}
};
JKQTPGET_SET_MACRO_I(QPen, dragShapePen, update())
JKQTPGET_SET_MACRO_I(bool, dragLine, update())
JKQTPGET_SET_MACRO_I(int, plotBorderLeft, update_plot())
JKQTPGET_SET_MACRO_I(int, plotBorderBottom, update_plot())
JKQTPGET_SET_MACRO_I(int, plotBorderRight, update_plot())
JKQTPGET_SET_MACRO_I(int, plotBorderTop, update_plot())
JKQTPGET_MACRO(int, plotWidth)
JKQTPGET_MACRO(int, plotHeight)
JKQTPGET_SET_MACRO(bool, doDrawing)
JKQTPGET_MACRO(int, internalPlotBorderLeft)
JKQTPGET_MACRO(int, internalPlotBorderBottom)
JKQTPGET_MACRO(int, internalPlotBorderRight)
JKQTPGET_MACRO(int, internalPlotBorderTop)
JKQTPGET_MACRO(double, xMin)
JKQTPGET_MACRO(double, xMax)
JKQTPGET_MACRO(double, yMin)
JKQTPGET_MACRO(double, yMax)
JKQTPGET_MACRO(bool, xAxisLog)
JKQTPGET_MACRO(bool, yAxisLog)
JKQTPGET_SET_MACRO_I(QColor, backgroundColor, update_plot())
JKQTPGET_SET_MACRO_I(QColor, plotBackgroundColor, update_plot())
JKQTPGET_SET_MACRO_I(bool, drawGrid, update_plot())
JKQTPGET_SET_MACRO_I(QColor, gridColor, update_plot())
JKQTPGET_SET_MACRO_I(Qt::PenStyle, gridStyle, update_plot())
JKQTPGET_SET_MACRO_I(double, gridWidth, update_plot())
JKQTPGET_SET_MACRO_I(double, labelFontSize, update_plot())
JKQTPGET_SET_MACRO_I(QString, labelFontName, update_plot())
JKQTPGET_SET_MACRO_I(double, tickFontSize, update_plot())
JKQTPGET_SET_MACRO_I(QString, tickFontName, update_plot())
JKQTPGET_SET_MACRO_I(double, tickLength, update_plot())
JKQTPGET_SET_MACRO_I(bool, drawSystemBox, update_plot())
JKQTPGET_SET_MACRO_I(bool, drawZeroAxes, update_plot())
JKQTPGET_SET_MACRO_I(QColor, systemColor, update_plot())
JKQTPGET_SET_MACRO_I(double, systemWidth, update_plot())
JKQTPGET_SET_MACRO_I(double, xZeroTick, update_plot())
JKQTPGET_SET_MACRO_I(double, yZeroTick, update_plot())
JKQTPGET_SET_MACRO_I(double, xTickDistance, update_plot())
JKQTPGET_SET_MACRO_I(double, yTickDistance, update_plot())
JKQTPGET_SET_MACRO_I(QString, xAxisLabel, update_plot())
JKQTPGET_SET_MACRO_I(QString, yAxisLabel, update_plot())
JKQTPGET_SET_MACRO_I(double, aspectRatio, update_plot())
JKQTPGET_SET_MACRO_I(bool, maintainAspectRatio, update_plot())
JKQTPGET_SET_MACRO_I(bool, xAxisLabelVisible, update_plot())
JKQTPGET_SET_MACRO_I(bool, yAxisLabelVisible, update_plot())
JKQTPGET_SET_MACRO_I(JKQTFastPlotter*, synchronizeX, update_plot())
JKQTPGET_SET_MACRO_I(JKQTFastPlotter*, synchronizeY, update_plot())
/** \brief draw the contents onto any QPainter, starting at (0,0), returns the size of the whole plot in \a size, if supplied with the default background color */
void draw(QPainter* painter, QSize* size=NULL);
/** \brief draw the contents onto any QPainter, starting at (0,0), returns the size of the whole plot in \a size, if supplied with the supplied\a background color */
void draw(QPainter* painter, QColor background, QSize* size);
signals:
/** \brief emitted whenever the graph sizes (borders, plotWidth, plotHeight) change*/
void plotterSizesChanged();
/** \brief emitted whenever the graph is replotted */
void replotting();
/** \brief emitted whenever the mouse is clicked inside the plot */
void clicked(double x, double y);
/** \brief emitted whenever the mouse is clicked inside the plot */
void clicked(double x, double y, Qt::KeyboardModifiers modifiers);
/** \brief emitted whenever the mouse is double-clicked inside the plot */
void doubleClicked(double x, double y);
/** \brief emitted whenever the mouse is double-clicked inside the plot */
void doubleClicked(double x, double y, Qt::KeyboardModifiers modifiers);
/** \brief emitted whenever the mouse is clicked inside the plot */
void mouseMoved(double x, double y);
/** \brief emitted when the mouse has been dragged with the left button clicked */
void mouseDragged(double x_start, double y_start, double x_end, double y_end, Qt::KeyboardModifiers modifiers);
/** \brief emitted after the mouse has been dragged with the left button clicked */
void mouseDragFinished(double x_start, double y_start, double x_end, double y_end, Qt::KeyboardModifiers modifiers);
public slots:
/** \brief copy the current plot image to the clipboard */
void copyImage();
/** \brief replot everything (slowest possible plotting) */
void update_plot();
/** \brief replot everything (slowest possible plotting) and forces a repaint calling QWidget::repaint() */
void update_plot_immediate();
/** \brief replot only the data
*
* This internally calls QWidget::update(), so no immediate repaint() is forced! If you want an immediate update,
* call update_data_immediate() instead!
*/
void update_data();
/** \brief replot only the data, forces a redraw by calling QWidget::repaint() */
void update_data_immediate();
/** \brief set xMin*/
void set_xMin(double value){
set_doDrawing(false);
setXRange(value,xMax,xAxisLog);
set_doDrawing(true);
}
/** \brief set xMax*/
void set_xMax(double value){
set_doDrawing(false);
setXRange(xMin,value,xAxisLog);
set_doDrawing(true);
}
/** \brief set yMin*/
void set_yMin(double value){
set_doDrawing(false);
setYRange(value,yMax,yAxisLog);
set_doDrawing(true);
}
/** \brief set yMax*/
void set_yMax(double value){
set_doDrawing(false);
setYRange(yMin,value,yAxisLog);
set_doDrawing(true);
}
};
/*! \brief base class for all plots that may be plotted by JKQTFastPlotter
\ingroup jkqtfastplotter
*/
class LIB_EXPORT JKQTFPPlot: public QObject {
Q_OBJECT
protected:
/** \brief parent class, i.e. the plotter to plot on */
JKQTFastPlotter* parent;
/** \brief indicates whether the plot is visible or not */
bool visible;
public:
/** \brief class constructor */
JKQTFPPlot(JKQTFastPlotter* parent);
/** \brief virtual class destructor */
virtual ~JKQTFPPlot() {};
/** \brief set the parent of the plot */
void setParent(JKQTFastPlotter* parent) { this->parent=parent; QObject::setParent(parent); };
bool isVisible() const { return this->visible; }
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter)=0;
/** \brief draw the graph */
void paint(QPainter& painter);
/** \brief start a replot of the parent widget */
void replot();
public slots:
void setVisible(bool visible) { this->visible=visible; replot(); }
};
/*! \brief a simple line plot for JKQTFastPlotter
\ingroup jkqtfastplotter
This class plots data as (x,y) points connected by straight lines. If errors for the y values are
provided, also y+/-yerr errorlines are drawn.
*/
class LIB_EXPORT JKQTFPLinePlot: public JKQTFPPlot {
public:
/** \brief used to store which datatype is used for the plot data */
enum DataType {
JKQTFPLPPointer,
JKQTFPLPVector
};
protected:
/** \brief number of datapoints in the plot */
unsigned int N;
/** \brief pointer to x-coordinate data to display */
double* x;
/** \brief pointer to y-coordinate data to display */
double* y;
/** \brief pointer to yerr-coordinate data to display */
double* yerr;
/** \brief pointer to x-coordinate data to display */
QVector<double>* xv;
/** \brief pointer to y-coordinate data to display */
QVector<double>* yv;
/** \brief pointer to yerr-coordinate data to display */
QVector<double>* yerrv;
/** \brief which type of data is used for plotting ? */
DataType datatype;
/** \brief color of the graph */
QColor color;
/** \brief style of the graph */
Qt::PenStyle style;
/** \brief width of the graph (in pixels) */
double width;
/** \brief color of the graph */
QColor errorColor;
/** \brief style of the graph */
Qt::PenStyle errorStyle;
/** \brief width of the graph (in pixels) */
double errorWidth;
public:
/*! \brief class constructor
\param parent parent widget
\param N number of datapoints in the plot
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPLinePlot(JKQTFastPlotter* parent, unsigned int N, double* x, double* y, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1) ;
/*! \brief class constructor
\param parent parent widget
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPLinePlot(JKQTFastPlotter* parent, QVector<double>* x, QVector<double>* y, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1) ;
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter);
inline void set_data(double* x, double* y, unsigned int N) {
this->x=x;
this->y=y;
this->yerr=NULL;
this->N=N;
datatype=JKQTFPLPPointer;
replot();
};
inline void set_data(double* x, double* y, double* yerr, unsigned int N) {
this->x=x;
this->y=y;
this->yerr=yerr;
this->N=N;
datatype=JKQTFPLPPointer;
replot();
};
inline void set_data(QVector<double>* x, QVector<double>* y) {
this->x=NULL;
this->y=NULL;
this->yerr=NULL;
this->xv=x;
this->yv=y;
this->yerrv=NULL;
this->N=x->size();
datatype=JKQTFPLPVector;
replot();
};
inline void set_data(QVector<double>* x, QVector<double>* y, QVector<double>* yerr) {
this->x=NULL;
this->y=NULL;
this->yerr=NULL;
this->xv=x;
this->yv=y;
this->yerrv=yerr;
this->N=x->size();
datatype=JKQTFPLPVector;
replot();
};
inline unsigned int get_N() {
if (datatype==JKQTFPLPPointer)
return N;
if (datatype==JKQTFPLPVector)
return xv->size();
return N;
}
JKQTPGET_MACRO(double*, x)
JKQTPGET_MACRO(double*, y)
JKQTPGET_MACRO(double*, yerr)
JKQTPGET_MACRO(QVector<double>*, xv)
JKQTPGET_MACRO(QVector<double>*, yv)
JKQTPGET_MACRO(QVector<double>*, yerrv)
JKQTPGET_MACRO(DataType, datatype)
JKQTPGET_SET_MACRO_I(QColor, color, replot())
JKQTPGET_SET_MACRO_I(Qt::PenStyle, style, replot())
JKQTPGET_SET_MACRO_I(double, width, replot())
JKQTPGET_SET_MACRO_I(QColor, errorColor, replot())
JKQTPGET_SET_MACRO_I(Qt::PenStyle, errorStyle, replot())
JKQTPGET_SET_MACRO_I(double, errorWidth, replot())
};
/*! \brief a simple plot that draws a cross for every datapoint
\ingroup jkqtfastplotter
This class does not support y errors!
*/
class LIB_EXPORT JKQTFPVCrossPlot: public JKQTFPLinePlot {
Q_OBJECT
public:
/*! \brief class constructor
\param parent parent widget
\param N number of datapoints in the plot
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPVCrossPlot(JKQTFastPlotter* parent, unsigned int N, double* x, double* y, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1) ;
/*! \brief class constructor
\param parent parent widget
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPVCrossPlot(JKQTFastPlotter* parent, QVector<double>* x, QVector<double>* y, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1) ;
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter);
JKQTPGET_SET_MACRO_I(double, crossWidth, replot())
protected:
/** \brief width of the crosses */
double crossWidth;
};
/*! \brief a simple vertical bar plot for JKQTFastPlotter
\ingroup jkqtfastplotter
This class does not support y errors!
*/
class LIB_EXPORT JKQTFPVBarPlot: public JKQTFPLinePlot {
Q_OBJECT
public:
/*! \brief class constructor
\param parent parent widget
\param N number of datapoints in the plot
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPVBarPlot(JKQTFastPlotter* parent, unsigned int N, double* x, double* y, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1) ;
/*! \brief class constructor
\param parent parent widget
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPVBarPlot(JKQTFastPlotter* parent, QVector<double>* x, QVector<double>* y, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1) ;
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter);
};
/*! \brief plot a range of x values
\ingroup jkqtfastplotter
*/
class LIB_EXPORT JKQTFPXRangePlot: public JKQTFPPlot {
Q_OBJECT
protected:
/** \brief start of x range */
double xmin;
/** \brief end of x range */
double xmax;
double centerline;
bool showCenterline;
/** \brief color of the graph */
QColor color;
/** \brief style of the graph */
Qt::PenStyle style;
/** \brief width of the graph (in pixels) */
double width;
/** \brief fill color of the graph */
QColor fillColor;
/** \brief fill style of the graph */
Qt::BrushStyle fillStyle;
public:
/*! \brief class constructor
\param parent parent widget
\param N number of datapoints in the plot
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPXRangePlot(JKQTFastPlotter* parent, double xmin, double xmax, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1, Qt::BrushStyle fillStyle=Qt::NoBrush) ;
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter);
JKQTPGET_SET_MACRO_I(QColor, color, replot())
JKQTPGET_SET_MACRO_I(QColor, fillColor, replot())
JKQTPGET_SET_MACRO_I(Qt::BrushStyle, fillStyle, replot())
JKQTPGET_SET_MACRO_I(Qt::PenStyle, style, replot())
JKQTPGET_SET_MACRO_I(double, width, replot())
JKQTPGET_MACRO(double, xmin)
JKQTPGET_MACRO(double, xmax)
JKQTPGET_MACRO(double, centerline)
JKQTPGET_SET_MACRO_I(bool, showCenterline, replot())
public slots:
void set_centerline(int centerline) {
if (this->centerline!=centerline) {
this->centerline=centerline;
replot();
}
}
void set_xmin(double xmin) {
if (this->xmin!=xmin) {
this->xmin=xmin;
replot();
}
}
void set_xmax(double xmax) {
if (this->xmax!=xmax) {
this->xmax=xmax;
replot();
}
}
void set_xmin(int xmin) {
if (this->xmin!=xmin) {
this->xmin=xmin;
replot();
}
}
void set_xmax(int xmax) {
if (this->xmax!=xmax) {
this->xmax=xmax;
replot();
}
}
};
/*! \brief plot a range of x values
\ingroup jkqtfastplotter
*/
class LIB_EXPORT JKQTFPYRangePlot: public JKQTFPPlot {
Q_OBJECT
protected:
/** \brief start of x range */
double ymin;
/** \brief end of x range */
double ymax;
double centerline;
bool showCenterline;
/** \brief color of the graph */
QColor color;
/** \brief style of the graph */
Qt::PenStyle style;
/** \brief width of the graph (in pixels) */
double width;
/** \brief fill color of the graph */
QColor fillColor;
/** \brief fill style of the graph */
Qt::BrushStyle fillStyle;
public:
/*! \brief class constructor
\param parent parent widget
\param N number of datapoints in the plot
\param x points to the x values in the plot
\param y points to the y values in the plot
\param color color of the plot
\param style style of the graph
\param width width of the plot (in pixels)
*/
JKQTFPYRangePlot(JKQTFastPlotter* parent, double ymin, double ymax, QColor color=QColor("red"), Qt::PenStyle style=Qt::SolidLine, double width=1, Qt::BrushStyle fillStyle=Qt::NoBrush) ;
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter);
JKQTPGET_SET_MACRO_I(QColor, color, replot())
JKQTPGET_SET_MACRO_I(QColor, fillColor, replot())
JKQTPGET_SET_MACRO_I(Qt::BrushStyle, fillStyle, replot())
JKQTPGET_SET_MACRO_I(Qt::PenStyle, style, replot())
JKQTPGET_SET_MACRO_I(double, width, replot())
JKQTPGET_MACRO(double, ymin)
JKQTPGET_MACRO(double, ymax)
JKQTPGET_MACRO(double, centerline)
JKQTPGET_SET_MACRO_I(bool, showCenterline, replot())
public slots:
void set_centerline(int centerline) {
if (this->centerline!=centerline) {
this->centerline=centerline;
replot();
}
}
void set_ymin(double xmin) {
if (this->ymin!=xmin) {
this->ymin=xmin;
replot();
}
}
void set_ymax(double xmax) {
if (this->ymax!=xmax) {
this->ymax=xmax;
replot();
}
}
void set_ymin(int xmin) {
if (this->ymin!=xmin) {
this->ymin=xmin;
replot();
}
}
void set_ymax(int xmax) {
if (this->ymax!=xmax) {
this->ymax=xmax;
replot();
}
}
};
/*! \brief a plot of a QImage
\ingroup jkqtfastplotter
*/
class LIB_EXPORT JKQTFPQImagePlot: public JKQTFPPlot {
Q_OBJECT
protected:
/** \brief image to plot */
QImage* image;
/** \brief minimum x value of the image */
double xmin;
/** \brief maximum x value of the image */
double xmax;
/** \brief minimum x value of the image */
double ymin;
/** \brief maximum x value of the image */
double ymax;
public:
/*! \brief class constructor
*/
JKQTFPQImagePlot(JKQTFastPlotter* parent, QImage* image, double xmin, double xmax, double ymin, double ymax) ;
JKQTFPQImagePlot(JKQTFastPlotter* parent, QImage* image);
/** \brief draw the graph */
virtual void drawGraph(QPainter& painter);
JKQTPGET_SET_MACRO_I(QImage*, image, replot())
JKQTPGET_SET_MACRO_I(double, xmin, replot())
JKQTPGET_SET_MACRO_I(double, xmax, replot())
JKQTPGET_SET_MACRO_I(double, ymin, replot())
JKQTPGET_SET_MACRO_I(double, ymax, replot())
};
/*!
\brief An enum for selecting the palette for coloring
\ingroup jkqtfastplotter
\details Here, the color palettes are illustrated (left is the color for the minimum and right for the maximum).
*/
enum JKQTFPColorPalette {
JKQTFP_RED=0, /*!< \image html RED.png */
JKQTFP_INVERTEDRED=1, /*!< \image html RED.png */
JKQTFP_GREEN=2, /*!< \image html GREEN.png */
JKQTFP_INVERTEDGREEN=3, /*!< \image html GREEN.png */
JKQTFP_BLUE=4, /*!< \image html BLUE.png */