Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_marker.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_marker.cpp
r4271 r8127 14 14 #include "qwt_text.h" 15 15 #include "qwt_math.h" 16 #include "qwt_legend.h"17 #include "qwt_legend_item.h"18 16 #include <qpainter.h> 19 17 … … 51 49 52 50 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 53 QwtPlotMarker::QwtPlotMarker(): 54 QwtPlotItem( QwtText( "Marker" ) ) 51 QwtPlotMarker::QwtPlotMarker( const QString &title ): 52 QwtPlotItem( QwtText( title ) ) 53 { 54 d_data = new PrivateData; 55 setZ( 30.0 ); 56 } 57 58 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 59 QwtPlotMarker::QwtPlotMarker( const QwtText &title ): 60 QwtPlotItem( title ) 55 61 { 56 62 d_data = new PrivateData; … … 123 129 \param xMap x Scale Map 124 130 \param yMap y Scale Map 125 \param canvasRect Contents rect of the canvas in painter coordinates131 \param canvasRect Contents rectangle of the canvas in painter coordinates 126 132 */ 127 133 void QwtPlotMarker::draw( QPainter *painter, … … 140 146 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) 141 147 { 142 d_data->symbol->drawSymbol( painter, pos ); 148 const QSizeF sz = d_data->symbol->size(); 149 150 const QRectF clipRect = canvasRect.adjusted( 151 -sz.width(), -sz.height(), sz.width(), sz.height() ); 152 153 if ( clipRect.contains( pos ) ) 154 d_data->symbol->drawSymbol( painter, pos ); 143 155 } 144 156 … … 150 162 151 163 \param painter Painter 152 \param canvasRect Contents rect of the canvas in painter coordinates164 \param canvasRect Contents rectangle of the canvas in painter coordinates 153 165 \param pos Position of the marker, translated into widget coordinates 154 166 … … 190 202 191 203 \param painter Painter 192 \param canvasRect Contents rect of the canvas in painter coordinates204 \param canvasRect Contents rectangle of the canvas in painter coordinates 193 205 \param pos Position of the marker, translated into widget coordinates 194 206 … … 334 346 { 335 347 d_data->style = style; 348 349 legendChanged(); 336 350 itemChanged(); 337 351 } … … 358 372 delete d_data->symbol; 359 373 d_data->symbol = symbol; 374 375 if ( symbol ) 376 setLegendIconSize( symbol->boundingRect().size() ); 377 378 legendChanged(); 360 379 itemChanged(); 361 380 } … … 373 392 /*! 374 393 \brief Set the label 375 \param label label text394 \param label Label text 376 395 \sa label() 377 396 */ … … 484 503 } 485 504 505 /*! 506 Build and assign a line pen 507 508 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 509 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 510 to hide this incompatibility. 511 512 \param color Pen color 513 \param width Pen width 514 \param style Pen style 515 516 \sa pen(), brush() 517 */ 518 void QwtPlotMarker::setLinePen( const QColor &color, qreal width, Qt::PenStyle style ) 519 { 520 setLinePen( QPen( color, width, style ) ); 521 } 522 486 523 /*! 487 524 Specify a pen for the line. … … 495 532 { 496 533 d_data->pen = pen; 534 535 legendChanged(); 497 536 itemChanged(); 498 537 } … … 514 553 515 554 /*! 516 \brief Update the widget that represents the item on the legend 517 518 \param legend Legend 519 \sa drawLegendIdentifier(), legendItem(), itemChanged(), QwtLegend() 520 521 \note In the default setting QwtPlotItem::Legend is disabled 522 */ 523 void QwtPlotMarker::updateLegend( QwtLegend *legend ) const 524 { 525 if ( legend && testItemAttribute( QwtPlotItem::Legend ) 526 && d_data->symbol && d_data->symbol->style() != QwtSymbol::NoSymbol ) 527 { 528 QWidget *lgdItem = legend->find( this ); 529 if ( lgdItem == NULL ) 530 { 531 lgdItem = legendItem(); 532 if ( lgdItem ) 533 legend->insert( this, lgdItem ); 534 } 535 536 QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem ); 537 if ( l ) 538 l->setIdentifierSize( d_data->symbol->boundingSize() ); 539 } 540 541 QwtPlotItem::updateLegend( legend ); 542 } 543 544 /*! 545 \brief Draw the identifier representing the marker on the legend 546 547 \param painter Painter 548 \param rect Bounding rectangle for the identifier 549 550 \sa updateLegend(), QwtPlotItem::Legend 551 */ 552 void QwtPlotMarker::drawLegendIdentifier( 553 QPainter *painter, const QRectF &rect ) const 554 { 555 if ( rect.isEmpty() ) 556 return; 557 558 painter->save(); 559 painter->setClipRect( rect, Qt::IntersectClip ); 555 \return Icon representing the marker on the legend 556 557 \param index Index of the legend entry 558 ( usually there is only one ) 559 \param size Icon size 560 561 \sa setLegendIconSize(), legendData() 562 */ 563 QwtGraphic QwtPlotMarker::legendIcon( int index, 564 const QSizeF &size ) const 565 { 566 Q_UNUSED( index ); 567 568 if ( size.isEmpty() ) 569 return QwtGraphic(); 570 571 QwtGraphic icon; 572 icon.setDefaultSize( size ); 573 icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 574 575 QPainter painter( &icon ); 576 painter.setRenderHint( QPainter::Antialiasing, 577 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 560 578 561 579 if ( d_data->style != QwtPlotMarker::NoLine ) 562 580 { 563 painter ->setPen( d_data->pen );581 painter.setPen( d_data->pen ); 564 582 565 583 if ( d_data->style == QwtPlotMarker::HLine || 566 584 d_data->style == QwtPlotMarker::Cross ) 567 585 { 568 QwtPainter::drawLine( painter, rect.left(), rect.center().y(), 569 rect.right(), rect.center().y() ); 586 const double y = 0.5 * size.height(); 587 588 QwtPainter::drawLine( &painter, 589 0.0, y, size.width(), y ); 570 590 } 571 591 … … 573 593 d_data->style == QwtPlotMarker::Cross ) 574 594 { 575 QwtPainter::drawLine( painter, rect.center().x(), rect.top(), 576 rect.center().x(), rect.bottom() ); 595 const double x = 0.5 * size.width(); 596 597 QwtPainter::drawLine( &painter, 598 x, 0.0, x, size.height() ); 577 599 } 578 600 } 579 601 580 if ( d_data->symbol && d_data->symbol->style() != QwtSymbol::NoSymbol ) 581 { 582 QSize symbolSize = d_data->symbol->boundingSize(); 583 symbolSize -= QSize( 2, 2 ); 584 585 // scale the symbol size down if it doesn't fit into rect. 586 587 double xRatio = 1.0; 588 if ( rect.width() < symbolSize.width() ) 589 xRatio = rect.width() / symbolSize.width(); 590 double yRatio = 1.0; 591 if ( rect.height() < symbolSize.height() ) 592 yRatio = rect.height() / symbolSize.height(); 593 594 const double ratio = qMin( xRatio, yRatio ); 595 596 painter->scale( ratio, ratio ); 597 d_data->symbol->drawSymbol( painter, rect.center() / ratio ); 598 } 599 600 painter->restore(); 601 } 602 602 if ( d_data->symbol ) 603 { 604 const QRect r( 0.0, 0.0, size.width(), size.height() ); 605 d_data->symbol->drawSymbol( &painter, r ); 606 } 607 608 return icon; 609 } 610
Note:
See TracChangeset
for help on using the changeset viewer.