Loading...
Searching...
No Matches
qwt_polar_marker.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_marker.h"
#include "qwt_polar.h"
#include "qwt_scale_map.h"
#include "qwt_symbol.h"
#include "qwt_text.h"
#include <qpainter.h>
static const int LabelDist = 2;
class QwtPolarMarker::PrivateData
{
public:
PrivateData()
: align( Qt::AlignCenter )
{
symbol = new QwtSymbol();
}
~PrivateData()
{
delete symbol;
}
QwtText label;
Qt::Alignment align;
QPen pen;
const QwtSymbol* symbol;
QwtPointPolar pos;
};
QwtPolarMarker::QwtPolarMarker()
: QwtPolarItem( QwtText( "Marker" ) )
{
m_data = new PrivateData;
setItemAttribute( QwtPolarItem::AutoScale );
setZ( 30.0 );
}
QwtPolarMarker::~QwtPolarMarker()
{
delete m_data;
}
int QwtPolarMarker::rtti() const
{
return QwtPolarItem::Rtti_PolarMarker;
}
QwtPointPolar QwtPolarMarker::position() const
{
return m_data->pos;
}
void QwtPolarMarker::setPosition( const QwtPointPolar& pos )
{
if ( m_data->pos != pos )
{
m_data->pos = pos;
itemChanged();
}
}
void QwtPolarMarker::draw( QPainter* painter,
const QwtScaleMap& azimuthMap, const QwtScaleMap& radialMap,
const QPointF& pole, double radius,
const QRectF& canvasRect ) const
{
Q_UNUSED( radius );
Q_UNUSED( canvasRect );
const double r = radialMap.transform( m_data->pos.radius() );
const double a = azimuthMap.transform( m_data->pos.azimuth() );
const QPointF pos = qwtPolar2Pos( pole, r, a );
// draw symbol
QSize sSym( 0, 0 );
if ( m_data->symbol->style() != QwtSymbol::NoSymbol )
{
sSym = m_data->symbol->size();
m_data->symbol->drawSymbol( painter, pos );
}
// draw label
if ( !m_data->label.isEmpty() )
{
int xlw = qMax( int( m_data->pen.width() ), 1 );
int ylw = xlw;
int xlw1 = qMax( ( xlw + 1 ) / 2, ( sSym.width() + 1 ) / 2 ) + LabelDist;
xlw = qMax( xlw / 2, ( sSym.width() + 1 ) / 2 ) + LabelDist;
int ylw1 = qMax( ( ylw + 1 ) / 2, ( sSym.height() + 1 ) / 2 ) + LabelDist;
ylw = qMax( ylw / 2, ( sSym.height() + 1 ) / 2 ) + LabelDist;
QRect tr( QPoint( 0, 0 ), m_data->label.textSize( painter->font() ).toSize() );
tr.moveCenter( QPoint( 0, 0 ) );
int dx = pos.x();
int dy = pos.y();
if ( m_data->align & Qt::AlignTop )
dy += tr.y() - ylw1;
else if ( m_data->align & Qt::AlignBottom )
dy -= tr.y() - ylw1;
if ( m_data->align & Qt::AlignLeft )
dx += tr.x() - xlw1;
else if ( m_data->align & Qt::AlignRight )
dx -= tr.x() - xlw1;
tr.translate( dx, dy );
m_data->label.draw( painter, tr );
}
}
void QwtPolarMarker::setSymbol( const QwtSymbol* symbol )
{
if ( m_data->symbol != symbol )
{
delete m_data->symbol;
m_data->symbol = symbol;
itemChanged();
}
}
const QwtSymbol* QwtPolarMarker::symbol() const
{
return m_data->symbol;
}
void QwtPolarMarker::setLabel( const QwtText& label )
{
if ( label != m_data->label )
{
m_data->label = label;
itemChanged();
}
}
QwtText QwtPolarMarker::label() const
{
return m_data->label;
}
void QwtPolarMarker::setLabelAlignment( Qt::Alignment align )
{
if ( align == m_data->align )
return;
m_data->align = align;
itemChanged();
}
Qt::Alignment QwtPolarMarker::labelAlignment() const
{
return m_data->align;
}
QwtInterval QwtPolarMarker::boundingInterval( int scaleId ) const
{
const double v = ( scaleId == QwtPolar::ScaleRadius )
? m_data->pos.radius() : m_data->pos.azimuth();
return QwtInterval( v, v );
}
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
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::azimuth
double azimuth() const
Returns the azimuth.
Definition qwt_point_polar.h:108
QwtPolarItem
Base class for items on a polar plot.
Definition qwt_polar_item.h:38
QwtPolarItem::itemChanged
virtual void itemChanged()
Definition qwt_polar_item.cpp:355
QwtPolarItem::AutoScale
@ AutoScale
Definition qwt_polar_item.h:83
QwtPolarItem::Rtti_PolarMarker
@ Rtti_PolarMarker
For QwtPolarMarker.
Definition qwt_polar_item.h:55
QwtPolarItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition qwt_polar_item.cpp:201
QwtPolarItem::setZ
void setZ(double z)
Set the z value.
Definition qwt_polar_item.cpp:142
QwtPolarMarker::~QwtPolarMarker
virtual ~QwtPolarMarker()
Destructor.
Definition qwt_polar_marker.cpp:52
QwtPolarMarker::rtti
virtual int rtti() const override
Definition qwt_polar_marker.cpp:58
QwtPolarMarker::setLabelAlignment
void setLabelAlignment(Qt::Alignment)
Set the alignment of the label.
Definition qwt_polar_marker.cpp:201
QwtPolarMarker::setSymbol
void setSymbol(const QwtSymbol *s)
Assign a symbol.
Definition qwt_polar_marker.cpp:148
QwtPolarMarker::setLabel
void setLabel(const QwtText &)
Set the label.
Definition qwt_polar_marker.cpp:172
QwtPolarMarker::boundingInterval
virtual QwtInterval boundingInterval(int scaleId) const override
Definition qwt_polar_marker.cpp:228
QwtPolarMarker::position
QwtPointPolar position() const
Definition qwt_polar_marker.cpp:64
QwtPolarMarker::labelAlignment
Qt::Alignment labelAlignment() const
Definition qwt_polar_marker.cpp:214
QwtPolarMarker::setPosition
void setPosition(const QwtPointPolar &)
Change the position of the marker.
Definition qwt_polar_marker.cpp:70
QwtPolarMarker::QwtPolarMarker
QwtPolarMarker()
Sets alignment to Qt::AlignCenter, and style to NoLine.
Definition qwt_polar_marker.cpp:42
QwtPolarMarker::draw
virtual void draw(QPainter *painter, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, double radius, const QRectF &canvasRect) const override
Definition qwt_polar_marker.cpp:89
QwtPolarMarker::symbol
const QwtSymbol * symbol() const
Definition qwt_polar_marker.cpp:162
QwtPolarMarker::label
QwtText label() const
Definition qwt_polar_marker.cpp:185
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtSymbol
A class for drawing symbols.
Definition qwt_symbol.h:32
QwtSymbol::style
Style style() const
Definition qwt_symbol.cpp:1795
QwtSymbol::drawSymbol
void drawSymbol(QPainter *, const QRectF &) const
Draw the symbol into a rectangle.
Definition qwt_symbol.cpp:1434
QwtSymbol::NoSymbol
@ NoSymbol
No Style. The symbol cannot be drawn.
Definition qwt_symbol.h:41
QwtSymbol::size
const QSize & size() const
Definition qwt_symbol.cpp:1094
QwtText
A class representing a text.
Definition qwt_text.h:52
QwtText::textSize
QSizeF textSize() const
Definition qwt_text.cpp:570
QwtText::isEmpty
bool isEmpty() const
Definition qwt_text.cpp:739
QwtText::draw
void draw(QPainter *painter, const QRectF &rect) const
Definition qwt_text.cpp:615