qwt_interval_symbol.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_interval_symbol.h"
11 #include "qwt_painter.h"
12 #include "qwt_math.h"
13 #include <qpainter.h>
14 
15 #if QT_VERSION < 0x040601
16 #define qAtan2(y, x) ::atan2(y, x)
17 #define qFastSin(x) qSin(x)
18 #define qFastCos(x) qCos(x)
19 #endif
20 
22 {
23 public:
26  width( 6 )
27  {
28  }
29 
30  bool operator==( const PrivateData &other ) const
31  {
32  return ( style == other.style )
33  && ( width == other.width )
34  && ( brush == other.brush )
35  && ( pen == other.pen );
36  }
37 
39  int width;
40 
41  QPen pen;
42  QBrush brush;
43 };
44 
52 {
53  d_data = new PrivateData();
54  d_data->style = style;
55 }
56 
59 {
60  d_data = new PrivateData();
61  *d_data = *other.d_data;
62 }
63 
66 {
67  delete d_data;
68 }
69 
72  const QwtIntervalSymbol &other )
73 {
74  *d_data = *other.d_data;
75  return *this;
76 }
77 
80  const QwtIntervalSymbol &other ) const
81 {
82  return *d_data == *other.d_data;
83 }
84 
87  const QwtIntervalSymbol &other ) const
88 {
89  return !( *d_data == *other.d_data );
90 }
91 
99 {
100  d_data->style = style;
101 }
102 
108 {
109  return d_data->style;
110 }
111 
120 {
121  d_data->width = width;
122 }
123 
129 {
130  return d_data->width;
131 }
132 
141 void QwtIntervalSymbol::setBrush( const QBrush &brush )
142 {
143  d_data->brush = brush;
144 }
145 
150 const QBrush& QwtIntervalSymbol::brush() const
151 {
152  return d_data->brush;
153 }
154 
168 void QwtIntervalSymbol::setPen( const QColor &color,
169  qreal width, Qt::PenStyle style )
170 {
171  setPen( QPen( color, width, style ) );
172 }
173 
180 void QwtIntervalSymbol::setPen( const QPen &pen )
181 {
182  d_data->pen = pen;
183 }
184 
189 const QPen& QwtIntervalSymbol::pen() const
190 {
191  return d_data->pen;
192 }
193 
204 void QwtIntervalSymbol::draw( QPainter *painter, Qt::Orientation orientation,
205  const QPointF &from, const QPointF &to ) const
206 {
207  const qreal pw = qMax( painter->pen().widthF(), qreal( 1.0 ) );
208 
209  QPointF p1 = from;
210  QPointF p2 = to;
211  if ( QwtPainter::roundingAlignment( painter ) )
212  {
213  p1 = p1.toPoint();
214  p2 = p2.toPoint();
215  }
216 
217  switch ( d_data->style )
218  {
220  {
221  QwtPainter::drawLine( painter, p1, p2 );
222  if ( d_data->width > pw )
223  {
224  if ( ( orientation == Qt::Horizontal )
225  && ( p1.y() == p2.y() ) )
226  {
227  const double sw = d_data->width;
228 
229  const double y = p1.y() - sw / 2;
230  QwtPainter::drawLine( painter,
231  p1.x(), y, p1.x(), y + sw );
232  QwtPainter::drawLine( painter,
233  p2.x(), y, p2.x(), y + sw );
234  }
235  else if ( ( orientation == Qt::Vertical )
236  && ( p1.x() == p2.x() ) )
237  {
238  const double sw = d_data->width;
239 
240  const double x = p1.x() - sw / 2;
241  QwtPainter::drawLine( painter,
242  x, p1.y(), x + sw, p1.y() );
243  QwtPainter::drawLine( painter,
244  x, p2.y(), x + sw, p2.y() );
245  }
246  else
247  {
248  const double sw = d_data->width;
249 
250  const double dx = p2.x() - p1.x();
251  const double dy = p2.y() - p1.y();
252  const double angle = qAtan2( dy, dx ) + M_PI_2;
253  double dw2 = sw / 2.0;
254 
255  const double cx = qFastCos( angle ) * dw2;
256  const double sy = qFastSin( angle ) * dw2;
257 
258  QwtPainter::drawLine( painter,
259  p1.x() - cx, p1.y() - sy,
260  p1.x() + cx, p1.y() + sy );
261  QwtPainter::drawLine( painter,
262  p2.x() - cx, p2.y() - sy,
263  p2.x() + cx, p2.y() + sy );
264  }
265  }
266  break;
267  }
269  {
270  if ( d_data->width <= pw )
271  {
272  QwtPainter::drawLine( painter, p1, p2 );
273  }
274  else
275  {
276  if ( ( orientation == Qt::Horizontal )
277  && ( p1.y() == p2.y() ) )
278  {
279  const double sw = d_data->width;
280 
281  const double y = p1.y() - d_data->width / 2;
282  QwtPainter::drawRect( painter,
283  p1.x(), y, p2.x() - p1.x(), sw );
284  }
285  else if ( ( orientation == Qt::Vertical )
286  && ( p1.x() == p2.x() ) )
287  {
288  const double sw = d_data->width;
289 
290  const double x = p1.x() - d_data->width / 2;
291  QwtPainter::drawRect( painter,
292  x, p1.y(), sw, p2.y() - p1.y() );
293  }
294  else
295  {
296  const double sw = d_data->width;
297 
298  const double dx = p2.x() - p1.x();
299  const double dy = p2.y() - p1.y();
300  const double angle = qAtan2( dy, dx ) + M_PI_2;
301  double dw2 = sw / 2.0;
302 
303  const double cx = qFastCos( angle ) * dw2;
304  const double sy = qFastSin( angle ) * dw2;
305 
306  QPolygonF polygon;
307  polygon += QPointF( p1.x() - cx, p1.y() - sy );
308  polygon += QPointF( p1.x() + cx, p1.y() + sy );
309  polygon += QPointF( p2.x() + cx, p2.y() + sy );
310  polygon += QPointF( p2.x() - cx, p2.y() - sy );
311 
312  QwtPainter::drawPolygon( painter, polygon );
313  }
314  }
315  break;
316  }
317  default:;
318  }
319 }
static void drawLine(QPainter *, double x1, double y1, double x2, double y2)
Wrapper for QPainter::drawLine()
Definition: qwt_painter.h:147
#define qFastSin(x)
#define qAtan2(y, x)
#define M_PI_2
Definition: qwt_math.h:32
virtual ~QwtIntervalSymbol()
Destructor.
TFSIMD_FORCE_INLINE const tfScalar & y() const
QwtIntervalSymbol & operator=(const QwtIntervalSymbol &)
Assignment operator.
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
QwtIntervalSymbol::Style style
bool operator!=(const QwtIntervalSymbol &) const
Compare two symbols.
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
QwtIntervalSymbol(Style=NoSymbol)
const QBrush & brush() const
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
static void drawRect(QPainter *, double x, double y, double w, double h)
Wrapper for QPainter::drawRect()
A drawing primitive for displaying an interval like an error bar.
TFSIMD_FORCE_INLINE const tfScalar & x() const
void setBrush(const QBrush &b)
Assign a brush.
const QPen & pen() const
virtual void draw(QPainter *, Qt::Orientation, const QPointF &from, const QPointF &to) const
bool operator==(const PrivateData &other) const
No Style. The symbol cannot be drawn.
bool operator==(const QwtIntervalSymbol &) const
Compare two symbols.
static bool roundingAlignment()
Definition: qwt_painter.h:176
#define qFastCos(x)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17