Changeset 9383 in ntrip for trunk/BNC/qwt/qwt_legend.cpp
- Timestamp:
- Mar 19, 2021, 9:15:03 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_legend.cpp
r8127 r9383 50 50 }; 51 51 52 void QwtLegendMap::insert( const QVariant &itemInfo, 52 void QwtLegendMap::insert( const QVariant &itemInfo, 53 53 const QList<QWidget *> &widgets ) 54 54 { … … 142 142 { 143 143 public: 144 LegendView( QWidget *parent ):144 explicit LegendView( QWidget *parent ): 145 145 QScrollArea( parent ) 146 146 { … … 296 296 if ( tl ) 297 297 tl->setMaxColumns( numColums ); 298 299 updateGeometry(); 298 300 } 299 301 … … 342 344 343 345 /*! 344 The contents widget is the only child of the viewport of 346 The contents widget is the only child of the viewport of 345 347 the internal QScrollArea and the parent widget of all legend items. 346 348 … … 371 373 372 374 /*! 373 The contents widget is the only child of the viewport of 375 The contents widget is the only child of the viewport of 374 376 the internal QScrollArea and the parent widget of all legend items. 375 377 … … 386 388 387 389 \param itemInfo Info for an item 388 \param data List of legend entry attributes for the item390 \param legendData List of legend entry attributes for the item 389 391 */ 390 void QwtLegend::updateLegend( const QVariant &itemInfo, 391 const QList<QwtLegendData> & data )392 void QwtLegend::updateLegend( const QVariant &itemInfo, 393 const QList<QwtLegendData> &legendData ) 392 394 { 393 395 QList<QWidget *> widgetList = legendWidgets( itemInfo ); 394 396 395 if ( widgetList.size() != data.size() )397 if ( widgetList.size() != legendData.size() ) 396 398 { 397 399 QLayout *contentsLayout = d_data->view->contentsWidget->layout(); 398 400 399 while ( widgetList.size() > data.size() )401 while ( widgetList.size() > legendData.size() ) 400 402 { 401 403 QWidget *w = widgetList.takeLast(); … … 410 412 } 411 413 412 for ( int i = widgetList.size(); i < data.size(); i++ ) 413 { 414 QWidget *widget = createWidget( data[i] ); 414 #if QT_VERSION >= 0x040700 415 widgetList.reserve( legendData.size() ); 416 #endif 417 418 for ( int i = widgetList.size(); i < legendData.size(); i++ ) 419 { 420 QWidget *widget = createWidget( legendData[i] ); 415 421 416 422 if ( contentsLayout ) … … 441 447 updateTabOrder(); 442 448 } 443 444 for ( int i = 0; i < data.size(); i++ )445 updateWidget( widgetList[i], data[i] );449 450 for ( int i = 0; i < legendData.size(); i++ ) 451 updateWidget( widgetList[i], legendData[i] ); 446 452 } 447 453 … … 451 457 The default implementation returns a QwtLegendLabel. 452 458 453 \param data Attributes of the legend entry459 \param legendData Attributes of the legend entry 454 460 \return Widget representing data on the legend 455 461 456 462 \note updateWidget() will called soon after createWidget() 457 463 with the same attributes. 458 464 */ 459 QWidget *QwtLegend::createWidget( const QwtLegendData & data ) const460 { 461 Q_UNUSED( data );465 QWidget *QwtLegend::createWidget( const QwtLegendData &legendData ) const 466 { 467 Q_UNUSED( legendData ); 462 468 463 469 QwtLegendLabel *label = new QwtLegendLabel(); 464 470 label->setItemMode( defaultItemMode() ); 465 471 466 connect( label, SIGNAL( clicked() ), SLOT( itemClicked()) );467 connect( label, SIGNAL( checked( bool ) ), SLOT( itemChecked( bool )) );472 connect( label, SIGNAL(clicked()), SLOT(itemClicked()) ); 473 connect( label, SIGNAL(checked(bool)), SLOT(itemChecked(bool)) ); 468 474 469 475 return label; … … 471 477 472 478 /*! 473 \brief Update the widget 479 \brief Update the widget 474 480 475 481 \param widget Usually a QwtLegendLabel 476 \param data Attributes to be displayed482 \param legendData Attributes to be displayed 477 483 478 484 \sa createWidget() 479 485 \note When widget is no QwtLegendLabel updateWidget() does nothing. 480 486 */ 481 void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData & data )487 void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData &legendData ) 482 488 { 483 489 QwtLegendLabel *label = qobject_cast<QwtLegendLabel *>( widget ); 484 490 if ( label ) 485 491 { 486 label->setData( data );487 if ( ! data.value( QwtLegendData::ModeRole ).isValid() )492 label->setData( legendData ); 493 if ( !legendData.value( QwtLegendData::ModeRole ).isValid() ) 488 494 { 489 495 // use the default mode, when there is no specific … … 541 547 542 548 /*! 543 Handle QEvent::ChildRemoved andQEvent::LayoutRequest events 549 Handle QEvent::ChildRemoved andQEvent::LayoutRequest events 544 550 for the contentsWidget(). 545 551 … … 557 563 case QEvent::ChildRemoved: 558 564 { 559 const QChildEvent *ce = 565 const QChildEvent *ce = 560 566 static_cast<const QChildEvent *>(event); 567 561 568 if ( ce->child()->isWidgetType() ) 562 569 { 563 QWidget *w = static_cast< QWidget * >( ce->child() ); 570 /* 571 We are called from the ~QObject and ce->child() is 572 no widget anymore. But all we need is the address 573 to remove it from the map. 574 */ 575 QWidget *w = reinterpret_cast< QWidget * >( ce->child() ); 564 576 d_data->itemMap.removeWidget( w ); 565 577 } … … 585 597 QApplication::postEvent( parentWidget(), 586 598 new QEvent( QEvent::LayoutRequest ) ); 587 } 599 } 588 600 break; 589 601 } … … 645 657 \param painter Painter 646 658 \param rect Bounding rectangle 647 \param fillBackground When true, fill rect with the widget background 659 \param fillBackground When true, fill rect with the widget background 648 660 649 661 \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself 650 662 */ 651 void QwtLegend::renderLegend( QPainter *painter, 663 void QwtLegend::renderLegend( QPainter *painter, 652 664 const QRectF &rect, bool fillBackground ) const 653 665 { … … 664 676 } 665 677 666 const QwtDynGridLayout *legendLayout = 678 const QwtDynGridLayout *legendLayout = 667 679 qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() ); 668 680 if ( legendLayout == NULL ) … … 672 684 getContentsMargins( &left, &top, &right, &bottom ); 673 685 674 QRect layoutRect; 686 QRect layoutRect; 675 687 layoutRect.setLeft( qCeil( rect.left() ) + left ); 676 688 layoutRect.setTop( qCeil( rect.top() ) + top ); … … 679 691 680 692 uint numCols = legendLayout->columnsForWidth( layoutRect.width() ); 681 QList<QRect> itemRects =693 const QList<QRect> itemRects = 682 694 legendLayout->layoutItems( layoutRect, numCols ); 683 695 … … 707 719 \param widget Widget representing a legend entry 708 720 \param rect Bounding rectangle 709 \param fillBackground When true, fill rect with the widget background 721 \param fillBackground When true, fill rect with the widget background 710 722 711 723 \note When widget is not derived from QwtLegendLabel renderItem 712 724 does nothing beside the background 713 725 */ 714 void QwtLegend::renderItem( QPainter *painter, 726 void QwtLegend::renderItem( QPainter *painter, 715 727 const QWidget *widget, const QRectF &rect, bool fillBackground ) const 716 728 { … … 733 745 734 746 const QRectF iconRect( rect.x() + label->margin(), 735 rect.center().y() - 0.5 * sz.height(), 747 rect.center().y() - 0.5 * sz.height(), 736 748 sz.width(), sz.height() ); 737 749 … … 743 755 titleRect.setX( iconRect.right() + 2 * label->spacing() ); 744 756 745 painter->setFont( label->font() ); 757 QFont labelFont = label->font(); 758 labelFont.resolve( QFont::AllPropertiesResolved ); 759 760 painter->setFont( labelFont ); 746 761 painter->setPen( label->palette().color( QPalette::Text ) ); 762 747 763 const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect ); 748 764 } … … 795 811 Return the extent, that is needed for the scrollbars 796 812 797 \param orientation Orientation (813 \param orientation Orientation 798 814 \return The width of the vertical scrollbar for Qt::Horizontal and v.v. 799 815 */
Note:
See TracChangeset
for help on using the changeset viewer.