qwt_polar_marker.cpp
Go to the documentation of this file.
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_marker.h"
10 #include "qwt_polar.h"
11 #include "qwt_scale_map.h"
12 #include "qwt_symbol.h"
13 #include "qwt_text.h"
14 
15 #include <qpainter.h>
16 
17 static const int LabelDist = 2;
18 
20 {
21  public:
23  : align( Qt::AlignCenter )
24  {
25  symbol = new QwtSymbol();
26  }
27 
29  {
30  delete symbol;
31  }
32 
34  Qt::Alignment align;
35  QPen pen;
36  const QwtSymbol* symbol;
37 
39 };
40 
43  : QwtPolarItem( QwtText( "Marker" ) )
44 {
45  m_data = new PrivateData;
46 
48  setZ( 30.0 );
49 }
50 
53 {
54  delete m_data;
55 }
56 
59 {
61 }
62 
65 {
66  return m_data->pos;
67 }
68 
71 {
72  if ( m_data->pos != pos )
73  {
74  m_data->pos = pos;
75  itemChanged();
76  }
77 }
78 
89 void QwtPolarMarker::draw( QPainter* painter,
90  const QwtScaleMap& azimuthMap, const QwtScaleMap& radialMap,
91  const QPointF& pole, double radius,
92  const QRectF& canvasRect ) const
93 {
94  Q_UNUSED( radius );
95  Q_UNUSED( canvasRect );
96 
97  const double r = radialMap.transform( m_data->pos.radius() );
98  const double a = azimuthMap.transform( m_data->pos.azimuth() );
99 
100  const QPointF pos = qwtPolar2Pos( pole, r, a );
101 
102 
103  // draw symbol
104  QSize sSym( 0, 0 );
105  if ( m_data->symbol->style() != QwtSymbol::NoSymbol )
106  {
107  sSym = m_data->symbol->size();
108  m_data->symbol->drawSymbol( painter, pos );
109  }
110 
111  // draw label
112  if ( !m_data->label.isEmpty() )
113  {
114  int xlw = qMax( int( m_data->pen.width() ), 1 );
115  int ylw = xlw;
116 
117  int xlw1 = qMax( ( xlw + 1 ) / 2, ( sSym.width() + 1 ) / 2 ) + LabelDist;
118  xlw = qMax( xlw / 2, ( sSym.width() + 1 ) / 2 ) + LabelDist;
119  int ylw1 = qMax( ( ylw + 1 ) / 2, ( sSym.height() + 1 ) / 2 ) + LabelDist;
120  ylw = qMax( ylw / 2, ( sSym.height() + 1 ) / 2 ) + LabelDist;
121 
122  QRect tr( QPoint( 0, 0 ), m_data->label.textSize( painter->font() ).toSize() );
123  tr.moveCenter( QPoint( 0, 0 ) );
124 
125  int dx = pos.x();
126  int dy = pos.y();
127 
128  if ( m_data->align & Qt::AlignTop )
129  dy += tr.y() - ylw1;
130  else if ( m_data->align & Qt::AlignBottom )
131  dy -= tr.y() - ylw1;
132 
133  if ( m_data->align & Qt::AlignLeft )
134  dx += tr.x() - xlw1;
135  else if ( m_data->align & Qt::AlignRight )
136  dx -= tr.x() - xlw1;
137 
138  tr.translate( dx, dy );
139  m_data->label.draw( painter, tr );
140  }
141 }
142 
149 {
150  if ( m_data->symbol != symbol )
151  {
152  delete m_data->symbol;
153  m_data->symbol = symbol;
154  itemChanged();
155  }
156 }
157 
163 {
164  return m_data->symbol;
165 }
166 
172 void QwtPolarMarker::setLabel( const QwtText& label )
173 {
174  if ( label != m_data->label )
175  {
176  m_data->label = label;
177  itemChanged();
178  }
179 }
180 
186 {
187  return m_data->label;
188 }
189 
202 {
203  if ( align == m_data->align )
204  return;
205 
206  m_data->align = align;
207  itemChanged();
208 }
209 
214 Qt::Alignment QwtPolarMarker::labelAlignment() const
215 {
216  return m_data->align;
217 }
218 
229 {
230  const double v = ( scaleId == QwtPolar::ScaleRadius )
231  ? m_data->pos.radius() : m_data->pos.azimuth();
232 
233  return QwtInterval( v, v );
234 }
QwtSymbol::size
const QSize & size() const
Definition: qwt_symbol.cpp:1094
QwtPolarItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition: qwt_polar_item.cpp:201
QwtPolarItem::AutoScale
@ AutoScale
Definition: qwt_polar_item.h:83
align
Definition: core.h:2016
QwtPolarMarker::setSymbol
void setSymbol(const QwtSymbol *s)
Assign a symbol.
Definition: qwt_polar_marker.cpp:148
QwtPolarMarker::label
QwtText label() const
Definition: qwt_polar_marker.cpp:185
QwtPolarMarker::PrivateData::~PrivateData
~PrivateData()
Definition: qwt_polar_marker.cpp:28
QwtPolarMarker::~QwtPolarMarker
virtual ~QwtPolarMarker()
Destructor.
Definition: qwt_polar_marker.cpp:52
QwtPolarMarker::PrivateData::align
Qt::Alignment align
Definition: qwt_polar_marker.cpp:34
qwt_polar.h
QwtPolarMarker::PrivateData::symbol
const QwtSymbol * symbol
Definition: qwt_polar_marker.cpp:36
qwtPolar2Pos
QPoint qwtPolar2Pos(const QPoint &pole, double radius, double angle)
Definition: qwt_point_polar.h:137
QwtPolarMarker::PrivateData
Definition: qwt_polar_marker.cpp:19
qwt_symbol.h
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:28
QwtPolarMarker::boundingInterval
virtual QwtInterval boundingInterval(int scaleId) const QWT_OVERRIDE
Definition: qwt_polar_marker.cpp:228
QwtPolarItem::setZ
void setZ(double z)
Set the z value.
Definition: qwt_polar_item.cpp:142
QwtSymbol::NoSymbol
@ NoSymbol
No Style. The symbol cannot be drawn.
Definition: qwt_symbol.h:41
QwtPolarMarker::QwtPolarMarker
QwtPolarMarker()
Sets alignment to Qt::AlignCenter, and style to NoLine.
Definition: qwt_polar_marker.cpp:42
QwtText::textSize
QSizeF textSize() const
Definition: qwt_text.cpp:570
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:22
QwtPolarMarker::symbol
const QwtSymbol * symbol() const
Definition: qwt_polar_marker.cpp:162
qwt_scale_map.h
QwtText
A class representing a text.
Definition: qwt_text.h:51
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition: qwt_point_polar.h:108
QwtSymbol
A class for drawing symbols.
Definition: qwt_symbol.h:31
QwtPolarItem::itemChanged
virtual void itemChanged()
Definition: qwt_polar_item.cpp:355
qwt_polar_marker.h
QwtSymbol::drawSymbol
void drawSymbol(QPainter *, const QRectF &) const
Draw the symbol into a rectangle.
Definition: qwt_symbol.cpp:1434
LabelDist
static const int LabelDist
Definition: qwt_polar_marker.cpp:17
QwtPolarItem
Base class for items on a polar plot.
Definition: qwt_polar_item.h:37
QwtPolarMarker::PrivateData::pos
QwtPointPolar pos
Definition: qwt_polar_marker.cpp:38
QwtPolarItem::Rtti_PolarMarker
@ Rtti_PolarMarker
For QwtPolarMarker.
Definition: qwt_polar_item.h:55
QwtPolarMarker::setLabelAlignment
void setLabelAlignment(Qt::Alignment)
Set the alignment of the label.
Definition: qwt_polar_marker.cpp:201
QwtPolarMarker::labelAlignment
Qt::Alignment labelAlignment() const
Definition: qwt_polar_marker.cpp:214
QwtScaleMap::transform
double transform(double s) const
Definition: qwt_scale_map.h:137
QwtPolarMarker::position
QwtPointPolar position() const
Definition: qwt_polar_marker.cpp:64
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
QwtPolarMarker::draw
virtual void draw(QPainter *painter, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, double radius, const QRectF &canvasRect) const QWT_OVERRIDE
Definition: qwt_polar_marker.cpp:89
QwtPolarMarker::setPosition
void setPosition(const QwtPointPolar &)
Change the position of the marker.
Definition: qwt_polar_marker.cpp:70
QwtPolarMarker::rtti
virtual int rtti() const QWT_OVERRIDE
Definition: qwt_polar_marker.cpp:58
sol::detail::align
constexpr std::uintptr_t align(std::size_t alignment, std::uintptr_t ptr, std::size_t &space)
Definition: sol.hpp:10963
QwtPolar::ScaleRadius
@ ScaleRadius
Radial scale.
Definition: qwt_polar.h:83
QwtPolarMarker::setLabel
void setLabel(const QwtText &)
Set the label.
Definition: qwt_polar_marker.cpp:172
QwtText::isEmpty
bool isEmpty() const
Definition: qwt_text.cpp:739
QwtPolarMarker::PrivateData::PrivateData
PrivateData()
Definition: qwt_polar_marker.cpp:22
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition: qwt_point_polar.h:102
QwtText::draw
void draw(QPainter *painter, const QRectF &rect) const
Definition: qwt_text.cpp:615
QwtSymbol::style
Style style() const
Definition: qwt_symbol.cpp:1795
QwtPolarMarker::PrivateData::pen
QPen pen
Definition: qwt_polar_marker.cpp:35
qwt_text.h
QwtPolarMarker::m_data
PrivateData * m_data
Definition: qwt_polar_marker.h:64
QwtPolarMarker::PrivateData::label
QwtText label
Definition: qwt_polar_marker.cpp:33


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46