Loading...
Searching...
No Matches
qwt_polar_plot.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_canvas.h"
#include "qwt_polar_layout.h"
#include "qwt_painter.h"
#include "qwt_scale_engine.h"
#include "qwt_scale_div.h"
#include "qwt_text_label.h"
#include "qwt_round_scale_draw.h"
#include "qwt_legend.h"
#include "qwt_dyngrid_layout.h"
#include <qpointer.h>
#include <qpaintengine.h>
#include <qpainter.h>
#include <qevent.h>
static inline double qwtDistance(
const QPointF& p1, const QPointF& p2 )
{
double dx = p2.x() - p1.x();
double dy = p2.y() - p1.y();
return qSqrt( dx * dx + dy * dy );
}
namespace
{
class ScaleData
{
public:
ScaleData()
: isValid( false )
, scaleEngine( NULL )
{
}
~ScaleData()
{
delete scaleEngine;
}
bool doAutoScale;
double minValue;
double maxValue;
double stepSize;
int maxMajor;
int maxMinor;
bool isValid;
QwtScaleDiv scaleDiv;
QwtScaleEngine* scaleEngine;
};
}
class QwtPolarPlot::PrivateData
{
public:
QBrush canvasBrush;
bool autoReplot;
QwtPointPolar zoomPos;
double zoomFactor;
ScaleData scaleData[QwtPolar::ScaleCount];
QPointer< QwtTextLabel > titleLabel;
QPointer< QwtPolarCanvas > canvas;
QPointer< QwtAbstractLegend > legend;
double azimuthOrigin;
QwtPolarLayout* layout;
};
QwtPolarPlot::QwtPolarPlot( QWidget* parent )
: QFrame( parent )
{
initPlot( QwtText() );
}
QwtPolarPlot::QwtPolarPlot( const QwtText& title, QWidget* parent )
: QFrame( parent )
{
initPlot( title );
}
QwtPolarPlot::~QwtPolarPlot()
{
detachItems( QwtPolarItem::Rtti_PolarItem, autoDelete() );
delete m_data->layout;
delete m_data;
}
void QwtPolarPlot::setTitle( const QString& title )
{
if ( title != m_data->titleLabel->text().text() )
{
m_data->titleLabel->setText( title );
if ( !title.isEmpty() )
m_data->titleLabel->show();
else
m_data->titleLabel->hide();
}
}
void QwtPolarPlot::setTitle( const QwtText& title )
{
if ( title != m_data->titleLabel->text() )
{
m_data->titleLabel->setText( title );
if ( !title.isEmpty() )
m_data->titleLabel->show();
else
m_data->titleLabel->hide();
}
}
QwtText QwtPolarPlot::title() const
{
return m_data->titleLabel->text();
}
QwtTextLabel* QwtPolarPlot::titleLabel()
{
return m_data->titleLabel;
}
const QwtTextLabel* QwtPolarPlot::titleLabel() const
{
return m_data->titleLabel;
}
void QwtPolarPlot::insertLegend( QwtAbstractLegend* legend,
QwtPolarPlot::LegendPosition pos, double ratio )
{
m_data->layout->setLegendPosition( pos, ratio );
if ( legend != m_data->legend )
{
if ( m_data->legend && m_data->legend->parent() == this )
delete m_data->legend;
m_data->legend = legend;
if ( m_data->legend )
{
connect( this,
SIGNAL(legendDataChanged(
const QVariant&,const QList<QwtLegendData>&)),
m_data->legend,
SLOT(updateLegend(
const QVariant&,const QList<QwtLegendData>&))
);
if ( m_data->legend->parent() != this )
m_data->legend->setParent( this );
updateLegend();
QwtLegend* lgd = qobject_cast< QwtLegend* >( legend );
if ( lgd )
{
switch ( m_data->layout->legendPosition() )
{
case LeftLegend:
case RightLegend:
{
if ( lgd->maxColumns() == 0 )
lgd->setMaxColumns( 1 ); // 1 column: align vertical
break;
}
case TopLegend:
case BottomLegend:
{
lgd->setMaxColumns( 0 ); // unlimited
break;
}
default:
break;
}
}
}
}
updateLayout();
}
void QwtPolarPlot::updateLegend()
{
const QwtPolarItemList& itmList = itemList();
for ( QwtPolarItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
updateLegend( *it );
}
}
void QwtPolarPlot::updateLegend( const QwtPolarItem* plotItem )
{
if ( plotItem == NULL )
return;
QList< QwtLegendData > legendData;
if ( plotItem->testItemAttribute( QwtPolarItem::Legend ) )
legendData = plotItem->legendData();
const QVariant itemInfo = itemToInfo( const_cast< QwtPolarItem* >( plotItem ) );
Q_EMIT legendDataChanged( itemInfo, legendData );
}
QwtAbstractLegend* QwtPolarPlot::legend()
{
return m_data->legend;
}
const QwtAbstractLegend* QwtPolarPlot::legend() const
{
return m_data->legend;
}
void QwtPolarPlot::setPlotBackground( const QBrush& brush )
{
if ( brush != m_data->canvasBrush )
{
m_data->canvasBrush = brush;
autoRefresh();
}
}
const QBrush& QwtPolarPlot::plotBackground() const
{
return m_data->canvasBrush;
}
void QwtPolarPlot::setAutoReplot( bool enable )
{
m_data->autoReplot = enable;
}
bool QwtPolarPlot::autoReplot() const
{
return m_data->autoReplot;
}
void QwtPolarPlot::setAutoScale( int scaleId )
{
if ( scaleId != QwtPolar::ScaleRadius )
return;
ScaleData& scaleData = m_data->scaleData[scaleId];
if ( !scaleData.doAutoScale )
{
scaleData.doAutoScale = true;
autoRefresh();
}
}
bool QwtPolarPlot::hasAutoScale( int scaleId ) const
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return false;
return m_data->scaleData[scaleId].doAutoScale;
}
void QwtPolarPlot::setScaleMaxMinor( int scaleId, int maxMinor )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return;
maxMinor = qBound( 0, maxMinor, 100 );
ScaleData& scaleData = m_data->scaleData[scaleId];
if ( maxMinor != scaleData.maxMinor )
{
scaleData.maxMinor = maxMinor;
scaleData.isValid = false;
autoRefresh();
}
}
int QwtPolarPlot::scaleMaxMinor( int scaleId ) const
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return 0;
return m_data->scaleData[scaleId].maxMinor;
}
void QwtPolarPlot::setScaleMaxMajor( int scaleId, int maxMajor )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return;
maxMajor = qBound( 1, maxMajor, 10000 );
ScaleData& scaleData = m_data->scaleData[scaleId];
if ( maxMajor != scaleData.maxMinor )
{
scaleData.maxMajor = maxMajor;
scaleData.isValid = false;
autoRefresh();
}
}
int QwtPolarPlot::scaleMaxMajor( int scaleId ) const
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return 0;
return m_data->scaleData[scaleId].maxMajor;
}
void QwtPolarPlot::setScaleEngine( int scaleId, QwtScaleEngine* scaleEngine )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return;
ScaleData& scaleData = m_data->scaleData[scaleId];
if ( scaleEngine == NULL || scaleEngine == scaleData.scaleEngine )
return;
delete scaleData.scaleEngine;
scaleData.scaleEngine = scaleEngine;
scaleData.isValid = false;
autoRefresh();
}
QwtScaleEngine* QwtPolarPlot::scaleEngine( int scaleId )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return NULL;
return m_data->scaleData[scaleId].scaleEngine;
}
const QwtScaleEngine* QwtPolarPlot::scaleEngine( int scaleId ) const
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return NULL;
return m_data->scaleData[scaleId].scaleEngine;
}
void QwtPolarPlot::setScale( int scaleId,
double min, double max, double stepSize )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return;
ScaleData& scaleData = m_data->scaleData[scaleId];
scaleData.isValid = false;
scaleData.minValue = min;
scaleData.maxValue = max;
scaleData.stepSize = stepSize;
scaleData.doAutoScale = false;
autoRefresh();
}
void QwtPolarPlot::setScaleDiv( int scaleId, const QwtScaleDiv& scaleDiv )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return;
ScaleData& scaleData = m_data->scaleData[scaleId];
scaleData.scaleDiv = scaleDiv;
scaleData.isValid = true;
scaleData.doAutoScale = false;
autoRefresh();
}
const QwtScaleDiv* QwtPolarPlot::scaleDiv( int scaleId ) const
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return NULL;
return &m_data->scaleData[scaleId].scaleDiv;
}
QwtScaleDiv* QwtPolarPlot::scaleDiv( int scaleId )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return NULL;
return &m_data->scaleData[scaleId].scaleDiv;
}
void QwtPolarPlot::setAzimuthOrigin( double origin )
{
origin = ::fmod( origin, 2 * M_PI );
if ( origin != m_data->azimuthOrigin )
{
m_data->azimuthOrigin = origin;
autoRefresh();
}
}
double QwtPolarPlot::azimuthOrigin() const
{
return m_data->azimuthOrigin;
}
void QwtPolarPlot::zoom( const QwtPointPolar& zoomPos, double zoomFactor )
{
zoomFactor = qAbs( zoomFactor );
if ( zoomPos != m_data->zoomPos ||
zoomFactor != m_data->zoomFactor )
{
m_data->zoomPos = zoomPos;
m_data->zoomFactor = zoomFactor;
updateLayout();
autoRefresh();
}
}
void QwtPolarPlot::unzoom()
{
if ( m_data->zoomFactor != 1.0 || m_data->zoomPos.isValid() )
{
m_data->zoomFactor = 1.0;
m_data->zoomPos = QwtPointPolar();
autoRefresh();
}
}
QwtPointPolar QwtPolarPlot::zoomPos() const
{
return m_data->zoomPos;
}
double QwtPolarPlot::zoomFactor() const
{
return m_data->zoomFactor;
}
QwtScaleMap QwtPolarPlot::scaleMap( int scaleId ) const
{
const QRectF pr = plotRect();
return scaleMap( scaleId, pr.width() / 2.0 );
}
QwtScaleMap QwtPolarPlot::scaleMap( int scaleId, const double radius ) const
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return QwtScaleMap();
QwtScaleMap map;
map.setTransformation( scaleEngine( scaleId )->transformation() );
const QwtScaleDiv* sd = scaleDiv( scaleId );
map.setScaleInterval( sd->lowerBound(), sd->upperBound() );
if ( scaleId == QwtPolar::Azimuth )
{
map.setPaintInterval( m_data->azimuthOrigin,
m_data->azimuthOrigin + 2 * M_PI );
}
else
{
map.setPaintInterval( 0.0, radius );
}
return map;
}
bool QwtPolarPlot::event( QEvent* e )
{
bool ok = QWidget::event( e );
switch( e->type() )
{
case QEvent::LayoutRequest:
{
updateLayout();
break;
}
case QEvent::PolishRequest:
{
updateLayout();
replot();
break;
}
default:;
}
return ok;
}
void QwtPolarPlot::resizeEvent( QResizeEvent* e )
{
QFrame::resizeEvent( e );
updateLayout();
}
void QwtPolarPlot::initPlot( const QwtText& title )
{
m_data = new PrivateData;
m_data->layout = new QwtPolarLayout;
QwtText text( title );
text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap );
m_data->titleLabel = new QwtTextLabel( text, this );
m_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );
if ( !text.isEmpty() )
m_data->titleLabel->show();
else
m_data->titleLabel->hide();
m_data->canvas = new QwtPolarCanvas( this );
m_data->autoReplot = false;
m_data->canvasBrush = QBrush( Qt::white );
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
{
ScaleData& scaleData = m_data->scaleData[scaleId];
if ( scaleId == QwtPolar::Azimuth )
{
scaleData.minValue = 0.0;
scaleData.maxValue = 360.0;
scaleData.stepSize = 30.0;
}
else
{
scaleData.minValue = 0.0;
scaleData.maxValue = 1000.0;
scaleData.stepSize = 0.0;
}
scaleData.doAutoScale = true;
scaleData.maxMinor = 5;
scaleData.maxMajor = 8;
scaleData.isValid = false;
scaleData.scaleEngine = new QwtLinearScaleEngine;
}
m_data->zoomFactor = 1.0;
m_data->azimuthOrigin = 0.0;
setSizePolicy( QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding );
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
updateScale( scaleId );
}
void QwtPolarPlot::autoRefresh()
{
if ( m_data->autoReplot )
replot();
}
void QwtPolarPlot::updateLayout()
{
m_data->layout->activate( this, contentsRect() );
// resize and show the visible widgets
if ( m_data->titleLabel )
{
if ( !m_data->titleLabel->text().isEmpty() )
{
m_data->titleLabel->setGeometry( m_data->layout->titleRect().toRect() );
if ( !m_data->titleLabel->isVisible() )
m_data->titleLabel->show();
}
else
m_data->titleLabel->hide();
}
if ( m_data->legend )
{
if ( m_data->legend->isEmpty() )
{
m_data->legend->hide();
}
else
{
const QRectF legendRect = m_data->layout->legendRect();
m_data->legend->setGeometry( legendRect.toRect() );
m_data->legend->show();
}
}
m_data->canvas->setGeometry( m_data->layout->canvasRect().toRect() );
Q_EMIT layoutChanged();
}
void QwtPolarPlot::replot()
{
bool doAutoReplot = autoReplot();
setAutoReplot( false );
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
updateScale( scaleId );
m_data->canvas->invalidateBackingStore();
m_data->canvas->repaint();
setAutoReplot( doAutoReplot );
}
QwtPolarCanvas* QwtPolarPlot::canvas()
{
return m_data->canvas;
}
const QwtPolarCanvas* QwtPolarPlot::canvas() const
{
return m_data->canvas;
}
void QwtPolarPlot::drawCanvas( QPainter* painter,
const QRectF& canvasRect ) const
{
const QRectF cr = canvasRect;
const QRectF pr = plotRect( cr );
const double radius = pr.width() / 2.0;
if ( m_data->canvasBrush.style() != Qt::NoBrush )
{
painter->save();
painter->setPen( Qt::NoPen );
painter->setBrush( m_data->canvasBrush );
if ( qwtDistance( pr.center(), cr.topLeft() ) < radius &&
qwtDistance( pr.center(), cr.topRight() ) < radius &&
qwtDistance( pr.center(), cr.bottomRight() ) < radius &&
qwtDistance( pr.center(), cr.bottomLeft() ) < radius )
{
QwtPainter::drawRect( painter, cr );
}
else
{
painter->setRenderHint( QPainter::Antialiasing, true );
QwtPainter::drawEllipse( painter, pr );
}
painter->restore();
}
drawItems( painter,
scaleMap( QwtPolar::Azimuth, radius ),
scaleMap( QwtPolar::Radius, radius ),
pr.center(), radius, canvasRect );
}
void QwtPolarPlot::drawItems( QPainter* painter,
const QwtScaleMap& azimuthMap, const QwtScaleMap& radialMap,
const QPointF& pole, double radius,
const QRectF& canvasRect ) const
{
const QRectF pr = plotRect( canvasRect );
const QwtPolarItemList& itmList = itemList();
for ( QwtPolarItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
QwtPolarItem* item = *it;
if ( item && item->isVisible() )
{
painter->save();
// Unfortunately circular clipping slows down
// painting a lot. So we better try to avoid it.
bool doClipping = false;
if ( item->rtti() != QwtPolarItem::Rtti_PolarGrid )
{
const QwtInterval intv =
item->boundingInterval( QwtPolar::Radius );
if ( !intv.isValid() )
doClipping = true;
else
{
if ( radialMap.s1() < radialMap.s2() )
doClipping = intv.maxValue() > radialMap.s2();
else
doClipping = intv.minValue() < radialMap.s2();
}
}
if ( doClipping )
{
const int margin = item->marginHint();
const QRectF clipRect = pr.adjusted(
-margin, -margin, margin, margin );
if ( !clipRect.contains( canvasRect ) )
{
QRegion clipRegion( clipRect.toRect(), QRegion::Ellipse );
painter->setClipRegion( clipRegion, Qt::IntersectClip );
}
}
painter->setRenderHint( QPainter::Antialiasing,
item->testRenderHint( QwtPolarItem::RenderAntialiased ) );
item->draw( painter, azimuthMap, radialMap,
pole, radius, canvasRect );
painter->restore();
}
}
}
void QwtPolarPlot::updateScale( int scaleId )
{
if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
return;
ScaleData& d = m_data->scaleData[scaleId];
double minValue = d.minValue;
double maxValue = d.maxValue;
double stepSize = d.stepSize;
if ( scaleId == QwtPolar::ScaleRadius && d.doAutoScale )
{
QwtInterval interval;
const QwtPolarItemList& itmList = itemList();
for ( QwtPolarItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
const QwtPolarItem* item = *it;
if ( item->testItemAttribute( QwtPolarItem::AutoScale ) )
interval |= item->boundingInterval( scaleId );
}
minValue = interval.minValue();
maxValue = interval.maxValue();
d.scaleEngine->autoScale( d.maxMajor,
minValue, maxValue, stepSize );
d.isValid = false;
}
if ( !d.isValid )
{
d.scaleDiv = d.scaleEngine->divideScale(
minValue, maxValue, d.maxMajor, d.maxMinor, stepSize );
d.isValid = true;
}
const QwtInterval interval = visibleInterval();
const QwtPolarItemList& itmList = itemList();
for ( QwtPolarItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
QwtPolarItem* item = *it;
item->updateScaleDiv( *scaleDiv( QwtPolar::Azimuth ),
*scaleDiv( QwtPolar::Radius ), interval );
}
}
int QwtPolarPlot::plotMarginHint() const
{
int margin = 0;
const QwtPolarItemList& itmList = itemList();
for ( QwtPolarItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
QwtPolarItem* item = *it;
if ( item && item->isVisible() )
{
const int hint = item->marginHint();
if ( hint > margin )
margin = hint;
}
}
return margin;
}
QRectF QwtPolarPlot::plotRect() const
{
return plotRect( canvas()->contentsRect() );
}
QRectF QwtPolarPlot::plotRect( const QRectF& canvasRect ) const
{
const QwtScaleDiv* sd = scaleDiv( QwtPolar::Radius );
const QwtScaleEngine* se = scaleEngine( QwtPolar::Radius );
const int margin = plotMarginHint();
const QRectF cr = canvasRect;
const int radius = qMin( cr.width(), cr.height() ) / 2 - margin;
QwtScaleMap map;
map.setTransformation( se->transformation() );
map.setPaintInterval( 0.0, radius / m_data->zoomFactor );
map.setScaleInterval( sd->lowerBound(), sd->upperBound() );
double v = map.s1();
if ( map.s1() <= map.s2() )
v += m_data->zoomPos.radius();
else
v -= m_data->zoomPos.radius();
v = map.transform( v );
const QPointF off =
QwtPointPolar( m_data->zoomPos.azimuth(), v ).toPoint();
QPointF center( cr.center().x(), cr.top() + margin + radius );
center -= QPointF( off.x(), -off.y() );
QRectF rect( 0, 0, 2 * map.p2(), 2 * map.p2() );
rect.moveCenter( center );
return rect;
}
QwtInterval QwtPolarPlot::visibleInterval() const
{
const QwtScaleDiv* sd = scaleDiv( QwtPolar::Radius );
const QRectF cRect = canvas()->contentsRect();
const QRectF pRect = plotRect( cRect );
if ( cRect.contains( pRect ) || !cRect.intersects( pRect ) )
{
return QwtInterval( sd->lowerBound(), sd->upperBound() );
}
const QPointF pole = pRect.center();
const QRectF scaleRect = pRect & cRect;
const QwtScaleMap map = scaleMap( QwtPolar::Radius );
double dmin = 0.0;
double dmax = 0.0;
if ( scaleRect.contains( pole ) )
{
dmin = 0.0;
QPointF corners[4];
corners[0] = scaleRect.bottomRight();
corners[1] = scaleRect.topRight();
corners[2] = scaleRect.topLeft();
corners[3] = scaleRect.bottomLeft();
dmax = 0.0;
for ( int i = 0; i < 4; i++ )
{
const double dist = qwtDistance( pole, corners[i] );
if ( dist > dmax )
dmax = dist;
}
}
else
{
if ( pole.x() < scaleRect.left() )
{
if ( pole.y() < scaleRect.top() )
{
dmin = qwtDistance( pole, scaleRect.topLeft() );
dmax = qwtDistance( pole, scaleRect.bottomRight() );
}
else if ( pole.y() > scaleRect.bottom() )
{
dmin = qwtDistance( pole, scaleRect.bottomLeft() );
dmax = qwtDistance( pole, scaleRect.topRight() );
}
else
{
dmin = scaleRect.left() - pole.x();
dmax = qMax( qwtDistance( pole, scaleRect.bottomRight() ),
qwtDistance( pole, scaleRect.topRight() ) );
}
}
else if ( pole.x() > scaleRect.right() )
{
if ( pole.y() < scaleRect.top() )
{
dmin = qwtDistance( pole, scaleRect.topRight() );
dmax = qwtDistance( pole, scaleRect.bottomLeft() );
}
else if ( pole.y() > scaleRect.bottom() )
{
dmin = qwtDistance( pole, scaleRect.bottomRight() );
dmax = qwtDistance( pole, scaleRect.topLeft() );
}
else
{
dmin = pole.x() - scaleRect.right();
dmax = qMax( qwtDistance( pole, scaleRect.bottomLeft() ),
qwtDistance( pole, scaleRect.topLeft() ) );
}
}
else if ( pole.y() < scaleRect.top() )
{
dmin = scaleRect.top() - pole.y();
dmax = qMax( qwtDistance( pole, scaleRect.bottomLeft() ),
qwtDistance( pole, scaleRect.bottomRight() ) );
}
else if ( pole.y() > scaleRect.bottom() )
{
dmin = pole.y() - scaleRect.bottom();
dmax = qMax( qwtDistance( pole, scaleRect.topLeft() ),
qwtDistance( pole, scaleRect.topRight() ) );
}
}
const double radius = pRect.width() / 2.0;
if ( dmax > radius )
dmax = radius;
QwtInterval interval;
interval.setMinValue( map.invTransform( dmin ) );
interval.setMaxValue( map.invTransform( dmax ) );
return interval;
}
QwtPolarLayout* QwtPolarPlot::plotLayout()
{
return m_data->layout;
}
const QwtPolarLayout* QwtPolarPlot::plotLayout() const
{
return m_data->layout;
}
void QwtPolarPlot::attachItem( QwtPolarItem* plotItem, bool on )
{
if ( on )
insertItem( plotItem );
else
removeItem( plotItem );
Q_EMIT itemAttached( plotItem, on );
if ( plotItem->testItemAttribute( QwtPolarItem::Legend ) )
{
// the item wants to be represented on the legend
if ( on )
{
updateLegend( plotItem );
}
else
{
const QVariant itemInfo = itemToInfo( plotItem );
Q_EMIT legendDataChanged( itemInfo, QList< QwtLegendData >() );
}
}
if ( autoReplot() )
update();
}
QVariant QwtPolarPlot::itemToInfo( QwtPolarItem* plotItem ) const
{
return QVariant::fromValue( plotItem );
}
QwtPolarItem* QwtPolarPlot::infoToItem( const QVariant& itemInfo ) const
{
if ( itemInfo.canConvert< QwtPolarItem* >() )
return qvariant_cast< QwtPolarItem* >( itemInfo );
return NULL;
}
#include "moc_qwt_polar_plot.cpp"
QList
Definition qwt_abstract_legend.h:17
QwtAbstractLegend
Abstract base class for legend widgets.
Definition qwt_abstract_legend.h:35
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::setMaxValue
void setMaxValue(double)
Definition qwt_interval.h:186
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtInterval::setMinValue
void setMinValue(double)
Definition qwt_interval.h:176
QwtInterval::isValid
bool isValid() const
Definition qwt_interval.h:210
QwtLegend
The legend widget.
Definition qwt_legend.h:32
QwtLegend::maxColumns
uint maxColumns() const
Definition qwt_legend.cpp:310
QwtLegend::setMaxColumns
void setMaxColumns(uint numColums)
Set the maximum number of entries in a row.
Definition qwt_legend.cpp:296
QwtLinearScaleEngine
A scale engine for linear scales.
Definition qwt_scale_engine.h:152
QwtPainter::drawEllipse
static void drawEllipse(QPainter *, const QRectF &)
Wrapper for QPainter::drawEllipse()
Definition qwt_painter.cpp:416
QwtPainter::drawRect
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
Definition qwt_painter.cpp:337
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition qwt_point_polar.h:102
QwtPointPolar::isValid
bool isValid() const
Returns true if radius() >= 0.0.
Definition qwt_point_polar.h:90
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition qwt_point_polar.h:108
QwtPointPolar::toPoint
QPointF toPoint() const
Definition qwt_point_polar.cpp:68
QwtPolarCanvas
Canvas of a QwtPolarPlot.
Definition qwt_polar_canvas.h:28
QwtPolarItemDict::autoDelete
bool autoDelete() const
Definition qwt_polar_itemdict.cpp:106
QwtPolarItemDict::itemList
const QwtPolarItemList & itemList() const
A QwtPolarItemList of all attached plot items.
Definition qwt_polar_itemdict.cpp:168
QwtPolarItemDict::insertItem
void insertItem(QwtPolarItem *)
Definition qwt_polar_itemdict.cpp:117
QwtPolarItemDict::detachItems
void detachItems(int rtti=QwtPolarItem::Rtti_PolarItem, bool autoDelete=true)
Definition qwt_polar_itemdict.cpp:140
QwtPolarItemDict::removeItem
void removeItem(QwtPolarItem *)
Definition qwt_polar_itemdict.cpp:128
QwtPolarItem
Base class for items on a polar plot.
Definition qwt_polar_item.h:38
QwtPolarItem::testItemAttribute
bool testItemAttribute(ItemAttribute) const
Definition qwt_polar_item.cpp:221
QwtPolarItem::draw
virtual void draw(QPainter *painter, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, double radius, const QRectF &canvasRect) const =0
Draw the item.
QwtPolarItem::boundingInterval
virtual QwtInterval boundingInterval(int scaleId) const
Definition qwt_polar_item.cpp:381
QwtPolarItem::isVisible
bool isVisible() const
Definition qwt_polar_item.cpp:344
QwtPolarItem::Legend
@ Legend
The item is represented on the legend.
Definition qwt_polar_item.h:77
QwtPolarItem::AutoScale
@ AutoScale
Definition qwt_polar_item.h:83
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::testRenderHint
bool testRenderHint(RenderHint) const
Definition qwt_polar_item.cpp:254
QwtPolarItem::Rtti_PolarGrid
@ Rtti_PolarGrid
For QwtPolarGrid.
Definition qwt_polar_item.h:52
QwtPolarItem::Rtti_PolarItem
@ Rtti_PolarItem
Unspecific value, that can be used, when it doesn't matter.
Definition qwt_polar_item.h:49
QwtPolarItem::marginHint
virtual int marginHint() const
Definition qwt_polar_item.cpp:478
QwtPolarItem::RenderAntialiased
@ RenderAntialiased
Enable antialiasing.
Definition qwt_polar_item.h:95
QwtPolarItem::rtti
virtual int rtti() const
Definition qwt_polar_item.cpp:112
QwtPolarLayout
Layout class for QwtPolarPlot.
Definition qwt_polar_layout.h:24
QwtPolarLayout::legendRect
const QRectF & legendRect() const
Definition qwt_polar_layout.cpp:239
QwtPolarLayout::setLegendPosition
void setLegendPosition(QwtPolarPlot::LegendPosition pos, double ratio)
Specify the position of the legend.
Definition qwt_polar_layout.cpp:141
QwtPolarLayout::legendPosition
QwtPolarPlot::LegendPosition legendPosition() const
Definition qwt_polar_layout.cpp:196
QwtPolarLayout::activate
virtual void activate(const QwtPolarPlot *, const QRectF &rect, Options options=Options())
Recalculate the geometry of all components.
Definition qwt_polar_layout.cpp:344
QwtPolarLayout::titleRect
const QRectF & titleRect() const
Definition qwt_polar_layout.cpp:229
QwtPolarLayout::canvasRect
const QRectF & canvasRect() const
Definition qwt_polar_layout.cpp:248
QwtPolarPlot::setScaleMaxMinor
void setScaleMaxMinor(int scaleId, int maxMinor)
Definition qwt_polar_plot.cpp:401
QwtPolarPlot::plotLayout
QwtPolarLayout * plotLayout()
Definition qwt_polar_plot.cpp:1274
QwtPolarPlot::itemToInfo
virtual QVariant itemToInfo(QwtPolarItem *) const
Build an information, that can be used to identify a plot item on the legend.
Definition qwt_polar_plot.cpp:1337
QwtPolarPlot::scaleMaxMajor
int scaleMaxMajor(int scaleId) const
Definition qwt_polar_plot.cpp:460
QwtPolarPlot::layoutChanged
void layoutChanged()
QwtPolarPlot::setScale
void setScale(int scaleId, double min, double max, double step=0)
Disable autoscaling and specify a fixed scale for a selected scale.
Definition qwt_polar_plot.cpp:530
QwtPolarPlot::visibleInterval
QwtInterval visibleInterval() const
Definition qwt_polar_plot.cpp:1170
QwtPolarPlot::scaleMap
QwtScaleMap scaleMap(int scaleId, double radius) const
Definition qwt_polar_plot.cpp:730
QwtPolarPlot::drawCanvas
virtual void drawCanvas(QPainter *, const QRectF &) const
Definition qwt_polar_plot.cpp:930
QwtPolarPlot::scaleMaxMinor
int scaleMaxMinor(int scaleId) const
Definition qwt_polar_plot.cpp:423
QwtPolarPlot::plotMarginHint
int plotMarginHint() const
Definition qwt_polar_plot.cpp:1095
QwtPolarPlot::zoomPos
QwtPointPolar zoomPos() const
Definition qwt_polar_plot.cpp:682
QwtPolarPlot::unzoom
void unzoom()
Definition qwt_polar_plot.cpp:668
QwtPolarPlot::autoRefresh
void autoRefresh()
Replots the plot if QwtPlot::autoReplot() is true.
Definition qwt_polar_plot.cpp:847
QwtPolarPlot::scaleDiv
const QwtScaleDiv * scaleDiv(int scaleId) const
Return the scale division of a specified scale.
Definition qwt_polar_plot.cpp:579
QwtPolarPlot::setAzimuthOrigin
void setAzimuthOrigin(double)
Change the origin of the azimuth scale.
Definition qwt_polar_plot.cpp:615
QwtPolarPlot::plotBackground
const QBrush & plotBackground() const
Definition qwt_polar_plot.cpp:322
QwtPolarPlot::scaleEngine
QwtScaleEngine * scaleEngine(int scaleId)
Definition qwt_polar_plot.cpp:499
QwtPolarPlot::setScaleMaxMajor
void setScaleMaxMajor(int scaleId, int maxMajor)
Definition qwt_polar_plot.cpp:438
QwtPolarPlot::updateLayout
virtual void updateLayout()
Rebuild the layout.
Definition qwt_polar_plot.cpp:854
QwtPolarPlot::event
virtual bool event(QEvent *) override
Qt event handler.
Definition qwt_polar_plot.cpp:762
QwtPolarPlot::hasAutoScale
bool hasAutoScale(int scaleId) const
Definition qwt_polar_plot.cpp:386
QwtPolarPlot::replot
virtual void replot()
Redraw the plot.
Definition qwt_polar_plot.cpp:899
QwtPolarPlot::zoom
void zoom(const QwtPointPolar &, double factor)
Translate and in/decrease the zoom factor.
Definition qwt_polar_plot.cpp:651
QwtPolarPlot::zoomFactor
double zoomFactor() const
Definition qwt_polar_plot.cpp:691
QwtPolarPlot::resizeEvent
virtual void resizeEvent(QResizeEvent *) override
Resize and update internal layout.
Definition qwt_polar_plot.cpp:784
QwtPolarPlot::~QwtPolarPlot
virtual ~QwtPolarPlot()
Destructor.
Definition qwt_polar_plot.cpp:106
QwtPolarPlot::autoReplot
bool autoReplot() const
Definition qwt_polar_plot.cpp:348
QwtPolarPlot::itemAttached
void itemAttached(QwtPolarItem *plotItem, bool on)
QwtPolarPlot::azimuthOrigin
double azimuthOrigin() const
Definition qwt_polar_plot.cpp:632
QwtPolarPlot::updateScale
void updateScale(int scaleId)
Definition qwt_polar_plot.cpp:1040
QwtPolarPlot::title
QwtText title() const
Definition qwt_polar_plot.cpp:147
QwtPolarPlot::insertLegend
void insertLegend(QwtAbstractLegend *, LegendPosition=RightLegend, double ratio=-1.0)
Insert a legend.
Definition qwt_polar_plot.cpp:191
QwtPolarPlot::drawItems
virtual void drawItems(QPainter *painter, const QwtScaleMap &radialMap, const QwtScaleMap &azimuthMap, const QPointF &pole, double radius, const QRectF &canvasRect) const
Definition qwt_polar_plot.cpp:975
QwtPolarPlot::setScaleEngine
void setScaleEngine(int scaleId, QwtScaleEngine *)
Definition qwt_polar_plot.cpp:476
QwtPolarPlot::setAutoReplot
void setAutoReplot(bool tf=true)
Set or reset the autoReplot option.
Definition qwt_polar_plot.cpp:342
QwtPolarPlot::QwtPolarPlot
QwtPolarPlot(QWidget *parent=NULL)
Definition qwt_polar_plot.cpp:88
QwtPolarPlot::legendDataChanged
void legendDataChanged(const QVariant &itemInfo, const QList< QwtLegendData > &data)
QwtPolarPlot::plotRect
QRectF plotRect() const
Definition qwt_polar_plot.cpp:1120
QwtPolarPlot::setScaleDiv
void setScaleDiv(int scaleId, const QwtScaleDiv &)
Disable autoscaling and specify a fixed scale for a selected scale.
Definition qwt_polar_plot.cpp:554
QwtPolarPlot::legend
QwtAbstractLegend * legend()
Definition qwt_polar_plot.cpp:286
QwtPolarPlot::setAutoScale
void setAutoScale(int scaleId)
Enable autoscaling.
Definition qwt_polar_plot.cpp:368
QwtPolarPlot::setPlotBackground
void setPlotBackground(const QBrush &c)
Set the background of the plot area.
Definition qwt_polar_plot.cpp:309
QwtPolarPlot::updateLegend
void updateLegend()
Definition qwt_polar_plot.cpp:252
QwtPolarPlot::canvas
QwtPolarCanvas * canvas()
Definition qwt_polar_plot.cpp:914
QwtPolarPlot::LegendPosition
LegendPosition
Definition qwt_polar_plot.h:60
QwtPolarPlot::BottomLegend
@ BottomLegend
The legend will be below the canvas.
Definition qwt_polar_plot.h:68
QwtPolarPlot::LeftLegend
@ LeftLegend
The legend will be left from the canvas.
Definition qwt_polar_plot.h:62
QwtPolarPlot::TopLegend
@ TopLegend
The legend will be between canvas and title.
Definition qwt_polar_plot.h:71
QwtPolarPlot::RightLegend
@ RightLegend
The legend will be right from the canvas.
Definition qwt_polar_plot.h:65
QwtPolarPlot::titleLabel
QwtTextLabel * titleLabel()
Definition qwt_polar_plot.cpp:153
QwtPolarPlot::setTitle
void setTitle(const QString &)
Definition qwt_polar_plot.cpp:118
QwtPolarPlot::infoToItem
virtual QwtPolarItem * infoToItem(const QVariant &) const
Identify the plot item according to an item info object, that has bee generated from itemToInfo().
Definition qwt_polar_plot.cpp:1357
QwtScaleDiv
A class representing a scale division.
Definition qwt_scale_div.h:34
QwtScaleDiv::lowerBound
double lowerBound() const
Definition qwt_scale_div.cpp:131
QwtScaleDiv::upperBound
double upperBound() const
Definition qwt_scale_div.cpp:151
QwtScaleEngine
Base class for scale engines.
Definition qwt_scale_engine.h:46
QwtScaleEngine::transformation
QwtTransform * transformation() const
Definition qwt_scale_engine.cpp:265
QwtScaleEngine::autoScale
virtual void autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const =0
QwtScaleEngine::divideScale
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const =0
Calculate a scale division.
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtScaleMap::s1
double s1() const
Definition qwt_scale_map.h:83
QwtScaleMap::s2
double s2() const
Definition qwt_scale_map.h:91
QwtScaleMap::setPaintInterval
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
Definition qwt_scale_map.cpp:119
QwtScaleMap::setScaleInterval
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
Definition qwt_scale_map.cpp:100
QwtScaleMap::invTransform
double invTransform(double p) const
Definition qwt_scale_map.h:154
QwtScaleMap::p2
double p2() const
Definition qwt_scale_map.h:107
QwtScaleMap::setTransformation
void setTransformation(QwtTransform *)
Definition qwt_scale_map.cpp:76
QwtText
A class representing a text.
Definition qwt_text.h:52
QwtText::isEmpty
bool isEmpty() const
Definition qwt_text.cpp:739
QwtTextLabel
A Widget which displays a QwtText.
Definition qwt_text_label.h:27
QwtAxis::isValid
bool isValid(int axisPos)
Definition qwt_axis.h:45