source: ntrip/trunk/BNC/qwtpolar/qwt_polar_item.cpp@ 10496

Last change on this file since 10496 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

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