qwt_plot_zoneitem.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_plot_zoneitem.h"
11 #include "qwt_painter.h"
12 #include "qwt_scale_map.h"
13 #include "qwt_text.h"
14 #include "qwt_interval.h"
15 
16 #include <qpainter.h>
17 
19 {
20 public:
22  orientation( Qt::Vertical ),
23  pen( Qt::NoPen )
24  {
25  QColor c( Qt::darkGray );
26  c.setAlpha( 100 );
27  brush = QBrush( c );
28  }
29 
30  Qt::Orientation orientation;
31  QPen pen;
32  QBrush brush;
34 };
35 
51  QwtPlotItem( QwtText( "Zone" ) )
52 {
53  d_data = new PrivateData;
54 
57 
58  setZ( 5 );
59 }
60 
63 {
64  delete d_data;
65 }
66 
69 {
71 }
72 
86 void QwtPlotZoneItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )
87 {
88  setPen( QPen( color, width, style ) );
89 }
90 
99 void QwtPlotZoneItem::setPen( const QPen &pen )
100 {
101  if ( d_data->pen != pen )
102  {
103  d_data->pen = pen;
104  itemChanged();
105  }
106 }
107 
112 const QPen &QwtPlotZoneItem::pen() const
113 {
114  return d_data->pen;
115 }
116 
125 void QwtPlotZoneItem::setBrush( const QBrush &brush )
126 {
127  if ( d_data->brush != brush )
128  {
129  d_data->brush = brush;
130  itemChanged();
131  }
132 }
133 
138 const QBrush &QwtPlotZoneItem::brush() const
139 {
140  return d_data->brush;
141 }
142 
153 {
154  if ( d_data->orientation != orientation )
155  {
157  itemChanged();
158  }
159 }
160 
165 Qt::Orientation QwtPlotZoneItem::orientation() const
166 {
167  return d_data->orientation;
168 }
169 
181 void QwtPlotZoneItem::setInterval( double min, double max )
182 {
183  setInterval( QwtInterval( min, max ) );
184 }
185 
197 {
198  if ( d_data->interval != interval )
199  {
201  itemChanged();
202  }
203 }
204 
210 {
211  return d_data->interval;
212 }
213 
223 void QwtPlotZoneItem::draw( QPainter *painter,
224  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
225  const QRectF &canvasRect ) const
226 {
227  if ( !d_data->interval.isValid() )
228  return;
229 
230  QPen pen = d_data->pen;
231  pen.setCapStyle( Qt::FlatCap );
232 
233  const bool doAlign = QwtPainter::roundingAlignment( painter );
234 
235  if ( d_data->orientation == Qt::Horizontal )
236  {
237  double y1 = yMap.transform( d_data->interval.minValue() );
238  double y2 = yMap.transform( d_data->interval.maxValue() );
239 
240  if ( doAlign )
241  {
242  y1 = qRound( y1 );
243  y2 = qRound( y2 );
244  }
245 
246  QRectF r( canvasRect.left(), y1, canvasRect.width(), y2 - y1 );
247  r = r.normalized();
248 
249  if ( ( d_data->brush.style() != Qt::NoBrush ) && ( y1 != y2 ) )
250  {
251  QwtPainter::fillRect( painter, r, d_data->brush );
252  }
253 
254  if ( d_data->pen.style() != Qt::NoPen )
255  {
256  painter->setPen( d_data->pen );
257 
258  QwtPainter::drawLine( painter, r.left(), r.top(), r.right(), r.top() );
259  QwtPainter::drawLine( painter, r.left(), r.bottom(), r.right(), r.bottom() );
260  }
261  }
262  else
263  {
264  double x1 = xMap.transform( d_data->interval.minValue() );
265  double x2 = xMap.transform( d_data->interval.maxValue() );
266 
267  if ( doAlign )
268  {
269  x1 = qRound( x1 );
270  x2 = qRound( x2 );
271  }
272 
273  QRectF r( x1, canvasRect.top(), x2 - x1, canvasRect.height() );
274  r = r.normalized();
275 
276  if ( ( d_data->brush.style() != Qt::NoBrush ) && ( x1 != x2 ) )
277  {
278  QwtPainter::fillRect( painter, r, d_data->brush );
279  }
280 
281  if ( d_data->pen.style() != Qt::NoPen )
282  {
283  painter->setPen( d_data->pen );
284 
285  QwtPainter::drawLine( painter, r.left(), r.top(), r.left(), r.bottom() );
286  QwtPainter::drawLine( painter, r.right(), r.top(), r.right(), r.bottom() );
287  }
288  }
289 }
290 
298 {
299  QRectF br = QwtPlotItem::boundingRect();
300 
301  const QwtInterval &intv = d_data->interval;
302 
303  if ( intv.isValid() )
304  {
305  if ( d_data->orientation == Qt::Horizontal )
306  {
307  br.setTop( intv.minValue() );
308  br.setBottom( intv.maxValue() );
309  }
310  else
311  {
312  br.setLeft( intv.minValue() );
313  br.setRight( intv.maxValue() );
314  }
315  }
316 
317  return br;
318 }
static void fillRect(QPainter *, const QRectF &, const QBrush &)
Wrapper for QPainter::fillRect()
PrivateData * d_data
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
Definition: qwt_painter.h:152
A class representing an interval.
Definition: qwt_interval.h:22
double minValue() const
Definition: qwt_interval.h:190
Qt::Orientation orientation() const
QwtPlotZoneItem()
Constructor.
double maxValue() const
Definition: qwt_interval.h:196
The item is represented on the legend.
void setBrush(const QBrush &)
Assign a brush.
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
#define min(A, B)
Definition: Log.c:64
#define max(A, B)
Definition: Socket.h:88
const QPen & pen() const
bool isValid() const
Definition: qwt_interval.h:208
void setOrientation(Qt::Orientation)
Set the orientation of the zone.
A class representing a text.
Definition: qwt_text.h:51
void setZ(double z)
Set the z value.
For QwtPlotZoneItem.
virtual ~QwtPlotZoneItem()
Destructor.
virtual void draw(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &canvasRect) const QWT_OVERRIDE
A scale map.
Definition: qwt_scale_map.h:26
virtual void itemChanged()
const QBrush & brush() const
void setInterval(double min, double max)
MQTTClient c
Definition: test10.c:1656
virtual int rtti() const QWT_OVERRIDE
QwtInterval interval() const
virtual QRectF boundingRect() const QWT_OVERRIDE
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:65
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
static bool roundingAlignment()
Definition: qwt_painter.h:181
virtual QRectF boundingRect() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10