Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_legend.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_legend.cpp (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_legend.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_dyngrid_layout.h" 13 13 #include "qwt_math.h" 14 #include "qwt_plot_item.h"15 14 #include "qwt_painter.h" 15 #include "qwt_graphic.h" 16 16 17 #include <qapplication.h> 17 18 #include <qscrollbar.h> 18 19 #include <qscrollarea.h> 19 20 #include <qpainter.h> 20 #include <qstyle.h> 21 #include <qstyleoption.h> 22 23 class QwtLegendMap 24 { 25 public: 26 inline bool isEmpty() const { return d_entries.isEmpty(); } 27 28 void insert( const QVariant &, const QList<QWidget *> & ); 29 void remove( const QVariant & ); 30 31 void removeWidget( const QWidget * ); 32 33 QList<QWidget *> legendWidgets( const QVariant & ) const; 34 QVariant itemInfo( const QWidget * ) const; 35 36 private: 37 // we don't know anything about itemInfo and therefore don't have 38 // any key that can be used for a map or hashtab. 39 // But a simple linear list is o.k. here, as we will never have 40 // more than a few entries. 41 42 class Entry 43 { 44 public: 45 QVariant itemInfo; 46 QList<QWidget *> widgets; 21 #include <qmargins.h> 22 23 namespace 24 { 25 class LegendMap 26 { 27 public: 28 inline bool isEmpty() const { return m_entries.isEmpty(); } 29 30 void insert( const QVariant&, const QList< QWidget* >& ); 31 void remove( const QVariant& ); 32 33 void removeWidget( const QWidget* ); 34 35 QList< QWidget* > legendWidgets( const QVariant& ) const; 36 QVariant itemInfo( const QWidget* ) const; 37 38 private: 39 // we don't know anything about itemInfo and therefore don't have 40 // any key that can be used for a map or hashtab. 41 // But a simple linear list is o.k. here, as we will never have 42 // more than a few entries. 43 44 class Entry 45 { 46 public: 47 QVariant itemInfo; 48 QList< QWidget* > widgets; 49 }; 50 51 QList< Entry > m_entries; 47 52 }; 48 53 49 QList< Entry > d_entries; 54 void LegendMap::insert( const QVariant& itemInfo, 55 const QList< QWidget* >& widgets ) 56 { 57 for ( int i = 0; i < m_entries.size(); i++ ) 58 { 59 Entry& entry = m_entries[i]; 60 if ( entry.itemInfo == itemInfo ) 61 { 62 entry.widgets = widgets; 63 return; 64 } 65 } 66 67 Entry newEntry; 68 newEntry.itemInfo = itemInfo; 69 newEntry.widgets = widgets; 70 71 m_entries += newEntry; 72 } 73 74 void LegendMap::remove( const QVariant& itemInfo ) 75 { 76 for ( int i = 0; i < m_entries.size(); i++ ) 77 { 78 Entry& entry = m_entries[i]; 79 if ( entry.itemInfo == itemInfo ) 80 { 81 m_entries.removeAt( i ); 82 return; 83 } 84 } 85 } 86 87 void LegendMap::removeWidget( const QWidget* widget ) 88 { 89 QWidget* w = const_cast< QWidget* >( widget ); 90 91 for ( int i = 0; i < m_entries.size(); i++ ) 92 m_entries[ i ].widgets.removeAll( w ); 93 } 94 95 QVariant LegendMap::itemInfo( const QWidget* widget ) const 96 { 97 if ( widget != NULL ) 98 { 99 QWidget* w = const_cast< QWidget* >( widget ); 100 101 for ( int i = 0; i < m_entries.size(); i++ ) 102 { 103 const Entry& entry = m_entries[i]; 104 if ( entry.widgets.indexOf( w ) >= 0 ) 105 return entry.itemInfo; 106 } 107 } 108 109 return QVariant(); 110 } 111 112 QList< QWidget* > LegendMap::legendWidgets( const QVariant& itemInfo ) const 113 { 114 if ( itemInfo.isValid() ) 115 { 116 for ( int i = 0; i < m_entries.size(); i++ ) 117 { 118 const Entry& entry = m_entries[i]; 119 if ( entry.itemInfo == itemInfo ) 120 return entry.widgets; 121 } 122 } 123 124 return QList< QWidget* >(); 125 } 126 } 127 128 class QwtLegend::PrivateData 129 { 130 public: 131 PrivateData() 132 : itemMode( QwtLegendData::ReadOnly ) 133 , view( NULL ) 134 { 135 } 136 137 QwtLegendData::Mode itemMode; 138 LegendMap itemMap; 139 140 class LegendView; 141 LegendView* view; 50 142 }; 51 143 52 void QwtLegendMap::insert( const QVariant &itemInfo, 53 const QList<QWidget *> &widgets ) 54 { 55 for ( int i = 0; i < d_entries.size(); i++ ) 56 { 57 Entry &entry = d_entries[i]; 58 if ( entry.itemInfo == itemInfo ) 59 { 60 entry.widgets = widgets; 61 return; 62 } 63 } 64 65 Entry newEntry; 66 newEntry.itemInfo = itemInfo; 67 newEntry.widgets = widgets; 68 69 d_entries += newEntry; 70 } 71 72 void QwtLegendMap::remove( const QVariant &itemInfo ) 73 { 74 for ( int i = 0; i < d_entries.size(); i++ ) 75 { 76 Entry &entry = d_entries[i]; 77 if ( entry.itemInfo == itemInfo ) 78 { 79 d_entries.removeAt( i ); 80 return; 81 } 82 } 83 } 84 85 void QwtLegendMap::removeWidget( const QWidget *widget ) 86 { 87 QWidget *w = const_cast<QWidget *>( widget ); 88 89 for ( int i = 0; i < d_entries.size(); i++ ) 90 d_entries[ i ].widgets.removeAll( w ); 91 } 92 93 QVariant QwtLegendMap::itemInfo( const QWidget *widget ) const 94 { 95 if ( widget != NULL ) 96 { 97 QWidget *w = const_cast<QWidget *>( widget ); 98 99 for ( int i = 0; i < d_entries.size(); i++ ) 100 { 101 const Entry &entry = d_entries[i]; 102 if ( entry.widgets.indexOf( w ) >= 0 ) 103 return entry.itemInfo; 104 } 105 } 106 107 return QVariant(); 108 } 109 110 QList<QWidget *> QwtLegendMap::legendWidgets( const QVariant &itemInfo ) const 111 { 112 if ( itemInfo.isValid() ) 113 { 114 for ( int i = 0; i < d_entries.size(); i++ ) 115 { 116 const Entry &entry = d_entries[i]; 117 if ( entry.itemInfo == itemInfo ) 118 return entry.widgets; 119 } 120 } 121 122 return QList<QWidget *>(); 123 } 124 125 class QwtLegend::PrivateData 126 { 127 public: 128 PrivateData(): 129 itemMode( QwtLegendData::ReadOnly ), 130 view( NULL ) 131 { 132 } 133 134 QwtLegendData::Mode itemMode; 135 QwtLegendMap itemMap; 136 137 class LegendView; 138 LegendView *view; 139 }; 140 141 class QwtLegend::PrivateData::LegendView: public QScrollArea 142 { 143 public: 144 explicit LegendView( QWidget *parent ): 144 class QwtLegend::PrivateData::LegendView QWT_FINAL : public QScrollArea 145 { 146 public: 147 explicit LegendView( QWidget * parent ) : 145 148 QScrollArea( parent ) 146 149 { … … 159 162 } 160 163 161 virtual bool event( QEvent *event )164 virtual bool event( QEvent* event ) QWT_OVERRIDE 162 165 { 163 166 if ( event->type() == QEvent::PolishRequest ) … … 187 190 } 188 191 189 virtual bool viewportEvent( QEvent *event )192 virtual bool viewportEvent( QEvent* event ) QWT_OVERRIDE 190 193 { 191 194 bool ok = QScrollArea::viewportEvent( event ); … … 223 226 void layoutContents() 224 227 { 225 const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout*>(228 const QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >( 226 229 contentsWidget->layout() ); 227 230 if ( tl == NULL ) … … 230 233 const QSize visibleSize = viewport()->contentsRect().size(); 231 234 232 const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin(); 235 const QMargins m = tl->contentsMargins(); 236 const int minW = tl->maxItemWidth() + m.left() + m.right(); 233 237 234 238 int w = qMax( visibleSize.width(), minW ); … … 245 249 } 246 250 247 QWidget *contentsWidget;251 QWidget* contentsWidget; 248 252 }; 249 253 250 254 /*! 251 Constructor 252 \param parent Parent widget 253 */ 254 QwtLegend::QwtLegend( QWidget *parent ):255 QwtAbstractLegend( parent ) 255 Constructor 256 \param parent Parent widget 257 */ 258 QwtLegend::QwtLegend( QWidget* parent ) 259 : QwtAbstractLegend( parent ) 256 260 { 257 261 setFrameStyle( NoFrame ); 258 262 259 d_data = new QwtLegend::PrivateData;260 261 d_data->view = new QwtLegend::PrivateData::LegendView( this );262 d_data->view->setObjectName( "QwtLegendView" );263 d_data->view->setFrameStyle( NoFrame );264 265 QwtDynGridLayout *gridLayout = new QwtDynGridLayout(266 d_data->view->contentsWidget );263 m_data = new QwtLegend::PrivateData; 264 265 m_data->view = new QwtLegend::PrivateData::LegendView( this ); 266 m_data->view->setObjectName( "QwtLegendView" ); 267 m_data->view->setFrameStyle( NoFrame ); 268 269 QwtDynGridLayout* gridLayout = new QwtDynGridLayout( 270 m_data->view->contentsWidget ); 267 271 gridLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop ); 268 272 269 d_data->view->contentsWidget->installEventFilter( this );270 271 QVBoxLayout *layout = new QVBoxLayout( this );273 m_data->view->contentsWidget->installEventFilter( this ); 274 275 QVBoxLayout* layout = new QVBoxLayout( this ); 272 276 layout->setContentsMargins( 0, 0, 0, 0 ); 273 layout->addWidget( d_data->view );277 layout->addWidget( m_data->view ); 274 278 } 275 279 … … 277 281 QwtLegend::~QwtLegend() 278 282 { 279 delete d_data;280 } 281 282 /*! 283 \brief Set the maximum number of entries in a row 284 285 F.e when the maximum is set to 1 all items are aligned 286 vertically. 0 means unlimited 287 288 \param numColums Maximum number of entries in a row 289 290 \sa maxColumns(), QwtDynGridLayout::setMaxColumns() 283 delete m_data; 284 } 285 286 /*! 287 \brief Set the maximum number of entries in a row 288 289 F.e when the maximum is set to 1 all items are aligned 290 vertically. 0 means unlimited 291 292 \param numColums Maximum number of entries in a row 293 294 \sa maxColumns(), QwtDynGridLayout::setMaxColumns() 291 295 */ 292 296 void QwtLegend::setMaxColumns( uint numColums ) 293 297 { 294 QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout*>(295 d_data->view->contentsWidget->layout() );298 QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >( 299 m_data->view->contentsWidget->layout() ); 296 300 if ( tl ) 297 301 tl->setMaxColumns( numColums ); … … 301 305 302 306 /*! 303 \return Maximum number of entries in a row 304 \sa setMaxColumns(), QwtDynGridLayout::maxColumns() 307 \return Maximum number of entries in a row 308 \sa setMaxColumns(), QwtDynGridLayout::maxColumns() 305 309 */ 306 310 uint QwtLegend::maxColumns() const … … 308 312 uint maxCols = 0; 309 313 310 const QwtDynGridLayout *tl = qobject_cast<const QwtDynGridLayout*>(311 d_data->view->contentsWidget->layout() );314 const QwtDynGridLayout* tl = qobject_cast< const QwtDynGridLayout* >( 315 m_data->view->contentsWidget->layout() ); 312 316 if ( tl ) 313 317 maxCols = tl->maxColumns(); … … 317 321 318 322 /*! 319 \brief Set the default mode for legend labels 320 321 Legend labels will be constructed according to the 322 attributes in a QwtLegendData object. When it doesn't 323 contain a value for the QwtLegendData::ModeRole the 324 label will be initialized with the default mode of the legend. 325 326 \param mode Default item mode 327 328 \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData() 329 \note Changing the mode doesn't have any effect on existing labels. 323 \brief Set the default mode for legend labels 324 325 Legend labels will be constructed according to the 326 attributes in a QwtLegendData object. When it doesn't 327 contain a value for the QwtLegendData::ModeRole the 328 label will be initialized with the default mode of the legend. 329 330 \param mode Default item mode 331 332 \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData() 333 \note Changing the mode doesn't have any effect on existing labels. 330 334 */ 331 335 void QwtLegend::setDefaultItemMode( QwtLegendData::Mode mode ) 332 336 { 333 d_data->itemMode = mode;334 } 335 336 /*! 337 \return Default item mode 338 \sa setDefaultItemMode() 339 */ 337 m_data->itemMode = mode; 338 } 339 340 /*! 341 \return Default item mode 342 \sa setDefaultItemMode() 343 */ 340 344 QwtLegendData::Mode QwtLegend::defaultItemMode() const 341 345 { 342 return d_data->itemMode;343 } 344 345 /*! 346 The contents widget is the only child of the viewport of 347 the internal QScrollArea and the parent widget of all legend items. 348 349 \return Container widget of the legend items 350 */ 351 QWidget *QwtLegend::contentsWidget()352 { 353 return d_data->view->contentsWidget;354 } 355 356 /*! 357 \return Horizontal scrollbar 358 \sa verticalScrollBar() 359 */ 360 QScrollBar *QwtLegend::horizontalScrollBar() const361 { 362 return d_data->view->horizontalScrollBar();363 } 364 365 /*! 366 \return Vertical scrollbar 367 \sa horizontalScrollBar() 368 */ 369 QScrollBar *QwtLegend::verticalScrollBar() const370 { 371 return d_data->view->verticalScrollBar();372 } 373 374 /*! 375 The contents widget is the only child of the viewport of 376 the internal QScrollArea and the parent widget of all legend items. 377 378 \return Container widget of the legend items 379 380 */ 381 const QWidget *QwtLegend::contentsWidget() const382 { 383 return d_data->view->contentsWidget;384 } 385 386 /*! 387 \brief Update the entries for an item 388 389 \param itemInfo Info for an item 390 \param legendData List of legend entry attributes for the item 391 */ 392 void QwtLegend::updateLegend( const QVariant &itemInfo,393 const QList<QwtLegendData > &legendData )394 { 395 QList<QWidget *> widgetList = legendWidgets( itemInfo );346 return m_data->itemMode; 347 } 348 349 /*! 350 The contents widget is the only child of the viewport of 351 the internal QScrollArea and the parent widget of all legend items. 352 353 \return Container widget of the legend items 354 */ 355 QWidget* QwtLegend::contentsWidget() 356 { 357 return m_data->view->contentsWidget; 358 } 359 360 /*! 361 \return Horizontal scrollbar 362 \sa verticalScrollBar() 363 */ 364 QScrollBar* QwtLegend::horizontalScrollBar() const 365 { 366 return m_data->view->horizontalScrollBar(); 367 } 368 369 /*! 370 \return Vertical scrollbar 371 \sa horizontalScrollBar() 372 */ 373 QScrollBar* QwtLegend::verticalScrollBar() const 374 { 375 return m_data->view->verticalScrollBar(); 376 } 377 378 /*! 379 The contents widget is the only child of the viewport of 380 the internal QScrollArea and the parent widget of all legend items. 381 382 \return Container widget of the legend items 383 384 */ 385 const QWidget* QwtLegend::contentsWidget() const 386 { 387 return m_data->view->contentsWidget; 388 } 389 390 /*! 391 \brief Update the entries for an item 392 393 \param itemInfo Info for an item 394 \param legendData List of legend entry attributes for the item 395 */ 396 void QwtLegend::updateLegend( const QVariant& itemInfo, 397 const QList< QwtLegendData >& legendData ) 398 { 399 QList< QWidget* > widgetList = legendWidgets( itemInfo ); 396 400 397 401 if ( widgetList.size() != legendData.size() ) 398 402 { 399 QLayout *contentsLayout =d_data->view->contentsWidget->layout();403 QLayout* contentsLayout = m_data->view->contentsWidget->layout(); 400 404 401 405 while ( widgetList.size() > legendData.size() ) 402 406 { 403 QWidget *w = widgetList.takeLast();407 QWidget* w = widgetList.takeLast(); 404 408 405 409 contentsLayout->removeWidget( w ); … … 412 416 } 413 417 414 #if QT_VERSION >= 0x040700415 418 widgetList.reserve( legendData.size() ); 416 #endif417 419 418 420 for ( int i = widgetList.size(); i < legendData.size(); i++ ) 419 421 { 420 QWidget *widget = createWidget( legendData[i] );422 QWidget* widget = createWidget( legendData[i] ); 421 423 422 424 if ( contentsLayout ) … … 438 440 if ( widgetList.isEmpty() ) 439 441 { 440 d_data->itemMap.remove( itemInfo );442 m_data->itemMap.remove( itemInfo ); 441 443 } 442 444 else 443 445 { 444 d_data->itemMap.insert( itemInfo, widgetList );446 m_data->itemMap.insert( itemInfo, widgetList ); 445 447 } 446 448 … … 453 455 454 456 /*! 455 \brief Create a widget to be inserted into the legend 456 457 The default implementation returns a QwtLegendLabel. 458 459 \param legendData Attributes of the legend entry 460 \return Widget representing data on the legend 461 462 \note updateWidget() will called soon after createWidget() 457 \brief Create a widget to be inserted into the legend 458 459 The default implementation returns a QwtLegendLabel. 460 461 \param legendData Attributes of the legend entry 462 \return Widget representing data on the legend 463 464 \note updateWidget() will called soon after createWidget() 463 465 with the same attributes. 464 466 */ 465 QWidget *QwtLegend::createWidget( const QwtLegendData&legendData ) const467 QWidget* QwtLegend::createWidget( const QwtLegendData& legendData ) const 466 468 { 467 469 Q_UNUSED( legendData ); 468 470 469 QwtLegendLabel *label = new QwtLegendLabel();471 QwtLegendLabel* label = new QwtLegendLabel(); 470 472 label->setItemMode( defaultItemMode() ); 471 473 … … 477 479 478 480 /*! 479 \brief Update the widget 480 481 \param widget Usually a QwtLegendLabel 482 \param legendData Attributes to be displayed 483 484 \sa createWidget() 485 \note When widget is no QwtLegendLabel updateWidget() does nothing. 486 */ 487 void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData&legendData )488 { 489 QwtLegendLabel *label = qobject_cast<QwtLegendLabel*>( widget );481 \brief Update the widget 482 483 \param widget Usually a QwtLegendLabel 484 \param legendData Attributes to be displayed 485 486 \sa createWidget() 487 \note When widget is no QwtLegendLabel updateWidget() does nothing. 488 */ 489 void QwtLegend::updateWidget( QWidget* widget, const QwtLegendData& legendData ) 490 { 491 QwtLegendLabel* label = qobject_cast< QwtLegendLabel* >( widget ); 490 492 if ( label ) 491 493 { … … 503 505 void QwtLegend::updateTabOrder() 504 506 { 505 QLayout *contentsLayout =d_data->view->contentsWidget->layout();507 QLayout* contentsLayout = m_data->view->contentsWidget->layout(); 506 508 if ( contentsLayout ) 507 509 { 508 510 // set tab focus chain 509 511 510 QWidget *w = NULL;512 QWidget* w = NULL; 511 513 512 514 for ( int i = 0; i < contentsLayout->count(); i++ ) 513 515 { 514 QLayoutItem *item = contentsLayout->itemAt( i );516 QLayoutItem* item = contentsLayout->itemAt( i ); 515 517 if ( w && item->widget() ) 516 518 QWidget::setTabOrder( w, item->widget() ); … … 524 526 QSize QwtLegend::sizeHint() const 525 527 { 526 QSize hint = d_data->view->contentsWidget->sizeHint();528 QSize hint = m_data->view->contentsWidget->sizeHint(); 527 529 hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); 528 530 … … 531 533 532 534 /*! 533 \return The preferred height, for a width. 534 \param width Width 535 */ 535 \return The preferred height, for a width. 536 \param width Width 537 */ 536 538 int QwtLegend::heightForWidth( int width ) const 537 539 { 538 540 width -= 2 * frameWidth(); 539 541 540 int h = d_data->view->contentsWidget->heightForWidth( width );542 int h = m_data->view->contentsWidget->heightForWidth( width ); 541 543 if ( h >= 0 ) 542 544 h += 2 * frameWidth(); … … 547 549 548 550 /*! 549 Handle QEvent::ChildRemoved andQEvent::LayoutRequest events 550 for the contentsWidget(). 551 552 \param object Object to be filtered 553 \param event Event 554 555 \return Forwarded to QwtAbstractLegend::eventFilter() 556 */ 557 bool QwtLegend::eventFilter( QObject *object, QEvent*event )558 { 559 if ( object == d_data->view->contentsWidget )551 Handle QEvent::ChildRemoved and QEvent::LayoutRequest events 552 for the contentsWidget(). 553 554 \param object Object to be filtered 555 \param event Event 556 557 \return Forwarded to QwtAbstractLegend::eventFilter() 558 */ 559 bool QwtLegend::eventFilter( QObject* object, QEvent* event ) 560 { 561 if ( object == m_data->view->contentsWidget ) 560 562 { 561 563 switch ( event->type() ) … … 563 565 case QEvent::ChildRemoved: 564 566 { 565 const QChildEvent *ce =566 static_cast<const QChildEvent *>(event);567 const QChildEvent* ce = 568 static_cast< const QChildEvent* >( event ); 567 569 568 570 if ( ce->child()->isWidgetType() ) … … 573 575 to remove it from the map. 574 576 */ 575 QWidget *w = reinterpret_cast< QWidget* >( ce->child() );576 d_data->itemMap.removeWidget( w );577 QWidget* w = reinterpret_cast< QWidget* >( ce->child() ); 578 m_data->itemMap.removeWidget( w ); 577 579 } 578 580 break; … … 580 582 case QEvent::LayoutRequest: 581 583 { 582 d_data->view->layoutContents();584 m_data->view->layoutContents(); 583 585 584 586 if ( parentWidget() && parentWidget()->layout() == NULL ) … … 609 611 610 612 /*! 611 Called internally when the legend has been clicked on. 612 Emits a clicked() signal. 613 */ 613 Called internally when the legend has been clicked on. 614 Emits a clicked() signal. 615 */ 614 616 void QwtLegend::itemClicked() 615 617 { 616 QWidget *w = qobject_cast<QWidget*>( sender() );618 QWidget* w = qobject_cast< QWidget* >( sender() ); 617 619 if ( w ) 618 620 { 619 const QVariant itemInfo = d_data->itemMap.itemInfo( w );621 const QVariant itemInfo = m_data->itemMap.itemInfo( w ); 620 622 if ( itemInfo.isValid() ) 621 623 { 622 const QList<QWidget *> widgetList =623 d_data->itemMap.legendWidgets( itemInfo );624 const QList< QWidget* > widgetList = 625 m_data->itemMap.legendWidgets( itemInfo ); 624 626 625 627 const int index = widgetList.indexOf( w ); … … 631 633 632 634 /*! 633 Called internally when the legend has been checked 634 Emits a checked() signal. 635 */ 635 Called internally when the legend has been checked 636 Emits a checked() signal. 637 */ 636 638 void QwtLegend::itemChecked( bool on ) 637 639 { 638 QWidget *w = qobject_cast<QWidget*>( sender() );640 QWidget* w = qobject_cast< QWidget* >( sender() ); 639 641 if ( w ) 640 642 { 641 const QVariant itemInfo = d_data->itemMap.itemInfo( w );643 const QVariant itemInfo = m_data->itemMap.itemInfo( w ); 642 644 if ( itemInfo.isValid() ) 643 645 { 644 const QList<QWidget *> widgetList =645 d_data->itemMap.legendWidgets( itemInfo );646 const QList< QWidget* > widgetList = 647 m_data->itemMap.legendWidgets( itemInfo ); 646 648 647 649 const int index = widgetList.indexOf( w ); … … 653 655 654 656 /*! 655 Render the legend into a given rectangle. 656 657 \param painter Painter 658 \param rect Bounding rectangle 659 \param fillBackground When true, fill rect with the widget background 660 661 \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself 662 */ 663 void QwtLegend::renderLegend( QPainter *painter,664 const QRectF &rect, bool fillBackground ) const665 { 666 if ( d_data->itemMap.isEmpty() )657 Render the legend into a given rectangle. 658 659 \param painter Painter 660 \param rect Bounding rectangle 661 \param fillBackground When true, fill rect with the widget background 662 663 \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself 664 */ 665 void QwtLegend::renderLegend( QPainter* painter, 666 const QRectF& rect, bool fillBackground ) const 667 { 668 if ( m_data->itemMap.isEmpty() ) 667 669 return; 668 670 … … 676 678 } 677 679 678 const QwtDynGridLayout *legendLayout =679 qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );680 const QwtDynGridLayout* legendLayout = 681 qobject_cast< QwtDynGridLayout* >( contentsWidget()->layout() ); 680 682 if ( legendLayout == NULL ) 681 683 return; 682 684 683 int left, right, top, bottom; 684 getContentsMargins( &left, &top, &right, &bottom ); 685 const QMargins m = contentsMargins(); 685 686 686 687 QRect layoutRect; 687 layoutRect.setLeft( qCeil( rect.left() ) + left);688 layoutRect.setTop( qCeil( rect.top() ) + top);689 layoutRect.setRight( qFloor( rect.right() ) - right);690 layoutRect.setBottom( qFloor( rect.bottom() ) - bottom);688 layoutRect.setLeft( qwtCeil( rect.left() ) + m.left() ); 689 layoutRect.setTop( qwtCeil( rect.top() ) + m.top() ); 690 layoutRect.setRight( qwtFloor( rect.right() ) - m.right() ); 691 layoutRect.setBottom( qwtFloor( rect.bottom() ) - m.bottom() ); 691 692 692 693 uint numCols = legendLayout->columnsForWidth( layoutRect.width() ); 693 const QList< QRect> itemRects =694 const QList< QRect > itemRects = 694 695 legendLayout->layoutItems( layoutRect, numCols ); 695 696 … … 698 699 for ( int i = 0; i < legendLayout->count(); i++ ) 699 700 { 700 QLayoutItem *item = legendLayout->itemAt( i );701 QWidget *w = item->widget();701 QLayoutItem* item = legendLayout->itemAt( i ); 702 QWidget* w = item->widget(); 702 703 if ( w ) 703 704 { … … 714 715 715 716 /*! 716 Render a legend entry into a given rectangle. 717 718 \param painter Painter 719 \param widget Widget representing a legend entry 720 \param rect Bounding rectangle 721 \param fillBackground When true, fill rect with the widget background 722 723 \note When widget is not derived from QwtLegendLabel renderItem 717 Render a legend entry into a given rectangle. 718 719 \param painter Painter 720 \param widget Widget representing a legend entry 721 \param rect Bounding rectangle 722 \param fillBackground When true, fill rect with the widget background 723 724 \note When widget is not derived from QwtLegendLabel renderItem 724 725 does nothing beside the background 725 */ 726 void QwtLegend::renderItem( QPainter *painter,727 const QWidget *widget, const QRectF&rect, bool fillBackground ) const726 */ 727 void QwtLegend::renderItem( QPainter* painter, 728 const QWidget* widget, const QRectF& rect, bool fillBackground ) const 728 729 { 729 730 if ( fillBackground ) … … 736 737 } 737 738 738 const QwtLegendLabel *label = qobject_cast<const QwtLegendLabel*>( widget );739 const QwtLegendLabel* label = qobject_cast< const QwtLegendLabel* >( widget ); 739 740 if ( label ) 740 741 { 741 742 // icon 742 743 743 const QwtGraphic &icon = label->data().icon();744 const QwtGraphic& icon = label->data().icon(); 744 745 const QSizeF sz = icon.defaultSize(); 745 746 … … 756 757 757 758 QFont labelFont = label->font(); 759 #if QT_VERSION >= 0x060000 760 labelFont.setResolveMask( QFont::AllPropertiesResolved ); 761 #else 758 762 labelFont.resolve( QFont::AllPropertiesResolved ); 763 #endif 759 764 760 765 painter->setFont( labelFont ); 761 766 painter->setPen( label->palette().color( QPalette::Text ) ); 762 767 763 const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect );764 } 765 } 766 767 /*! 768 \return List of widgets associated to a item 769 \param itemInfo Info about an item 770 \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo() 771 */ 772 QList<QWidget *> QwtLegend::legendWidgets( const QVariant&itemInfo ) const773 { 774 return d_data->itemMap.legendWidgets( itemInfo );775 } 776 777 /*! 778 \return First widget in the list of widgets associated to an item 779 \param itemInfo Info about an item 780 \sa itemInfo(), QwtPlot::itemToInfo() 781 \note Almost all types of items have only one widget 782 */ 783 QWidget *QwtLegend::legendWidget( const QVariant&itemInfo ) const784 { 785 const QList<QWidget *> list =d_data->itemMap.legendWidgets( itemInfo );768 const_cast< QwtLegendLabel* >( label )->drawText( painter, titleRect ); 769 } 770 } 771 772 /*! 773 \return List of widgets associated to a item 774 \param itemInfo Info about an item 775 \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo() 776 */ 777 QList< QWidget* > QwtLegend::legendWidgets( const QVariant& itemInfo ) const 778 { 779 return m_data->itemMap.legendWidgets( itemInfo ); 780 } 781 782 /*! 783 \return First widget in the list of widgets associated to an item 784 \param itemInfo Info about an item 785 \sa itemInfo(), QwtPlot::itemToInfo() 786 \note Almost all types of items have only one widget 787 */ 788 QWidget* QwtLegend::legendWidget( const QVariant& itemInfo ) const 789 { 790 const QList< QWidget* > list = m_data->itemMap.legendWidgets( itemInfo ); 786 791 if ( list.isEmpty() ) 787 792 return NULL; … … 791 796 792 797 /*! 793 Find the item that is associated to a widget 794 795 \param widget Widget on the legend 796 \return Associated item info 797 \sa legendWidget() 798 */ 799 QVariant QwtLegend::itemInfo( const QWidget *widget ) const800 { 801 return d_data->itemMap.itemInfo( widget );798 Find the item that is associated to a widget 799 800 \param widget Widget on the legend 801 \return Associated item info 802 \sa legendWidget() 803 */ 804 QVariant QwtLegend::itemInfo( const QWidget* widget ) const 805 { 806 return m_data->itemMap.itemInfo( widget ); 802 807 } 803 808 … … 805 810 bool QwtLegend::isEmpty() const 806 811 { 807 return d_data->itemMap.isEmpty();812 return m_data->itemMap.isEmpty(); 808 813 } 809 814 … … 826 831 } 827 832 833 #include "moc_qwt_legend.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
