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 <qpainter.h>
14 
16 {
17 public:
19  orientation( Qt::Vertical ),
20  pen( Qt::NoPen )
21  {
22  QColor c( Qt::darkGray );
23  c.setAlpha( 100 );
24  brush = QBrush( c );
25  }
26 
27  Qt::Orientation orientation;
28  QPen pen;
29  QBrush brush;
31 };
32 
48  QwtPlotItem( QwtText( "Zone" ) )
49 {
50  d_data = new PrivateData;
51 
54 
55  setZ( 5 );
56 }
57 
60 {
61  delete d_data;
62 }
63 
66 {
68 }
69 
83 void QwtPlotZoneItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )
84 {
85  setPen( QPen( color, width, style ) );
86 }
87 
96 void QwtPlotZoneItem::setPen( const QPen &pen )
97 {
98  if ( d_data->pen != pen )
99  {
100  d_data->pen = pen;
101  itemChanged();
102  }
103 }
104 
109 const QPen &QwtPlotZoneItem::pen() const
110 {
111  return d_data->pen;
112 }
113 
122 void QwtPlotZoneItem::setBrush( const QBrush &brush )
123 {
124  if ( d_data->brush != brush )
125  {
126  d_data->brush = brush;
127  itemChanged();
128  }
129 }
130 
135 const QBrush &QwtPlotZoneItem::brush() const
136 {
137  return d_data->brush;
138 }
139 
150 {
151  if ( d_data->orientation != orientation )
152  {
154  itemChanged();
155  }
156 }
157 
162 Qt::Orientation QwtPlotZoneItem::orientation() const
163 {
164  return d_data->orientation;
165 }
166 
178 void QwtPlotZoneItem::setInterval( double min, double max )
179 {
180  setInterval( QwtInterval( min, max ) );
181 }
182 
194 {
195  if ( d_data->interval != interval )
196  {
198  itemChanged();
199  }
200 }
201 
207 {
208  return d_data->interval;
209 }
210 
220 void QwtPlotZoneItem::draw( QPainter *painter,
221  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
222  const QRectF &canvasRect ) const
223 {
224  if ( !d_data->interval.isValid() )
225  return;
226 
227  QPen pen = d_data->pen;
228  pen.setCapStyle( Qt::FlatCap );
229 
230  const bool doAlign = QwtPainter::roundingAlignment( painter );
231 
232  if ( d_data->orientation == Qt::Horizontal )
233  {
234  double y1 = yMap.transform( d_data->interval.minValue() );
235  double y2 = yMap.transform( d_data->interval.maxValue() );
236 
237  if ( doAlign )
238  {
239  y1 = qRound( y1 );
240  y2 = qRound( y2 );
241  }
242 
243  QRectF r( canvasRect.left(), y1, canvasRect.width(), y2 - y1 );
244  r = r.normalized();
245 
246  if ( ( d_data->brush.style() != Qt::NoBrush ) && ( y1 != y2 ) )
247  {
248  QwtPainter::fillRect( painter, r, d_data->brush );
249  }
250 
251  if ( d_data->pen.style() != Qt::NoPen )
252  {
253  painter->setPen( d_data->pen );
254 
255  QwtPainter::drawLine( painter, r.left(), r.top(), r.right(), r.top() );
256  QwtPainter::drawLine( painter, r.left(), r.bottom(), r.right(), r.bottom() );
257  }
258  }
259  else
260  {
261  double x1 = xMap.transform( d_data->interval.minValue() );
262  double x2 = xMap.transform( d_data->interval.maxValue() );
263 
264  if ( doAlign )
265  {
266  x1 = qRound( x1 );
267  x2 = qRound( x2 );
268  }
269 
270  QRectF r( x1, canvasRect.top(), x2 - x1, canvasRect.height() );
271  r = r.normalized();
272 
273  if ( ( d_data->brush.style() != Qt::NoBrush ) && ( x1 != x2 ) )
274  {
275  QwtPainter::fillRect( painter, r, d_data->brush );
276  }
277 
278  if ( d_data->pen.style() != Qt::NoPen )
279  {
280  painter->setPen( d_data->pen );
281 
282  QwtPainter::drawLine( painter, r.left(), r.top(), r.left(), r.bottom() );
283  QwtPainter::drawLine( painter, r.right(), r.top(), r.right(), r.bottom() );
284  }
285  }
286 }
287 
295 {
296  QRectF br = QwtPlotItem::boundingRect();
297 
298  const QwtInterval &intv = d_data->interval;
299 
300  if ( intv.isValid() )
301  {
302  if ( d_data->orientation == Qt::Horizontal )
303  {
304  br.setTop( intv.minValue() );
305  br.setBottom( intv.maxValue() );
306  }
307  else
308  {
309  br.setLeft( intv.minValue() );
310  br.setRight( intv.maxValue() );
311  }
312  }
313 
314  return br;
315 }
virtual void draw(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &) const
static void drawLine(QPainter *, double x1, double y1, double x2, double y2)
Wrapper for QPainter::drawLine()
Definition: qwt_painter.h:147
static void fillRect(QPainter *, const QRectF &, const QBrush &)
Wrapper for QPainter::fillRect()
PrivateData * d_data
A class representing an interval.
Definition: qwt_interval.h:26
double minValue() const
Definition: qwt_interval.h:193
Qt::Orientation orientation() const
QwtPlotZoneItem()
Constructor.
double maxValue() const
Definition: qwt_interval.h:199
The item is represented on the legend.
virtual QRectF boundingRect() const
void setBrush(const QBrush &)
Assign a brush.
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
const QPen & pen() const
bool isValid() const
Definition: qwt_interval.h:211
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.
A scale map.
Definition: qwt_scale_map.h:30
virtual void itemChanged()
const QBrush & brush() const
void setInterval(double min, double max)
virtual int rtti() const
QwtInterval interval() const
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:64
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
static bool roundingAlignment()
Definition: qwt_painter.h:176
virtual QRectF boundingRect() const


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