qwt_compass.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_compass.h"
11 #include "qwt_compass_rose.h"
12 #include "qwt_text.h"
13 
14 #include <qevent.h>
15 #include <qmap.h>
16 
18 {
19 public:
21 };
22 
29 {
30  d_data = new PrivateData;
31 
34 
36 
37  map.insert( 0.0, QString::fromLatin1( "N" ) );
38  map.insert( 45.0, QString::fromLatin1( "NE" ) );
39  map.insert( 90.0, QString::fromLatin1( "E" ) );
40  map.insert( 135.0, QString::fromLatin1( "SE" ) );
41  map.insert( 180.0, QString::fromLatin1( "S" ) );
42  map.insert( 225.0, QString::fromLatin1( "SW" ) );
43  map.insert( 270.0, QString::fromLatin1( "W" ) );
44  map.insert( 315.0, QString::fromLatin1( "NW" ) );
45 
46 #if 0
47  map.insert( 22.5, QString::fromLatin1( "NNE" ) );
48  map.insert( 67.5, QString::fromLatin1( "NEE" ) );
49  map.insert( 112.5, QString::fromLatin1( "SEE" ) );
50  map.insert( 157.5, QString::fromLatin1( "SSE" ) );
51  map.insert( 202.5, QString::fromLatin1( "SSW" ) );
52  map.insert( 247.5, QString::fromLatin1( "SWW" ) );
53  map.insert( 292.5, QString::fromLatin1( "NWW" ) );
54  map.insert( 337.5, QString::fromLatin1( "NNW" ) );
55 #endif
56 }
57 
64 {
65  d_data = new PrivateData;
66  d_data->labelMap = map;
67 
70 }
71 
74 {
75  delete d_data;
76 }
77 
91 {
92  d_data->labelMap = map;
93 }
94 
100 {
101  return d_data->labelMap;
102 }
103 
117 {
118  if ( qFuzzyCompare( value + 1.0, 1.0 ) )
119  value = 0.0;
120 
121  if ( value < 0.0 )
122  value += 360.0;
123 
125  d_data->labelMap.constFind( value );
126 
127  if ( it != d_data->labelMap.constEnd() )
128  return *it;
129 
130  return QwtText();
131 }
132 
134 {
135 public:
137  rose( NULL )
138  {
139  }
140 
142  {
143  delete rose;
144  }
145 
147 };
148 
158 QwtCompass::QwtCompass( QWidget* parent ):
159  QwtDial( parent )
160 {
161  d_data = new PrivateData;
162 
164 
165  setOrigin( 270.0 );
166  setWrapping( true );
167 
168  setScaleMaxMajor( 36 );
169  setScaleMaxMinor( 10 );
170 
171  setScale( 0.0, 360.0 ); // degrees as default
172  setTotalSteps( 360 );
173 }
174 
177 {
178  delete d_data;
179 }
180 
181 
189 void QwtCompass::drawScaleContents( QPainter *painter,
190  const QPointF &center, double radius ) const
191 {
192  QPalette::ColorGroup cg;
193  if ( isEnabled() )
194  cg = hasFocus() ? QPalette::Active : QPalette::Inactive;
195  else
196  cg = QPalette::Disabled;
197 
198  double north = origin();
199  if ( isValid() )
200  {
201  if ( mode() == RotateScale )
202  north -= value();
203  }
204 
205  const int margin = 4;
206  drawRose( painter, center, radius - margin, 360.0 - north, cg );
207 }
208 
218 void QwtCompass::drawRose( QPainter *painter, const QPointF &center,
219  double radius, double north, QPalette::ColorGroup cg ) const
220 {
221  if ( d_data->rose )
222  d_data->rose->draw( painter, center, radius, north, cg );
223 }
224 
233 {
234  if ( rose != d_data->rose )
235  {
236  if ( d_data->rose )
237  delete d_data->rose;
238 
239  d_data->rose = rose;
240  update();
241  }
242 }
243 
249 {
250  return d_data->rose;
251 }
252 
258 {
259  return d_data->rose;
260 }
261 
271 void QwtCompass::keyPressEvent( QKeyEvent *kev )
272 {
273  if ( isReadOnly() )
274  return;
275 
276 #if 0
277  if ( kev->key() == Key_5 )
278  {
279  invalidate(); // signal ???
280  return;
281  }
282 #endif
283 
284  double newValue = value();
285 
286  if ( kev->key() >= Qt::Key_1 && kev->key() <= Qt::Key_9 )
287  {
288  if ( mode() != RotateNeedle || kev->key() == Qt::Key_5 )
289  return;
290 
291  switch ( kev->key() )
292  {
293  case Qt::Key_6:
294  newValue = 180.0 * 0.0;
295  break;
296  case Qt::Key_3:
297  newValue = 180.0 * 0.25;
298  break;
299  case Qt::Key_2:
300  newValue = 180.0 * 0.5;
301  break;
302  case Qt::Key_1:
303  newValue = 180.0 * 0.75;
304  break;
305  case Qt::Key_4:
306  newValue = 180.0 * 1.0;
307  break;
308  case Qt::Key_7:
309  newValue = 180.0 * 1.25;
310  break;
311  case Qt::Key_8:
312  newValue = 180.0 * 1.5;
313  break;
314  case Qt::Key_9:
315  newValue = 180.0 * 1.75;
316  break;
317  }
318  newValue -= origin();
319  setValue( newValue );
320  }
321  else
322  {
323  QwtDial::keyPressEvent( kev );
324  }
325 }
326 
327 #if QWT_MOC_INCLUDE
328 #include "moc_qwt_compass.cpp"
329 #endif
void setScale(double lowerBound, double upperBound)
Specify a scale.
virtual ~QwtCompass()
Destructor.
enum MQTTPropertyCodes value
The needle is fixed, the scales are rotating.
Definition: qwt_dial.h:92
The needle is rotating.
Definition: qwt_dial.h:89
PrivateData * d_data
Definition: qwt_compass.h:46
QwtCompass(QWidget *parent=NULL)
Constructor.
void setRose(QwtCompassRose *rose)
virtual void draw(QPainter *painter, const QPointF &center, double radius, double north, QPalette::ColorGroup colorGroup=QPalette::Active) const =0
virtual void keyPressEvent(QKeyEvent *) QWT_OVERRIDE
void setValue(double value)
virtual void setOrigin(double)
Change the origin.
Definition: qwt_dial.cpp:660
virtual QwtText label(double value) const QWT_OVERRIDE
void setScaleMaxMajor(int ticks)
Set the maximum number of major tick intervals.
QwtDial class provides a rounded range control.
Definition: qwt_dial.h:50
double value() const
virtual void drawRose(QPainter *, const QPointF &center, double radius, double north, QPalette::ColorGroup) const
double origin() const
QwtCompassRose * rose
void setTotalSteps(uint)
Set the number of steps.
virtual ~QwtCompassScaleDraw()
Destructor.
Definition: qwt_compass.cpp:73
A class representing a text.
Definition: qwt_text.h:51
Abstract base class for a compass rose.
const QwtCompassRose * rose() const
Backbone = the line where the ticks are located.
void setScaleMaxMinor(int ticks)
Set the maximum number of minor tick intervals.
A special scale draw made for QwtCompass.
Definition: qwt_compass.h:32
void enableComponent(ScaleComponent, bool enable=true)
virtual void drawScaleContents(QPainter *, const QPointF &center, double radius) const QWT_OVERRIDE
QwtCompassScaleDraw()
Constructor.
Definition: qwt_compass.cpp:28
void setScaleDraw(QwtRoundScaleDraw *)
Definition: qwt_dial.cpp:574
Mode mode() const
PrivateData * d_data
Definition: qwt_compass.h:83
void setLabelMap(const QMap< double, QString > &map)
Set a map, mapping values to labels.
Definition: qwt_compass.cpp:90
QMap< double, QString > labelMap() const
Definition: qwt_compass.cpp:99
virtual void keyPressEvent(QKeyEvent *) QWT_OVERRIDE
QMap< double, QString > labelMap
Definition: qwt_compass.cpp:20


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