-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqwt_plot_curve.cpp
942 lines (786 loc) · 24.1 KB
/
qwt_plot_curve.cpp
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
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_curve.h"
#include "qwt_legend.h"
#include "qwt_legend_item.h"
#include "qwt_scale_map.h"
#include "qwt_plot.h"
#include "qwt_plot_canvas.h"
#include "qwt_symbol.h"
#include <qpainter.h>
#include <qpixmap.h>
#include <qalgorithms.h>
#include <qmath.h>
static int verifyRange( int size, int &i1, int &i2 )
{
if ( size < 1 )
return 0;
i1 = qBound( 0, i1, size - 1 );
i2 = qBound( 0, i2, size - 1 );
if ( i1 > i2 )
qSwap( i1, i2 );
return ( i2 - i1 + 1 );
}
class QwtPlotCurve::PrivateData
{
public:
PrivateData():
style( QwtPlotCurve::Lines ),
baseline( 0.0 ),
symbol( NULL ),
attributes( 0 ),
legendAttributes( 0 )
{
pen = QPen( Qt::black );
}
~PrivateData()
{
delete symbol;
}
QwtPlotCurve::CurveStyle style;
double baseline;
const QwtSymbol *symbol;
QPen pen;
QBrush brush;
QwtPlotCurve::CurveAttributes attributes;
QwtPlotCurve::LegendAttributes legendAttributes;
};
/*!
Constructor
\param title Title of the curve
*/
QwtPlotCurve::QwtPlotCurve( const QwtText &title ):
QwtPlotSeriesItem<QPointF>( title )
{
init();
}
/*!
Constructor
\param title Title of the curve
*/
QwtPlotCurve::QwtPlotCurve( const QString &title ):
QwtPlotSeriesItem<QPointF>( QwtText( title ) )
{
init();
}
//! Destructor
QwtPlotCurve::~QwtPlotCurve()
{
delete d_data;
}
//! Initialize internal members
void QwtPlotCurve::init()
{
d_data = new PrivateData;
d_series = new QwtPointSeriesData();
setZ( 20.0 );
}
/*!
Specify an attribute how to draw the legend identifier
\param attribute Attribute
\param on On/Off
/sa testLegendAttribute()
*/
void QwtPlotCurve::setLegendAttribute( LegendAttribute attribute, bool on )
{
if ( on )
d_data->legendAttributes |= attribute;
else
d_data->legendAttributes &= ~attribute;
}
/*!
\brief Return the current paint attributes
\sa setLegendAttribute()
*/
bool QwtPlotCurve::testLegendAttribute( LegendAttribute attribute ) const
{
return ( d_data->legendAttributes & attribute );
}
/*!
Set the curve's drawing style
\param style Curve style
\sa style()
*/
void QwtPlotCurve::setStyle( CurveStyle style )
{
if ( style != d_data->style )
{
d_data->style = style;
itemChanged();
}
}
/*!
Return the current style
\sa setStyle()
*/
QwtPlotCurve::CurveStyle QwtPlotCurve::style() const
{
return d_data->style;
}
/*!
Assign a symbol
\param symbol Symbol
\sa symbol()
*/
void QwtPlotCurve::setSymbol( const QwtSymbol *symbol )
{
if ( symbol != d_data->symbol )
{
delete d_data->symbol;
d_data->symbol = symbol;
itemChanged();
}
}
/*!
\return Current symbol or NULL, when no symbol has been assigned
\sa setSymbol()
*/
const QwtSymbol *QwtPlotCurve::symbol() const
{
return d_data->symbol;
}
/*!
Assign a pen
\param pen New pen
\sa pen(), brush()
*/
void QwtPlotCurve::setPen( const QPen &pen )
{
if ( pen != d_data->pen )
{
d_data->pen = pen;
itemChanged();
}
}
/*!
\return Pen used to draw the lines
\sa setPen(), brush()
*/
const QPen& QwtPlotCurve::pen() const
{
return d_data->pen;
}
/*!
\brief Assign a brush.
In case of brush.style() != QBrush::NoBrush
and style() != QwtPlotCurve::Sticks
the area between the curve and the baseline will be filled.
In case !brush.color().isValid() the area will be filled by
pen.color(). The fill algorithm simply connects the first and the
last curve point to the baseline. So the curve data has to be sorted
(ascending or descending).
\param brush New brush
\sa brush(), setBaseline(), baseline()
*/
void QwtPlotCurve::setBrush( const QBrush &brush )
{
if ( brush != d_data->brush )
{
d_data->brush = brush;
itemChanged();
}
}
/*!
\return Brush used to fill the area between lines and the baseline
\sa setBrush(), setBaseline(), baseline()
*/
const QBrush& QwtPlotCurve::brush() const
{
return d_data->brush;
}
/*!
Draw an interval of the curve
\param painter Painter
\param xMap Maps x-values into pixel coordinates.
\param yMap Maps y-values into pixel coordinates.
\param canvasRect Contents rect of the canvas
\param from Index of the first point to be painted
\param to Index of the last point to be painted. If to < 0 the
curve will be painted to its last point.
\sa drawCurve(), drawSymbols(),
*/
void QwtPlotCurve::drawSeries( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const
{
if ( !painter || dataSize() <= 0 )
return;
if ( to < 0 )
to = dataSize() - 1;
if ( verifyRange( dataSize(), from, to ) > 0 )
{
painter->save();
painter->setPen( d_data->pen );
/*
Qt 4.0.0 is slow when drawing lines, but it's even
slower when the painter has a brush. So we don't
set the brush before we really need it.
*/
drawCurve( painter, d_data->style, xMap, yMap, from, to );
painter->restore();
if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
painter->save();
drawSymbols( painter, *d_data->symbol,
xMap, yMap, canvasRect, from, to );
painter->restore();
}
}
}
/*!
\brief Draw the line part (without symbols) of a curve interval.
\param painter Painter
\param style curve style, see QwtPlotCurve::CurveStyle
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks()
*/
void QwtPlotCurve::drawCurve( QPainter *painter, int style,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to ) const
{
switch ( style )
{
case Lines:
drawLines( painter, xMap, yMap, from, to );
break;
case Sticks:
drawSticks( painter, xMap, yMap, from, to );
break;
case Steps:
drawSteps( painter, xMap, yMap, from, to );
break;
case Dots:
drawDots( painter, xMap, yMap, from, to );
break;
case NoCurve:
default:
break;
}
}
/*!
\brief Draw lines
If the CurveAttribute Fitted is enabled a QwtCurveFitter tries
to interpolate/smooth the curve, before it is painted.
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa setCurveAttribute(), setCurveFitter(), draw(),
drawLines(), drawDots(), drawSteps(), drawSticks()
*/
#include <qnumeric.h>
void QwtPlotCurve::drawLines( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to ) const
{
int size = to - from + 1;
if ( size <= 0 )
return;
QPolygonF polyline( size );
QPointF *points = polyline.data();
int new_size = 0;
int prevx = INT_MAX, prevy = INT_MAX;
double dx = 0, dy = 0; //average distance from pixel center
for ( int i = from; i <= to; i++ )
{
const QPointF sample = d_series->sample( i );
double x = xMap.transform( sample.x() );
double y = yMap.transform( sample.y() );
x = qBound<double>(0, x, INT_MAX);
y = qBound<double>(0, y, INT_MAX);
int _x = x;
int _y = y;
#ifndef QWT_CURVE_NO_SKIP
if (_x == prevx && _y == prevy)
continue;
prevx = _x;
prevy = _y;
#endif
dx += (x - _x);
dy += (y - _y);
points[new_size].rx() = x;
points[new_size].ry() = y;
new_size++;
}
#ifndef QWT_CURVE_NO_PIXEL_SNAP
dx /= new_size;
dy /= new_size;
double target = painter->pen().widthF() / 2.;
target = target - int(target); //0.5 for width 1,3..., 0 for 2,4...
for ( int i = 0; i < new_size; i++ )
{
points[i].rx() += (target - dx);
points[i].ry() += (-target - dy);
}
#endif
const int chunkSize = 50;
for ( int i = 0; i < new_size-1; i += chunkSize-1 )
{
const int n = qMin( chunkSize, new_size - i );
painter->drawPolyline( polyline.constData() + i, n );
}
if ( d_data->brush.style() != Qt::NoBrush )
fillCurve( painter, xMap, yMap, polyline );
}
/*!
Draw sticks
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawSticks( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to ) const
{
painter->save();
painter->setRenderHint( QPainter::Antialiasing, false );
double x0 = xMap.transform( d_data->baseline );
double y0 = yMap.transform( d_data->baseline );
const Qt::Orientation o = orientation();
for ( int i = from; i <= to; i++ )
{
const QPointF sample = d_series->sample( i );
double xi = xMap.transform( sample.x() );
double yi = yMap.transform( sample.y() );
if ( o == Qt::Horizontal )
painter->drawLine( x0, yi, xi, yi );
else
painter->drawLine( xi, y0, xi, yi );
}
painter->restore();
}
/*!
Draw dots
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawDots( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to ) const
{
const bool doFill = d_data->brush.style() != Qt::NoBrush;
QPolygonF polyline;
if ( doFill )
polyline.resize( to - from + 1 );
QPointF *points = polyline.data();
for ( int i = from; i <= to; i++ )
{
const QPointF sample = d_series->sample( i );
double xi = xMap.transform( sample.x() );
double yi = yMap.transform( sample.y() );
painter->drawPoint( QPointF( xi, yi ) );
if ( doFill )
{
points[i - from].rx() = xi;
points[i - from].ry() = yi;
}
}
if ( doFill )
fillCurve( painter, xMap, yMap, polyline );
}
/*!
Draw step function
The direction of the steps depends on Inverted attribute.
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa CurveAttribute, setCurveAttribute(),
draw(), drawCurve(), drawDots(), drawLines(), drawSticks()
*/
void QwtPlotCurve::drawSteps( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to ) const
{
QPolygonF polygon( 2 * ( to - from ) + 1 );
QPointF *points = polygon.data();
bool inverted = orientation() == Qt::Vertical;
if ( d_data->attributes & Inverted )
inverted = !inverted;
int i, ip;
for ( i = from, ip = 0; i <= to; i++, ip += 2 )
{
const QPointF sample = d_series->sample( i );
double xi = xMap.transform( sample.x() );
double yi = yMap.transform( sample.y() );
if ( ip > 0 )
{
const QPointF &p0 = points[ip - 2];
QPointF &p = points[ip - 1];
if ( inverted )
{
p.rx() = p0.x();
p.ry() = yi;
}
else
{
p.rx() = xi;
p.ry() = p0.y();
}
}
points[ip].rx() = xi;
points[ip].ry() = yi;
}
painter->drawPolyline( polygon.constData(), polygon.size() );
if ( d_data->brush.style() != Qt::NoBrush )
fillCurve( painter, xMap, yMap, polygon );
}
/*!
Specify an attribute for drawing the curve
\param attribute Curve attribute
\param on On/Off
/sa testCurveAttribute(), setCurveFitter()
*/
void QwtPlotCurve::setCurveAttribute( CurveAttribute attribute, bool on )
{
if ( bool( d_data->attributes & attribute ) == on )
return;
if ( on )
d_data->attributes |= attribute;
else
d_data->attributes &= ~attribute;
itemChanged();
}
/*!
\return true, if attribute is enabled
\sa setCurveAttribute()
*/
bool QwtPlotCurve::testCurveAttribute( CurveAttribute attribute ) const
{
return d_data->attributes & attribute;
}
/*!
Fill the area between the curve and the baseline with
the curve brush
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param polygon Polygon - will be modified !
\sa setBrush(), setBaseline(), setStyle()
*/
void QwtPlotCurve::fillCurve( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
QPolygonF &polygon ) const
{
if ( d_data->brush.style() == Qt::NoBrush )
return;
closePolyline( xMap, yMap, polygon );
if ( polygon.count() <= 2 ) // a line can't be filled
return;
QBrush brush = d_data->brush;
if ( !brush.color().isValid() )
brush.setColor( d_data->pen.color() );
painter->save();
painter->setPen( Qt::NoPen );
painter->setBrush( brush );
painter->drawPolygon( polygon );
painter->restore();
}
/*!
\brief Complete a polygon to be a closed polygon including the
area between the original polygon and the baseline.
\param painter Painter
\param xMap X map
\param yMap Y map
\param polygon Polygon to be completed
*/
void QwtPlotCurve::closePolyline(
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
QPolygonF &polygon ) const
{
if ( polygon.size() < 2 )
return;
double baseline = d_data->baseline;
if ( orientation() == Qt::Vertical )
{
if ( yMap.transformation()->type() == QwtScaleTransformation::Log10 )
{
if ( baseline < QwtScaleMap::LogMin )
baseline = QwtScaleMap::LogMin;
}
double refY = yMap.transform( baseline );
polygon += QPointF( polygon.last().x(), refY );
polygon += QPointF( polygon.first().x(), refY );
}
else
{
if ( xMap.transformation()->type() == QwtScaleTransformation::Log10 )
{
if ( baseline < QwtScaleMap::LogMin )
baseline = QwtScaleMap::LogMin;
}
double refX = xMap.transform( baseline );
polygon += QPointF( refX, polygon.last().y() );
polygon += QPointF( refX, polygon.first().y() );
}
}
/*!
Draw symbols
\param painter Painter
\param symbol Curve symbol
\param xMap x map
\param yMap y map
\param canvasRect Contents rect of the canvas
\param from Index of the first point to be painted
\param to Index of the last point to be painted
\sa setSymbol(), drawSeries(), drawCurve()
*/
void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const
{
const int chunkSize = 500;
for ( int i = from; i <= to; i += chunkSize )
{
const int n = qMin( chunkSize, to - i + 1 );
QPolygonF points;
for ( int j = 0; j < n; j++ )
{
const QPointF sample = d_series->sample( i + j );
const double xi = xMap.transform( sample.x() );
const double yi = yMap.transform( sample.y() );
if ( canvasRect.contains( xi, yi ) )
points += QPointF( xi, yi );
}
if ( points.size() > 0 )
symbol.drawSymbols( painter, points );
}
}
/*!
\brief Set the value of the baseline
The baseline is needed for filling the curve with a brush or
the Sticks drawing style.
The interpretation of the baseline depends on the CurveType.
With QwtPlotCurve::Yfx, the baseline is interpreted as a horizontal line
at y = baseline(), with QwtPlotCurve::Yfy, it is interpreted as a vertical
line at x = baseline().
The default value is 0.0.
\param value Value of the baseline
\sa baseline(), setBrush(), setStyle(), setStyle()
*/
void QwtPlotCurve::setBaseline( double value )
{
if ( d_data->baseline != value )
{
d_data->baseline = value;
itemChanged();
}
}
/*!
\return Value of the baseline
\sa setBaseline()
*/
double QwtPlotCurve::baseline() const
{
return d_data->baseline;
}
/*!
Find the closest curve point for a specific position
\param pos Position, where to look for the closest curve point
\param dist If dist != NULL, closestPoint() returns the distance between
the position and the clostest curve point
\return Index of the closest curve point, or -1 if none can be found
( f.e when the curve has no points )
\note closestPoint() implements a dumb algorithm, that iterates
over all points
*/
int QwtPlotCurve::closestPoint( const QPoint &pos, double *dist ) const
{
if ( plot() == NULL || dataSize() <= 0 )
return -1;
const QwtScaleMap xMap = plot()->canvasMap( QwtPlot::xBottom );
const QwtScaleMap yMap = plot()->canvasMap( QwtPlot::yLeft );
int index = -1;
double dmin = 1.0e10;
for ( int i = 0; i < dataSize(); i++ )
{
const QPointF sample = d_series->sample( i );
const double cx = xMap.transform( sample.x() ) - pos.x();
const double cy = yMap.transform( sample.y() ) - pos.y();
const double f = qwtSqr( cx ) + qwtSqr( cy );
if ( f < dmin )
{
index = i;
dmin = f;
}
}
if ( dist )
*dist = qSqrt( dmin );
return index;
}
/*!
\brief Update the widget that represents the item on the legend
\param legend Legend
\sa drawLegendIdentifier(), legendItem(), QwtPlotItem::Legend
*/
void QwtPlotCurve::updateLegend( QwtLegend *legend ) const
{
if ( legend && !title().isNull()
&& ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
&& d_data->symbol
&& d_data->symbol->style() != QwtSymbol::NoSymbol )
{
QWidget *lgdItem = legend->find( this );
if ( lgdItem == NULL )
{
lgdItem = legendItem();
if ( lgdItem )
legend->insert( this, lgdItem );
}
if ( lgdItem && lgdItem->inherits( "QwtLegendItem" ) )
{
QwtLegendItem *l = ( QwtLegendItem * )lgdItem;
l->setIdentifierSize( d_data->symbol->boundingSize() );
}
}
QwtPlotItem::updateLegend( legend );
}
/*!
\brief Draw the identifier representing the curve on the legend
\param painter Painter
\param rect Bounding rectangle for the identifier
\sa setLegendAttribute(), QwtPlotItem::Legend
*/
void QwtPlotCurve::drawLegendIdentifier(
QPainter *painter, const QRectF &rect ) const
{
if ( rect.isEmpty() )
return;
const int dim = qMin( rect.width(), rect.height() );
QSize size( dim, dim );
QRectF r( 0, 0, size.width(), size.height() );
r.moveCenter( rect.center() );
if ( d_data->legendAttributes == 0 )
{
QBrush brush = d_data->brush;
if ( brush.style() == Qt::NoBrush )
{
if ( style() != QwtPlotCurve::NoCurve )
brush = QBrush( pen().color() );
else if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
brush = QBrush( d_data->symbol->pen().color() );
}
}
if ( brush.style() != Qt::NoBrush )
painter->fillRect( r, brush );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
{
if ( d_data->brush.style() != Qt::NoBrush )
painter->fillRect( r, d_data->brush );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
{
if ( pen() != Qt::NoPen )
{
painter->setPen( pen() );
painter->drawLine( rect.left(), rect.center().y(),
rect.right() - 1.0, rect.center().y() );
}
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
{
if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
QSize symbolSize = d_data->symbol->boundingSize();
symbolSize -= QSize( 2, 2 );
// scale the symbol size down if it doesn't fit into rect.
double xRatio = 1.0;
if ( rect.width() < symbolSize.width() )
xRatio = rect.width() / symbolSize.width();
double yRatio = 1.0;
if ( rect.height() < symbolSize.height() )
yRatio = rect.height() / symbolSize.height();
const double ratio = qMin( xRatio, yRatio );
painter->save();
painter->scale( ratio, ratio );
d_data->symbol->drawSymbol( painter, rect.center() / ratio );
painter->restore();
}
}
}
/*!
Initialize data with an array of points (explicitly shared).
\param samples Vector of points
*/
void QwtPlotCurve::setSamples( const QVector<QPointF> &samples )
{
delete d_series;
d_series = new QwtPointSeriesData( samples );
itemChanged();
}
/*!
\brief Initialize the data by pointing to memory blocks which
are not managed by QwtPlotCurve.
setRawSamples is provided for efficiency.
It is important to keep the pointers
during the lifetime of the underlying QwtCPointerData class.
\param xData pointer to x data
\param yData pointer to y data
\param size size of x and y
\sa QwtCPointerData
*/
void QwtPlotCurve::setRawSamples(
const double *xData, const double *yData, int size )
{
delete d_series;
d_series = new QwtCPointerData( xData, yData, size );
itemChanged();
}
/*!
Set data by copying x- and y-values from specified memory blocks.
Contrary to setRawSamples(), this function makes a 'deep copy' of
the data.
\param xData pointer to x values
\param yData pointer to y values
\param size size of xData and yData
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples(
const double *xData, const double *yData, int size )
{
delete d_series;
d_series = new QwtPointArrayData( xData, yData, size );
itemChanged();
}
/*!
\brief Initialize data with x- and y-arrays (explicitly shared)
\param xData x data
\param yData y data
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples( const QVector<double> &xData,
const QVector<double> &yData )
{
delete d_series;
d_series = new QwtPointArrayData( xData, yData );
itemChanged();
}