source: ntrip/trunk/BNC/qwt/qwt_polar_item.cpp

Last change on this file was 11158, checked in by stuerze, 5 weeks ago

deprecated functions exchanged libs updated

File size: 10.2 KB
Line 
1/******************************************************************************
2 * QwtPolar Widget Library
3 * Copyright (C) 2008 Uwe Rathmann
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the Qwt License, Version 1.0
7 *****************************************************************************/
8
9#include "qwt_polar_plot.h"
10#include "qwt_polar_item.h"
11#include "qwt_legend.h"
12#include "qwt_scale_div.h"
13
14#include <qpainter.h>
15
16class QwtPolarItem::PrivateData
17{
18 public:
19 PrivateData()
20 : plot( NULL )
21 , isVisible( true )
22 , renderThreadCount( 1 )
23 , z( 0.0 )
24 , legendIconSize( 8, 8 )
25 {
26 }
27
28 mutable QwtPolarPlot* plot;
29
30 bool isVisible;
31 QwtPolarItem::ItemAttributes attributes;
32 QwtPolarItem::RenderHints renderHints;
33 uint renderThreadCount;
34
35 double z;
36
37 QwtText title;
38 QSize legendIconSize;
39};
40
41/*!
42 Constructor
43
44 \param title Item title, f.e used on a legend
45
46 \sa setTitle()
47 */
48QwtPolarItem::QwtPolarItem( const QwtText& title )
49{
50 m_data = new PrivateData;
51 m_data->title = title;
52}
53
54//! Destroy the QwtPolarItem
55QwtPolarItem::~QwtPolarItem()
56{
57 attach( NULL );
58 delete m_data;
59}
60
61/*!
62 \brief Attach the item to a plot.
63
64 This method will attach a QwtPolarItem to the QwtPolarPlot argument.
65 It will first detach the QwtPolarItem from any plot from a previous
66 call to attach (if necessary).
67 If a NULL argument is passed, it will detach from any QwtPolarPlot it
68 was attached to.
69
70 \param plot Plot widget
71
72 \sa QwtPolarItem::detach()
73 */
74void QwtPolarItem::attach( QwtPolarPlot* plot )
75{
76 if ( plot == m_data->plot )
77 return;
78
79 if ( m_data->plot )
80 m_data->plot->attachItem( this, false );
81
82 m_data->plot = plot;
83
84 if ( m_data->plot )
85 m_data->plot->attachItem( this, true );
86}
87
88/*!
89 \brief This method detaches a QwtPolarItem from the QwtPolarPlot it
90 has been associated with.
91
92 detach() is equivalent to calling attach( NULL )
93 \sa attach()
94 */
95void QwtPolarItem::detach()
96{
97 attach( NULL );
98}
99
100/*!
101 Return rtti for the specific class represented. QwtPolarItem is simply
102 a virtual interface class, and base classes will implement this method
103 with specific rtti values so a user can differentiate them.
104
105 The rtti value is useful for environments, where the
106 runtime type information is disabled and it is not possible
107 to do a dynamic_cast<...>.
108
109 \return rtti value
110 \sa RttiValues
111 */
112int QwtPolarItem::rtti() const
113{
114 return Rtti_PolarItem;
115}
116
117//! \return Attached plot
118QwtPolarPlot* QwtPolarItem::plot() const
119{
120 return m_data->plot;
121}
122
123/*!
124 Plot items are painted in increasing z-order.
125
126 \return Z value
127 \sa setZ(), QwtPolarItemDict::itemList()
128 */
129double QwtPolarItem::z() const
130{
131 return m_data->z;
132}
133
134/*!
135 \brief Set the z value
136
137 Plot items are painted in increasing z-order.
138
139 \param z Z-value
140 \sa z(), QwtPolarItemDict::itemList()
141 */
142void QwtPolarItem::setZ( double z )
143{
144 if ( m_data->z != z )
145 {
146 if ( m_data->plot )
147 m_data->plot->attachItem( this, false );
148
149 m_data->z = z;
150
151 if ( m_data->plot )
152 m_data->plot->attachItem( this, true );
153
154 itemChanged();
155 }
156}
157
158/*!
159 Set a new title
160
161 \param title Title
162 \sa title()
163 */
164void QwtPolarItem::setTitle( const QString& title )
165{
166 setTitle( QwtText( title ) );
167}
168
169/*!
170 Set a new title
171
172 \param title Title
173 \sa title()
174 */
175void QwtPolarItem::setTitle( const QwtText& title )
176{
177 if ( m_data->title != title )
178 {
179 m_data->title = title;
180 itemChanged();
181 }
182}
183
184/*!
185 \return Title of the item
186 \sa setTitle()
187 */
188const QwtText& QwtPolarItem::title() const
189{
190 return m_data->title;
191}
192
193/*!
194 Toggle an item attribute
195
196 \param attribute Attribute type
197 \param on true/false
198
199 \sa testItemAttribute(), ItemAttribute
200 */
201void QwtPolarItem::setItemAttribute( ItemAttribute attribute, bool on )
202{
203 if ( bool( m_data->attributes & attribute ) != on )
204 {
205 if ( on )
206 m_data->attributes |= attribute;
207 else
208 m_data->attributes &= ~attribute;
209
210 itemChanged();
211 }
212}
213
214/*!
215 Test an item attribute
216
217 \param attribute Attribute type
218 \return true/false
219 \sa setItemAttribute(), ItemAttribute
220 */
221bool QwtPolarItem::testItemAttribute( ItemAttribute attribute ) const
222{
223 return m_data->attributes & attribute;
224}
225
226/*!
227 Toggle an render hint
228
229 \param hint Render hint
230 \param on true/false
231
232 \sa testRenderHint(), RenderHint
233 */
234void QwtPolarItem::setRenderHint( RenderHint hint, bool on )
235{
236 if ( ( ( m_data->renderHints & hint ) != 0 ) != on )
237 {
238 if ( on )
239 m_data->renderHints |= hint;
240 else
241 m_data->renderHints &= ~hint;
242
243 itemChanged();
244 }
245}
246
247/*!
248 Test a render hint
249
250 \param hint Render hint
251 \return true/false
252 \sa setRenderHint(), RenderHint
253 */
254bool QwtPolarItem::testRenderHint( RenderHint hint ) const
255{
256 return ( m_data->renderHints & hint );
257}
258
259/*!
260 On multi core systems rendering of certain plot item
261 ( f.e QwtPolarSpectrogram ) can be done in parallel in
262 several threads.
263
264 The default setting is set to 1.
265
266 \param numThreads Number of threads to be used for rendering.
267 If numThreads is set to 0, the system specific
268 ideal thread count is used.
269
270 The default thread count is 1 ( = no additional threads )
271 */
272void QwtPolarItem::setRenderThreadCount( uint numThreads )
273{
274 m_data->renderThreadCount = numThreads;
275}
276
277/*!
278 \return Number of threads to be used for rendering.
279 If numThreads() is set to 0, the system specific
280 ideal thread count is used.
281 */
282uint QwtPolarItem::renderThreadCount() const
283{
284 return m_data->renderThreadCount;
285}
286
287/*!
288 Set the size of the legend icon
289
290 The default setting is 8x8 pixels
291
292 \param size Size
293 \sa legendIconSize(), legendIcon()
294 */
295void QwtPolarItem::setLegendIconSize( const QSize& size )
296{
297 if ( m_data->legendIconSize != size )
298 {
299 m_data->legendIconSize = size;
300 legendChanged();
301 }
302}
303
304/*!
305 \return Legend icon size
306 \sa setLegendIconSize(), legendIcon()
307 */
308QSize QwtPolarItem::legendIconSize() const
309{
310 return m_data->legendIconSize;
311}
312
313//! Show the item
314void QwtPolarItem::show()
315{
316 setVisible( true );
317}
318
319//! Hide the item
320void QwtPolarItem::hide()
321{
322 setVisible( false );
323}
324
325/*!
326 Show/Hide the item
327
328 \param on Show if true, otherwise hide
329 \sa isVisible(), show(), hide()
330 */
331void QwtPolarItem::setVisible( bool on )
332{
333 if ( on != m_data->isVisible )
334 {
335 m_data->isVisible = on;
336 itemChanged();
337 }
338}
339
340/*!
341 \return true if visible
342 \sa setVisible(), show(), hide()
343 */
344bool QwtPolarItem::isVisible() const
345{
346 return m_data->isVisible;
347}
348
349/*!
350 Update the legend and call QwtPolarPlot::autoRefresh for the
351 parent plot.
352
353 \sa updateLegend()
354 */
355void QwtPolarItem::itemChanged()
356{
357 if ( m_data->plot )
358 m_data->plot->autoRefresh();
359}
360
361/*!
362 Update the legend of the parent plot.
363 \sa QwtPolarPlot::updateLegend(), itemChanged()
364 */
365void QwtPolarItem::legendChanged()
366{
367 if ( testItemAttribute( QwtPolarItem::Legend ) && m_data->plot )
368 m_data->plot->updateLegend( this );
369}
370
371/*!
372 Interval, that is necessary to display the item
373
374 This interval can be useful for operations like clipping or autoscaling
375 For items ( like the grid ), where a bounding interval makes no
376 sense an invalid interval is returned.
377
378 \param scaleId Scale id ( QwtPolar::Scale )
379 \return Bounding interval of the plot item for a specific scale
380 */
381QwtInterval QwtPolarItem::boundingInterval( int scaleId ) const
382{
383 Q_UNUSED( scaleId );
384
385 return QwtInterval(); // invalid
386}
387
388/*!
389 \brief Update the item to changes of the axes scale division
390
391 Update the item, when the axes of plot have changed.
392 The default implementation does nothing, but items that depend
393 on the scale division (like QwtPolarGrid()) have to reimplement
394 updateScaleDiv()
395
396 \param azimuthScaleDiv Scale division of the azimuth-scale
397 \param radialScaleDiv Scale division of the radius-axis
398 \param interval The interval of the radius-axis, that is
399 visible on the canvas
400
401 \sa QwtPolarPlot::updateAxes()
402 */
403void QwtPolarItem::updateScaleDiv( const QwtScaleDiv& azimuthScaleDiv,
404 const QwtScaleDiv& radialScaleDiv, const QwtInterval& interval )
405{
406 Q_UNUSED( azimuthScaleDiv );
407 Q_UNUSED( radialScaleDiv );
408 Q_UNUSED( interval );
409}
410
411/*!
412 \brief Return all information, that is needed to represent
413 the item on the legend
414
415 Most items are represented by one entry on the legend
416 showing an icon and a text.
417
418 QwtLegendData is basically a list of QVariants that makes it
419 possible to overload and reimplement legendData() to
420 return almost any type of information, that is understood
421 by the receiver that acts as the legend.
422
423 The default implementation returns one entry with
424 the title() of the item and the legendIcon().
425
426 \sa title(), legendIcon(), QwtLegend
427 */
428QList< QwtLegendData > QwtPolarItem::legendData() const
429{
430 QwtLegendData data;
431
432 QwtText label = title();
433 label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
434
435 data.setValue( QwtLegendData::TitleRole,
436 QVariant::fromValue( label ) );
437
438 const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
439 if ( !graphic.isNull() )
440 {
441 data.setValue( QwtLegendData::IconRole,
442 QVariant::fromValue( graphic ) );
443 }
444
445 QList< QwtLegendData > list;
446 list += data;
447
448 return list;
449}
450
451/*!
452 \return Icon representing the item on the legend
453
454 The default implementation returns an invalid icon
455
456 \param index Index of the legend entry
457 ( usually there is only one )
458 \param size Icon size
459
460 \sa setLegendIconSize(), legendData()
461 */
462QwtGraphic QwtPolarItem::legendIcon(
463 int index, const QSizeF& size ) const
464{
465 Q_UNUSED( index )
466 Q_UNUSED( size )
467
468 return QwtGraphic();
469}
470
471/*!
472 Some items like to display something (f.e. the azimuth axis) outside
473 of the area of the interval of the radial scale.
474 The default implementation returns 0 pixels
475
476 \return Hint for the margin
477 */
478int QwtPolarItem::marginHint() const
479{
480 return 0;
481}
Note: See TracBrowser for help on using the repository browser.