Loading...
Searching...
No Matches
qwt_polar_item.cpp
/******************************************************************************
* QwtPolar Widget Library
* Copyright (C) 2008 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_polar_plot.h"
#include "qwt_polar_item.h"
#include "qwt_legend.h"
#include "qwt_scale_div.h"
#include <qpainter.h>
class QwtPolarItem::PrivateData
{
public:
PrivateData()
: plot( NULL )
, isVisible( true )
, renderThreadCount( 1 )
, z( 0.0 )
, legendIconSize( 8, 8 )
{
}
mutable QwtPolarPlot* plot;
bool isVisible;
QwtPolarItem::ItemAttributes attributes;
QwtPolarItem::RenderHints renderHints;
uint renderThreadCount;
double z;
QwtText title;
QSize legendIconSize;
};
QwtPolarItem::QwtPolarItem( const QwtText& title )
{
m_data = new PrivateData;
m_data->title = title;
}
QwtPolarItem::~QwtPolarItem()
{
attach( NULL );
delete m_data;
}
void QwtPolarItem::attach( QwtPolarPlot* plot )
{
if ( plot == m_data->plot )
return;
if ( m_data->plot )
m_data->plot->attachItem( this, false );
m_data->plot = plot;
if ( m_data->plot )
m_data->plot->attachItem( this, true );
}
void QwtPolarItem::detach()
{
attach( NULL );
}
int QwtPolarItem::rtti() const
{
return Rtti_PolarItem;
}
QwtPolarPlot* QwtPolarItem::plot() const
{
return m_data->plot;
}
double QwtPolarItem::z() const
{
return m_data->z;
}
void QwtPolarItem::setZ( double z )
{
if ( m_data->z != z )
{
if ( m_data->plot )
m_data->plot->attachItem( this, false );
m_data->z = z;
if ( m_data->plot )
m_data->plot->attachItem( this, true );
itemChanged();
}
}
void QwtPolarItem::setTitle( const QString& title )
{
setTitle( QwtText( title ) );
}
void QwtPolarItem::setTitle( const QwtText& title )
{
if ( m_data->title != title )
{
m_data->title = title;
itemChanged();
}
}
const QwtText& QwtPolarItem::title() const
{
return m_data->title;
}
void QwtPolarItem::setItemAttribute( ItemAttribute attribute, bool on )
{
if ( bool( m_data->attributes & attribute ) != on )
{
if ( on )
m_data->attributes |= attribute;
else
m_data->attributes &= ~attribute;
itemChanged();
}
}
bool QwtPolarItem::testItemAttribute( ItemAttribute attribute ) const
{
return m_data->attributes & attribute;
}
void QwtPolarItem::setRenderHint( RenderHint hint, bool on )
{
if ( ( ( m_data->renderHints & hint ) != 0 ) != on )
{
if ( on )
m_data->renderHints |= hint;
else
m_data->renderHints &= ~hint;
itemChanged();
}
}
bool QwtPolarItem::testRenderHint( RenderHint hint ) const
{
return ( m_data->renderHints & hint );
}
void QwtPolarItem::setRenderThreadCount( uint numThreads )
{
m_data->renderThreadCount = numThreads;
}
uint QwtPolarItem::renderThreadCount() const
{
return m_data->renderThreadCount;
}
void QwtPolarItem::setLegendIconSize( const QSize& size )
{
if ( m_data->legendIconSize != size )
{
m_data->legendIconSize = size;
legendChanged();
}
}
QSize QwtPolarItem::legendIconSize() const
{
return m_data->legendIconSize;
}
void QwtPolarItem::show()
{
setVisible( true );
}
void QwtPolarItem::hide()
{
setVisible( false );
}
void QwtPolarItem::setVisible( bool on )
{
if ( on != m_data->isVisible )
{
m_data->isVisible = on;
itemChanged();
}
}
bool QwtPolarItem::isVisible() const
{
return m_data->isVisible;
}
void QwtPolarItem::itemChanged()
{
if ( m_data->plot )
m_data->plot->autoRefresh();
}
void QwtPolarItem::legendChanged()
{
if ( testItemAttribute( QwtPolarItem::Legend ) && m_data->plot )
m_data->plot->updateLegend( this );
}
QwtInterval QwtPolarItem::boundingInterval( int scaleId ) const
{
Q_UNUSED( scaleId );
return QwtInterval(); // invalid
}
void QwtPolarItem::updateScaleDiv( const QwtScaleDiv& azimuthScaleDiv,
const QwtScaleDiv& radialScaleDiv, const QwtInterval& interval )
{
Q_UNUSED( azimuthScaleDiv );
Q_UNUSED( radialScaleDiv );
Q_UNUSED( interval );
}
QList< QwtLegendData > QwtPolarItem::legendData() const
{
QwtLegendData data;
QwtText label = title();
label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
data.setValue( QwtLegendData::TitleRole,
QVariant::fromValue( label ) );
const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
if ( !graphic.isNull() )
{
data.setValue( QwtLegendData::IconRole,
QVariant::fromValue( graphic ) );
}
QList< QwtLegendData > list;
list += data;
return list;
}
QwtGraphic QwtPolarItem::legendIcon(
int index, const QSizeF& size ) const
{
Q_UNUSED( index )
Q_UNUSED( size )
return QwtGraphic();
}
int QwtPolarItem::marginHint() const
{
return 0;
}
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