9#include "qwt_polar_curve.h"
11#include "qwt_painter.h"
12#include "qwt_scale_map.h"
14#include "qwt_symbol.h"
15#include "qwt_legend.h"
16#include "qwt_curve_fitter.h"
17#include "qwt_clipper.h"
21static inline bool qwtInsidePole(
const QwtScaleMap& map,
double radius )
23 return map.
isInverting() ? ( radius > map.
s1() ) : ( radius < map.s1() );
26static int qwtVerifyRange(
int size,
int& i1,
int& i2 )
31 i1 = qBound( 0, i1, size - 1 );
32 i2 = qBound( 0, i2, size - 1 );
37 return ( i2 - i1 + 1 );
40class QwtPolarCurve::PrivateData
48 pen = QPen( Qt::black );
102 m_data =
new PrivateData;
128 m_data->legendAttributes |= attribute;
130 m_data->legendAttributes &= ~attribute;
143 return ( m_data->legendAttributes & attribute );
154 if (
style != m_data->style )
156 m_data->style =
style;
167 return m_data->style;
177 if (
symbol != m_data->symbol )
179 delete m_data->symbol;
191 return m_data->symbol;
201 if (
pen != m_data->pen )
227 if ( m_series !=
data )
250 delete m_data->curveFitter;
263 return m_data->curveFitter;
278 const QPointF& pole,
double radius,
279 const QRectF& canvasRect )
const
282 Q_UNUSED( canvasRect );
284 draw( painter, azimuthMap, radialMap, pole, 0, -1 );
301 const QPointF& pole,
int from,
int to )
const
309 if ( qwtVerifyRange(
dataSize(), from, to ) > 0 )
312 painter->setPen( m_data->pen );
315 azimuthMap, radialMap, pole, from, to );
323 azimuthMap, radialMap, pole, from, to );
343 const QPointF& pole,
int from,
int to )
const
348 drawLines( painter, azimuthMap, radialMap, pole, from, to );
369 const QPointF& pole,
int from,
int to )
const
371 int size = to - from + 1;
377 if ( m_data->curveFitter )
379 QPolygonF points( size );
380 for (
int j = from; j <= to; j++ )
383 points[j - from] = QPointF( point.
azimuth(), point.
radius() );
386 points = m_data->curveFitter->
fitCurve( points );
388 polyline.resize( points.size() );
390 QPointF* polylineData = polyline.data();
391 QPointF* pointsData = points.data();
393 for (
int i = 0; i < points.size(); i++ )
395 const QwtPointPolar point( pointsData[i].x(), pointsData[i].y() );
400 polylineData[i] = qwtPolar2Pos( pole, r, a );
405 polyline.resize( size );
406 QPointF* polylineData = polyline.data();
408 for (
int i = from; i <= to; i++ )
411 if ( !qwtInsidePole( radialMap, point.
radius() ) )
415 polylineData[i - from] = qwtPolar2Pos( pole, r, a );
419 polylineData[i - from] = pole;
425 if ( painter->hasClipping() )
427 clipRect = painter->clipRegion().boundingRect();
431 clipRect = painter->window();
432 if ( !clipRect.isEmpty() )
433 clipRect = painter->transform().inverted().mapRect( clipRect );
436 if ( !clipRect.isEmpty() )
438 double off = qCeil( qMax( qreal( 1.0 ), painter->pen().widthF() ) );
439 clipRect = clipRect.toRect().adjusted( -off, -off, off, off );
461 const QPointF& pole,
int from,
int to )
const
466 const int chunkSize = 500;
468 for (
int i = from; i <= to; i += chunkSize )
470 const int n = qMin( chunkSize, to - i + 1 );
473 for (
int j = 0; j < n; j++ )
477 if ( !qwtInsidePole( radialMap, point.
radius() ) )
482 points += qwtPolar2Pos( pole, r, a );
490 if ( points.size() > 0 )
501 return m_series->
size();
514 const QSizeF& size )
const
518 if ( size.isEmpty() )
525 QPainter painter( &graphic );
526 painter.setRenderHint( QPainter::Antialiasing,
529 if ( m_data->legendAttributes == 0 )
535 brush = QBrush(
pen().color() );
537 else if ( m_data->symbol &&
540 brush = QBrush( m_data->symbol->
pen().color() );
543 if ( brush.style() != Qt::NoBrush )
545 QRectF r( 0, 0, size.width(), size.height() );
546 painter.fillRect( r, brush );
552 if (
pen() != Qt::NoPen )
555 pn.setCapStyle( Qt::FlatCap );
557 painter.setPen( pn );
559 const double y = 0.5 * size.height();
566 if ( m_data->symbol )
568 QRectF r( 0, 0, size.width(), size.height() );
589 if ( scaleId == QwtPolar::ScaleAzimuth )
590 return QwtInterval( boundingRect.left(), boundingRect.right() );
592 if ( scaleId == QwtPolar::ScaleRadius )
593 return QwtInterval( boundingRect.top(), boundingRect.bottom() );
Abstract base class for a curve fitter.
virtual QPolygonF fitCurve(const QPolygonF &polygon) const =0
A paint device for scalable graphics.
void setRenderHint(RenderHint, bool on=true)
void setDefaultSize(const QSizeF &)
Set a default size.
A class representing an interval.
static void drawPolyline(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolyline()
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
A point in polar coordinates.
double radius() const
Returns the radius.
double azimuth() const
Returns the azimuth.
An item, that represents a series of points.
bool testLegendAttribute(LegendAttribute) const
Test if a legend attribute is enabled.
virtual QwtInterval boundingInterval(int scaleId) const override
virtual void drawSymbols(QPainter *, const QwtSymbol &, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, int from, int to) const
virtual void drawCurve(QPainter *, int style, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, int from, int to) const
void setStyle(CurveStyle style)
LegendAttribute
Attributes how to represent the curve on the legend.
@ LegendShowSymbol
If the curve has a valid symbol it is painted.
QFlags< LegendAttribute > LegendAttributes
const QwtSeriesData< QwtPointPolar > * data() const
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
void setPen(const QPen &)
Assign a pen.
const QwtSymbol * symbol() const
@ NoCurve
Don't draw a curve. Note: This doesn't affect the symbols.
void setSymbol(QwtSymbol *)
Assign a symbol.
QwtPointPolar sample(int i) const
void setLegendAttribute(LegendAttribute, bool on=true)
QwtPolarCurve()
Constructor.
virtual void draw(QPainter *p, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, double radius, const QRectF &canvasRect) const override
void setCurveFitter(QwtCurveFitter *)
Insert a curve fitter.
QwtCurveFitter * curveFitter() const
void init()
Initialize data members.
virtual int rtti() const override
void setData(QwtSeriesData< QwtPointPolar > *data)
virtual ~QwtPolarCurve()
Destructor.
void drawLines(QPainter *, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, int from, int to) const
Base class for items on a polar plot.
virtual void itemChanged()
@ Legend
The item is represented on the legend.
bool testRenderHint(RenderHint) const
@ Rtti_PolarCurve
For QwtPolarCurve.
void setItemAttribute(ItemAttribute, bool on=true)
@ RenderAntialiased
Enable antialiasing.
void setRenderHint(RenderHint, bool on=true)
void setZ(double z)
Set the z value.
double transform(double s) const
virtual size_t size() const =0
virtual QRectF boundingRect() const
A class for drawing symbols.
const QBrush & brush() const
void drawSymbol(QPainter *, const QRectF &) const
Draw the symbol into a rectangle.
void drawSymbols(QPainter *, const QPolygonF &) const
Draw symbols at the specified points.
@ NoSymbol
No Style. The symbol cannot be drawn.
A class representing a text.
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)