Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_axis.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_axis.cpp (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_axis.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_plot.h" 11 #include "qwt_math.h"12 11 #include "qwt_scale_widget.h" 12 #include "qwt_scale_map.h" 13 13 #include "qwt_scale_div.h" 14 14 #include "qwt_scale_engine.h" 15 16 class QwtPlot::AxisData 17 { 18 public: 19 bool isEnabled; 20 bool doAutoScale; 21 22 double minValue; 23 double maxValue; 24 double stepSize; 25 26 int maxMajor; 27 int maxMinor; 28 29 bool isValid; 30 31 QwtScaleDiv scaleDiv; 32 QwtScaleEngine *scaleEngine; 33 QwtScaleWidget *scaleWidget; 15 #include "qwt_interval.h" 16 17 namespace 18 { 19 class AxisData 20 { 21 public: 22 AxisData() 23 : isVisible( true ) 24 , doAutoScale( true ) 25 , minValue( 0.0 ) 26 , maxValue( 1000.0 ) 27 , stepSize( 0.0 ) 28 , maxMajor( 8 ) 29 , maxMinor( 5 ) 30 , isValid( false ) 31 , scaleEngine( new QwtLinearScaleEngine() ) 32 , scaleWidget( NULL ) 33 { 34 } 35 36 ~AxisData() 37 { 38 delete scaleEngine; 39 } 40 41 void initWidget( QwtScaleDraw::Alignment align, const QString& name, QwtPlot* plot ) 42 { 43 scaleWidget = new QwtScaleWidget( align, plot ); 44 scaleWidget->setObjectName( name ); 45 46 #if 1 47 // better find the font sizes from the application font 48 const QFont fscl( plot->fontInfo().family(), 10 ); 49 const QFont fttl( plot->fontInfo().family(), 12, QFont::Bold ); 50 #endif 51 52 scaleWidget->setTransformation( scaleEngine->transformation() ); 53 54 scaleWidget->setFont( fscl ); 55 scaleWidget->setMargin( 2 ); 56 57 QwtText text = scaleWidget->title(); 58 text.setFont( fttl ); 59 scaleWidget->setTitle( text ); 60 } 61 62 bool isVisible; 63 bool doAutoScale; 64 65 double minValue; 66 double maxValue; 67 double stepSize; 68 69 int maxMajor; 70 int maxMinor; 71 72 bool isValid; 73 74 QwtScaleDiv scaleDiv; 75 QwtScaleEngine* scaleEngine; 76 QwtScaleWidget* scaleWidget; 77 }; 78 } 79 80 class QwtPlot::ScaleData 81 { 82 public: 83 ScaleData( QwtPlot* plot ) 84 { 85 using namespace QwtAxis; 86 87 m_axisData[YLeft].initWidget( QwtScaleDraw::LeftScale, "QwtPlotAxisYLeft", plot ); 88 m_axisData[YRight].initWidget( QwtScaleDraw::RightScale, "QwtPlotAxisYRight", plot ); 89 m_axisData[XTop].initWidget( QwtScaleDraw::TopScale, "QwtPlotAxisXTop", plot ); 90 m_axisData[XBottom].initWidget( QwtScaleDraw::BottomScale, "QwtPlotAxisXBottom", plot ); 91 } 92 93 inline AxisData& axisData( QwtAxisId axisId ) 94 { 95 return m_axisData[ axisId ]; 96 } 97 98 inline const AxisData& axisData( QwtAxisId axisId ) const 99 { 100 return m_axisData[ axisId ]; 101 } 102 103 private: 104 AxisData m_axisData[ QwtAxis::AxisPositions ]; 34 105 }; 35 106 36 //! Initialize axes37 107 void QwtPlot::initAxesData() 38 108 { 39 int axisId; 40 41 for ( axisId = 0; axisId < axisCnt; axisId++ ) 42 d_axisData[axisId] = new AxisData; 43 44 d_axisData[yLeft]->scaleWidget = 45 new QwtScaleWidget( QwtScaleDraw::LeftScale, this ); 46 d_axisData[yRight]->scaleWidget = 47 new QwtScaleWidget( QwtScaleDraw::RightScale, this ); 48 d_axisData[xTop]->scaleWidget = 49 new QwtScaleWidget( QwtScaleDraw::TopScale, this ); 50 d_axisData[xBottom]->scaleWidget = 51 new QwtScaleWidget( QwtScaleDraw::BottomScale, this ); 52 53 d_axisData[yLeft]->scaleWidget->setObjectName( "QwtPlotAxisYLeft" ); 54 d_axisData[yRight]->scaleWidget->setObjectName( "QwtPlotAxisYRight" ); 55 d_axisData[xTop]->scaleWidget->setObjectName( "QwtPlotAxisXTop" ); 56 d_axisData[xBottom]->scaleWidget->setObjectName( "QwtPlotAxisXBottom" ); 57 58 #if 1 59 // better find the font sizes from the application font 60 QFont fscl( fontInfo().family(), 10 ); 61 QFont fttl( fontInfo().family(), 12, QFont::Bold ); 62 #endif 63 64 for ( axisId = 0; axisId < axisCnt; axisId++ ) 65 { 66 AxisData &d = *d_axisData[axisId]; 67 68 d.scaleEngine = new QwtLinearScaleEngine; 69 70 d.scaleWidget->setTransformation( 71 d.scaleEngine->transformation() ); 72 73 d.scaleWidget->setFont( fscl ); 74 d.scaleWidget->setMargin( 2 ); 75 76 QwtText text = d.scaleWidget->title(); 77 text.setFont( fttl ); 78 d.scaleWidget->setTitle( text ); 79 80 d.doAutoScale = true; 81 82 d.minValue = 0.0; 83 d.maxValue = 1000.0; 84 d.stepSize = 0.0; 85 86 d.maxMinor = 5; 87 d.maxMajor = 8; 88 89 90 d.isValid = false; 91 } 92 93 d_axisData[yLeft]->isEnabled = true; 94 d_axisData[yRight]->isEnabled = false; 95 d_axisData[xBottom]->isEnabled = true; 96 d_axisData[xTop]->isEnabled = false; 109 m_scaleData = new ScaleData( this ); 110 111 m_scaleData->axisData( QwtAxis::YRight ).isVisible = false; 112 m_scaleData->axisData( QwtAxis::XTop ).isVisible = false; 97 113 } 98 114 99 115 void QwtPlot::deleteAxesData() 100 116 { 101 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 102 { 103 delete d_axisData[axisId]->scaleEngine; 104 delete d_axisData[axisId]; 105 d_axisData[axisId] = NULL; 106 } 107 } 108 109 /*! 110 \return Scale widget of the specified axis, or NULL if axisId is invalid. 111 \param axisId Axis index 112 */ 113 const QwtScaleWidget *QwtPlot::axisWidget( int axisId ) const 114 { 115 if ( axisValid( axisId ) ) 116 return d_axisData[axisId]->scaleWidget; 117 delete m_scaleData; 118 m_scaleData = NULL; 119 } 120 121 /*! 122 Checks if an axis is valid 123 124 \param axisId axis 125 \return \c true if the specified axis exists, otherwise \c false 126 127 \note This method is equivalent to QwtAxis::isValid( axisId ) and simply checks 128 if axisId is one of the values of QwtAxis::Position. It is a placeholder 129 for future releases, where it will be possible to have a customizable number 130 of axes ( multiaxes branch ) at each side. 131 */ 132 bool QwtPlot::isAxisValid( QwtAxisId axisId ) const 133 { 134 return QwtAxis::isValid( axisId ); 135 } 136 137 /*! 138 \return Scale widget of the specified axis, or NULL if axisId is invalid. 139 \param axisId Axis 140 */ 141 const QwtScaleWidget* QwtPlot::axisWidget( QwtAxisId axisId ) const 142 { 143 if ( isAxisValid( axisId ) ) 144 return m_scaleData->axisData( axisId ).scaleWidget; 117 145 118 146 return NULL; … … 120 148 121 149 /*! 122 \return Scale widget of the specified axis, or NULL if axisId is invalid. 123 \param axisId Axis index124 */ 125 QwtScaleWidget *QwtPlot::axisWidget(intaxisId )126 { 127 if ( axisValid( axisId ) )128 return d_axisData[axisId]->scaleWidget;150 \return Scale widget of the specified axis, or NULL if axisId is invalid. 151 \param axisId Axis 152 */ 153 QwtScaleWidget* QwtPlot::axisWidget( QwtAxisId axisId ) 154 { 155 if ( isAxisValid( axisId ) ) 156 return m_scaleData->axisData( axisId ).scaleWidget; 129 157 130 158 return NULL; … … 132 160 133 161 /*! 134 Change the scale engine for an axis 135 136 \param axisId Axis index137 \param scaleEngine Scale engine 138 139 \sa axisScaleEngine() 140 */ 141 void QwtPlot::setAxisScaleEngine( intaxisId, QwtScaleEngine*scaleEngine )142 { 143 if ( axisValid( axisId ) && scaleEngine != NULL )144 { 145 AxisData &d = *d_axisData[axisId];162 Change the scale engine for an axis 163 164 \param axisId Axis 165 \param scaleEngine Scale engine 166 167 \sa axisScaleEngine() 168 */ 169 void QwtPlot::setAxisScaleEngine( QwtAxisId axisId, QwtScaleEngine* scaleEngine ) 170 { 171 if ( isAxisValid( axisId ) && scaleEngine != NULL ) 172 { 173 AxisData& d = m_scaleData->axisData( axisId ); 146 174 147 175 delete d.scaleEngine; 148 176 d.scaleEngine = scaleEngine; 149 177 150 d_axisData[axisId]->scaleWidget->setTransformation( 151 scaleEngine->transformation() ); 178 d.scaleWidget->setTransformation( scaleEngine->transformation() ); 152 179 153 180 d.isValid = false; … … 158 185 159 186 /*! 160 \param axisId Axis index161 \return Scale engine for a specific axis 162 */ 163 QwtScaleEngine *QwtPlot::axisScaleEngine(intaxisId )164 { 165 if ( axisValid( axisId ) )166 return d_axisData[axisId]->scaleEngine;187 \param axisId Axis 188 \return Scale engine for a specific axis 189 */ 190 QwtScaleEngine* QwtPlot::axisScaleEngine( QwtAxisId axisId ) 191 { 192 if ( isAxisValid( axisId ) ) 193 return m_scaleData->axisData( axisId ).scaleEngine; 167 194 else 168 195 return NULL; … … 170 197 171 198 /*! 172 \param axisId Axis index173 \return Scale engine for a specific axis 174 */ 175 const QwtScaleEngine *QwtPlot::axisScaleEngine(intaxisId ) const176 { 177 if ( axisValid( axisId ) )178 return d_axisData[axisId]->scaleEngine;199 \param axisId Axis 200 \return Scale engine for a specific axis 201 */ 202 const QwtScaleEngine* QwtPlot::axisScaleEngine( QwtAxisId axisId ) const 203 { 204 if ( isAxisValid( axisId ) ) 205 return m_scaleData->axisData( axisId ).scaleEngine; 179 206 else 180 207 return NULL; 181 208 } 182 209 /*! 183 \return \c True, if autoscaling is enabled 184 \param axisId Axis index185 */ 186 bool QwtPlot::axisAutoScale( intaxisId ) const187 { 188 if ( axisValid( axisId ) )189 return d_axisData[axisId]->doAutoScale;210 \return \c True, if autoscaling is enabled 211 \param axisId Axis 212 */ 213 bool QwtPlot::axisAutoScale( QwtAxisId axisId ) const 214 { 215 if ( isAxisValid( axisId ) ) 216 return m_scaleData->axisData( axisId ).doAutoScale; 190 217 else 191 218 return false; … … 193 220 194 221 /*! 195 \return \c True, if a specified axis is enabled196 \param axisId Axis index197 */ 198 bool QwtPlot:: axisEnabled( intaxisId ) const199 { 200 if ( axisValid( axisId ) )201 return d_axisData[axisId]->isEnabled;222 \return \c True, if a specified axis is visible 223 \param axisId Axis 224 */ 225 bool QwtPlot::isAxisVisible( QwtAxisId axisId ) const 226 { 227 if ( isAxisValid( axisId ) ) 228 return m_scaleData->axisData( axisId ).isVisible; 202 229 else 203 230 return false; … … 205 232 206 233 /*! 207 \return The font of the scale labels for a specified axis 208 \param axisId Axis index209 */ 210 QFont QwtPlot::axisFont( intaxisId ) const211 { 212 if ( axisValid( axisId ) )234 \return The font of the scale labels for a specified axis 235 \param axisId Axis 236 */ 237 QFont QwtPlot::axisFont( QwtAxisId axisId ) const 238 { 239 if ( isAxisValid( axisId ) ) 213 240 return axisWidget( axisId )->font(); 214 241 else … … 218 245 219 246 /*! 220 \return The maximum number of major ticks for a specified axis 221 \param axisId Axis index222 \sa setAxisMaxMajor(), QwtScaleEngine::divideScale() 223 */ 224 int QwtPlot::axisMaxMajor( intaxisId ) const225 { 226 if ( axisValid( axisId ) )227 return d_axisData[axisId]->maxMajor;247 \return The maximum number of major ticks for a specified axis 248 \param axisId Axis 249 \sa setAxisMaxMajor(), QwtScaleEngine::divideScale() 250 */ 251 int QwtPlot::axisMaxMajor( QwtAxisId axisId ) const 252 { 253 if ( isAxisValid( axisId ) ) 254 return m_scaleData->axisData( axisId ).maxMajor; 228 255 else 229 256 return 0; … … 231 258 232 259 /*! 233 \return the maximum number of minor ticks for a specified axis 234 \param axisId Axis index235 \sa setAxisMaxMinor(), QwtScaleEngine::divideScale() 236 */ 237 int QwtPlot::axisMaxMinor( intaxisId ) const238 { 239 if ( axisValid( axisId ) )240 return d_axisData[axisId]->maxMinor;260 \return the maximum number of minor ticks for a specified axis 261 \param axisId Axis 262 \sa setAxisMaxMinor(), QwtScaleEngine::divideScale() 263 */ 264 int QwtPlot::axisMaxMinor( QwtAxisId axisId ) const 265 { 266 if ( isAxisValid( axisId ) ) 267 return m_scaleData->axisData( axisId ).maxMinor; 241 268 else 242 269 return 0; … … 244 271 245 272 /*! 246 \brief Return the scale division of a specified axis 247 248 axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound() 249 are the current limits of the axis scale. 250 251 \param axisId Axis index 252 \return Scale division 253 254 \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale() 255 */ 256 const QwtScaleDiv &QwtPlot::axisScaleDiv( int axisId ) const 257 { 258 return d_axisData[axisId]->scaleDiv; 259 } 260 261 /*! 262 \brief Return the scale draw of a specified axis 263 264 \param axisId Axis index 265 \return Specified scaleDraw for axis, or NULL if axis is invalid. 266 */ 267 const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const 268 { 269 if ( !axisValid( axisId ) ) 273 \brief Return the scale division of a specified axis 274 275 axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound() 276 are the current limits of the axis scale. 277 278 \param axisId Axis 279 \return Scale division 280 281 \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale() 282 */ 283 const QwtScaleDiv& QwtPlot::axisScaleDiv( QwtAxisId axisId ) const 284 { 285 if ( isAxisValid( axisId ) ) 286 return m_scaleData->axisData( axisId ).scaleDiv; 287 288 static QwtScaleDiv dummyScaleDiv; 289 return dummyScaleDiv; 290 } 291 292 /*! 293 \brief Return the scale draw of a specified axis 294 295 \param axisId Axis 296 \return Specified scaleDraw for axis, or NULL if axis is invalid. 297 */ 298 const QwtScaleDraw* QwtPlot::axisScaleDraw( QwtAxisId axisId ) const 299 { 300 if ( !isAxisValid( axisId ) ) 270 301 return NULL; 271 302 … … 274 305 275 306 /*! 276 \brief Return the scale draw of a specified axis 277 278 \param axisId Axis index279 \return Specified scaleDraw for axis, or NULL if axis is invalid. 280 */ 281 QwtScaleDraw *QwtPlot::axisScaleDraw(intaxisId )282 { 283 if ( ! axisValid( axisId ) )307 \brief Return the scale draw of a specified axis 308 309 \param axisId Axis 310 \return Specified scaleDraw for axis, or NULL if axis is invalid. 311 */ 312 QwtScaleDraw* QwtPlot::axisScaleDraw( QwtAxisId axisId ) 313 { 314 if ( !isAxisValid( axisId ) ) 284 315 return NULL; 285 316 … … 288 319 289 320 /*! 290 \brief Return the step size parameter that has been set in setAxisScale. 291 292 This doesn't need to be the step size of the current scale. 293 294 \param axisId Axis index295 \return step size parameter value 321 \brief Return the step size parameter that has been set in setAxisScale. 322 323 This doesn't need to be the step size of the current scale. 324 325 \param axisId Axis 326 \return step size parameter value 296 327 297 328 \sa setAxisScale(), QwtScaleEngine::divideScale() 298 */ 299 double QwtPlot::axisStepSize( intaxisId ) const300 { 301 if ( ! axisValid( axisId ) )329 */ 330 double QwtPlot::axisStepSize( QwtAxisId axisId ) const 331 { 332 if ( !isAxisValid( axisId ) ) 302 333 return 0; 303 334 304 return d_axisData[axisId]->stepSize;305 } 306 307 /*! 308 \brief Return the current interval of the specified axis 309 310 This is only a convenience function for axisScaleDiv( axisId )->interval(); 311 312 \param axisId Axis index313 \return Scale interval 314 315 \sa QwtScaleDiv, axisScaleDiv() 316 */ 317 QwtInterval QwtPlot::axisInterval( intaxisId ) const318 { 319 if ( ! axisValid( axisId ) )335 return m_scaleData->axisData( axisId ).stepSize; 336 } 337 338 /*! 339 \brief Return the current interval of the specified axis 340 341 This is only a convenience function for axisScaleDiv( axisId )->interval(); 342 343 \param axisId Axis 344 \return Scale interval 345 346 \sa QwtScaleDiv, axisScaleDiv() 347 */ 348 QwtInterval QwtPlot::axisInterval( QwtAxisId axisId ) const 349 { 350 if ( !isAxisValid( axisId ) ) 320 351 return QwtInterval(); 321 352 322 return d_axisData[axisId]->scaleDiv.interval();323 } 324 325 /*! 326 \return Title of a specified axis 327 \param axisId Axis index328 */ 329 QwtText QwtPlot::axisTitle( intaxisId ) const330 { 331 if ( axisValid( axisId ) )353 return m_scaleData->axisData( axisId ).scaleDiv.interval(); 354 } 355 356 /*! 357 \return Title of a specified axis 358 \param axisId Axis 359 */ 360 QwtText QwtPlot::axisTitle( QwtAxisId axisId ) const 361 { 362 if ( isAxisValid( axisId ) ) 332 363 return axisWidget( axisId )->title(); 333 364 else … … 336 367 337 368 /*! 338 \brief Enable or disable a specified axis 339 340 When an axis is disabled, this only means that it is not 341 visible on the screen. Curves, markers and can be attached 342 to disabled axes, and transformation of screen coordinates 343 into values works as normal. 344 345 Only xBottom and yLeft are enabled by default. 346 347 \param axisId Axis index 348 \param tf \c true (enabled) or \c false (disabled) 349 */ 350 void QwtPlot::enableAxis( int axisId, bool tf ) 351 { 352 if ( axisValid( axisId ) && tf != d_axisData[axisId]->isEnabled ) 353 { 354 d_axisData[axisId]->isEnabled = tf; 369 \brief Hide or show a specified axis 370 371 Curves, markers and other items can be attached 372 to hidden axes, and transformation of screen coordinates 373 into values works as normal. 374 375 Only QwtAxis::XBottom and QwtAxis::YLeft are enabled by default. 376 377 \param axisId Axis 378 \param on \c true (visible) or \c false (hidden) 379 */ 380 void QwtPlot::setAxisVisible( QwtAxisId axisId, bool on ) 381 { 382 if ( isAxisValid( axisId ) && on != m_scaleData->axisData( axisId ).isVisible ) 383 { 384 m_scaleData->axisData( axisId ).isVisible = on; 355 385 updateLayout(); 356 386 } … … 358 388 359 389 /*! 360 Transform the x or y coordinate of a position in the 361 drawing region into a value. 362 363 \param axisId Axis index364 \param pos position 365 366 \return Position as axis coordinate 367 368 \warning The position can be an x or a y coordinate, 390 Transform the x or y coordinate of a position in the 391 drawing region into a value. 392 393 \param axisId Axis 394 \param pos position 395 396 \return Position as axis coordinate 397 398 \warning The position can be an x or a y coordinate, 369 399 depending on the specified axis. 370 */ 371 double QwtPlot::invTransform( intaxisId,intpos ) const372 { 373 if ( axisValid( axisId ) )400 */ 401 double QwtPlot::invTransform( QwtAxisId axisId, double pos ) const 402 { 403 if ( isAxisValid( axisId ) ) 374 404 return( canvasMap( axisId ).invTransform( pos ) ); 375 405 else … … 379 409 380 410 /*! 381 \brief Transform a value into a coordinate in the plotting region 382 383 \param axisId Axis index384 \param value value 385 \return X or Y coordinate in the plotting region corresponding 411 \brief Transform a value into a coordinate in the plotting region 412 413 \param axisId Axis 414 \param value value 415 \return X or Y coordinate in the plotting region corresponding 386 416 to the value. 387 */ 388 double QwtPlot::transform( intaxisId, double value ) const389 { 390 if ( axisValid( axisId ) )417 */ 418 double QwtPlot::transform( QwtAxisId axisId, double value ) const 419 { 420 if ( isAxisValid( axisId ) ) 391 421 return( canvasMap( axisId ).transform( value ) ); 392 422 else … … 395 425 396 426 /*! 397 \brief Change the font of an axis 398 399 \param axisId Axis index400 \param font Font 401 \warning This function changes the font of the tick labels, 427 \brief Change the font of an axis 428 429 \param axisId Axis 430 \param font Font 431 \warning This function changes the font of the tick labels, 402 432 not of the axis title. 403 */ 404 void QwtPlot::setAxisFont( intaxisId, const QFont&font )405 { 406 if ( axisValid( axisId ) )433 */ 434 void QwtPlot::setAxisFont( QwtAxisId axisId, const QFont& font ) 435 { 436 if ( isAxisValid( axisId ) ) 407 437 axisWidget( axisId )->setFont( font ); 408 438 } 409 439 410 440 /*! 411 \brief Enable autoscaling for a specified axis 412 413 This member function is used to switch back to autoscaling mode 414 after a fixed scale has been set. Autoscaling is enabled by default. 415 416 \param axisId Axis index417 \param on On/Off 418 \sa setAxisScale(), setAxisScaleDiv(), updateAxes() 419 420 \note The autoscaling flag has no effect until updateAxes() is executed 441 \brief Enable autoscaling for a specified axis 442 443 This member function is used to switch back to autoscaling mode 444 after a fixed scale has been set. Autoscaling is enabled by default. 445 446 \param axisId Axis 447 \param on On/Off 448 \sa setAxisScale(), setAxisScaleDiv(), updateAxes() 449 450 \note The autoscaling flag has no effect until updateAxes() is executed 421 451 ( called by replot() ). 422 */ 423 void QwtPlot::setAxisAutoScale( intaxisId, bool on )424 { 425 if ( axisValid( axisId ) && (d_axisData[axisId]->doAutoScale != on ) )426 { 427 d_axisData[axisId]->doAutoScale = on;452 */ 453 void QwtPlot::setAxisAutoScale( QwtAxisId axisId, bool on ) 454 { 455 if ( isAxisValid( axisId ) && ( m_scaleData->axisData( axisId ).doAutoScale != on ) ) 456 { 457 m_scaleData->axisData( axisId ).doAutoScale = on; 428 458 autoRefresh(); 429 459 } … … 431 461 432 462 /*! 433 \brief Disable autoscaling and specify a fixed scale for a selected axis. 434 435 In updateAxes() the scale engine calculates a scale division from the 436 specified parameters, that will be assigned to the scale widget. So 437 updates of the scale widget usually happen delayed with the next replot. 438 439 \param axisId Axis index440 \param min Minimum of the scale 441 \param max Maximum of the scale 442 \param stepSize Major step size. If <code>step == 0</code>, the step size is 463 \brief Disable autoscaling and specify a fixed scale for a selected axis. 464 465 In updateAxes() the scale engine calculates a scale division from the 466 specified parameters, that will be assigned to the scale widget. So 467 updates of the scale widget usually happen delayed with the next replot. 468 469 \param axisId Axis 470 \param min Minimum of the scale 471 \param max Maximum of the scale 472 \param stepSize Major step size. If <code>step == 0</code>, the step size is 443 473 calculated automatically using the maxMajor setting. 444 474 445 \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale() 446 */ 447 void QwtPlot::setAxisScale( intaxisId, double min, double max, double stepSize )448 { 449 if ( axisValid( axisId ) )450 { 451 AxisData &d = *d_axisData[axisId];475 \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale() 476 */ 477 void QwtPlot::setAxisScale( QwtAxisId axisId, double min, double max, double stepSize ) 478 { 479 if ( isAxisValid( axisId ) ) 480 { 481 AxisData& d = m_scaleData->axisData( axisId ); 452 482 453 483 d.doAutoScale = false; … … 463 493 464 494 /*! 465 \brief Disable autoscaling and specify a fixed scale for a selected axis. 466 467 The scale division will be stored locally only until the next call 468 of updateAxes(). So updates of the scale widget usually happen delayed with 469 the next replot. 470 471 \param axisId Axis index472 \param scaleDiv Scale division 473 474 \sa setAxisScale(), setAxisAutoScale() 475 */ 476 void QwtPlot::setAxisScaleDiv( intaxisId, const QwtScaleDiv&scaleDiv )477 { 478 if ( axisValid( axisId ) )479 { 480 AxisData &d = *d_axisData[axisId];495 \brief Disable autoscaling and specify a fixed scale for a selected axis. 496 497 The scale division will be stored locally only until the next call 498 of updateAxes(). So updates of the scale widget usually happen delayed with 499 the next replot. 500 501 \param axisId Axis 502 \param scaleDiv Scale division 503 504 \sa setAxisScale(), setAxisAutoScale() 505 */ 506 void QwtPlot::setAxisScaleDiv( QwtAxisId axisId, const QwtScaleDiv& scaleDiv ) 507 { 508 if ( isAxisValid( axisId ) ) 509 { 510 AxisData& d = m_scaleData->axisData( axisId ); 481 511 482 512 d.doAutoScale = false; … … 489 519 490 520 /*! 491 \brief Set a scale draw 492 493 \param axisId Axis index494 \param scaleDraw Object responsible for drawing scales. 495 496 By passing scaleDraw it is possible to extend QwtScaleDraw 497 functionality and let it take place in QwtPlot. Please note 498 that scaleDraw has to be created with new and will be deleted 499 by the corresponding QwtScale member ( like a child object ). 500 501 \sa QwtScaleDraw, QwtScaleWidget 502 \warning The attributes of scaleDraw will be overwritten by those of the 521 \brief Set a scale draw 522 523 \param axisId Axis 524 \param scaleDraw Object responsible for drawing scales. 525 526 By passing scaleDraw it is possible to extend QwtScaleDraw 527 functionality and let it take place in QwtPlot. Please note 528 that scaleDraw has to be created with new and will be deleted 529 by the corresponding QwtScale member ( like a child object ). 530 531 \sa QwtScaleDraw, QwtScaleWidget 532 \warning The attributes of scaleDraw will be overwritten by those of the 503 533 previous QwtScaleDraw. 504 */ 505 506 void QwtPlot::setAxisScaleDraw( intaxisId, QwtScaleDraw*scaleDraw )507 { 508 if ( axisValid( axisId ) )534 */ 535 536 void QwtPlot::setAxisScaleDraw( QwtAxisId axisId, QwtScaleDraw* scaleDraw ) 537 { 538 if ( isAxisValid( axisId ) ) 509 539 { 510 540 axisWidget( axisId )->setScaleDraw( scaleDraw ); … … 514 544 515 545 /*! 516 Change the alignment of the tick labels 517 518 \param axisId Axis index519 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 520 521 \sa QwtScaleDraw::setLabelAlignment() 522 */ 523 void QwtPlot::setAxisLabelAlignment( intaxisId, Qt::Alignment alignment )524 { 525 if ( axisValid( axisId ) )546 Change the alignment of the tick labels 547 548 \param axisId Axis 549 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 550 551 \sa QwtScaleDraw::setLabelAlignment() 552 */ 553 void QwtPlot::setAxisLabelAlignment( QwtAxisId axisId, Qt::Alignment alignment ) 554 { 555 if ( isAxisValid( axisId ) ) 526 556 axisWidget( axisId )->setLabelAlignment( alignment ); 527 557 } 528 558 529 559 /*! 530 Rotate all tick labels 531 532 \param axisId Axis index533 \param rotation Angle in degrees. When changing the label rotation, 560 Rotate all tick labels 561 562 \param axisId Axis 563 \param rotation Angle in degrees. When changing the label rotation, 534 564 the label alignment might be adjusted too. 535 565 536 \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment() 537 */ 538 void QwtPlot::setAxisLabelRotation( intaxisId, double rotation )539 { 540 if ( axisValid( axisId ) )566 \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment() 567 */ 568 void QwtPlot::setAxisLabelRotation( QwtAxisId axisId, double rotation ) 569 { 570 if ( isAxisValid( axisId ) ) 541 571 axisWidget( axisId )->setLabelRotation( rotation ); 542 572 } 543 573 544 574 /*! 545 Set the maximum number of minor scale intervals for a specified axis 546 547 \param axisId Axis index548 \param maxMinor Maximum number of minor steps 549 550 \sa axisMaxMinor() 551 */ 552 void QwtPlot::setAxisMaxMinor( intaxisId, int maxMinor )553 { 554 if ( axisValid( axisId ) )575 Set the maximum number of minor scale intervals for a specified axis 576 577 \param axisId Axis 578 \param maxMinor Maximum number of minor steps 579 580 \sa axisMaxMinor() 581 */ 582 void QwtPlot::setAxisMaxMinor( QwtAxisId axisId, int maxMinor ) 583 { 584 if ( isAxisValid( axisId ) ) 555 585 { 556 586 maxMinor = qBound( 0, maxMinor, 100 ); 557 587 558 AxisData &d = *d_axisData[axisId];588 AxisData& d = m_scaleData->axisData( axisId ); 559 589 if ( maxMinor != d.maxMinor ) 560 590 { … … 567 597 568 598 /*! 569 Set the maximum number of major scale intervals for a specified axis 570 571 \param axisId Axis index572 \param maxMajor Maximum number of major steps 573 574 \sa axisMaxMajor() 575 */ 576 void QwtPlot::setAxisMaxMajor( intaxisId, int maxMajor )577 { 578 if ( axisValid( axisId ) )599 Set the maximum number of major scale intervals for a specified axis 600 601 \param axisId Axis 602 \param maxMajor Maximum number of major steps 603 604 \sa axisMaxMajor() 605 */ 606 void QwtPlot::setAxisMaxMajor( QwtAxisId axisId, int maxMajor ) 607 { 608 if ( isAxisValid( axisId ) ) 579 609 { 580 610 maxMajor = qBound( 1, maxMajor, 10000 ); 581 611 582 AxisData &d = *d_axisData[axisId];612 AxisData& d = m_scaleData->axisData( axisId ); 583 613 if ( maxMajor != d.maxMajor ) 584 614 { … … 591 621 592 622 /*! 593 \brief Change the title of a specified axis 594 595 \param axisId Axis index596 \param title axis title 597 */ 598 void QwtPlot::setAxisTitle( intaxisId, const QString&title )599 { 600 if ( axisValid( axisId ) )623 \brief Change the title of a specified axis 624 625 \param axisId Axis 626 \param title axis title 627 */ 628 void QwtPlot::setAxisTitle( QwtAxisId axisId, const QString& title ) 629 { 630 if ( isAxisValid( axisId ) ) 601 631 axisWidget( axisId )->setTitle( title ); 602 632 } 603 633 604 634 /*! 605 \brief Change the title of a specified axis 606 607 \param axisId Axis index608 \param title Axis title 609 */ 610 void QwtPlot::setAxisTitle( intaxisId, const QwtText&title )611 { 612 if ( axisValid( axisId ) )635 \brief Change the title of a specified axis 636 637 \param axisId Axis 638 \param title Axis title 639 */ 640 void QwtPlot::setAxisTitle( QwtAxisId axisId, const QwtText& title ) 641 { 642 if ( isAxisValid( axisId ) ) 613 643 axisWidget( axisId )->setTitle( title ); 614 644 } 615 645 616 646 /*! 617 \brief Rebuild the axes scales 618 619 In case of autoscaling the boundaries of a scale are calculated 620 from the bounding rectangles of all plot items, having the 621 QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ). 622 Then a scale division is calculated ( QwtScaleEngine::didvideScale() ) 623 and assigned to scale widget. 624 625 When the scale boundaries have been assigned with setAxisScale() a 626 scale division is calculated ( QwtScaleEngine::didvideScale() ) 627 for this interval and assigned to the scale widget. 628 629 When the scale has been set explicitly by setAxisScaleDiv() the 630 locally stored scale division gets assigned to the scale widget. 631 632 The scale widget indicates modifications by emitting a 633 QwtScaleWidget::scaleDivChanged() signal. 634 635 updateAxes() is usually called by replot(). 636 637 \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot() 647 \brief Rebuild the axes scales 648 649 In case of autoscaling the boundaries of a scale are calculated 650 from the bounding rectangles of all plot items, having the 651 QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ). 652 Then a scale division is calculated ( QwtScaleEngine::didvideScale() ) 653 and assigned to scale widget. 654 655 When the scale boundaries have been assigned with setAxisScale() a 656 scale division is calculated ( QwtScaleEngine::didvideScale() ) 657 for this interval and assigned to the scale widget. 658 659 When the scale has been set explicitly by setAxisScaleDiv() the 660 locally stored scale division gets assigned to the scale widget. 661 662 The scale widget indicates modifications by emitting a 663 QwtScaleWidget::scaleDivChanged() signal. 664 665 updateAxes() is usually called by replot(). 666 667 \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot() 638 668 QwtPlotItem::boundingRect() 639 669 */ … … 643 673 // for all axes, where autoscaling is enabled 644 674 645 QwtInterval intv[axisCnt];675 QwtInterval boundingIntervals[QwtAxis::AxisPositions]; 646 676 647 677 const QwtPlotItemList& itmList = itemList(); … … 650 680 for ( it = itmList.begin(); it != itmList.end(); ++it ) 651 681 { 652 const QwtPlotItem *item = *it;682 const QwtPlotItem* item = *it; 653 683 654 684 if ( !item->testItemAttribute( QwtPlotItem::AutoScale ) ) … … 658 688 continue; 659 689 660 if ( axisAutoScale( item->xAxis() ) || axisAutoScale( item->yAxis() ) ) 690 const QwtAxisId xAxis = item->xAxis(); 691 const QwtAxisId yAxis = item->yAxis(); 692 693 if ( axisAutoScale( xAxis ) || axisAutoScale( yAxis ) ) 661 694 { 662 695 const QRectF rect = item->boundingRect(); 663 696 664 if ( rect.width() >= 0.0 ) 665 intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );666 667 if ( rect.height() >= 0.0 ) 668 intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() );697 if ( axisAutoScale( xAxis ) && rect.width() >= 0.0 ) 698 boundingIntervals[xAxis] |= QwtInterval( rect.left(), rect.right() ); 699 700 if ( axisAutoScale( yAxis ) && rect.height() >= 0.0 ) 701 boundingIntervals[yAxis] |= QwtInterval( rect.top(), rect.bottom() ); 669 702 } 670 703 } … … 672 705 // Adjust scales 673 706 674 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 675 { 676 AxisData &d = *d_axisData[axisId]; 677 678 double minValue = d.minValue; 679 double maxValue = d.maxValue; 680 double stepSize = d.stepSize; 681 682 if ( d.doAutoScale && intv[axisId].isValid() ) 707 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 708 { 683 709 { 684 d.isValid = false; 685 686 minValue = intv[axisId].minValue(); 687 maxValue = intv[axisId].maxValue(); 688 689 d.scaleEngine->autoScale( d.maxMajor, 690 minValue, maxValue, stepSize ); 710 const QwtAxisId axisId( axisPos ); 711 712 AxisData& d = m_scaleData->axisData( axisId ); 713 714 double minValue = d.minValue; 715 double maxValue = d.maxValue; 716 double stepSize = d.stepSize; 717 718 const QwtInterval& interval = boundingIntervals[axisId]; 719 720 if ( d.doAutoScale && interval.isValid() ) 721 { 722 d.isValid = false; 723 724 minValue = interval.minValue(); 725 maxValue = interval.maxValue(); 726 727 d.scaleEngine->autoScale( d.maxMajor, 728 minValue, maxValue, stepSize ); 729 } 730 if ( !d.isValid ) 731 { 732 d.scaleDiv = d.scaleEngine->divideScale( 733 minValue, maxValue, d.maxMajor, d.maxMinor, stepSize ); 734 d.isValid = true; 735 } 736 737 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 738 scaleWidget->setScaleDiv( d.scaleDiv ); 739 740 int startDist, endDist; 741 scaleWidget->getBorderDistHint( startDist, endDist ); 742 scaleWidget->setBorderDist( startDist, endDist ); 691 743 } 692 if ( !d.isValid )693 {694 d.scaleDiv = d.scaleEngine->divideScale(695 minValue, maxValue,696 d.maxMajor, d.maxMinor, stepSize );697 d.isValid = true;698 }699 700 QwtScaleWidget *scaleWidget = axisWidget( axisId );701 scaleWidget->setScaleDiv( d.scaleDiv );702 703 int startDist, endDist;704 scaleWidget->getBorderDistHint( startDist, endDist );705 scaleWidget->setBorderDist( startDist, endDist );706 744 } 707 745 708 746 for ( it = itmList.begin(); it != itmList.end(); ++it ) 709 747 { 710 QwtPlotItem *item = *it;748 QwtPlotItem* item = *it; 711 749 if ( item->testItemInterest( QwtPlotItem::ScaleInterest ) ) 712 750 { … … 716 754 } 717 755 } 718
Note:
See TracChangeset
for help on using the changeset viewer.
