Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot.cpp (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_scale_widget.h" 14 14 #include "qwt_scale_engine.h" 15 #include "qwt_scale_map.h" 15 16 #include "qwt_text_label.h" 16 17 #include "qwt_legend.h" 17 18 #include "qwt_legend_data.h" 18 19 #include "qwt_plot_canvas.h" 19 #include <qmath.h> 20 #include "qwt_math.h" 21 20 22 #include <qpainter.h> 21 23 #include <qpointer.h> 22 #include <qpaintengine.h>23 24 #include <qapplication.h> 24 #include <qevent.h> 25 26 static inline void qwtEnableLegendItems( QwtPlot *plot, bool on ) 27 { 25 #include <qcoreevent.h> 26 27 static inline void qwtEnableLegendItems( QwtPlot* plot, bool on ) 28 { 29 // gcc seems to have problems with const char sig[] in combination with certain options 30 const char* sig = SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)); 31 const char* slot = SLOT(updateLegendItems(QVariant,QList<QwtLegendData>)); 32 28 33 if ( on ) 29 { 30 QObject::connect( 31 plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)), 32 plot, SLOT(updateLegendItems(QVariant,QList<QwtLegendData>)) 33 ); 34 } 34 QObject::connect( plot, sig, plot, slot ); 35 35 else 36 { 37 QObject::disconnect( 38 plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>) ), 39 plot, SLOT( updateLegendItems(QVariant,QList<QwtLegendData>)) 40 ); 41 } 36 QObject::disconnect( plot, sig, plot, slot ); 42 37 } 43 38 44 39 static void qwtSetTabOrder( 45 QWidget *first, QWidget*second, bool withChildren )46 { 47 QList<QWidget *> tabChain;40 QWidget* first, QWidget* second, bool withChildren ) 41 { 42 QList< QWidget* > tabChain; 48 43 tabChain += first; 49 44 tabChain += second; … … 51 46 if ( withChildren ) 52 47 { 53 QList<QWidget *> children = second->findChildren<QWidget*>();54 55 QWidget *w = second->nextInFocusChain();48 QList< QWidget* > children = second->findChildren< QWidget* >(); 49 50 QWidget* w = second->nextInFocusChain(); 56 51 while ( children.contains( w ) ) 57 52 { … … 65 60 for ( int i = 0; i < tabChain.size() - 1; i++ ) 66 61 { 67 QWidget *from = tabChain[i];68 QWidget *to = tabChain[i+1];62 QWidget* from = tabChain[i]; 63 QWidget* to = tabChain[i + 1]; 69 64 70 65 const Qt::FocusPolicy policy1 = from->focusPolicy(); 71 66 const Qt::FocusPolicy policy2 = to->focusPolicy(); 72 67 73 QWidget *proxy1 = from->focusProxy();74 QWidget *proxy2 = to->focusProxy();68 QWidget* proxy1 = from->focusProxy(); 69 QWidget* proxy2 = to->focusProxy(); 75 70 76 71 from->setFocusPolicy( Qt::TabFocus ); … … 92 87 class QwtPlot::PrivateData 93 88 { 94 public: 95 QPointer<QwtTextLabel> titleLabel; 96 QPointer<QwtTextLabel> footerLabel; 97 QPointer< QWidget> canvas;98 QPointer<QwtAbstractLegend> legend; 99 QwtPlotLayout *layout;89 public: 90 QPointer< QwtTextLabel > titleLabel; 91 QPointer< QwtTextLabel > footerLabel; 92 QPointer< QWidget > canvas; 93 QPointer< QwtAbstractLegend > legend; 94 QwtPlotLayout* layout; 100 95 101 96 bool autoReplot; … … 103 98 104 99 /*! 105 \brief Constructor 106 \param parent Parent widget 107 */ 108 QwtPlot::QwtPlot( QWidget *parent ):109 QFrame( parent ) 100 \brief Constructor 101 \param parent Parent widget 102 */ 103 QwtPlot::QwtPlot( QWidget* parent ) 104 : QFrame( parent ) 110 105 { 111 106 initPlot( QwtText() ); … … 113 108 114 109 /*! 115 \brief Constructor 116 \param title Title text 117 \param parent Parent widget 118 */ 119 QwtPlot::QwtPlot( const QwtText &title, QWidget*parent ):120 QFrame( parent ) 110 \brief Constructor 111 \param title Title text 112 \param parent Parent widget 113 */ 114 QwtPlot::QwtPlot( const QwtText& title, QWidget* parent ) 115 : QFrame( parent ) 121 116 { 122 117 initPlot( title ); … … 129 124 detachItems( QwtPlotItem::Rtti_PlotItem, autoDelete() ); 130 125 131 delete d_data->layout;126 delete m_data->layout; 132 127 deleteAxesData(); 133 delete d_data;134 } 135 136 /*! 137 \brief Initializes a QwtPlot instance 138 \param title Title text 139 */ 140 void QwtPlot::initPlot( const QwtText &title )141 { 142 d_data = new PrivateData;143 144 d_data->layout = new QwtPlotLayout;145 d_data->autoReplot = false;128 delete m_data; 129 } 130 131 /*! 132 \brief Initializes a QwtPlot instance 133 \param title Title text 134 */ 135 void QwtPlot::initPlot( const QwtText& title ) 136 { 137 m_data = new PrivateData; 138 139 m_data->layout = new QwtPlotLayout; 140 m_data->autoReplot = false; 146 141 147 142 // title 148 d_data->titleLabel = new QwtTextLabel( this );149 d_data->titleLabel->setObjectName( "QwtPlotTitle" );150 d_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );143 m_data->titleLabel = new QwtTextLabel( this ); 144 m_data->titleLabel->setObjectName( "QwtPlotTitle" ); 145 m_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) ); 151 146 152 147 QwtText text( title ); 153 148 text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); 154 d_data->titleLabel->setText( text );149 m_data->titleLabel->setText( text ); 155 150 156 151 // footer 157 d_data->footerLabel = new QwtTextLabel( this );158 d_data->footerLabel->setObjectName( "QwtPlotFooter" );152 m_data->footerLabel = new QwtTextLabel( this ); 153 m_data->footerLabel->setObjectName( "QwtPlotFooter" ); 159 154 160 155 QwtText footer; 161 156 footer.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); 162 d_data->footerLabel->setText( footer );157 m_data->footerLabel->setText( footer ); 163 158 164 159 // legend 165 d_data->legend = NULL;166 167 // ax is160 m_data->legend = NULL; 161 162 // axes 168 163 initAxesData(); 169 164 170 165 // canvas 171 d_data->canvas = new QwtPlotCanvas( this );172 d_data->canvas->setObjectName( "QwtPlotCanvas" );173 d_data->canvas->installEventFilter( this );166 m_data->canvas = new QwtPlotCanvas( this ); 167 m_data->canvas->setObjectName( "QwtPlotCanvas" ); 168 m_data->canvas->installEventFilter( this ); 174 169 175 170 setSizePolicy( QSizePolicy::MinimumExpanding, … … 178 173 resize( 200, 200 ); 179 174 180 QList<QWidget *> focusChain; 181 focusChain << this << d_data->titleLabel << axisWidget( xTop ) 182 << axisWidget( yLeft ) << d_data->canvas << axisWidget( yRight ) 183 << axisWidget( xBottom ) << d_data->footerLabel; 175 using namespace QwtAxis; 176 177 QList< QWidget* > focusChain; 178 focusChain << this << m_data->titleLabel << axisWidget( XTop ) 179 << axisWidget( YLeft ) << m_data->canvas 180 << axisWidget( YRight ) << axisWidget( XBottom ) 181 << m_data->footerLabel; 184 182 185 183 for ( int i = 0; i < focusChain.size() - 1; i++ ) 186 qwtSetTabOrder( focusChain[i], focusChain[i +1], false );184 qwtSetTabOrder( focusChain[i], focusChain[i + 1], false ); 187 185 188 186 qwtEnableLegendItems( this, true ); … … 190 188 191 189 /*! 192 \brief Set the drawing canvas of the plot widget 193 194 QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ). 195 In opposite to using conventional C++ techniques like virtual methods 196 they allow to use canvas implementations that are derived from 197 QWidget or QGLWidget. 198 199 The following meta methods could be implemented: 200 201 - replot() 190 \brief Set the drawing canvas of the plot widget 191 192 QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ). 193 In opposite to using conventional C++ techniques like virtual methods 194 they allow to use canvas implementations that are derived from 195 QWidget or QGLWidget. 196 197 The following meta methods could be implemented: 198 199 - replot() 202 200 When the canvas doesn't offer a replot method, QwtPlot calls 203 201 update() instead. 204 202 205 - borderPath() 203 - borderPath() 206 204 The border path is necessary to clip the content of the canvas 207 205 When the canvas doesn't have any special border ( f.e rounded corners ) 208 206 it is o.k. not to implement this method. 209 207 210 The default canvas is a QwtPlotCanvas 211 212 \param canvas Canvas Widget 213 \sa canvas() 214 */ 215 void QwtPlot::setCanvas( QWidget *canvas )216 { 217 if ( canvas == d_data->canvas )208 The default canvas is a QwtPlotCanvas 209 210 \param canvas Canvas Widget 211 \sa canvas() 212 */ 213 void QwtPlot::setCanvas( QWidget* canvas ) 214 { 215 if ( canvas == m_data->canvas ) 218 216 return; 219 217 220 delete d_data->canvas;221 d_data->canvas = canvas;218 delete m_data->canvas; 219 m_data->canvas = canvas; 222 220 223 221 if ( canvas ) … … 232 230 233 231 /*! 234 \brief Adds handling of layout requests 235 \param event Event 236 237 \return See QFrame::event() 238 */ 239 bool QwtPlot::event( QEvent *event )232 \brief Adds handling of layout requests 233 \param event Event 234 235 \return See QFrame::event() 236 */ 237 bool QwtPlot::event( QEvent* event ) 240 238 { 241 239 bool ok = QFrame::event( event ); … … 254 252 255 253 /*! 256 \brief Event filter 257 258 The plot handles the following events for the canvas: 259 260 - QEvent::Resize 254 \brief Event filter 255 256 The plot handles the following events for the canvas: 257 258 - QEvent::Resize 261 259 The canvas margins might depend on its size 262 260 263 - QEvent::ContentsRectChange 261 - QEvent::ContentsRectChange 264 262 The layout needs to be recalculated 265 263 266 \param object Object to be filtered 267 \param event Event 268 269 \return See QFrame::eventFilter() 270 271 \sa updateCanvasMargins(), updateLayout() 272 */ 273 bool QwtPlot::eventFilter( QObject *object, QEvent*event )274 { 275 if ( object == d_data->canvas )264 \param object Object to be filtered 265 \param event Event 266 267 \return See QFrame::eventFilter() 268 269 \sa updateCanvasMargins(), updateLayout() 270 */ 271 bool QwtPlot::eventFilter( QObject* object, QEvent* event ) 272 { 273 if ( object == m_data->canvas ) 276 274 { 277 275 if ( event->type() == QEvent::Resize ) … … 291 289 void QwtPlot::autoRefresh() 292 290 { 293 if ( d_data->autoReplot )291 if ( m_data->autoReplot ) 294 292 replot(); 295 293 } 296 294 297 295 /*! 298 \brief Set or reset the autoReplot option 299 300 If the autoReplot option is set, the plot will be 301 updated implicitly by manipulating member functions. 302 Since this may be time-consuming, it is recommended 303 to leave this option switched off and call replot() 304 explicitly if necessary. 305 306 The autoReplot option is set to false by default, which 307 means that the user has to call replot() in order to make 308 changes visible. 309 \param tf \c true or \c false. Defaults to \c true. 310 \sa replot() 311 */ 296 \brief Set or reset the autoReplot option 297 298 If the autoReplot option is set, the plot will be 299 updated implicitly by manipulating member functions. 300 Since this may be time-consuming, it is recommended 301 to leave this option switched off and call replot() 302 explicitly if necessary. 303 304 The autoReplot option is set to false by default, which 305 means that the user has to call replot() in order to make 306 changes visible. 307 \param tf \c true or \c false. Defaults to \c true. 308 \sa replot() 309 */ 312 310 void QwtPlot::setAutoReplot( bool tf ) 313 311 { 314 d_data->autoReplot = tf;315 } 316 317 /*! 318 \return true if the autoReplot option is set. 319 \sa setAutoReplot() 320 */ 312 m_data->autoReplot = tf; 313 } 314 315 /*! 316 \return true if the autoReplot option is set. 317 \sa setAutoReplot() 318 */ 321 319 bool QwtPlot::autoReplot() const 322 320 { 323 return d_data->autoReplot;324 } 325 326 /*! 327 Change the plot's title 328 \param title New title 329 */ 330 void QwtPlot::setTitle( const QString &title )331 { 332 if ( title != d_data->titleLabel->text().text() )333 { 334 d_data->titleLabel->setText( title );321 return m_data->autoReplot; 322 } 323 324 /*! 325 Change the plot's title 326 \param title New title 327 */ 328 void QwtPlot::setTitle( const QString& title ) 329 { 330 if ( title != m_data->titleLabel->text().text() ) 331 { 332 m_data->titleLabel->setText( title ); 335 333 updateLayout(); 336 334 } … … 338 336 339 337 /*! 340 Change the plot's title 341 \param title New title 342 */ 343 void QwtPlot::setTitle( const QwtText &title )344 { 345 if ( title != d_data->titleLabel->text() )346 { 347 d_data->titleLabel->setText( title );338 Change the plot's title 339 \param title New title 340 */ 341 void QwtPlot::setTitle( const QwtText& title ) 342 { 343 if ( title != m_data->titleLabel->text() ) 344 { 345 m_data->titleLabel->setText( title ); 348 346 updateLayout(); 349 347 } … … 353 351 QwtText QwtPlot::title() const 354 352 { 355 return d_data->titleLabel->text();353 return m_data->titleLabel->text(); 356 354 } 357 355 358 356 //! \return Title label widget. 359 QwtTextLabel *QwtPlot::titleLabel()360 { 361 return d_data->titleLabel;357 QwtTextLabel* QwtPlot::titleLabel() 358 { 359 return m_data->titleLabel; 362 360 } 363 361 364 362 //! \return Title label widget. 365 const QwtTextLabel *QwtPlot::titleLabel() const366 { 367 return d_data->titleLabel;368 } 369 370 /*! 371 Change the text the footer 372 \param text New text of the footer 373 */ 374 void QwtPlot::setFooter( const QString &text )375 { 376 if ( text != d_data->footerLabel->text().text() )377 { 378 d_data->footerLabel->setText( text );363 const QwtTextLabel* QwtPlot::titleLabel() const 364 { 365 return m_data->titleLabel; 366 } 367 368 /*! 369 Change the text the footer 370 \param text New text of the footer 371 */ 372 void QwtPlot::setFooter( const QString& text ) 373 { 374 if ( text != m_data->footerLabel->text().text() ) 375 { 376 m_data->footerLabel->setText( text ); 379 377 updateLayout(); 380 378 } … … 382 380 383 381 /*! 384 Change the text the footer 385 \param text New text of the footer 386 */ 387 void QwtPlot::setFooter( const QwtText &text )388 { 389 if ( text != d_data->footerLabel->text() )390 { 391 d_data->footerLabel->setText( text );382 Change the text the footer 383 \param text New text of the footer 384 */ 385 void QwtPlot::setFooter( const QwtText& text ) 386 { 387 if ( text != m_data->footerLabel->text() ) 388 { 389 m_data->footerLabel->setText( text ); 392 390 updateLayout(); 393 391 } … … 397 395 QwtText QwtPlot::footer() const 398 396 { 399 return d_data->footerLabel->text();397 return m_data->footerLabel->text(); 400 398 } 401 399 402 400 //! \return Footer label widget. 403 QwtTextLabel *QwtPlot::footerLabel()404 { 405 return d_data->footerLabel;401 QwtTextLabel* QwtPlot::footerLabel() 402 { 403 return m_data->footerLabel; 406 404 } 407 405 408 406 //! \return Footer label widget. 409 const QwtTextLabel *QwtPlot::footerLabel() const410 { 411 return d_data->footerLabel;407 const QwtTextLabel* QwtPlot::footerLabel() const 408 { 409 return m_data->footerLabel; 412 410 } 413 411 … … 418 416 \sa plotLayout() 419 417 */ 420 void QwtPlot::setPlotLayout( QwtPlotLayout *layout )421 { 422 if ( layout != d_data->layout )423 { 424 delete d_data->layout;425 d_data->layout = layout;418 void QwtPlot::setPlotLayout( QwtPlotLayout* layout ) 419 { 420 if ( layout != m_data->layout ) 421 { 422 delete m_data->layout; 423 m_data->layout = layout; 426 424 427 425 updateLayout(); … … 430 428 431 429 //! \return the plot's layout 432 QwtPlotLayout *QwtPlot::plotLayout()433 { 434 return d_data->layout;430 QwtPlotLayout* QwtPlot::plotLayout() 431 { 432 return m_data->layout; 435 433 } 436 434 437 435 //! \return the plot's layout 438 const QwtPlotLayout *QwtPlot::plotLayout() const439 { 440 return d_data->layout;441 } 442 443 /*! 444 \return the plot's legend 445 \sa insertLegend() 446 */ 447 QwtAbstractLegend *QwtPlot::legend()448 { 449 return d_data->legend;450 } 451 452 /*! 453 \return the plot's legend 454 \sa insertLegend() 455 */ 456 const QwtAbstractLegend *QwtPlot::legend() const457 { 458 return d_data->legend;459 } 460 461 462 /*! 463 \return the plot's canvas 464 */ 465 QWidget *QwtPlot::canvas()466 { 467 return d_data->canvas;468 } 469 470 /*! 471 \return the plot's canvas 472 */ 473 const QWidget *QwtPlot::canvas() const474 { 475 return d_data->canvas;476 } 477 478 /*! 479 \return Size hint for the plot widget 480 \sa minimumSizeHint() 481 */ 436 const QwtPlotLayout* QwtPlot::plotLayout() const 437 { 438 return m_data->layout; 439 } 440 441 /*! 442 \return the plot's legend 443 \sa insertLegend() 444 */ 445 QwtAbstractLegend* QwtPlot::legend() 446 { 447 return m_data->legend; 448 } 449 450 /*! 451 \return the plot's legend 452 \sa insertLegend() 453 */ 454 const QwtAbstractLegend* QwtPlot::legend() const 455 { 456 return m_data->legend; 457 } 458 459 460 /*! 461 \return the plot's canvas 462 */ 463 QWidget* QwtPlot::canvas() 464 { 465 return m_data->canvas; 466 } 467 468 /*! 469 \return the plot's canvas 470 */ 471 const QWidget* QwtPlot::canvas() const 472 { 473 return m_data->canvas; 474 } 475 476 /*! 477 \return Size hint for the plot widget 478 \sa minimumSizeHint() 479 */ 482 480 QSize QwtPlot::sizeHint() const 483 481 { 484 482 int dw = 0; 485 483 int dh = 0; 486 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 487 { 488 if ( axisEnabled( axisId ) ) 489 { 490 const int niceDist = 40; 491 const QwtScaleWidget *scaleWidget = axisWidget( axisId ); 492 const QwtScaleDiv &scaleDiv = scaleWidget->scaleDraw()->scaleDiv(); 493 const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count(); 494 495 if ( axisId == yLeft || axisId == yRight ) 484 485 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 486 { 487 { 488 const QwtAxisId axisId( axisPos ); 489 490 if ( isAxisVisible( axisId ) ) 496 491 { 497 int hDiff = ( majCnt - 1 ) * niceDist 498 - scaleWidget->minimumSizeHint().height(); 499 if ( hDiff > dh ) 500 dh = hDiff; 492 const int niceDist = 40; 493 const QwtScaleWidget* scaleWidget = axisWidget( axisId ); 494 const QwtScaleDiv& scaleDiv = scaleWidget->scaleDraw()->scaleDiv(); 495 const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count(); 496 497 const QSize hint = scaleWidget->minimumSizeHint(); 498 499 if ( QwtAxis::isYAxis( axisPos ) ) 500 { 501 const int hDiff = ( majCnt - 1 ) * niceDist - hint.height(); 502 dh = qMax( dh, hDiff ); 503 } 504 else 505 { 506 const int wDiff = ( majCnt - 1 ) * niceDist - hint.width(); 507 dw = qMax( dw, wDiff ); 508 } 509 } 510 } 511 } 512 return minimumSizeHint() + QSize( dw, dh ); 513 } 514 515 /*! 516 \brief Return a minimum size hint 517 */ 518 QSize QwtPlot::minimumSizeHint() const 519 { 520 QSize hint = m_data->layout->minimumSizeHint( this ); 521 hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); 522 523 return hint; 524 } 525 526 /*! 527 Resize and update internal layout 528 \param e Resize event 529 */ 530 void QwtPlot::resizeEvent( QResizeEvent* e ) 531 { 532 QFrame::resizeEvent( e ); 533 updateLayout(); 534 } 535 536 /*! 537 \brief Redraw the plot 538 539 If the autoReplot option is not set (which is the default) 540 or if any curves are attached to raw data, the plot has to 541 be refreshed explicitly in order to make changes visible. 542 543 \sa updateAxes(), setAutoReplot() 544 */ 545 void QwtPlot::replot() 546 { 547 bool doAutoReplot = autoReplot(); 548 setAutoReplot( false ); 549 550 updateAxes(); 551 552 /* 553 Maybe the layout needs to be updated, because of changed 554 axes labels. We need to process them here before painting 555 to avoid that scales and canvas get out of sync. 556 */ 557 QApplication::sendPostedEvents( this, QEvent::LayoutRequest ); 558 559 if ( m_data->canvas ) 560 { 561 const bool ok = QMetaObject::invokeMethod( 562 m_data->canvas, "replot", Qt::DirectConnection ); 563 if ( !ok ) 564 { 565 // fallback, when canvas has no a replot method 566 m_data->canvas->update( m_data->canvas->contentsRect() ); 567 } 568 } 569 570 setAutoReplot( doAutoReplot ); 571 } 572 573 /*! 574 \brief Adjust plot content to its current size. 575 \sa resizeEvent() 576 */ 577 void QwtPlot::updateLayout() 578 { 579 QwtPlotLayout* layout = m_data->layout; 580 layout->activate( this, contentsRect() ); 581 582 const QRect titleRect = layout->titleRect().toRect(); 583 const QRect footerRect = layout->footerRect().toRect(); 584 const QRect legendRect = layout->legendRect().toRect(); 585 const QRect canvasRect = layout->canvasRect().toRect(); 586 587 // resize and show the visible widgets 588 589 if ( !m_data->titleLabel->text().isEmpty() ) 590 { 591 m_data->titleLabel->setGeometry( titleRect ); 592 if ( !m_data->titleLabel->isVisibleTo( this ) ) 593 m_data->titleLabel->show(); 594 } 595 else 596 m_data->titleLabel->hide(); 597 598 if ( !m_data->footerLabel->text().isEmpty() ) 599 { 600 m_data->footerLabel->setGeometry( footerRect ); 601 if ( !m_data->footerLabel->isVisibleTo( this ) ) 602 m_data->footerLabel->show(); 603 } 604 else 605 { 606 m_data->footerLabel->hide(); 607 } 608 609 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 610 { 611 { 612 const QwtAxisId axisId( axisPos ); 613 614 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 615 616 if ( isAxisVisible( axisId ) ) 617 { 618 const QRect scaleRect = layout->scaleRect( axisId ).toRect(); 619 620 if ( scaleRect != scaleWidget->geometry() ) 621 { 622 scaleWidget->setGeometry( scaleRect ); 623 624 int startDist, endDist; 625 scaleWidget->getBorderDistHint( startDist, endDist ); 626 scaleWidget->setBorderDist( startDist, endDist ); 627 } 628 629 if ( !scaleWidget->isVisibleTo( this ) ) 630 scaleWidget->show(); 501 631 } 502 632 else 503 633 { 504 int wDiff = ( majCnt - 1 ) * niceDist 505 - scaleWidget->minimumSizeHint().width(); 506 if ( wDiff > dw ) 507 dw = wDiff; 634 scaleWidget->hide(); 508 635 } 509 636 } 510 637 } 511 return minimumSizeHint() + QSize( dw, dh ); 512 } 513 514 /*! 515 \brief Return a minimum size hint 516 */ 517 QSize QwtPlot::minimumSizeHint() const 518 { 519 QSize hint = d_data->layout->minimumSizeHint( this ); 520 hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); 521 522 return hint; 523 } 524 525 /*! 526 Resize and update internal layout 527 \param e Resize event 528 */ 529 void QwtPlot::resizeEvent( QResizeEvent *e ) 530 { 531 QFrame::resizeEvent( e ); 532 updateLayout(); 533 } 534 535 /*! 536 \brief Redraw the plot 537 538 If the autoReplot option is not set (which is the default) 539 or if any curves are attached to raw data, the plot has to 540 be refreshed explicitly in order to make changes visible. 541 542 \sa updateAxes(), setAutoReplot() 543 */ 544 void QwtPlot::replot() 545 { 546 bool doAutoReplot = autoReplot(); 547 setAutoReplot( false ); 548 549 updateAxes(); 550 551 /* 552 Maybe the layout needs to be updated, because of changed 553 axes labels. We need to process them here before painting 554 to avoid that scales and canvas get out of sync. 555 */ 556 QApplication::sendPostedEvents( this, QEvent::LayoutRequest ); 557 558 if ( d_data->canvas ) 559 { 560 const bool ok = QMetaObject::invokeMethod( 561 d_data->canvas, "replot", Qt::DirectConnection ); 562 if ( !ok ) 563 { 564 // fallback, when canvas has no a replot method 565 d_data->canvas->update( d_data->canvas->contentsRect() ); 566 } 567 } 568 569 setAutoReplot( doAutoReplot ); 570 } 571 572 /*! 573 \brief Adjust plot content to its current size. 574 \sa resizeEvent() 575 */ 576 void QwtPlot::updateLayout() 577 { 578 d_data->layout->activate( this, contentsRect() ); 579 580 QRect titleRect = d_data->layout->titleRect().toRect(); 581 QRect footerRect = d_data->layout->footerRect().toRect(); 582 QRect scaleRect[QwtPlot::axisCnt]; 583 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 584 scaleRect[axisId] = d_data->layout->scaleRect( axisId ).toRect(); 585 QRect legendRect = d_data->layout->legendRect().toRect(); 586 QRect canvasRect = d_data->layout->canvasRect().toRect(); 587 588 // resize and show the visible widgets 589 590 if ( !d_data->titleLabel->text().isEmpty() ) 591 { 592 d_data->titleLabel->setGeometry( titleRect ); 593 if ( !d_data->titleLabel->isVisibleTo( this ) ) 594 d_data->titleLabel->show(); 595 } 596 else 597 d_data->titleLabel->hide(); 598 599 if ( !d_data->footerLabel->text().isEmpty() ) 600 { 601 d_data->footerLabel->setGeometry( footerRect ); 602 if ( !d_data->footerLabel->isVisibleTo( this ) ) 603 d_data->footerLabel->show(); 604 } 605 else 606 { 607 d_data->footerLabel->hide(); 608 } 609 610 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 611 { 612 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 613 614 if ( axisEnabled( axisId ) ) 615 { 616 if ( scaleRect[axisId] != scaleWidget->geometry() ) 617 { 618 scaleWidget->setGeometry( scaleRect[axisId] ); 619 620 int startDist, endDist; 621 scaleWidget->getBorderDistHint( startDist, endDist ); 622 scaleWidget->setBorderDist( startDist, endDist ); 623 } 624 625 #if 1 626 if ( axisId == xBottom || axisId == xTop ) 627 { 628 // do we need this code any longer ??? 629 630 QRegion r( scaleRect[axisId] ); 631 if ( axisEnabled( yLeft ) ) 632 r = r.subtracted( QRegion( scaleRect[yLeft] ) ); 633 if ( axisEnabled( yRight ) ) 634 r = r.subtracted( QRegion( scaleRect[yRight] ) ); 635 r.translate( -scaleRect[ axisId ].x(), 636 -scaleRect[axisId].y() ); 637 638 scaleWidget->setMask( r ); 639 } 640 #endif 641 if ( !scaleWidget->isVisibleTo( this ) ) 642 scaleWidget->show(); 638 639 if ( m_data->legend ) 640 { 641 if ( m_data->legend->isEmpty() ) 642 { 643 m_data->legend->hide(); 643 644 } 644 645 else 645 646 { 646 scaleWidget->hide(); 647 } 648 } 649 650 if ( d_data->legend ) 651 { 652 if ( d_data->legend->isEmpty() ) 653 { 654 d_data->legend->hide(); 655 } 656 else 657 { 658 d_data->legend->setGeometry( legendRect ); 659 d_data->legend->show(); 660 } 661 } 662 663 d_data->canvas->setGeometry( canvasRect ); 664 } 665 666 /*! 667 \brief Calculate the canvas margins 668 669 \param maps QwtPlot::axisCnt maps, mapping between plot and paint device coordinates 670 \param canvasRect Bounding rectangle where to paint 671 \param left Return parameter for the left margin 672 \param top Return parameter for the top margin 673 \param right Return parameter for the right margin 674 \param bottom Return parameter for the bottom margin 675 676 Plot items might indicate, that they need some extra space 677 at the borders of the canvas by the QwtPlotItem::Margins flag. 678 679 updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint() 647 m_data->legend->setGeometry( legendRect ); 648 m_data->legend->show(); 649 } 650 } 651 652 m_data->canvas->setGeometry( canvasRect ); 653 } 654 655 /*! 656 \brief Calculate the canvas margins 657 658 \param maps QwtAxis::AxisCount maps, mapping between plot and paint device coordinates 659 \param canvasRect Bounding rectangle where to paint 660 \param left Return parameter for the left margin 661 \param top Return parameter for the top margin 662 \param right Return parameter for the right margin 663 \param bottom Return parameter for the bottom margin 664 665 Plot items might indicate, that they need some extra space 666 at the borders of the canvas by the QwtPlotItem::Margins flag. 667 668 updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint() 680 669 */ 681 670 void QwtPlot::getCanvasMarginsHint( 682 const QwtScaleMap maps[], const QRectF &canvasRect,683 double &left, double&top, double&right, double&bottom) const671 const QwtScaleMap maps[], const QRectF& canvasRect, 672 double& left, double& top, double& right, double& bottom) const 684 673 { 685 674 left = top = right = bottom = -1.0; … … 689 678 it != itmList.end(); ++it ) 690 679 { 691 const QwtPlotItem *item = *it;680 const QwtPlotItem* item = *it; 692 681 if ( item->testItemAttribute( QwtPlotItem::Margins ) ) 693 682 { 694 double m[ QwtPlot::axisCnt ]; 683 using namespace QwtAxis; 684 685 double m[ AxisPositions ]; 695 686 item->getCanvasMarginHint( 696 687 maps[ item->xAxis() ], maps[ item->yAxis() ], 697 canvasRect, m[ yLeft], m[xTop], m[yRight], m[xBottom] );698 699 left = q Max( left, m[yLeft] );700 top = q Max( top, m[xTop] );701 right = q Max( right, m[yRight] );702 bottom = q Max( bottom, m[xBottom] );703 } 704 } 705 } 706 707 /*! 708 \brief Update the canvas margins 709 710 Plot items might indicate, that they need some extra space 711 at the borders of the canvas by the QwtPlotItem::Margins flag. 712 713 getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint() 688 canvasRect, m[YLeft], m[XTop], m[YRight], m[XBottom] ); 689 690 left = qwtMaxF( left, m[YLeft] ); 691 top = qwtMaxF( top, m[XTop] ); 692 right = qwtMaxF( right, m[YRight] ); 693 bottom = qwtMaxF( bottom, m[XBottom] ); 694 } 695 } 696 } 697 698 /*! 699 \brief Update the canvas margins 700 701 Plot items might indicate, that they need some extra space 702 at the borders of the canvas by the QwtPlotItem::Margins flag. 703 704 getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint() 714 705 */ 715 706 void QwtPlot::updateCanvasMargins() 716 707 { 717 QwtScaleMap maps[axisCnt]; 718 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 708 using namespace QwtAxis; 709 710 QwtScaleMap maps[ AxisPositions ]; 711 for ( int axisId = 0; axisId < AxisPositions; axisId++ ) 719 712 maps[axisId] = canvasMap( axisId ); 720 713 721 double margins[ axisCnt];714 double margins[AxisPositions]; 722 715 getCanvasMarginsHint( maps, canvas()->contentsRect(), 723 margins[ yLeft], margins[xTop], margins[yRight], margins[xBottom] );716 margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] ); 724 717 725 718 bool doUpdate = false; 726 for ( int axis Id= 0; axisId < axisCnt; axisId++ )727 { 728 if ( margins[axis Id] >= 0.0 )729 { 730 const int m = qCeil( margins[axis Id] );731 plotLayout()->setCanvasMargin( m, axis Id);719 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 720 { 721 if ( margins[axisPos] >= 0.0 ) 722 { 723 const int m = qwtCeil( margins[axisPos] ); 724 plotLayout()->setCanvasMargin( m, axisPos); 732 725 doUpdate = true; 733 726 } … … 739 732 740 733 /*! 741 Redraw the canvas. 742 \param painter Painter used for drawing 743 744 \warning drawCanvas calls drawItems what is also used 734 Redraw the canvas. 735 \param painter Painter used for drawing 736 737 \warning drawCanvas calls drawItems what is also used 745 738 for printing. Applications that like to add individual 746 739 plot items better overload drawItems() 747 \sa drawItems() 748 */ 749 void QwtPlot::drawCanvas( QPainter *painter )750 { 751 QwtScaleMap maps[ axisCnt];752 for ( int axis Id= 0; axisId < axisCnt; axisId++ )753 maps[axis Id] = canvasMap( axisId);754 755 drawItems( painter, d_data->canvas->contentsRect(), maps );756 } 757 758 /*! 759 Redraw the canvas items. 760 761 \param painter Painter used for drawing 762 \param canvasRect Bounding rectangle where to paint 763 \param maps Qwt Plot::axisCnt maps, mapping between plot and paint device coordinates764 765 \note Usually canvasRect is contentsRect() of the plot canvas. 740 \sa drawItems() 741 */ 742 void QwtPlot::drawCanvas( QPainter* painter ) 743 { 744 QwtScaleMap maps[ QwtAxis::AxisPositions ]; 745 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 746 maps[axisPos] = canvasMap( axisPos ); 747 748 drawItems( painter, m_data->canvas->contentsRect(), maps ); 749 } 750 751 /*! 752 Redraw the canvas items. 753 754 \param painter Painter used for drawing 755 \param canvasRect Bounding rectangle where to paint 756 \param maps QwtAxis::AxisCount maps, mapping between plot and paint device coordinates 757 758 \note Usually canvasRect is contentsRect() of the plot canvas. 766 759 Due to a bug in Qt this rectangle might be wrong for certain 767 760 frame styles ( f.e QFrame::Box ) and it might be necessary to 768 761 fix the margins manually using QWidget::setContentsMargins() 769 */ 770 771 void QwtPlot::drawItems( QPainter *painter, const QRectF&canvasRect,772 const QwtScaleMap maps[axisCnt] ) const762 */ 763 764 void QwtPlot::drawItems( QPainter* painter, const QRectF& canvasRect, 765 const QwtScaleMap maps[ QwtAxis::AxisPositions ] ) const 773 766 { 774 767 const QwtPlotItemList& itmList = itemList(); … … 776 769 it != itmList.end(); ++it ) 777 770 { 778 QwtPlotItem *item = *it;771 QwtPlotItem* item = *it; 779 772 if ( item && item->isVisible() ) 780 773 { 774 const QwtAxisId xAxis = item->xAxis(); 775 const QwtAxisId yAxis = item->yAxis(); 776 781 777 painter->save(); 782 778 783 779 painter->setRenderHint( QPainter::Antialiasing, 784 780 item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 781 782 #if QT_VERSION < 0x050100 785 783 painter->setRenderHint( QPainter::HighQualityAntialiasing, 786 784 item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 787 788 item->draw( painter, 789 maps[item->xAxis()], maps[item->yAxis()], 790 canvasRect ); 785 #endif 786 787 item->draw( painter, maps[xAxis], maps[yAxis], canvasRect ); 791 788 792 789 painter->restore(); … … 796 793 797 794 /*! 798 \param axisId Axis 799 \return Map for the axis on the canvas. With this map pixel coordinates can 795 \param axisId Axis 796 \return Map for the axis on the canvas. With this map pixel coordinates can 800 797 translated to plot coordinates and vice versa. 801 \sa QwtScaleMap, transform(), invTransform() 802 803 */ 804 QwtScaleMap QwtPlot::canvasMap( int axisId ) const 798 \sa QwtScaleMap, transform(), invTransform() 799 */ 800 QwtScaleMap QwtPlot::canvasMap( QwtAxisId axisId ) const 805 801 { 806 802 QwtScaleMap map; 807 if ( ! d_data->canvas )803 if ( !m_data->canvas ) 808 804 return map; 809 805 810 806 map.setTransformation( axisScaleEngine( axisId )->transformation() ); 811 807 812 const QwtScaleDiv &sd = axisScaleDiv( axisId );808 const QwtScaleDiv& sd = axisScaleDiv( axisId ); 813 809 map.setScaleInterval( sd.lowerBound(), sd.upperBound() ); 814 810 815 if ( axisEnabled( axisId ) )816 { 817 const QwtScaleWidget *s = axisWidget( axisId );818 if ( axisId == yLeft ||axisId== yRight)819 { 820 double y = s->y() + s->startBorderDist() - d_data->canvas->y();811 if ( isAxisVisible( axisId ) ) 812 { 813 const QwtScaleWidget* s = axisWidget( axisId ); 814 if ( QwtAxis::isYAxis( axisId ) ) 815 { 816 double y = s->y() + s->startBorderDist() - m_data->canvas->y(); 821 817 double h = s->height() - s->startBorderDist() - s->endBorderDist(); 822 818 map.setPaintInterval( y + h, y ); … … 824 820 else 825 821 { 826 double x = s->x() + s->startBorderDist() - d_data->canvas->x();822 double x = s->x() + s->startBorderDist() - m_data->canvas->x(); 827 823 double w = s->width() - s->startBorderDist() - s->endBorderDist(); 828 824 map.setPaintInterval( x, x + w ); … … 831 827 else 832 828 { 833 const QRect &canvasRect = d_data->canvas->contentsRect(); 834 if ( axisId == yLeft || axisId == yRight ) 829 using namespace QwtAxis; 830 831 const QRect& canvasRect = m_data->canvas->contentsRect(); 832 if ( isYAxis( axisId ) ) 835 833 { 836 834 int top = 0; 837 if ( !plotLayout()->alignCanvasToScale( xTop ) )838 top = plotLayout()->canvasMargin( xTop );835 if ( !plotLayout()->alignCanvasToScale( XTop ) ) 836 top = plotLayout()->canvasMargin( XTop ); 839 837 840 838 int bottom = 0; 841 if ( !plotLayout()->alignCanvasToScale( xBottom ) )842 bottom = plotLayout()->canvasMargin( xBottom );839 if ( !plotLayout()->alignCanvasToScale( XBottom ) ) 840 bottom = plotLayout()->canvasMargin( XBottom ); 843 841 844 842 map.setPaintInterval( canvasRect.bottom() - bottom, … … 848 846 { 849 847 int left = 0; 850 if ( !plotLayout()->alignCanvasToScale( yLeft ) )851 left = plotLayout()->canvasMargin( yLeft );848 if ( !plotLayout()->alignCanvasToScale( YLeft ) ) 849 left = plotLayout()->canvasMargin( YLeft ); 852 850 853 851 int right = 0; 854 if ( !plotLayout()->alignCanvasToScale( yRight ) )855 right = plotLayout()->canvasMargin( yRight );852 if ( !plotLayout()->alignCanvasToScale( YRight ) ) 853 right = plotLayout()->canvasMargin( YRight ); 856 854 857 855 map.setPaintInterval( canvasRect.left() + left, … … 864 862 865 863 /*! 866 \brief Change the background of the plotting area 867 868 Sets brush to QPalette::Window of all color groups of 869 the palette of the canvas. Using canvas()->setPalette() 870 is a more powerful way to set these colors. 871 872 \param brush New background brush 873 \sa canvasBackground() 874 */ 875 void QwtPlot::setCanvasBackground( const QBrush &brush )876 { 877 QPalette pal = d_data->canvas->palette();864 \brief Change the background of the plotting area 865 866 Sets brush to QPalette::Window of all color groups of 867 the palette of the canvas. Using canvas()->setPalette() 868 is a more powerful way to set these colors. 869 870 \param brush New background brush 871 \sa canvasBackground() 872 */ 873 void QwtPlot::setCanvasBackground( const QBrush& brush ) 874 { 875 QPalette pal = m_data->canvas->palette(); 878 876 pal.setBrush( QPalette::Window, brush ); 879 877 … … 882 880 883 881 /*! 884 Nothing else than: canvas()->palette().brush( 882 Nothing else than: canvas()->palette().brush( 885 883 QPalette::Normal, QPalette::Window); 886 884 887 \return Background brush of the plotting area. 888 \sa setCanvasBackground() 889 */ 885 \return Background brush of the plotting area. 886 \sa setCanvasBackground() 887 */ 890 888 QBrush QwtPlot::canvasBackground() const 891 889 { … … 895 893 896 894 /*! 897 \return \c true if the specified axis exists, otherwise \c false 898 \param axisId axis index 899 */ 900 bool QwtPlot::axisValid( int axisId ) 901 { 902 return ( ( axisId >= QwtPlot::yLeft ) && ( axisId < QwtPlot::axisCnt ) ); 903 } 904 905 /*! 906 \brief Insert a legend 907 908 If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend 909 the legend will be organized in one column from top to down. 910 Otherwise the legend items will be placed in a table 911 with a best fit number of columns from left to right. 912 913 insertLegend() will set the plot widget as parent for the legend. 914 The legend will be deleted in the destructor of the plot or when 915 another legend is inserted. 916 917 Legends, that are not inserted into the layout of the plot widget 918 need to connect to the legendDataChanged() signal. Calling updateLegend() 919 initiates this signal for an initial update. When the application code 920 wants to implement its own layout this also needs to be done for 921 rendering plots to a document ( see QwtPlotRenderer ). 922 923 \param legend Legend 924 \param pos The legend's position. For top/left position the number 895 \brief Insert a legend 896 897 If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend 898 the legend will be organized in one column from top to down. 899 Otherwise the legend items will be placed in a table 900 with a best fit number of columns from left to right. 901 902 insertLegend() will set the plot widget as parent for the legend. 903 The legend will be deleted in the destructor of the plot or when 904 another legend is inserted. 905 906 Legends, that are not inserted into the layout of the plot widget 907 need to connect to the legendDataChanged() signal. Calling updateLegend() 908 initiates this signal for an initial update. When the application code 909 wants to implement its own layout this also needs to be done for 910 rendering plots to a document ( see QwtPlotRenderer ). 911 912 \param legend Legend 913 \param pos The legend's position. For top/left position the number 925 914 of columns will be limited to 1, otherwise it will be set to 926 915 unlimited. 927 916 928 \param ratio Ratio between legend and the bounding rectangle 917 \param ratio Ratio between legend and the bounding rectangle 929 918 of title, canvas and axes. The legend will be shrunk 930 919 if it would need more space than the given ratio. … … 933 922 The default vertical/horizontal ratio is 0.33/0.5. 934 923 935 \sa legend(), QwtPlotLayout::legendPosition(), 924 \sa legend(), QwtPlotLayout::legendPosition(), 936 925 QwtPlotLayout::setLegendPosition() 937 */ 938 void QwtPlot::insertLegend( QwtAbstractLegend *legend,926 */ 927 void QwtPlot::insertLegend( QwtAbstractLegend* legend, 939 928 QwtPlot::LegendPosition pos, double ratio ) 940 929 { 941 d_data->layout->setLegendPosition( pos, ratio );942 943 if ( legend != d_data->legend )944 { 945 if ( d_data->legend &&d_data->legend->parent() == this )946 delete d_data->legend;947 948 d_data->legend = legend;949 950 if ( d_data->legend )930 m_data->layout->setLegendPosition( pos, ratio ); 931 932 if ( legend != m_data->legend ) 933 { 934 if ( m_data->legend && m_data->legend->parent() == this ) 935 delete m_data->legend; 936 937 m_data->legend = legend; 938 939 if ( m_data->legend ) 951 940 { 952 941 connect( 953 942 this, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)), 954 d_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>))955 ); 956 957 if ( d_data->legend->parent() != this )958 d_data->legend->setParent( this );943 m_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>)) 944 ); 945 946 if ( m_data->legend->parent() != this ) 947 m_data->legend->setParent( this ); 959 948 960 949 qwtEnableLegendItems( this, false ); … … 962 951 qwtEnableLegendItems( this, true ); 963 952 964 QwtLegend *lgd = qobject_cast<QwtLegend*>( legend );953 QwtLegend* lgd = qobject_cast< QwtLegend* >( legend ); 965 954 if ( lgd ) 966 955 { 967 switch ( d_data->layout->legendPosition() )956 switch ( m_data->layout->legendPosition() ) 968 957 { 969 958 case LeftLegend: … … 985 974 } 986 975 987 QWidget *previousInChain = NULL;988 switch ( d_data->layout->legendPosition() )976 QWidget* previousInChain = NULL; 977 switch ( m_data->layout->legendPosition() ) 989 978 { 990 979 case LeftLegend: 991 980 { 992 previousInChain = axisWidget( QwtPlot::xTop ); 981 const QwtAxisId axisId( QwtAxis::XTop ); 982 previousInChain = axisWidget( axisId ); 993 983 break; 994 984 } … … 1000 990 case RightLegend: 1001 991 { 1002 previousInChain = axisWidget( QwtPlot::yRight ); 992 const QwtAxisId axisId( QwtAxis::YRight ); 993 previousInChain = axisWidget( axisId ); 1003 994 break; 1004 995 } … … 1019 1010 1020 1011 /*! 1021 Emit legendDataChanged() for all plot item 1022 1023 \sa QwtPlotItem::legendData(), legendDataChanged() 1012 Emit legendDataChanged() for all plot item 1013 1014 \sa QwtPlotItem::legendData(), legendDataChanged() 1024 1015 */ 1025 1016 void QwtPlot::updateLegend() … … 1034 1025 1035 1026 /*! 1036 Emit legendDataChanged() for a plot item 1037 1038 \param plotItem Plot item 1039 \sa QwtPlotItem::legendData(), legendDataChanged() 1040 */ 1041 void QwtPlot::updateLegend( const QwtPlotItem *plotItem )1027 Emit legendDataChanged() for a plot item 1028 1029 \param plotItem Plot item 1030 \sa QwtPlotItem::legendData(), legendDataChanged() 1031 */ 1032 void QwtPlot::updateLegend( const QwtPlotItem* plotItem ) 1042 1033 { 1043 1034 if ( plotItem == NULL ) 1044 1035 return; 1045 1036 1046 QList<QwtLegendData> legendData; 1037 QList< QwtLegendData > legendData; 1047 1038 1048 1039 if ( plotItem->testItemAttribute( QwtPlotItem::Legend ) ) 1049 1040 legendData = plotItem->legendData(); 1050 1041 1051 const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem *>( plotItem) );1042 const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem* >( plotItem ) ); 1052 1043 Q_EMIT legendDataChanged( itemInfo, legendData ); 1053 1044 } 1054 1045 1055 1046 /*! 1056 \brief Update all plot items interested in legend attributes 1057 1058 Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest 1059 flag is set. 1060 1061 \param itemInfo Info about the plot item 1062 \param legendData Entries to be displayed for the plot item ( usually 1 ) 1063 1064 \sa QwtPlotItem::LegendInterest, 1047 \brief Update all plot items interested in legend attributes 1048 1049 Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest 1050 flag is set. 1051 1052 \param itemInfo Info about the plot item 1053 \param legendData Entries to be displayed for the plot item ( usually 1 ) 1054 1055 \sa QwtPlotItem::LegendInterest, 1065 1056 QwtPlotLegendItem, QwtPlotItem::updateLegend() 1066 1057 */ 1067 void QwtPlot::updateLegendItems( const QVariant &itemInfo,1068 const QList<QwtLegendData > &legendData )1069 { 1070 QwtPlotItem *plotItem = infoToItem( itemInfo );1058 void QwtPlot::updateLegendItems( const QVariant& itemInfo, 1059 const QList< QwtLegendData >& legendData ) 1060 { 1061 QwtPlotItem* plotItem = infoToItem( itemInfo ); 1071 1062 if ( plotItem ) 1072 1063 { … … 1075 1066 it != itmList.end(); ++it ) 1076 1067 { 1077 QwtPlotItem *item = *it;1068 QwtPlotItem* item = *it; 1078 1069 if ( item->testItemInterest( QwtPlotItem::LegendInterest ) ) 1079 1070 item->updateLegend( plotItem, legendData ); … … 1083 1074 1084 1075 /*! 1085 \brief Attach/Detach a plot item 1086 1087 \param plotItem Plot item 1088 \param on When true attach the item, otherwise detach it 1089 */ 1090 void QwtPlot::attachItem( QwtPlotItem *plotItem, bool on )1076 \brief Attach/Detach a plot item 1077 1078 \param plotItem Plot item 1079 \param on When true attach the item, otherwise detach it 1080 */ 1081 void QwtPlot::attachItem( QwtPlotItem* plotItem, bool on ) 1091 1082 { 1092 1083 if ( plotItem->testItemInterest( QwtPlotItem::LegendInterest ) ) … … 1098 1089 it != itmList.end(); ++it ) 1099 1090 { 1100 QwtPlotItem *item = *it;1101 1102 QList<QwtLegendData> legendData; 1091 QwtPlotItem* item = *it; 1092 1093 QList< QwtLegendData > legendData; 1103 1094 if ( on && item->testItemAttribute( QwtPlotItem::Legend ) ) 1104 1095 { … … 1127 1118 { 1128 1119 const QVariant itemInfo = itemToInfo( plotItem ); 1129 Q_EMIT legendDataChanged( itemInfo, QList<QwtLegendData>() ); 1120 Q_EMIT legendDataChanged( itemInfo, QList< QwtLegendData >() ); 1130 1121 } 1131 1122 } … … 1135 1126 1136 1127 /*! 1137 \brief Build an information, that can be used to identify 1128 \brief Build an information, that can be used to identify 1138 1129 a plot item on the legend. 1139 1130 1140 The default implementation simply wraps the plot item 1141 into a QVariant object. When overloading itemToInfo() 1142 usually infoToItem() needs to reimplemeted too. 1143 1144 \code 1145 QVariant itemInfo; 1146 qVariantSetValue( itemInfo, plotItem ); 1147 \endcode 1148 1149 \param plotItem Plot item 1150 \return Plot item embedded in a QVariant 1151 \sa infoToItem() 1152 */ 1153 QVariant QwtPlot::itemToInfo( QwtPlotItem *plotItem ) const 1154 { 1155 QVariant itemInfo; 1156 qVariantSetValue( itemInfo, plotItem ); 1157 1158 return itemInfo; 1159 } 1160 1161 /*! 1162 \brief Identify the plot item according to an item info object, 1131 The default implementation simply wraps the plot item 1132 into a QVariant object. When overloading itemToInfo() 1133 usually infoToItem() needs to reimplemeted too. 1134 1135 \param plotItem Plot item 1136 \return Plot item embedded in a QVariant 1137 \sa infoToItem() 1138 */ 1139 QVariant QwtPlot::itemToInfo( QwtPlotItem* plotItem ) const 1140 { 1141 return QVariant::fromValue( plotItem ); 1142 } 1143 1144 /*! 1145 \brief Identify the plot item according to an item info object, 1163 1146 that has bee generated from itemToInfo(). 1164 1147 1165 The default implementation simply tries to unwrap a QwtPlotItem 1166 pointer: 1167 1168 \code 1148 The default implementation simply tries to unwrap a QwtPlotItem 1149 pointer: 1150 1151 \code 1169 1152 if ( itemInfo.canConvert<QwtPlotItem *>() ) 1170 1153 return qvariant_cast<QwtPlotItem *>( itemInfo ); 1171 \endcode 1172 \param itemInfo Plot item 1173 \return A plot item, when successful, otherwise a NULL pointer. 1174 \sa itemToInfo() 1175 */ 1176 QwtPlotItem *QwtPlot::infoToItem( const QVariant&itemInfo ) const1177 { 1178 if ( itemInfo.canConvert<QwtPlotItem *>() )1179 return qvariant_cast<QwtPlotItem *>( itemInfo );1154 \endcode 1155 \param itemInfo Plot item 1156 \return A plot item, when successful, otherwise a NULL pointer. 1157 \sa itemToInfo() 1158 */ 1159 QwtPlotItem* QwtPlot::infoToItem( const QVariant& itemInfo ) const 1160 { 1161 if ( itemInfo.canConvert< QwtPlotItem* >() ) 1162 return qvariant_cast< QwtPlotItem* >( itemInfo ); 1180 1163 1181 1164 return NULL; 1182 1165 } 1183 1166 1184 1167 #include "moc_qwt_plot.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
