Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_abstract_scale_draw.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_abstract_scale_draw.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_abstract_scale_draw.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_abstract_scale_draw.h" 11 #include "qwt_math.h"12 11 #include "qwt_text.h" 13 12 #include "qwt_painter.h" 14 13 #include "qwt_scale_map.h" 14 #include "qwt_math.h" 15 15 16 #include <qpainter.h> 16 17 #include <qpalette.h> 17 18 #include <qmap.h> 19 #include <qlist.h> 18 20 #include <qlocale.h> 19 21 20 22 class QwtAbstractScaleDraw::PrivateData 21 23 { 22 public: 24 public: 23 25 PrivateData(): 24 26 spacing( 4.0 ), 25 penWidth (0 ),27 penWidthF( 0.0 ), 26 28 minExtent( 0.0 ) 27 29 { … … 42 44 double spacing; 43 45 double tickLength[QwtScaleDiv::NTickTypes]; 44 intpenWidth;46 qreal penWidthF; 45 47 46 48 double minExtent; 47 49 48 QMap<double, QwtText> labelCache; 50 QMap< double, QwtText > labelCache; 49 51 }; 50 52 51 53 /*! 52 \brief Constructor 53 54 The range of the scale is initialized to [0, 100], 55 The spacing (distance between ticks and labels) is 56 set to 4, the tick lengths are set to 4,6 and 8 pixels 57 */ 54 \brief Constructor 55 56 The range of the scale is initialized to [0, 100], 57 The spacing (distance between ticks and labels) is 58 set to 4, the tick lengths are set to 4,6 and 8 pixels 59 */ 58 60 QwtAbstractScaleDraw::QwtAbstractScaleDraw() 59 61 { 60 d_data = new QwtAbstractScaleDraw::PrivateData;62 m_data = new QwtAbstractScaleDraw::PrivateData; 61 63 } 62 64 … … 64 66 QwtAbstractScaleDraw::~QwtAbstractScaleDraw() 65 67 { 66 delete d_data;67 } 68 69 /*! 70 En/Disable a component of the scale 71 72 \param component Scale component 73 \param enable On/Off 74 75 \sa hasComponent() 76 */ 68 delete m_data; 69 } 70 71 /*! 72 En/Disable a component of the scale 73 74 \param component Scale component 75 \param enable On/Off 76 77 \sa hasComponent() 78 */ 77 79 void QwtAbstractScaleDraw::enableComponent( 78 80 ScaleComponent component, bool enable ) 79 81 { 80 82 if ( enable ) 81 d_data->components |= component;83 m_data->components |= component; 82 84 else 83 d_data->components &= ~component;84 } 85 86 /*! 87 Check if a component is enabled 88 89 \param component Component type 90 \return true, when component is enabled 91 \sa enableComponent() 92 */ 85 m_data->components &= ~component; 86 } 87 88 /*! 89 Check if a component is enabled 90 91 \param component Component type 92 \return true, when component is enabled 93 \sa enableComponent() 94 */ 93 95 bool QwtAbstractScaleDraw::hasComponent( ScaleComponent component ) const 94 96 { 95 return ( d_data->components & component ); 96 } 97 98 /*! 99 Change the scale division 100 \param scaleDiv New scale division 101 */ 102 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &scaleDiv ) 103 { 104 d_data->scaleDiv = scaleDiv; 105 d_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() ); 106 d_data->labelCache.clear(); 107 } 108 109 /*! 110 Change the transformation of the scale 111 \param transformation New scale transformation 112 */ 113 void QwtAbstractScaleDraw::setTransformation( 114 QwtTransform *transformation ) 115 { 116 d_data->map.setTransformation( transformation ); 97 return ( m_data->components & component ); 98 } 99 100 /*! 101 Change the scale division 102 \param scaleDiv New scale division 103 */ 104 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv& scaleDiv ) 105 { 106 m_data->scaleDiv = scaleDiv; 107 m_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() ); 108 m_data->labelCache.clear(); 109 } 110 111 /*! 112 Change the transformation of the scale 113 \param transformation New scale transformation 114 */ 115 void QwtAbstractScaleDraw::setTransformation( QwtTransform* transformation ) 116 { 117 m_data->map.setTransformation( transformation ); 117 118 } 118 119 119 120 //! \return Map how to translate between scale and pixel values 120 const QwtScaleMap &QwtAbstractScaleDraw::scaleMap() const121 { 122 return d_data->map;121 const QwtScaleMap& QwtAbstractScaleDraw::scaleMap() const 122 { 123 return m_data->map; 123 124 } 124 125 125 126 //! \return Map how to translate between scale and pixel values 126 QwtScaleMap &QwtAbstractScaleDraw::scaleMap()127 { 128 return d_data->map;127 QwtScaleMap& QwtAbstractScaleDraw::scaleMap() 128 { 129 return m_data->map; 129 130 } 130 131 … … 132 133 const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const 133 134 { 134 return d_data->scaleDiv;135 } 136 137 /*! 138 \brief Specify the width of the scale pen 139 \param width Pen width 140 \sa penWidth() 141 */ 142 void QwtAbstractScaleDraw::setPenWidth( int width ) 143 { 144 if ( width < 0 ) 145 width= 0;146 147 if ( width != d_data->penWidth ) 148 d_data->penWidth = width;135 return m_data->scaleDiv; 136 } 137 138 /*! 139 \brief Specify the width of the scale pen 140 \param width Pen width 141 142 \sa penWidth() 143 */ 144 void QwtAbstractScaleDraw::setPenWidthF( qreal width ) 145 { 146 if ( width < 0.0 ) 147 width = 0.0; 148 149 m_data->penWidthF = width; 149 150 } 150 151 … … 152 153 \return Scale pen width 153 154 \sa setPenWidth() 154 */ 155 intQwtAbstractScaleDraw::penWidth() const156 { 157 return d_data->penWidth;158 } 159 160 /*! 161 \brief Draw the scale 162 163 \param painter The painter 164 165 \param palette Palette, text color is used for the labels, 155 */ 156 qreal QwtAbstractScaleDraw::penWidthF() const 157 { 158 return m_data->penWidthF; 159 } 160 161 /*! 162 \brief Draw the scale 163 164 \param painter The painter 165 166 \param palette Palette, text color is used for the labels, 166 167 foreground color for ticks and backbone 167 */ 168 void QwtAbstractScaleDraw::draw( QPainter *painter,168 */ 169 void QwtAbstractScaleDraw::draw( QPainter* painter, 169 170 const QPalette& palette ) const 170 171 { … … 172 173 173 174 QPen pen = painter->pen(); 174 pen.setWidth ( d_data->penWidth );175 pen.setCosmetic( false ); 175 pen.setWidthF( m_data->penWidthF ); 176 176 177 painter->setPen( pen ); 177 178 … … 181 182 painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style 182 183 183 const QList< double> &majorTicks =184 d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick );184 const QList< double >& majorTicks = 185 m_data->scaleDiv.ticks( QwtScaleDiv::MajorTick ); 185 186 186 187 for ( int i = 0; i < majorTicks.count(); i++ ) 187 188 { 188 189 const double v = majorTicks[i]; 189 if ( d_data->scaleDiv.contains( v ) )190 if ( m_data->scaleDiv.contains( v ) ) 190 191 drawLabel( painter, v ); 191 192 } … … 207 208 tickType < QwtScaleDiv::NTickTypes; tickType++ ) 208 209 { 209 const double tickLen = d_data->tickLength[tickType];210 const double tickLen = m_data->tickLength[tickType]; 210 211 if ( tickLen <= 0.0 ) 211 212 continue; 212 213 213 const QList< double> &ticks =d_data->scaleDiv.ticks( tickType );214 const QList< double >& ticks = m_data->scaleDiv.ticks( tickType ); 214 215 for ( int i = 0; i < ticks.count(); i++ ) 215 216 { 216 217 const double v = ticks[i]; 217 if ( d_data->scaleDiv.contains( v ) )218 if ( m_data->scaleDiv.contains( v ) ) 218 219 drawTick( painter, v, tickLen ); 219 220 } … … 242 243 243 244 /*! 244 \brief Set the spacing between tick and labels 245 246 The spacing is the distance between ticks and labels. 247 The default spacing is 4 pixels. 248 249 \param spacing Spacing 250 251 \sa spacing() 252 */ 245 \brief Set the spacing between tick and labels 246 247 The spacing is the distance between ticks and labels. 248 The default spacing is 4 pixels. 249 250 \param spacing Spacing 251 252 \sa spacing() 253 */ 253 254 void QwtAbstractScaleDraw::setSpacing( double spacing ) 254 255 { … … 256 257 spacing = 0; 257 258 258 d_data->spacing = spacing;259 } 260 261 /*! 262 \brief Get the spacing 263 264 The spacing is the distance between ticks and labels. 265 The default spacing is 4 pixels. 266 267 \return Spacing 268 \sa setSpacing() 269 */ 259 m_data->spacing = spacing; 260 } 261 262 /*! 263 \brief Get the spacing 264 265 The spacing is the distance between ticks and labels. 266 The default spacing is 4 pixels. 267 268 \return Spacing 269 \sa setSpacing() 270 */ 270 271 double QwtAbstractScaleDraw::spacing() const 271 272 { 272 return d_data->spacing;273 } 274 275 /*! 276 \brief Set a minimum for the extent 277 278 The extent is calculated from the components of the 279 scale draw. In situations, where the labels are 280 changing and the layout depends on the extent (f.e scrolling 281 a scale), setting an upper limit as minimum extent will 282 avoid jumps of the layout. 283 284 \param minExtent Minimum extent 285 286 \sa extent(), minimumExtent() 287 */ 273 return m_data->spacing; 274 } 275 276 /*! 277 \brief Set a minimum for the extent 278 279 The extent is calculated from the components of the 280 scale draw. In situations, where the labels are 281 changing and the layout depends on the extent (f.e scrolling 282 a scale), setting an upper limit as minimum extent will 283 avoid jumps of the layout. 284 285 \param minExtent Minimum extent 286 287 \sa extent(), minimumExtent() 288 */ 288 289 void QwtAbstractScaleDraw::setMinimumExtent( double minExtent ) 289 290 { … … 291 292 minExtent = 0.0; 292 293 293 d_data->minExtent = minExtent;294 } 295 296 /*! 297 Get the minimum extent 298 \return Minimum extent 299 \sa extent(), setMinimumExtent() 300 */ 294 m_data->minExtent = minExtent; 295 } 296 297 /*! 298 Get the minimum extent 299 \return Minimum extent 300 \sa extent(), setMinimumExtent() 301 */ 301 302 double QwtAbstractScaleDraw::minimumExtent() const 302 303 { 303 return d_data->minExtent;304 } 305 306 /*! 307 Set the length of the ticks 308 309 \param tickType Tick type 310 \param length New length 311 312 \warning the length is limited to [0..1000] 313 */ 304 return m_data->minExtent; 305 } 306 307 /*! 308 Set the length of the ticks 309 310 \param tickType Tick type 311 \param length New length 312 313 \warning the length is limited to [0..1000] 314 */ 314 315 void QwtAbstractScaleDraw::setTickLength( 315 316 QwtScaleDiv::TickType tickType, double length ) … … 328 329 length = maxTickLen; 329 330 330 d_data->tickLength[tickType] = length;331 m_data->tickLength[tickType] = length; 331 332 } 332 333 … … 334 335 \return Length of the ticks 335 336 \sa setTickLength(), maxTickLength() 336 */ 337 */ 337 338 double QwtAbstractScaleDraw::tickLength( QwtScaleDiv::TickType tickType ) const 338 339 { … … 343 344 } 344 345 345 return d_data->tickLength[tickType];346 return m_data->tickLength[tickType]; 346 347 } 347 348 … … 351 352 Useful for layout calculations 352 353 \sa tickLength(), setTickLength() 353 */ 354 */ 354 355 double QwtAbstractScaleDraw::maxTickLength() const 355 356 { 356 357 double length = 0.0; 357 358 for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ ) 358 length = q Max( length,d_data->tickLength[i] );359 length = qwtMaxF( length, m_data->tickLength[i] ); 359 360 360 361 return length; … … 362 363 363 364 /*! 364 \brief Convert a value into its representing label 365 366 The value is converted to a plain text using 367 QLocale().toString(value). 368 This method is often overloaded by applications to have individual 369 labels. 370 371 \param value Value 372 \return Label string. 373 */ 365 \brief Convert a value into its representing label 366 367 The value is converted to a plain text using 368 QLocale().toString(value). 369 This method is often overloaded by applications to have individual 370 labels. 371 372 \param value Value 373 \return Label string. 374 */ 374 375 QwtText QwtAbstractScaleDraw::label( double value ) const 375 376 { … … 389 390 390 391 \return Tick label 391 */ 392 const QwtText &QwtAbstractScaleDraw::tickLabel(393 const QFont &font, double value ) const394 { 395 QMap<double, QwtText>::const_iterator it1 = d_data->labelCache.constFind( value );396 if ( it1 != d_data->labelCache.constEnd() )392 */ 393 const QwtText& QwtAbstractScaleDraw::tickLabel( 394 const QFont& font, double value ) const 395 { 396 QMap< double, QwtText >::const_iterator it1 = m_data->labelCache.constFind( value ); 397 if ( it1 != m_data->labelCache.constEnd() ) 397 398 return *it1; 398 399 … … 403 404 ( void )lbl.textSize( font ); // initialize the internal cache 404 405 405 QMap<double, QwtText>::iterator it2 = d_data->labelCache.insert( value, lbl );406 QMap< double, QwtText >::iterator it2 = m_data->labelCache.insert( value, lbl ); 406 407 return *it2; 407 408 } … … 413 414 the labels need to be changed. while the same QwtScaleDiv is set, 414 415 invalidateCache() needs to be called manually. 415 */ 416 */ 416 417 void QwtAbstractScaleDraw::invalidateCache() 417 418 { 418 d_data->labelCache.clear();419 } 419 m_data->labelCache.clear(); 420 }
Note:
See TracChangeset
for help on using the changeset viewer.
