Qwt User's Guide: qwt_polar_item.cpp Source File

Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
qwt_polar_item.cpp
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
48QwtPolarItem::QwtPolarItem( const QwtText& title )
49{
50 m_data = new PrivateData;
51 m_data->title = title;
52}
53
55QwtPolarItem::~QwtPolarItem()
56{
57 attach( NULL );
58 delete m_data;
59}
60
74 void 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
95 void QwtPolarItem::detach()
96{
97 attach( NULL );
98}
99
112 int QwtPolarItem::rtti() const
113{
114 return Rtti_PolarItem;
115}
116
118 QwtPolarPlot* QwtPolarItem::plot() const
119{
120 return m_data->plot;
121}
122
129 double QwtPolarItem::z() const
130{
131 return m_data->z;
132}
133
142 void 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
164 void QwtPolarItem::setTitle( const QString& title )
165{
166 setTitle( QwtText( title ) );
167}
168
175 void QwtPolarItem::setTitle( const QwtText& title )
176{
177 if ( m_data->title != title )
178 {
179 m_data->title = title;
180 itemChanged();
181 }
182}
183
188 const QwtText& QwtPolarItem::title() const
189{
190 return m_data->title;
191}
192
201 void 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
221 bool QwtPolarItem::testItemAttribute( ItemAttribute attribute ) const
222{
223 return m_data->attributes & attribute;
224}
225
234 void 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
254 bool QwtPolarItem::testRenderHint( RenderHint hint ) const
255{
256 return ( m_data->renderHints & hint );
257}
258
272 void QwtPolarItem::setRenderThreadCount( uint numThreads )
273{
274 m_data->renderThreadCount = numThreads;
275}
276
282uint QwtPolarItem::renderThreadCount() const
283{
284 return m_data->renderThreadCount;
285}
286
295 void QwtPolarItem::setLegendIconSize( const QSize& size )
296{
297 if ( m_data->legendIconSize != size )
298 {
299 m_data->legendIconSize = size;
300 legendChanged();
301 }
302}
303
308QSize QwtPolarItem::legendIconSize() const
309{
310 return m_data->legendIconSize;
311}
312
314 void QwtPolarItem::show()
315{
316 setVisible( true );
317}
318
320 void QwtPolarItem::hide()
321{
322 setVisible( false );
323}
324
331 void QwtPolarItem::setVisible( bool on )
332{
333 if ( on != m_data->isVisible )
334 {
335 m_data->isVisible = on;
336 itemChanged();
337 }
338}
339
344 bool QwtPolarItem::isVisible() const
345{
346 return m_data->isVisible;
347}
348
355 void QwtPolarItem::itemChanged()
356{
357 if ( m_data->plot )
358 m_data->plot->autoRefresh();
359}
360
365 void QwtPolarItem::legendChanged()
366{
367 if ( testItemAttribute( QwtPolarItem::Legend ) && m_data->plot )
368 m_data->plot->updateLegend( this );
369}
370
381 QwtInterval QwtPolarItem::boundingInterval( int scaleId ) const
382{
383 Q_UNUSED( scaleId );
384
385 return QwtInterval(); // invalid
386}
387
403 void 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
428 QList< 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
462 QwtGraphic QwtPolarItem::legendIcon(
463 int index, const QSizeF& size ) const
464{
465 Q_UNUSED( index )
466 Q_UNUSED( size )
467
468 return QwtGraphic();
469}
470
478 int QwtPolarItem::marginHint() const
479{
480 return 0;
481}
QList
Definition qwt_abstract_legend.h:17
QwtGraphic
A paint device for scalable graphics.
Definition qwt_graphic.h:76
QwtGraphic::isNull
bool isNull() const
Definition qwt_graphic.cpp:413
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtLegendData
Attributes of an entry on a legend.
Definition qwt_legend_data.h:37
QwtLegendData::setValue
void setValue(int role, const QVariant &)
Definition qwt_legend_data.cpp:64
QwtPolarItem::testItemAttribute
bool testItemAttribute(ItemAttribute) const
Definition qwt_polar_item.cpp:221
QwtPolarItem::boundingInterval
virtual QwtInterval boundingInterval(int scaleId) const
Definition qwt_polar_item.cpp:381
QwtPolarItem::legendIconSize
QSize legendIconSize() const
Definition qwt_polar_item.cpp:308
QwtPolarItem::itemChanged
virtual void itemChanged()
Definition qwt_polar_item.cpp:355
QwtPolarItem::setLegendIconSize
void setLegendIconSize(const QSize &)
Definition qwt_polar_item.cpp:295
QwtPolarItem::QwtPolarItem
QwtPolarItem(const QwtText &title=QwtText())
Definition qwt_polar_item.cpp:48
QwtPolarItem::isVisible
bool isVisible() const
Definition qwt_polar_item.cpp:344
QwtPolarItem::detach
void detach()
This method detaches a QwtPolarItem from the QwtPolarPlot it has been associated with.
Definition qwt_polar_item.cpp:95
QwtPolarItem::setRenderThreadCount
void setRenderThreadCount(uint numThreads)
Definition qwt_polar_item.cpp:272
QwtPolarItem::ItemAttribute
ItemAttribute
Plot Item Attributes.
Definition qwt_polar_item.h:75
QwtPolarItem::Legend
@ Legend
The item is represented on the legend.
Definition qwt_polar_item.h:77
QwtPolarItem::z
double z() const
Definition qwt_polar_item.cpp:129
QwtPolarItem::updateScaleDiv
virtual void updateScaleDiv(const QwtScaleDiv &, const QwtScaleDiv &, const QwtInterval &)
Update the item to changes of the axes scale division.
Definition qwt_polar_item.cpp:403
QwtPolarItem::legendData
virtual QList< QwtLegendData > legendData() const
Return all information, that is needed to represent the item on the legend.
Definition qwt_polar_item.cpp:428
QwtPolarItem::setTitle
void setTitle(const QString &title)
Definition qwt_polar_item.cpp:164
QwtPolarItem::title
const QwtText & title() const
Definition qwt_polar_item.cpp:188
QwtPolarItem::ItemAttributes
QFlags< ItemAttribute > ItemAttributes
Definition qwt_polar_item.h:86
QwtPolarItem::testRenderHint
bool testRenderHint(RenderHint) const
Definition qwt_polar_item.cpp:254
QwtPolarItem::Rtti_PolarItem
@ Rtti_PolarItem
Unspecific value, that can be used, when it doesn't matter.
Definition qwt_polar_item.h:49
QwtPolarItem::hide
void hide()
Hide the item.
Definition qwt_polar_item.cpp:320
QwtPolarItem::setVisible
virtual void setVisible(bool)
Definition qwt_polar_item.cpp:331
QwtPolarItem::plot
QwtPolarPlot * plot() const
Definition qwt_polar_item.cpp:118
QwtPolarItem::~QwtPolarItem
virtual ~QwtPolarItem()
Destroy the QwtPolarItem.
Definition qwt_polar_item.cpp:55
QwtPolarItem::marginHint
virtual int marginHint() const
Definition qwt_polar_item.cpp:478
QwtPolarItem::RenderHints
QFlags< RenderHint > RenderHints
Definition qwt_polar_item.h:98
QwtPolarItem::attach
void attach(QwtPolarPlot *plot)
Attach the item to a plot.
Definition qwt_polar_item.cpp:74
QwtPolarItem::legendIcon
virtual QwtGraphic legendIcon(int index, const QSizeF &) const
Definition qwt_polar_item.cpp:462
QwtPolarItem::renderThreadCount
uint renderThreadCount() const
Definition qwt_polar_item.cpp:282
QwtPolarItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition qwt_polar_item.cpp:201
QwtPolarItem::RenderHint
RenderHint
Render hints.
Definition qwt_polar_item.h:93
QwtPolarItem::show
void show()
Show the item.
Definition qwt_polar_item.cpp:314
QwtPolarItem::legendChanged
virtual void legendChanged()
Definition qwt_polar_item.cpp:365
QwtPolarItem::setRenderHint
void setRenderHint(RenderHint, bool on=true)
Definition qwt_polar_item.cpp:234
QwtPolarItem::setZ
void setZ(double z)
Set the z value.
Definition qwt_polar_item.cpp:142
QwtPolarItem::rtti
virtual int rtti() const
Definition qwt_polar_item.cpp:112
QwtPolarPlot
A plotting widget, displaying a polar coordinate system.
Definition qwt_polar_plot.h:47
QwtPolarPlot::autoRefresh
void autoRefresh()
Replots the plot if QwtPlot::autoReplot() is true.
Definition qwt_polar_plot.cpp:847
QwtPolarPlot::updateLegend
void updateLegend()
Definition qwt_polar_plot.cpp:252
QwtScaleDiv
A class representing a scale division.
Definition qwt_scale_div.h:34
QwtText
A class representing a text.
Definition qwt_text.h:52
QwtText::renderFlags
int renderFlags() const
Definition qwt_text.cpp:317
QwtText::setRenderFlags
void setRenderFlags(int)
Change the render flags.
Definition qwt_text.cpp:304