10 #include "qwt_interval_symbol.h"
11 #include "qwt_painter.h"
17 class QwtIntervalSymbol::PrivateData
26 bool operator==(
const PrivateData& other )
const
28 return (
style == other.style )
29 && (
width == other.width )
30 && (
brush == other.brush )
31 && (
pen == other.pen );
49 m_data =
new PrivateData();
50 m_data->style =
style;
56 m_data =
new PrivateData();
57 *m_data = *other.m_data;
70 *m_data = *other.m_data;
78 return *m_data == *other.m_data;
85 return !( *m_data == *other.m_data );
96 m_data->style =
style;
105 return m_data->style;
117 m_data->width =
width;
126 return m_data->width;
139 m_data->brush =
brush;
148 return m_data->brush;
165 qreal width, Qt::PenStyle style )
201 const QPointF& from,
const QPointF& to )
const
213 switch ( m_data->style )
218 if ( m_data->width > pw )
220 if ( ( orientation == Qt::Horizontal )
221 && ( p1.y() == p2.y() ) )
223 const double sw = m_data->width;
225 const double y = p1.y() - sw / 2;
227 p1.x(), y, p1.x(), y + sw );
229 p2.x(), y, p2.x(), y + sw );
231 else if ( ( orientation == Qt::Vertical )
232 && ( p1.x() == p2.x() ) )
234 const double sw = m_data->width;
236 const double x = p1.x() - sw / 2;
238 x, p1.y(), x + sw, p1.y() );
240 x, p2.y(), x + sw, p2.y() );
244 const double sw = m_data->width;
246 const double dx = p2.x() - p1.x();
247 const double dy = p2.y() - p1.y();
248 const double angle = std::atan2( dy, dx ) + M_PI_2;
249 double dw2 = sw / 2.0;
251 const double cx = qFastCos( angle ) * dw2;
252 const double sy = qFastSin( angle ) * dw2;
255 p1.x() - cx, p1.y() - sy,
256 p1.x() + cx, p1.y() + sy );
258 p2.x() - cx, p2.y() - sy,
259 p2.x() + cx, p2.y() + sy );
266 if ( m_data->width <= pw )
272 if ( ( orientation == Qt::Horizontal )
273 && ( p1.y() == p2.y() ) )
275 const double sw = m_data->width;
277 const double y = p1.y() - m_data->width / 2;
279 p1.x(), y, p2.x() - p1.x(), sw );
281 else if ( ( orientation == Qt::Vertical )
282 && ( p1.x() == p2.x() ) )
284 const double sw = m_data->width;
286 const double x = p1.x() - m_data->width / 2;
288 x, p1.y(), sw, p2.y() - p1.y() );
292 const double sw = m_data->width;
294 const double dx = p2.x() - p1.x();
295 const double dy = p2.y() - p1.y();
296 const double angle = std::atan2( dy, dx ) + M_PI_2;
297 double dw2 = sw / 2.0;
299 const double cx = qFastCos( angle ) * dw2;
300 const double sy = qFastSin( angle ) * dw2;
303 polygon += QPointF( p1.x() - cx, p1.y() - sy );
304 polygon += QPointF( p1.x() + cx, p1.y() + sy );
305 polygon += QPointF( p2.x() + cx, p2.y() + sy );
306 polygon += QPointF( p2.x() - cx, p2.y() - sy );
A drawing primitive for displaying an interval like an error bar.
virtual void draw(QPainter *, Qt::Orientation, const QPointF &from, const QPointF &to) const
void setBrush(const QBrush &)
Assign a brush.
QwtIntervalSymbol(Style=NoSymbol)
QwtIntervalSymbol & operator=(const QwtIntervalSymbol &)
Assignment operator.
bool operator==(const QwtIntervalSymbol &) const
Compare two symbols.
@ NoSymbol
No Style. The symbol cannot be drawn.
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
bool operator!=(const QwtIntervalSymbol &) const
Compare two symbols.
const QBrush & brush() const
virtual ~QwtIntervalSymbol()
Destructor.
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
static qreal effectivePenWidth(const QPen &)
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
static bool roundingAlignment()
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()