source: ntrip/trunk/BNC/qwt/qwt_symbol.h@ 9184

Last change on this file since 9184 was 8127, checked in by stoecker, 7 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 6.1 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#ifndef QWT_SYMBOL_H
11#define QWT_SYMBOL_H
12
13#include "qwt_global.h"
14#include <qpolygon.h>
15
16class QPainter;
17class QRect;
18class QSize;
19class QBrush;
20class QPen;
21class QColor;
22class QPointF;
23class QPolygonF;
24class QPainterPath;
25class QPixmap;
26class QByteArray;
27class QwtGraphic;
28
29//! A class for drawing symbols
30class QWT_EXPORT QwtSymbol
31{
32public:
33 /*!
34 Symbol Style
35 \sa setStyle(), style()
36 */
37 enum Style
38 {
39 //! No Style. The symbol cannot be drawn.
40 NoSymbol = -1,
41
42 //! Ellipse or circle
43 Ellipse,
44
45 //! Rectangle
46 Rect,
47
48 //! Diamond
49 Diamond,
50
51 //! Triangle pointing upwards
52 Triangle,
53
54 //! Triangle pointing downwards
55 DTriangle,
56
57 //! Triangle pointing upwards
58 UTriangle,
59
60 //! Triangle pointing left
61 LTriangle,
62
63 //! Triangle pointing right
64 RTriangle,
65
66 //! Cross (+)
67 Cross,
68
69 //! Diagonal cross (X)
70 XCross,
71
72 //! Horizontal line
73 HLine,
74
75 //! Vertical line
76 VLine,
77
78 //! X combined with +
79 Star1,
80
81 //! Six-pointed star
82 Star2,
83
84 //! Hexagon
85 Hexagon,
86
87 /*!
88 The symbol is represented by a painter path, where the
89 origin ( 0, 0 ) of the path coordinate system is mapped to
90 the position of the symbol.
91
92 \sa setPath(), path()
93 */
94 Path,
95
96 /*!
97 The symbol is represented by a pixmap. The pixmap is centered
98 or aligned to its pin point.
99
100 \sa setPinPoint()
101 */
102 Pixmap,
103
104 /*!
105 The symbol is represented by a graphic. The graphic is centered
106 or aligned to its pin point.
107
108 \sa setPinPoint()
109 */
110 Graphic,
111
112 /*!
113 The symbol is represented by a SVG graphic. The graphic is centered
114 or aligned to its pin point.
115
116 \sa setPinPoint()
117 */
118 SvgDocument,
119
120 /*!
121 Styles >= QwtSymbol::UserSymbol are reserved for derived
122 classes of QwtSymbol that overload drawSymbols() with
123 additional application specific symbol types.
124 */
125 UserStyle = 1000
126 };
127
128 /*!
129 Depending on the render engine and the complexity of the
130 symbol shape it might be faster to render the symbol
131 to a pixmap and to paint this pixmap.
132
133 F.e. the raster paint engine is a pure software renderer
134 where in cache mode a draw operation usually ends in
135 raster operation with the the backing store, that are usually
136 faster, than the algorithms for rendering polygons.
137 But the opposite can be expected for graphic pipelines
138 that can make use of hardware acceleration.
139
140 The default setting is AutoCache
141
142 \sa setCachePolicy(), cachePolicy()
143
144 \note The policy has no effect, when the symbol is painted
145 to a vector graphics format ( PDF, SVG ).
146 \warning Since Qt 4.8 raster is the default backend on X11
147 */
148
149 enum CachePolicy
150 {
151 //! Don't use a pixmap cache
152 NoCache,
153
154 //! Always use a pixmap cache
155 Cache,
156
157 /*!
158 Use a cache when one of the following conditions is true:
159
160 - The symbol is rendered with the software
161 renderer ( QPaintEngine::Raster )
162 */
163 AutoCache
164 };
165
166public:
167 QwtSymbol( Style = NoSymbol );
168 QwtSymbol( Style, const QBrush &, const QPen &, const QSize & );
169 QwtSymbol( const QPainterPath &, const QBrush &, const QPen & );
170
171 virtual ~QwtSymbol();
172
173 void setCachePolicy( CachePolicy );
174 CachePolicy cachePolicy() const;
175
176 void setSize( const QSize & );
177 void setSize( int width, int height = -1 );
178 const QSize& size() const;
179
180 void setPinPoint( const QPointF &pos, bool enable = true );
181 QPointF pinPoint() const;
182
183 void setPinPointEnabled( bool );
184 bool isPinPointEnabled() const;
185
186 virtual void setColor( const QColor & );
187
188 void setBrush( const QBrush& b );
189 const QBrush& brush() const;
190
191 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
192 void setPen( const QPen & );
193 const QPen& pen() const;
194
195 void setStyle( Style );
196 Style style() const;
197
198 void setPath( const QPainterPath & );
199 const QPainterPath &path() const;
200
201 void setPixmap( const QPixmap & );
202 const QPixmap &pixmap() const;
203
204 void setGraphic( const QwtGraphic & );
205 const QwtGraphic &graphic() const;
206
207#ifndef QWT_NO_SVG
208 void setSvgDocument( const QByteArray & );
209#endif
210
211 void drawSymbol( QPainter *, const QRectF & ) const;
212 void drawSymbol( QPainter *, const QPointF & ) const;
213 void drawSymbols( QPainter *, const QPolygonF & ) const;
214 void drawSymbols( QPainter *,
215 const QPointF *, int numPoints ) const;
216
217 virtual QRect boundingRect() const;
218 void invalidateCache();
219
220protected:
221 virtual void renderSymbols( QPainter *,
222 const QPointF *, int numPoints ) const;
223
224private:
225 // Disabled copy constructor and operator=
226 QwtSymbol( const QwtSymbol & );
227 QwtSymbol &operator=( const QwtSymbol & );
228
229 class PrivateData;
230 PrivateData *d_data;
231};
232
233/*!
234 \brief Draw the symbol at a specified position
235
236 \param painter Painter
237 \param pos Position of the symbol in screen coordinates
238*/
239inline void QwtSymbol::drawSymbol(
240 QPainter *painter, const QPointF &pos ) const
241{
242 drawSymbols( painter, &pos, 1 );
243}
244
245/*!
246 \brief Draw symbols at the specified points
247
248 \param painter Painter
249 \param points Positions of the symbols in screen coordinates
250*/
251
252inline void QwtSymbol::drawSymbols(
253 QPainter *painter, const QPolygonF &points ) const
254{
255 drawSymbols( painter, points.data(), points.size() );
256}
257
258#endif
Note: See TracBrowser for help on using the repository browser.