source: ntrip/trunk/GnssCenter/qwt/qwt_symbol.cpp@ 9265

Last change on this file since 9265 was 4839, checked in by mervart, 12 years ago
File size: 25.0 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#include "qwt_symbol.h"
11#include "qwt_painter.h"
12#include <qapplication.h>
13#include <qpainter.h>
14#include <qmath.h>
15
16namespace QwtTriangle
17{
18 enum Type
19 {
20 Left,
21 Right,
22 Up,
23 Down
24 };
25}
26
27static inline void qwtDrawEllipseSymbols( QPainter *painter,
28 const QPointF *points, int numPoints, const QwtSymbol &symbol )
29{
30 painter->setBrush( symbol.brush() );
31 painter->setPen( symbol.pen() );
32
33 const QSize size = symbol.size();
34
35 if ( QwtPainter::roundingAlignment( painter ) )
36 {
37 const int sw = size.width();
38 const int sh = size.height();
39 const int sw2 = size.width() / 2;
40 const int sh2 = size.height() / 2;
41
42 for ( int i = 0; i < numPoints; i++ )
43 {
44 const int x = qRound( points[i].x() );
45 const int y = qRound( points[i].y() );
46
47 const QRectF r( x - sw2, y - sh2, sw, sh );
48 QwtPainter::drawEllipse( painter, r );
49 }
50 }
51 else
52 {
53 const double sw = size.width();
54 const double sh = size.height();
55 const double sw2 = 0.5 * size.width();
56 const double sh2 = 0.5 * size.height();
57
58 for ( int i = 0; i < numPoints; i++ )
59 {
60 const double x = points[i].x();
61 const double y = points[i].y();
62
63 const QRectF r( x - sw2, y - sh2, sw, sh );
64 QwtPainter::drawEllipse( painter, r );
65 }
66 }
67}
68
69static inline void qwtDrawRectSymbols( QPainter *painter,
70 const QPointF *points, int numPoints, const QwtSymbol &symbol )
71{
72 const QSize size = symbol.size();
73
74 QPen pen = symbol.pen();
75 pen.setJoinStyle( Qt::MiterJoin );
76 painter->setPen( pen );
77 painter->setBrush( symbol.brush() );
78 painter->setRenderHint( QPainter::Antialiasing, false );
79
80 if ( QwtPainter::roundingAlignment( painter ) )
81 {
82 const int sw = size.width();
83 const int sh = size.height();
84 const int sw2 = size.width() / 2;
85 const int sh2 = size.height() / 2;
86
87 for ( int i = 0; i < numPoints; i++ )
88 {
89 const int x = qRound( points[i].x() );
90 const int y = qRound( points[i].y() );
91
92 const QRect r( x - sw2, y - sh2, sw, sh );
93 QwtPainter::drawRect( painter, r );
94 }
95 }
96 else
97 {
98 const double sw = size.width();
99 const double sh = size.height();
100 const double sw2 = 0.5 * size.width();
101 const double sh2 = 0.5 * size.height();
102
103 for ( int i = 0; i < numPoints; i++ )
104 {
105 const double x = points[i].x();
106 const double y = points[i].y();
107
108 const QRectF r( x - sw2, y - sh2, sw, sh );
109 QwtPainter::drawRect( painter, r );
110 }
111 }
112}
113
114static inline void qwtDrawDiamondSymbols( QPainter *painter,
115 const QPointF *points, int numPoints, const QwtSymbol &symbol )
116{
117 const QSize size = symbol.size();
118
119 QPen pen = symbol.pen();
120 pen.setJoinStyle( Qt::MiterJoin );
121 painter->setPen( pen );
122 painter->setBrush( symbol.brush() );
123
124 if ( QwtPainter::roundingAlignment( painter ) )
125 {
126 for ( int i = 0; i < numPoints; i++ )
127 {
128 const int x = qRound( points[i].x() );
129 const int y = qRound( points[i].y() );
130
131 const int x1 = x - size.width() / 2;
132 const int y1 = y - size.height() / 2;
133 const int x2 = x1 + size.width();
134 const int y2 = y1 + size.height();
135
136 QPolygonF polygon;
137 polygon += QPointF( x, y1 );
138 polygon += QPointF( x1, y );
139 polygon += QPointF( x, y2 );
140 polygon += QPointF( x2, y );
141
142 QwtPainter::drawPolygon( painter, polygon );
143 }
144 }
145 else
146 {
147 for ( int i = 0; i < numPoints; i++ )
148 {
149 const QPointF &pos = points[i];
150
151 const double x1 = pos.x() - 0.5 * size.width();
152 const double y1 = pos.y() - 0.5 * size.height();
153 const double x2 = x1 + size.width();
154 const double y2 = y1 + size.height();
155
156 QPolygonF polygon;
157 polygon += QPointF( pos.x(), y1 );
158 polygon += QPointF( x2, pos.y() );
159 polygon += QPointF( pos.x(), y2 );
160 polygon += QPointF( x1, pos.y() );
161
162 QwtPainter::drawPolygon( painter, polygon );
163 }
164 }
165}
166
167static inline void qwtDrawTriangleSymbols(
168 QPainter *painter, QwtTriangle::Type type,
169 const QPointF *points, int numPoints,
170 const QwtSymbol &symbol )
171{
172 const QSize size = symbol.size();
173
174 QPen pen = symbol.pen();
175 pen.setJoinStyle( Qt::MiterJoin );
176 painter->setPen( pen );
177
178 painter->setBrush( symbol.brush() );
179
180 const bool doAlign = QwtPainter::roundingAlignment( painter );
181
182 double sw2 = 0.5 * size.width();
183 double sh2 = 0.5 * size.height();
184
185 if ( doAlign )
186 {
187 sw2 = qFloor( sw2 );
188 sh2 = qFloor( sh2 );
189 }
190
191 QPolygonF triangle( 3 );
192 QPointF *trianglePoints = triangle.data();
193
194 for ( int i = 0; i < numPoints; i++ )
195 {
196 const QPointF &pos = points[i];
197
198 double x = pos.x();
199 double y = pos.y();
200
201 if ( doAlign )
202 {
203 x = qRound( x );
204 y = qRound( y );
205 }
206
207 const double x1 = x - sw2;
208 const double x2 = x1 + size.width();
209 const double y1 = y - sh2;
210 const double y2 = y1 + size.height();
211
212 switch ( type )
213 {
214 case QwtTriangle::Left:
215 {
216 trianglePoints[0].rx() = x2;
217 trianglePoints[0].ry() = y1;
218
219 trianglePoints[1].rx() = x1;
220 trianglePoints[1].ry() = y;
221
222 trianglePoints[2].rx() = x2;
223 trianglePoints[2].ry() = y2;
224
225 break;
226 }
227 case QwtTriangle::Right:
228 {
229 trianglePoints[0].rx() = x1;
230 trianglePoints[0].ry() = y1;
231
232 trianglePoints[1].rx() = x2;
233 trianglePoints[1].ry() = y;
234
235 trianglePoints[2].rx() = x1;
236 trianglePoints[2].ry() = y2;
237
238 break;
239 }
240 case QwtTriangle::Up:
241 {
242 trianglePoints[0].rx() = x1;
243 trianglePoints[0].ry() = y2;
244
245 trianglePoints[1].rx() = x;
246 trianglePoints[1].ry() = y1;
247
248 trianglePoints[2].rx() = x2;
249 trianglePoints[2].ry() = y2;
250
251 break;
252 }
253 case QwtTriangle::Down:
254 {
255 trianglePoints[0].rx() = x1;
256 trianglePoints[0].ry() = y1;
257
258 trianglePoints[1].rx() = x;
259 trianglePoints[1].ry() = y2;
260
261 trianglePoints[2].rx() = x2;
262 trianglePoints[2].ry() = y1;
263
264 break;
265 }
266 }
267 QwtPainter::drawPolygon( painter, triangle );
268 }
269}
270
271static inline void qwtDrawLineSymbols(
272 QPainter *painter, int orientations,
273 const QPointF *points, int numPoints, const QwtSymbol &symbol )
274{
275 const QSize size = symbol.size();
276
277 int off = 0;
278
279 QPen pen = symbol.pen();
280 if ( pen.width() > 1 )
281 {
282 pen.setCapStyle( Qt::FlatCap );
283 off = 1;
284 }
285
286 painter->setPen( pen );
287 painter->setRenderHint( QPainter::Antialiasing, false );
288
289 if ( QwtPainter::roundingAlignment( painter ) )
290 {
291 const int sw = qFloor( size.width() );
292 const int sh = qFloor( size.height() );
293 const int sw2 = size.width() / 2;
294 const int sh2 = size.height() / 2;
295
296 for ( int i = 0; i < numPoints; i++ )
297 {
298 if ( orientations & Qt::Horizontal )
299 {
300 const int x = qRound( points[i].x() ) - sw2;
301 const int y = qRound( points[i].y() );
302
303 QwtPainter::drawLine( painter, x, y, x + sw + off, y );
304 }
305 if ( orientations & Qt::Vertical )
306 {
307 const int x = qRound( points[i].x() );
308 const int y = qRound( points[i].y() ) - sh2;
309
310 QwtPainter::drawLine( painter, x, y, x, y + sh + off );
311 }
312 }
313 }
314 else
315 {
316 const double sw = size.width();
317 const double sh = size.height();
318 const double sw2 = 0.5 * size.width();
319 const double sh2 = 0.5 * size.height();
320
321 for ( int i = 0; i < numPoints; i++ )
322 {
323 if ( orientations & Qt::Horizontal )
324 {
325 const double x = points[i].x() - sw2;
326 const double y = points[i].y();
327
328 QwtPainter::drawLine( painter, x, y, x + sw, y );
329 }
330 if ( orientations & Qt::Vertical )
331 {
332 const double y = points[i].y() - sh2;
333 const double x = points[i].x();
334
335 QwtPainter::drawLine( painter, x, y, x, y + sh );
336 }
337 }
338 }
339}
340
341static inline void qwtDrawXCrossSymbols( QPainter *painter,
342 const QPointF *points, int numPoints, const QwtSymbol &symbol )
343{
344 const QSize size = symbol.size();
345 int off = 0;
346
347 QPen pen = symbol.pen();
348 if ( pen.width() > 1 )
349 {
350 pen.setCapStyle( Qt::FlatCap );
351 off = 1;
352 }
353 painter->setPen( pen );
354
355
356 if ( QwtPainter::roundingAlignment( painter ) )
357 {
358 const int sw = size.width();
359 const int sh = size.height();
360 const int sw2 = size.width() / 2;
361 const int sh2 = size.height() / 2;
362
363 for ( int i = 0; i < numPoints; i++ )
364 {
365 const QPointF &pos = points[i];
366
367 const int x = qRound( pos.x() );
368 const int y = qRound( pos.y() );
369
370 const int x1 = x - sw2;
371 const int x2 = x1 + sw + off;
372 const int y1 = y - sh2;
373 const int y2 = y1 + sh + off;
374
375 QwtPainter::drawLine( painter, x1, y1, x2, y2 );
376 QwtPainter::drawLine( painter, x2, y1, x1, y2 );
377 }
378 }
379 else
380 {
381 const double sw = size.width();
382 const double sh = size.height();
383 const double sw2 = 0.5 * size.width();
384 const double sh2 = 0.5 * size.height();
385
386 for ( int i = 0; i < numPoints; i++ )
387 {
388 const QPointF &pos = points[i];
389
390 const double x1 = pos.x() - sw2;
391 const double x2 = x1 + sw;
392 const double y1 = pos.y() - sh2;
393 const double y2 = y1 + sh;
394
395 QwtPainter::drawLine( painter, x1, y1, x2, y2 );
396 QwtPainter::drawLine( painter, x1, y2, x2, y1 );
397 }
398 }
399}
400
401static inline void qwtDrawStar1Symbols( QPainter *painter,
402 const QPointF *points, int numPoints, const QwtSymbol &symbol )
403{
404 const QSize size = symbol.size();
405 painter->setPen( symbol.pen() );
406
407 if ( QwtPainter::roundingAlignment( painter ) )
408 {
409 QRect r( 0, 0, size.width(), size.height() );
410
411 for ( int i = 0; i < numPoints; i++ )
412 {
413 r.moveCenter( points[i].toPoint() );
414
415 const double sqrt1_2 = 0.70710678118654752440; /* 1/sqrt(2) */
416
417 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
418
419 QwtPainter::drawLine( painter,
420 qRound( r.left() + d1 ), qRound( r.top() + d1 ),
421 qRound( r.right() - d1 ), qRound( r.bottom() - d1 ) );
422 QwtPainter::drawLine( painter,
423 qRound( r.left() + d1 ), qRound( r.bottom() - d1 ),
424 qRound( r .right() - d1), qRound( r.top() + d1 ) );
425
426 const QPoint c = r.center();
427
428 QwtPainter::drawLine( painter,
429 c.x(), r.top(), c.x(), r.bottom() );
430 QwtPainter::drawLine( painter,
431 r.left(), c.y(), r.right(), c.y() );
432 }
433 }
434 else
435 {
436 QRectF r( 0, 0, size.width(), size.height() );
437
438 for ( int i = 0; i < numPoints; i++ )
439 {
440 r.moveCenter( points[i] );
441
442 const double sqrt1_2 = 0.70710678118654752440; /* 1/sqrt(2) */
443
444 const QPointF c = r.center();
445 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
446
447 QwtPainter::drawLine( painter,
448 r.left() + d1, r.top() + d1,
449 r.right() - d1, r.bottom() - d1 );
450 QwtPainter::drawLine( painter,
451 r.left() + d1, r.bottom() - d1,
452 r.right() - d1, r.top() + d1 );
453 QwtPainter::drawLine( painter,
454 c.x(), r.top(),
455 c.x(), r.bottom() );
456 QwtPainter::drawLine( painter,
457 r.left(), c.y(),
458 r.right(), c.y() );
459 }
460 }
461}
462
463static inline void qwtDrawStar2Symbols( QPainter *painter,
464 const QPointF *points, int numPoints, const QwtSymbol &symbol )
465{
466 QPen pen = symbol.pen();
467 if ( pen.width() > 1 )
468 pen.setCapStyle( Qt::FlatCap );
469 pen.setJoinStyle( Qt::MiterJoin );
470 painter->setPen( pen );
471
472 painter->setBrush( symbol.brush() );
473
474 const double cos30 = 0.866025; // cos(30°)
475
476 const double dy = 0.25 * symbol.size().height();
477 const double dx = 0.5 * symbol.size().width() * cos30 / 3.0;
478
479 QPolygonF star( 12 );
480 QPointF *starPoints = star.data();
481
482 const bool doAlign = QwtPainter::roundingAlignment( painter );
483
484 for ( int i = 0; i < numPoints; i++ )
485 {
486 double x = points[i].x();
487 double y = points[i].y();
488 if ( doAlign )
489 {
490 x = qRound( x );
491 y = qRound( y );
492 }
493
494 double x1 = x - 3 * dx;
495 double y1 = y - 2 * dy;
496 if ( doAlign )
497 {
498 x1 = qRound( x - 3 * dx );
499 y1 = qRound( y - 2 * dy );
500 }
501
502 const double x2 = x1 + 1 * dx;
503 const double x3 = x1 + 2 * dx;
504 const double x4 = x1 + 3 * dx;
505 const double x5 = x1 + 4 * dx;
506 const double x6 = x1 + 5 * dx;
507 const double x7 = x1 + 6 * dx;
508
509 const double y2 = y1 + 1 * dy;
510 const double y3 = y1 + 2 * dy;
511 const double y4 = y1 + 3 * dy;
512 const double y5 = y1 + 4 * dy;
513
514 starPoints[0].rx() = x4;
515 starPoints[0].ry() = y1;
516
517 starPoints[1].rx() = x5;
518 starPoints[1].ry() = y2;
519
520 starPoints[2].rx() = x7;
521 starPoints[2].ry() = y2;
522
523 starPoints[3].rx() = x6;
524 starPoints[3].ry() = y3;
525
526 starPoints[4].rx() = x7;
527 starPoints[4].ry() = y4;
528
529 starPoints[5].rx() = x5;
530 starPoints[5].ry() = y4;
531
532 starPoints[6].rx() = x4;
533 starPoints[6].ry() = y5;
534
535 starPoints[7].rx() = x3;
536 starPoints[7].ry() = y4;
537
538 starPoints[8].rx() = x1;
539 starPoints[8].ry() = y4;
540
541 starPoints[9].rx() = x2;
542 starPoints[9].ry() = y3;
543
544 starPoints[10].rx() = x1;
545 starPoints[10].ry() = y2;
546
547 starPoints[11].rx() = x3;
548 starPoints[11].ry() = y2;
549
550 QwtPainter::drawPolygon( painter, star );
551 }
552}
553
554static inline void qwtDrawHexagonSymbols( QPainter *painter,
555 const QPointF *points, int numPoints, const QwtSymbol &symbol )
556{
557 painter->setBrush( symbol.brush() );
558 painter->setPen( symbol.pen() );
559
560 const double cos30 = 0.866025; // cos(30°)
561 const double dx = 0.5 * ( symbol.size().width() - cos30 );
562
563 const double dy = 0.25 * symbol.size().height();
564
565 QPolygonF hexaPolygon( 6 );
566 QPointF *hexaPoints = hexaPolygon.data();
567
568 const bool doAlign = QwtPainter::roundingAlignment( painter );
569
570 for ( int i = 0; i < numPoints; i++ )
571 {
572 double x = points[i].x();
573 double y = points[i].y();
574 if ( doAlign )
575 {
576 x = qRound( x );
577 y = qRound( y );
578 }
579
580 double x1 = x - dx;
581 double y1 = y - 2 * dy;
582 if ( doAlign )
583 {
584 x1 = qCeil( x1 );
585 y1 = qCeil( y1 );
586 }
587
588 const double x2 = x1 + 1 * dx;
589 const double x3 = x1 + 2 * dx;
590
591 const double y2 = y1 + 1 * dy;
592 const double y3 = y1 + 3 * dy;
593 const double y4 = y1 + 4 * dy;
594
595 hexaPoints[0].rx() = x2;
596 hexaPoints[0].ry() = y1;
597
598 hexaPoints[1].rx() = x3;
599 hexaPoints[1].ry() = y2;
600
601 hexaPoints[2].rx() = x3;
602 hexaPoints[2].ry() = y3;
603
604 hexaPoints[3].rx() = x2;
605 hexaPoints[3].ry() = y4;
606
607 hexaPoints[4].rx() = x1;
608 hexaPoints[4].ry() = y3;
609
610 hexaPoints[5].rx() = x1;
611 hexaPoints[5].ry() = y2;
612
613 QwtPainter::drawPolygon( painter, hexaPolygon );
614 }
615}
616
617class QwtSymbol::PrivateData
618{
619public:
620 PrivateData( QwtSymbol::Style st, const QBrush &br,
621 const QPen &pn, const QSize &sz ):
622 style( st ),
623 size( sz ),
624 brush( br ),
625 pen( pn )
626 {
627 }
628
629 bool operator==( const PrivateData &other ) const
630 {
631 return ( style == other.style )
632 && ( size == other.size )
633 && ( brush == other.brush )
634 && ( pen == other.pen );
635 }
636
637
638 Style style;
639 QSize size;
640 QBrush brush;
641 QPen pen;
642};
643
644/*!
645 Default Constructor
646 \param style Symbol Style
647
648 The symbol is constructed with gray interior,
649 black outline with zero width, no size and style 'NoSymbol'.
650*/
651QwtSymbol::QwtSymbol( Style style )
652{
653 d_data = new PrivateData( style, QBrush( Qt::gray ),
654 QPen( Qt::black ), QSize( 0.0, 0.0 ) );
655}
656
657/*!
658 \brief Constructor
659 \param style Symbol Style
660 \param brush brush to fill the interior
661 \param pen outline pen
662 \param size size
663
664 \sa setStyle(), setBrush(), setPen(), setSize()
665*/
666QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush &brush,
667 const QPen &pen, const QSize &size )
668{
669 d_data = new PrivateData( style, brush, pen, size );
670}
671
672/*!
673 \brief Copy constructor
674
675 \param other Symbol
676*/
677QwtSymbol::QwtSymbol( const QwtSymbol &other )
678{
679 d_data = new PrivateData( other.style(), other.brush(),
680 other.pen(), other.size() );
681};
682
683//! Destructor
684QwtSymbol::~QwtSymbol()
685{
686 delete d_data;
687}
688
689//! \brief Assignment operator
690QwtSymbol &QwtSymbol::operator=( const QwtSymbol &other )
691{
692 *d_data = *other.d_data;
693 return *this;
694}
695
696//! \brief Compare two symbols
697bool QwtSymbol::operator==( const QwtSymbol &other ) const
698{
699 return *d_data == *other.d_data;
700}
701
702//! \brief Compare two symbols
703bool QwtSymbol::operator!=( const QwtSymbol &other ) const
704{
705 return !( *d_data == *other.d_data );
706}
707
708/*!
709 \brief Specify the symbol's size
710
711 If the 'h' parameter is left out or less than 0,
712 and the 'w' parameter is greater than or equal to 0,
713 the symbol size will be set to (w,w).
714 \param width Width
715 \param height Height (defaults to -1)
716
717 \sa size()
718*/
719void QwtSymbol::setSize( int width, int height )
720{
721 if ( ( width >= 0 ) && ( height < 0 ) )
722 height = width;
723
724 d_data->size = QSize( width, height );
725}
726
727/*!
728 Set the symbol's size
729 \param size Size
730
731 \sa size()
732*/
733void QwtSymbol::setSize( const QSize &size )
734{
735 if ( size.isValid() )
736 d_data->size = size;
737}
738
739/*!
740 \return Size
741 \sa setSize()
742*/
743const QSize& QwtSymbol::size() const
744{
745 return d_data->size;
746}
747
748/*!
749 \brief Assign a brush
750
751 The brush is used to draw the interior of the symbol.
752 \param brush Brush
753
754 \sa brush()
755*/
756void QwtSymbol::setBrush( const QBrush &brush )
757{
758 d_data->brush = brush;
759}
760
761/*!
762 \return Brush
763 \sa setBrush()
764*/
765const QBrush& QwtSymbol::brush() const
766{
767 return d_data->brush;
768}
769
770/*!
771 Assign a pen
772
773 The pen is used to draw the symbol's outline.
774
775 \param pen Pen
776 \sa pen(), setBrush()
777*/
778void QwtSymbol::setPen( const QPen &pen )
779{
780 d_data->pen = pen;
781}
782
783/*!
784 \return Pen
785 \sa setPen(), brush()
786*/
787const QPen& QwtSymbol::pen() const
788{
789 return d_data->pen;
790}
791
792/*!
793 \brief Set the color of the symbol
794
795 Change the color of the brush for symbol types with a filled area.
796 For all other symbol types the color will be assigned to the pen.
797
798 \param color Color
799
800 \sa setBrush(), setPen(), brush(), pen()
801*/
802void QwtSymbol::setColor( const QColor &color )
803{
804 switch ( d_data->style )
805 {
806 case QwtSymbol::Ellipse:
807 case QwtSymbol::Rect:
808 case QwtSymbol::Diamond:
809 case QwtSymbol::Triangle:
810 case QwtSymbol::UTriangle:
811 case QwtSymbol::DTriangle:
812 case QwtSymbol::RTriangle:
813 case QwtSymbol::LTriangle:
814 case QwtSymbol::Star2:
815 case QwtSymbol::Hexagon:
816 {
817 d_data->brush.setColor( color );
818 break;
819 }
820 case QwtSymbol::Cross:
821 case QwtSymbol::XCross:
822 case QwtSymbol::HLine:
823 case QwtSymbol::VLine:
824 case QwtSymbol::Star1:
825 {
826 d_data->pen.setColor( color );
827 break;
828 }
829 default:
830 {
831 d_data->brush.setColor( color );
832 d_data->pen.setColor( color );
833 }
834 }
835}
836
837/*!
838 Draw an array of symbols
839
840 Painting several symbols is more effective than drawing symbols
841 one by one, as a couple of layout calculations and setting of pen/brush
842 can be done once for the complete array.
843
844 \param painter Painter
845 \param points Array of points
846 \param numPoints Number of points
847*/
848void QwtSymbol::drawSymbols( QPainter *painter,
849 const QPointF *points, int numPoints ) const
850{
851 if ( numPoints <= 0 )
852 return;
853
854 painter->save();
855
856 switch ( d_data->style )
857 {
858 case QwtSymbol::Ellipse:
859 {
860 qwtDrawEllipseSymbols( painter, points, numPoints, *this );
861 break;
862 }
863 case QwtSymbol::Rect:
864 {
865 qwtDrawRectSymbols( painter, points, numPoints, *this );
866 break;
867 }
868 case QwtSymbol::Diamond:
869 {
870 qwtDrawDiamondSymbols( painter, points, numPoints, *this );
871 break;
872 }
873 case QwtSymbol::Cross:
874 {
875 qwtDrawLineSymbols( painter, Qt::Horizontal | Qt::Vertical,
876 points, numPoints, *this );
877 break;
878 }
879 case QwtSymbol::XCross:
880 {
881 qwtDrawXCrossSymbols( painter, points, numPoints, *this );
882 break;
883 }
884 case QwtSymbol::Triangle:
885 case QwtSymbol::UTriangle:
886 {
887 qwtDrawTriangleSymbols( painter, QwtTriangle::Up,
888 points, numPoints, *this );
889 break;
890 }
891 case QwtSymbol::DTriangle:
892 {
893 qwtDrawTriangleSymbols( painter, QwtTriangle::Down,
894 points, numPoints, *this );
895 break;
896 }
897 case QwtSymbol::RTriangle:
898 {
899 qwtDrawTriangleSymbols( painter, QwtTriangle::Right,
900 points, numPoints, *this );
901 break;
902 }
903 case QwtSymbol::LTriangle:
904 {
905 qwtDrawTriangleSymbols( painter, QwtTriangle::Left,
906 points, numPoints, *this );
907 break;
908 }
909 case QwtSymbol::HLine:
910 {
911 qwtDrawLineSymbols( painter, Qt::Horizontal,
912 points, numPoints, *this );
913 break;
914 }
915 case QwtSymbol::VLine:
916 {
917 qwtDrawLineSymbols( painter, Qt::Vertical,
918 points, numPoints, *this );
919 break;
920 }
921 case QwtSymbol::Star1:
922 {
923 qwtDrawStar1Symbols( painter, points, numPoints, *this );
924 break;
925 }
926 case QwtSymbol::Star2:
927 {
928 qwtDrawStar2Symbols( painter, points, numPoints, *this );
929 break;
930 }
931 case QwtSymbol::Hexagon:
932 {
933 qwtDrawHexagonSymbols( painter, points, numPoints, *this );
934 break;
935 }
936 default:;
937 }
938 painter->restore();
939}
940
941//! \return Size of the bounding rectangle of a symbol
942QSize QwtSymbol::boundingSize() const
943{
944 QSize size;
945
946 switch ( d_data->style )
947 {
948 case QwtSymbol::Ellipse:
949 case QwtSymbol::Rect:
950 case QwtSymbol::Hexagon:
951 {
952 qreal pw = 0.0;
953 if ( d_data->pen.style() != Qt::NoPen )
954 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) );
955
956 size = d_data->size + QSize( pw, pw );
957
958 break;
959 }
960 case QwtSymbol::XCross:
961 case QwtSymbol::Diamond:
962 case QwtSymbol::Triangle:
963 case QwtSymbol::UTriangle:
964 case QwtSymbol::DTriangle:
965 case QwtSymbol::RTriangle:
966 case QwtSymbol::LTriangle:
967 case QwtSymbol::Star1:
968 case QwtSymbol::Star2:
969 {
970 qreal pw = 0.0;
971 if ( d_data->pen.style() != Qt::NoPen )
972 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) );
973
974 size = d_data->size + QSize( 2 * pw, 2 * pw );
975 break;
976 }
977 default:
978 {
979 size = d_data->size;
980 }
981 }
982
983 return size + QSize( 1, 1 ); // for antialiasing
984}
985
986/*!
987 Specify the symbol style
988
989 \param style Style
990 \sa style()
991*/
992void QwtSymbol::setStyle( QwtSymbol::Style style )
993{
994 d_data->style = style;
995}
996
997/*!
998 \return Current symbol style
999 \sa setStyle()
1000*/
1001QwtSymbol::Style QwtSymbol::style() const
1002{
1003 return d_data->style;
1004}
Note: See TracBrowser for help on using the repository browser.