qwt_compass.cpp
Go to the documentation of this file.
1 /******************************************************************************
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  m_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  m_data = new PrivateData;
66  m_data->labelMap = map;
67 
70 }
71 
74 {
75  delete m_data;
76 }
77 
91 {
92  m_data->labelMap = map;
93 }
94 
100 {
101  return m_data->labelMap;
102 }
103 
116 QwtText QwtCompassScaleDraw::label( double value ) const
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  m_data->labelMap.constFind( value );
126 
127  if ( it != m_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  m_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 m_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 ( m_data->rose )
222  m_data->rose->draw( painter, center, radius, north, cg );
223 }
224 
233 {
234  if ( rose != m_data->rose )
235  {
236  if ( m_data->rose )
237  delete m_data->rose;
238 
239  m_data->rose = rose;
240  update();
241  }
242 }
243 
249 {
250  return m_data->rose;
251 }
252 
258 {
259  return m_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
QwtDial::mode
Mode mode
Definition: qwt_dial.h:58
QwtCompass::rose
const QwtCompassRose * rose() const
Definition: qwt_compass.cpp:248
QwtCompassScaleDraw::setLabelMap
void setLabelMap(const QMap< double, QString > &map)
Set a map, mapping values to labels.
Definition: qwt_compass.cpp:90
QwtCompassScaleDraw::PrivateData::labelMap
QMap< double, QString > labelMap
Definition: qwt_compass.cpp:27
QwtCompass::PrivateData
Definition: qwt_compass.cpp:133
QwtAbstractSlider::setWrapping
void setWrapping(bool)
Definition: qwt_abstract_slider.cpp:599
QwtDial
QwtDial class provides a rounded range control.
Definition: qwt_dial.h:50
QwtCompassScaleDraw::~QwtCompassScaleDraw
virtual ~QwtCompassScaleDraw()
Destructor.
Definition: qwt_compass.cpp:73
QwtCompassRose::draw
virtual void draw(QPainter *painter, const QPointF &center, double radius, double north, QPalette::ColorGroup colorGroup=QPalette::Active) const =0
QwtCompass::PrivateData::~PrivateData
~PrivateData()
Definition: qwt_compass.cpp:141
QwtCompassScaleDraw::m_data
PrivateData * m_data
Definition: qwt_compass.h:46
QwtDial::RotateNeedle
@ RotateNeedle
The needle is rotating.
Definition: qwt_dial.h:89
QwtAbstractSlider::keyPressEvent
virtual void keyPressEvent(QKeyEvent *) QWT_OVERRIDE
Definition: qwt_abstract_slider.cpp:370
qwt_compass_rose.h
QwtAbstractScaleDraw::Ticks
@ Ticks
Ticks.
Definition: qwt_abstract_scale_draw.h:45
QwtAbstractSlider::setValue
void setValue(double value)
Definition: qwt_abstract_slider.cpp:570
QwtCompass::drawScaleContents
virtual void drawScaleContents(QPainter *, const QPointF &center, double radius) const QWT_OVERRIDE
Definition: qwt_compass.cpp:189
QwtCompassScaleDraw::PrivateData
Definition: qwt_compass.cpp:17
QMap< double, QString >
QwtCompass::PrivateData::rose
QwtCompassRose * rose
Definition: qwt_compass.cpp:146
QwtCompass::keyPressEvent
virtual void keyPressEvent(QKeyEvent *) QWT_OVERRIDE
Definition: qwt_compass.cpp:271
QwtCompass::PrivateData::PrivateData
PrivateData()
Definition: qwt_compass.cpp:136
QwtCompassScaleDraw::QwtCompassScaleDraw
QwtCompassScaleDraw()
Constructor.
Definition: qwt_compass.cpp:28
QwtAbstractScale::setScaleMaxMajor
void setScaleMaxMajor(int ticks)
Set the maximum number of major tick intervals.
Definition: qwt_abstract_scale.cpp:189
QwtAbstractScaleDraw::Backbone
@ Backbone
Backbone = the line where the ticks are located.
Definition: qwt_abstract_scale_draw.h:42
QwtCompassScaleDraw::labelMap
QMap< double, QString > labelMap() const
Definition: qwt_compass.cpp:99
QwtDial::setScaleDraw
void setScaleDraw(QwtRoundScaleDraw *)
Definition: qwt_dial.cpp:574
QwtCompass::drawRose
virtual void drawRose(QPainter *, const QPointF &center, double radius, double north, QPalette::ColorGroup) const
Definition: qwt_compass.cpp:218
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
QwtDial::setOrigin
virtual void setOrigin(double)
Change the origin.
Definition: qwt_dial.cpp:660
QwtAbstractScaleDraw::enableComponent
void enableComponent(ScaleComponent, bool enable=true)
Definition: qwt_abstract_scale_draw.cpp:79
QwtText
A class representing a text.
Definition: qwt_text.h:51
range_format::map
@ map
QwtDial::RotateScale
@ RotateScale
The needle is fixed, the scales are rotating.
Definition: qwt_dial.h:92
QwtCompass::~QwtCompass
virtual ~QwtCompass()
Destructor.
Definition: qwt_compass.cpp:176
QwtCompassScaleDraw::label
virtual QwtText label(double value) const QWT_OVERRIDE
Definition: qwt_compass.cpp:116
QwtCompass::QwtCompass
QwtCompass(QWidget *parent=NULL)
Constructor.
Definition: qwt_compass.cpp:158
QwtAbstractSlider::setTotalSteps
void setTotalSteps(uint)
Set the number of steps.
Definition: qwt_abstract_slider.cpp:474
QwtAbstractScale::setScaleMaxMinor
void setScaleMaxMinor(int ticks)
Set the maximum number of minor tick intervals.
Definition: qwt_abstract_scale.cpp:219
QwtAbstractSlider::isValid
bool isValid() const
Definition: qwt_abstract_slider.cpp:125
QwtAbstractSlider::value
double value
Returns the current value.
Definition: qwt_abstract_slider.h:43
QwtAbstractSlider::isReadOnly
bool isReadOnly() const
Definition: qwt_abstract_slider.cpp:159
QwtCompass::setRose
void setRose(QwtCompassRose *rose)
Definition: qwt_compass.cpp:232
qwt_compass.h
QwtAbstractScale::setScale
void setScale(double lowerBound, double upperBound)
Specify a scale.
Definition: qwt_abstract_scale.cpp:130
QwtCompass::m_data
PrivateData * m_data
Definition: qwt_compass.h:83
qwt_text.h
QwtCompassScaleDraw
A special scale draw made for QwtCompass.
Definition: qwt_compass.h:32
QwtDial::origin
double origin
Definition: qwt_dial.h:59
QwtCompassRose
Abstract base class for a compass rose.
Definition: qwt_compass_rose.h:21


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45