Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_item.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_item.cpp
r4271 r8127 11 11 #include "qwt_text.h" 12 12 #include "qwt_plot.h" 13 #include "qwt_legend.h" 14 #include "qwt_legend_item.h" 13 #include "qwt_legend_data.h" 15 14 #include "qwt_scale_div.h" 15 #include "qwt_graphic.h" 16 16 #include <qpainter.h> 17 17 … … 23 23 isVisible( true ), 24 24 attributes( 0 ), 25 interests( 0 ), 25 26 renderHints( 0 ), 27 renderThreadCount( 1 ), 26 28 z( 0.0 ), 27 29 xAxis( QwtPlot::xBottom ), 28 yAxis( QwtPlot::yLeft ) 30 yAxis( QwtPlot::yLeft ), 31 legendIconSize( 8, 8 ) 29 32 { 30 33 } … … 33 36 34 37 bool isVisible; 38 35 39 QwtPlotItem::ItemAttributes attributes; 40 QwtPlotItem::ItemInterests interests; 41 36 42 QwtPlotItem::RenderHints renderHints; 43 uint renderThreadCount; 44 37 45 double z; 38 46 … … 41 49 42 50 QwtText title; 51 QSize legendIconSize; 43 52 }; 44 53 … … 76 85 return; 77 86 78 // remove the item from the previous plot79 80 87 if ( d_data->plot ) 81 {82 if ( d_data->plot->legend() )83 d_data->plot->legend()->remove( this );84 85 88 d_data->plot->attachItem( this, false ); 86 89 87 if ( d_data->plot->autoReplot() )88 d_data->plot->update();89 }90 91 90 d_data->plot = plot; 92 91 93 92 if ( d_data->plot ) 94 {95 // insert the item into the current plot96 97 93 d_data->plot->attachItem( this, true ); 98 itemChanged();99 }100 94 } 101 95 … … 191 185 { 192 186 d_data->title = title; 193 itemChanged(); 187 188 legendChanged(); 189 #if 0 190 itemChanged(); 191 #endif 194 192 } 195 193 } … … 210 208 \param on true/false 211 209 212 \sa testItemAttribute(), Item Attribute210 \sa testItemAttribute(), ItemInterest 213 211 */ 214 212 void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on ) 215 213 { 216 if ( bool( d_data->attributes &attribute ) != on )214 if ( d_data->attributes.testFlag( attribute ) != on ) 217 215 { 218 216 if ( on ) … … 221 219 d_data->attributes &= ~attribute; 222 220 221 if ( attribute == QwtPlotItem::Legend ) 222 legendChanged(); 223 223 224 itemChanged(); 224 225 } … … 230 231 \param attribute Attribute type 231 232 \return true/false 232 \sa setItemAttribute(), Item Attribute233 \sa setItemAttribute(), ItemInterest 233 234 */ 234 235 bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const 235 236 { 236 return ( d_data->attributes & attribute ); 237 return d_data->attributes.testFlag( attribute ); 238 } 239 240 /*! 241 Toggle an item interest 242 243 \param interest Interest type 244 \param on true/false 245 246 \sa testItemInterest(), ItemAttribute 247 */ 248 void QwtPlotItem::setItemInterest( ItemInterest interest, bool on ) 249 { 250 if ( d_data->interests.testFlag( interest ) != on ) 251 { 252 if ( on ) 253 d_data->interests |= interest; 254 else 255 d_data->interests &= ~interest; 256 257 itemChanged(); 258 } 259 } 260 261 /*! 262 Test an item interest 263 264 \param interest Interest type 265 \return true/false 266 \sa setItemInterest(), ItemAttribute 267 */ 268 bool QwtPlotItem::testItemInterest( ItemInterest interest ) const 269 { 270 return d_data->interests.testFlag( interest ); 237 271 } 238 272 … … 247 281 void QwtPlotItem::setRenderHint( RenderHint hint, bool on ) 248 282 { 249 if ( ( ( d_data->renderHints & hint ) != 0) != on )283 if ( d_data->renderHints.testFlag( hint ) != on ) 250 284 { 251 285 if ( on ) … … 267 301 bool QwtPlotItem::testRenderHint( RenderHint hint ) const 268 302 { 269 return ( d_data->renderHints & hint ); 270 } 303 return d_data->renderHints.testFlag( hint ); 304 } 305 306 /*! 307 On multi core systems rendering of certain plot item 308 ( f.e QwtPlotRasterItem ) can be done in parallel in 309 several threads. 310 311 The default setting is set to 1. 312 313 \param numThreads Number of threads to be used for rendering. 314 If numThreads is set to 0, the system specific 315 ideal thread count is used. 316 317 The default thread count is 1 ( = no additional threads ) 318 */ 319 void QwtPlotItem::setRenderThreadCount( uint numThreads ) 320 { 321 d_data->renderThreadCount = numThreads; 322 } 323 324 /*! 325 \return Number of threads to be used for rendering. 326 If numThreads() is set to 0, the system specific 327 ideal thread count is used. 328 */ 329 uint QwtPlotItem::renderThreadCount() const 330 { 331 return d_data->renderThreadCount; 332 } 333 334 /*! 335 Set the size of the legend icon 336 337 The default setting is 8x8 pixels 338 339 \param size Size 340 \sa legendIconSize(), legendIcon() 341 */ 342 void QwtPlotItem::setLegendIconSize( const QSize &size ) 343 { 344 if ( d_data->legendIconSize != size ) 345 { 346 d_data->legendIconSize = size; 347 legendChanged(); 348 } 349 } 350 351 /*! 352 \return Legend icon size 353 \sa setLegendIconSize(), legendIcon() 354 */ 355 QSize QwtPlotItem::legendIconSize() const 356 { 357 return d_data->legendIconSize; 358 } 359 360 /*! 361 \return Icon representing the item on the legend 362 363 The default implementation returns an invalid icon 364 365 \param index Index of the legend entry 366 ( usually there is only one ) 367 \param size Icon size 368 369 \sa setLegendIconSize(), legendData() 370 */ 371 QwtGraphic QwtPlotItem::legendIcon( 372 int index, const QSizeF &size ) const 373 { 374 Q_UNUSED( index ) 375 Q_UNUSED( size ) 376 377 return QwtGraphic(); 378 } 379 380 /*! 381 \brief Return a default icon from a brush 382 383 The default icon is a filled rectangle used 384 in several derived classes as legendIcon(). 385 386 \param brush Fill brush 387 \param size Icon size 388 389 \return A filled rectangle 390 */ 391 QwtGraphic QwtPlotItem::defaultIcon( 392 const QBrush &brush, const QSizeF &size ) const 393 { 394 QwtGraphic icon; 395 if ( !size.isEmpty() ) 396 { 397 icon.setDefaultSize( size ); 398 399 QRectF r( 0, 0, size.width(), size.height() ); 400 401 QPainter painter( &icon ); 402 painter.fillRect( r, brush ); 403 } 404 405 return icon; 406 } 271 407 272 408 //! Show the item … … 307 443 308 444 /*! 309 Update the legend and call QwtPlot::autoRefresh for the445 Update the legend and call QwtPlot::autoRefresh() for the 310 446 parent plot. 311 447 312 \sa updateLegend()448 \sa QwtPlot::legendChanged(), QwtPlot::autoRefresh() 313 449 */ 314 450 void QwtPlotItem::itemChanged() 315 451 { 316 452 if ( d_data->plot ) 317 {318 if ( d_data->plot->legend() )319 updateLegend( d_data->plot->legend() );320 321 453 d_data->plot->autoRefresh(); 322 } 454 } 455 456 /*! 457 Update the legend of the parent plot. 458 \sa QwtPlot::updateLegend(), itemChanged() 459 */ 460 void QwtPlotItem::legendChanged() 461 { 462 if ( testItemAttribute( QwtPlotItem::Legend ) && d_data->plot ) 463 d_data->plot->updateLegend( this ); 323 464 } 324 465 … … 326 467 Set X and Y axis 327 468 328 The item will painted according to the coordinates its Axes.329 330 \param xAxis X Axis 331 \param yAxis Y Axis 332 333 \sa setXAxis(), setYAxis(), xAxis(), yAxis() 469 The item will painted according to the coordinates of its Axes. 470 471 \param xAxis X Axis ( QwtPlot::xBottom or QwtPlot::xTop ) 472 \param yAxis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight ) 473 474 \sa setXAxis(), setYAxis(), xAxis(), yAxis(), QwtPlot::Axis 334 475 */ 335 476 void QwtPlotItem::setAxes( int xAxis, int yAxis ) … … 349 490 The item will painted according to the coordinates its Axes. 350 491 351 \param axis X Axis 352 \sa setAxes(), setYAxis(), xAxis() 492 \param axis X Axis ( QwtPlot::xBottom or QwtPlot::xTop ) 493 \sa setAxes(), setYAxis(), xAxis(), QwtPlot::Axis 353 494 */ 354 495 void QwtPlotItem::setXAxis( int axis ) … … 366 507 The item will painted according to the coordinates its Axes. 367 508 368 \param axis Y Axis 369 \sa setAxes(), setXAxis(), yAxis() 509 \param axis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight ) 510 \sa setAxes(), setXAxis(), yAxis(), QwtPlot::Axis 370 511 */ 371 512 void QwtPlotItem::setYAxis( int axis ) … … 392 533 /*! 393 534 \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0) 535 \note A width or height < 0.0 is ignored by the autoscaler 394 536 */ 395 537 QRectF QwtPlotItem::boundingRect() const … … 399 541 400 542 /*! 401 \brief Allocate the widget that represents the item on the legend 402 403 The default implementation returns a QwtLegendItem(), but an item 404 could be represented by any type of widget, 405 by overloading legendItem() and updateLegend(). 406 407 \return QwtLegendItem() 408 \sa updateLegend() QwtLegend() 409 */ 410 QWidget *QwtPlotItem::legendItem() const 411 { 412 QwtLegendItem *item = new QwtLegendItem; 413 if ( d_data->plot ) 414 { 415 QObject::connect( item, SIGNAL( clicked() ), 416 d_data->plot, SLOT( legendItemClicked() ) ); 417 QObject::connect( item, SIGNAL( checked( bool ) ), 418 d_data->plot, SLOT( legendItemChecked( bool ) ) ); 419 } 420 return item; 421 } 422 423 /*! 424 \brief Update the widget that represents the item on the legend 425 426 updateLegend() is called from itemChanged() to adopt the widget 427 representing the item on the legend to its new configuration. 428 429 The default implementation updates a QwtLegendItem(), 430 but an item could be represented by any type of widget, 431 by overloading legendItem() and updateLegend(). 432 433 \param legend Legend 434 435 \sa legendItem(), itemChanged(), QwtLegend() 436 */ 437 void QwtPlotItem::updateLegend( QwtLegend *legend ) const 438 { 439 if ( legend == NULL ) 440 return; 441 442 QWidget *lgdItem = legend->find( this ); 443 if ( testItemAttribute( QwtPlotItem::Legend ) ) 444 { 445 if ( lgdItem == NULL ) 446 { 447 lgdItem = legendItem(); 448 if ( lgdItem ) 449 legend->insert( this, lgdItem ); 450 } 451 452 QwtLegendItem *label = qobject_cast<QwtLegendItem *>( lgdItem ); 453 if ( label ) 454 { 455 // paint the identifier 456 const QSize sz = label->identifierSize(); 457 458 QPixmap identifier( sz.width(), sz.height() ); 459 identifier.fill( Qt::transparent ); 460 461 QPainter painter( &identifier ); 462 painter.setRenderHint( QPainter::Antialiasing, 463 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 464 drawLegendIdentifier( &painter, 465 QRect( 0, 0, sz.width(), sz.height() ) ); 466 painter.end(); 467 468 const bool doUpdate = label->updatesEnabled(); 469 if ( doUpdate ) 470 label->setUpdatesEnabled( false ); 471 472 label->setText( title() ); 473 label->setIdentifier( identifier ); 474 label->setItemMode( legend->itemMode() ); 475 476 if ( doUpdate ) 477 label->setUpdatesEnabled( true ); 478 479 label->update(); 480 } 481 } 482 else 483 { 484 if ( lgdItem ) 485 { 486 lgdItem->hide(); 487 lgdItem->deleteLater(); 488 } 489 } 543 \brief Calculate a hint for the canvas margin 544 545 When the QwtPlotItem::Margins flag is enabled the plot item 546 indicates, that it needs some margins at the borders of the canvas. 547 This is f.e. used by bar charts to reserve space for displaying 548 the bars. 549 550 The margins are in target device coordinates ( pixels on screen ) 551 552 \param xMap Maps x-values into pixel coordinates. 553 \param yMap Maps y-values into pixel coordinates. 554 \param canvasRect Contents rectangle of the canvas in painter coordinates 555 \param left Returns the left margin 556 \param top Returns the top margin 557 \param right Returns the right margin 558 \param bottom Returns the bottom margin 559 560 \return The default implementation returns 0 for all margins 561 562 \sa QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins() 563 */ 564 void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap &xMap, 565 const QwtScaleMap &yMap, const QRectF &canvasRect, 566 double &left, double &top, double &right, double &bottom ) const 567 { 568 Q_UNUSED( xMap ); 569 Q_UNUSED( yMap ); 570 Q_UNUSED( canvasRect ); 571 572 // use QMargins, when we don't need to support Qt < 4.6 anymore 573 left = top = right = bottom = 0.0; 574 } 575 576 /*! 577 \brief Return all information, that is needed to represent 578 the item on the legend 579 580 Most items are represented by one entry on the legend 581 showing an icon and a text, but f.e. QwtPlotMultiBarChart 582 displays one entry for each bar. 583 584 QwtLegendData is basically a list of QVariants that makes it 585 possible to overload and reimplement legendData() to 586 return almost any type of information, that is understood 587 by the receiver that acts as the legend. 588 589 The default implementation returns one entry with 590 the title() of the item and the legendIcon(). 591 592 \return Data, that is needed to represent the item on the legend 593 \sa title(), legendIcon(), QwtLegend, QwtPlotLegendItem 594 */ 595 QList<QwtLegendData> QwtPlotItem::legendData() const 596 { 597 QwtLegendData data; 598 599 QwtText label = title(); 600 label.setRenderFlags( label.renderFlags() & Qt::AlignLeft ); 601 602 QVariant titleValue; 603 qVariantSetValue( titleValue, label ); 604 data.setValue( QwtLegendData::TitleRole, titleValue ); 605 606 const QwtGraphic graphic = legendIcon( 0, legendIconSize() ); 607 if ( !graphic.isNull() ) 608 { 609 QVariant iconValue; 610 qVariantSetValue( iconValue, graphic ); 611 data.setValue( QwtLegendData::IconRole, iconValue ); 612 } 613 614 QList<QwtLegendData> list; 615 list += data; 616 617 return list; 490 618 } 491 619 … … 498 626 updateScaleDiv() 499 627 628 updateScaleDiv() is only called when the ScaleInterest interest 629 is enabled. The default implementation does nothing. 630 500 631 \param xScaleDiv Scale division of the x-axis 501 632 \param yScaleDiv Scale division of the y-axis 502 633 503 \sa QwtPlot::updateAxes() 634 \sa QwtPlot::updateAxes(), ScaleInterest 504 635 */ 505 636 void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv, … … 511 642 512 643 /*! 513 \brief Calculate the bounding scale rect of 2 maps 514 515 \param xMap X map 516 \param yMap X map 517 518 \return Bounding scale rect of the scale maps, normalized 644 \brief Update the item to changes of the legend info 645 646 Plot items that want to display a legend ( not those, that want to 647 be displayed on a legend ! ) will have to implement updateLegend(). 648 649 updateLegend() is only called when the LegendInterest interest 650 is enabled. The default implementation does nothing. 651 652 \param item Plot item to be displayed on a legend 653 \param data Attributes how to display item on the legend 654 655 \sa QwtPlotLegendItem 656 657 \note Plot items, that want to be displayed on a legend 658 need to enable the QwtPlotItem::Legend flag and to implement 659 legendData() and legendIcon() 660 */ 661 void QwtPlotItem::updateLegend( const QwtPlotItem *item, 662 const QList<QwtLegendData> &data ) 663 { 664 Q_UNUSED( item ); 665 Q_UNUSED( data ); 666 } 667 668 /*! 669 \brief Calculate the bounding scale rectangle of 2 maps 670 671 \param xMap Maps x-values into pixel coordinates. 672 \param yMap Maps y-values into pixel coordinates. 673 674 \return Bounding scale rect of the scale maps, not normalized 519 675 */ 520 676 QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap, … … 526 682 527 683 /*! 528 \brief Calculate the bounding paint rect of 2 maps529 530 \param xMap X map531 \param yMap X map532 533 \return Bounding paint rect of the scale maps,normalized684 \brief Calculate the bounding paint rectangle of 2 maps 685 686 \param xMap Maps x-values into pixel coordinates. 687 \param yMap Maps y-values into pixel coordinates. 688 689 \return Bounding paint rectangle of the scale maps, not normalized 534 690 */ 535 691 QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap,
Note:
See TracChangeset
for help on using the changeset viewer.