Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_compass.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_compass.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_compass.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_compass.h" 11 11 #include "qwt_compass_rose.h" 12 #include "qwt_math.h" 13 #include "qwt_scale_draw.h" 14 #include "qwt_painter.h" 15 #include "qwt_dial_needle.h" 16 #include <qpainter.h> 17 #include <qpixmap.h> 12 #include "qwt_text.h" 13 18 14 #include <qevent.h> 19 20 /*! 21 \brief Constructor 22 23 Initializes a label map for multiples of 45 degrees 15 #include <qmap.h> 16 17 class QwtCompassScaleDraw::PrivateData 18 { 19 public: 20 QMap< double, QString > labelMap; 21 }; 22 23 /*! 24 \brief Constructor 25 26 Initializes a label map for multiples of 45 degrees 24 27 */ 25 28 QwtCompassScaleDraw::QwtCompassScaleDraw() 26 29 { 30 m_data = new PrivateData; 31 27 32 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 28 33 enableComponent( QwtAbstractScaleDraw::Ticks, false ); 29 34 30 d_labelMap.insert( 0.0, QString::fromLatin1( "N" ) ); 31 d_labelMap.insert( 45.0, QString::fromLatin1( "NE" ) ); 32 d_labelMap.insert( 90.0, QString::fromLatin1( "E" ) ); 33 d_labelMap.insert( 135.0, QString::fromLatin1( "SE" ) ); 34 d_labelMap.insert( 180.0, QString::fromLatin1( "S" ) ); 35 d_labelMap.insert( 225.0, QString::fromLatin1( "SW" ) ); 36 d_labelMap.insert( 270.0, QString::fromLatin1( "W" ) ); 37 d_labelMap.insert( 315.0, QString::fromLatin1( "NW" ) ); 35 QMap< double, QString >& map = m_data->labelMap; 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" ) ); 38 45 39 46 #if 0 40 d_labelMap.insert( 22.5, QString::fromLatin1( "NNE" ) );41 d_labelMap.insert( 67.5, QString::fromLatin1( "NEE" ) );42 d_labelMap.insert( 112.5, QString::fromLatin1( "SEE" ) );43 d_labelMap.insert( 157.5, QString::fromLatin1( "SSE" ) );44 d_labelMap.insert( 202.5, QString::fromLatin1( "SSW" ) );45 d_labelMap.insert( 247.5, QString::fromLatin1( "SWW" ) );46 d_labelMap.insert( 292.5, QString::fromLatin1( "NWW" ) );47 d_labelMap.insert( 337.5, QString::fromLatin1( "NNW" ) );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" ) ); 48 55 #endif 49 56 } 50 57 51 58 /*! 52 \brief Constructor 53 54 \param map Value to label map 55 */ 56 QwtCompassScaleDraw::QwtCompassScaleDraw( const QMap<double, QString> &map ): 57 d_labelMap( map ) 58 { 59 \brief Constructor 60 61 \param map Value to label map 62 */ 63 QwtCompassScaleDraw::QwtCompassScaleDraw( const QMap< double, QString >& map ) 64 { 65 m_data = new PrivateData; 66 m_data->labelMap = map; 67 59 68 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 60 69 enableComponent( QwtAbstractScaleDraw::Ticks, false ); 61 70 } 62 71 63 /*! 64 \brief Set a map, mapping values to labels 65 \param map Value to label map 66 67 The values of the major ticks are found by looking into this 68 map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW. 69 70 \warning The map will have no effect for values that are no major 72 //! Destructor 73 QwtCompassScaleDraw::~QwtCompassScaleDraw() 74 { 75 delete m_data; 76 } 77 78 /*! 79 \brief Set a map, mapping values to labels 80 \param map Value to label map 81 82 The values of the major ticks are found by looking into this 83 map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW. 84 85 \warning The map will have no effect for values that are no major 71 86 tick values. Major ticks can be changed by QwtScaleDraw::setScale 72 87 73 \sa labelMap(), scaleDraw(), setScale() 74 */ 75 void QwtCompassScaleDraw::setLabelMap( const QMap<double, QString> &map ) 76 { 77 d_labelMap = map; 78 } 79 80 81 /*! 82 \return map, mapping values to labels 83 \sa setLabelMap() 84 */ 85 QMap<double, QString> QwtCompassScaleDraw::labelMap() const 86 { 87 return d_labelMap; 88 } 89 90 /*! 91 Map a value to a corresponding label 92 93 \param value Value that will be mapped 94 95 label() looks in the labelMap() for a corresponding label for value 96 or returns an null text. 97 98 \return Label 99 \sa labelMap(), setLabelMap() 100 */ 88 \sa labelMap(), scaleDraw(), setScale() 89 */ 90 void QwtCompassScaleDraw::setLabelMap( const QMap< double, QString >& map ) 91 { 92 m_data->labelMap = map; 93 } 94 95 /*! 96 \return map, mapping values to labels 97 \sa setLabelMap() 98 */ 99 QMap< double, QString > QwtCompassScaleDraw::labelMap() const 100 { 101 return m_data->labelMap; 102 } 103 104 /*! 105 Map a value to a corresponding label 106 107 \param value Value that will be mapped 108 109 label() looks in the labelMap() for a corresponding label for value 110 or returns an null text. 111 112 \return Label 113 \sa labelMap(), setLabelMap() 114 */ 101 115 102 116 QwtText QwtCompassScaleDraw::label( double value ) const … … 108 122 value += 360.0; 109 123 110 if ( d_labelMap.contains( value ) ) 111 return d_labelMap[value]; 124 QMap< double, QString >::const_iterator it = 125 m_data->labelMap.constFind( value ); 126 127 if ( it != m_data->labelMap.constEnd() ) 128 return *it; 112 129 113 130 return QwtText(); … … 116 133 class QwtCompass::PrivateData 117 134 { 118 public: 135 public: 119 136 PrivateData(): 120 137 rose( NULL ) … … 127 144 } 128 145 129 QwtCompassRose *rose;146 QwtCompassRose* rose; 130 147 }; 131 148 132 149 /*! 133 \brief Constructor 134 \param parent Parent widget 135 136 Create a compass widget with a scale, no needle and no rose. 137 The default origin is 270.0 with no valid value. It accepts 138 mouse and keyboard inputs and has no step size. The default mode 139 is QwtDial::RotateNeedle. 140 */ 141 QwtCompass::QwtCompass( QWidget* parent ) :142 QwtDial( parent ) 143 { 144 d_data = new PrivateData;150 \brief Constructor 151 \param parent Parent widget 152 153 Create a compass widget with a scale, no needle and no rose. 154 The default origin is 270.0 with no valid value. It accepts 155 mouse and keyboard inputs and has no step size. The default mode 156 is QwtDial::RotateNeedle. 157 */ 158 QwtCompass::QwtCompass( QWidget* parent ) 159 : QwtDial( parent ) 160 { 161 m_data = new PrivateData; 145 162 146 163 setScaleDraw( new QwtCompassScaleDraw() ); … … 159 176 QwtCompass::~QwtCompass() 160 177 { 161 delete d_data;178 delete m_data; 162 179 } 163 180 … … 169 186 \param center Center of the content circle 170 187 \param radius Radius of the content circle 171 */ 172 void QwtCompass::drawScaleContents( QPainter *painter,173 const QPointF ¢er, double radius ) const188 */ 189 void QwtCompass::drawScaleContents( QPainter* painter, 190 const QPointF& center, double radius ) const 174 191 { 175 192 QPalette::ColorGroup cg; … … 191 208 192 209 /*! 193 Draw the compass rose 194 195 \param painter Painter 196 \param center Center of the compass 197 \param radius of the circle, where to paint the rose 198 \param north Direction pointing north, in degrees counter clockwise 199 \param cg Color group 200 */ 201 void QwtCompass::drawRose( QPainter *painter, const QPointF¢er,210 Draw the compass rose 211 212 \param painter Painter 213 \param center Center of the compass 214 \param radius of the circle, where to paint the rose 215 \param north Direction pointing north, in degrees counter clockwise 216 \param cg Color group 217 */ 218 void QwtCompass::drawRose( QPainter* painter, const QPointF& center, 202 219 double radius, double north, QPalette::ColorGroup cg ) const 203 220 { 204 if ( d_data->rose )205 d_data->rose->draw( painter, center, radius, north, cg );206 } 207 208 /*! 209 Set a rose for the compass 210 \param rose Compass rose 211 \warning The rose will be deleted, when a different rose is 221 if ( m_data->rose ) 222 m_data->rose->draw( painter, center, radius, north, cg ); 223 } 224 225 /*! 226 Set a rose for the compass 227 \param rose Compass rose 228 \warning The rose will be deleted, when a different rose is 212 229 set or in ~QwtCompass 213 \sa rose() 214 */ 215 void QwtCompass::setRose( QwtCompassRose *rose )216 { 217 if ( rose != d_data->rose )218 { 219 if ( d_data->rose )220 delete d_data->rose;221 222 d_data->rose = rose;230 \sa rose() 231 */ 232 void QwtCompass::setRose( QwtCompassRose* rose ) 233 { 234 if ( rose != m_data->rose ) 235 { 236 if ( m_data->rose ) 237 delete m_data->rose; 238 239 m_data->rose = rose; 223 240 update(); 224 241 } … … 226 243 227 244 /*! 228 \return rose 229 \sa setRose() 230 */ 231 const QwtCompassRose *QwtCompass::rose() const232 { 233 return d_data->rose;234 } 235 236 /*! 237 \return rose 238 \sa setRose() 239 */ 240 QwtCompassRose *QwtCompass::rose()241 { 242 return d_data->rose;243 } 244 245 /*! 246 Handles key events 247 248 Beside the keys described in QwtDial::keyPressEvent numbers 249 from 1-9 (without 5) set the direction according to their 250 position on the num pad. 251 252 \sa isReadOnly() 253 */ 254 void QwtCompass::keyPressEvent( QKeyEvent *kev )245 \return rose 246 \sa setRose() 247 */ 248 const QwtCompassRose* QwtCompass::rose() const 249 { 250 return m_data->rose; 251 } 252 253 /*! 254 \return rose 255 \sa setRose() 256 */ 257 QwtCompassRose* QwtCompass::rose() 258 { 259 return m_data->rose; 260 } 261 262 /*! 263 Handles key events 264 265 Beside the keys described in QwtDial::keyPressEvent numbers 266 from 1-9 (without 5) set the direction according to their 267 position on the num pad. 268 269 \sa isReadOnly() 270 */ 271 void QwtCompass::keyPressEvent( QKeyEvent* kev ) 255 272 { 256 273 if ( isReadOnly() ) … … 307 324 } 308 325 } 326 327 #include "moc_qwt_compass.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
