Changeset 8127 in ntrip for trunk/BNC/qwtpolar/qwt_polar_curve.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwtpolar/qwt_polar_curve.cpp
r7990 r8127 14 14 #include <qwt_symbol.h> 15 15 #include <qwt_legend.h> 16 #include <qwt_legend_item.h>17 16 #include <qwt_curve_fitter.h> 18 17 #include <qwt_clipper.h> … … 174 173 \sa symbol() 175 174 */ 176 void QwtPolarCurve::setSymbol( constQwtSymbol *symbol )175 void QwtPolarCurve::setSymbol( QwtSymbol *symbol ) 177 176 { 178 177 if ( symbol != d_data->symbol ) … … 434 433 if ( !clipRect.isEmpty() ) 435 434 { 436 double off = qCeil( qMax( qreal(1.0), painter->pen().widthF() ) );435 double off = qCeil( qMax( qreal( 1.0 ), painter->pen().widthF() ) ); 437 436 clipRect = clipRect.toRect().adjusted( -off, -off, off, off ); 438 437 polyline = QwtClipper::clipPolygonF( clipRect, polyline ); … … 501 500 } 502 501 503 //! Update the widget that represents the curve on the legend 504 void QwtPolarCurve::updateLegend( QwtLegend *legend ) const 505 { 506 if ( legend && testItemAttribute( QwtPolarCurve::Legend ) 507 && ( d_data->legendAttributes & QwtPolarCurve::LegendShowSymbol ) 508 && d_data->symbol 509 && d_data->symbol->style() != QwtSymbol::NoSymbol ) 510 { 511 QWidget *lgdItem = legend->find( this ); 512 if ( lgdItem == NULL ) 513 { 514 lgdItem = legendItem(); 515 if ( lgdItem ) 516 legend->insert( this, lgdItem ); 517 } 518 519 QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem ); 520 if ( l ) 521 { 522 QSize sz = d_data->symbol->boundingSize(); 523 sz += QSize( 2, 2 ); // margin 524 525 if ( d_data->legendAttributes & QwtPolarCurve::LegendShowLine ) 526 { 527 // Avoid, that the line is completely covered by the symbol 528 529 int w = qCeil( 1.5 * sz.width() ); 530 if ( w % 2 ) 531 w++; 532 533 sz.setWidth( qMax( 8, w ) ); 534 } 535 536 l->setIdentifierSize( sz ); 537 } 538 } 539 540 QwtPolarItem::updateLegend( legend ); 541 } 542 543 /*! 544 \brief Draw the identifier representing the curve on the legend 545 546 \param painter Qt Painter 547 \param rect Bounding rectangle for the identifier 548 549 \sa setLegendAttribute 550 */ 551 void QwtPolarCurve::drawLegendIdentifier( 552 QPainter *painter, const QRectF &rect ) const 553 { 554 if ( rect.isEmpty() ) 555 return; 556 557 const double dim = qMin( rect.width(), rect.height() ); 558 559 QSizeF size( dim, dim ); 560 561 QRectF r( 0, 0, size.width(), size.height() ); 562 r.moveCenter( rect.center() ); 502 /*! 503 \return Icon representing the curve on the legend 504 505 \param index Index of the legend entry 506 ( ignored as there is only one ) 507 \param size Icon size 508 509 \sa QwtPolarItem::setLegendIconSize(), QwtPolarItem::legendData() 510 */ 511 QwtGraphic QwtPolarCurve::legendIcon( int index, 512 const QSizeF &size ) const 513 { 514 Q_UNUSED( index ); 515 516 if ( size.isEmpty() ) 517 return QwtGraphic(); 518 519 QwtGraphic graphic; 520 graphic.setDefaultSize( size ); 521 graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 522 523 QPainter painter( &graphic ); 524 painter.setRenderHint( QPainter::Antialiasing, 525 testRenderHint( QwtPolarItem::RenderAntialiased ) ); 563 526 564 527 if ( d_data->legendAttributes == 0 ) 565 528 { 566 529 QBrush brush; 530 567 531 if ( style() != QwtPolarCurve::NoCurve ) 532 { 568 533 brush = QBrush( pen().color() ); 534 } 569 535 else if ( d_data->symbol && 570 536 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) … … 572 538 brush = QBrush( d_data->symbol->pen().color() ); 573 539 } 540 574 541 if ( brush.style() != Qt::NoBrush ) 575 painter->fillRect( r, brush ); 576 } 542 { 543 QRectF r( 0, 0, size.width(), size.height() ); 544 painter.fillRect( r, brush ); 545 } 546 } 547 577 548 if ( d_data->legendAttributes & QwtPolarCurve::LegendShowLine ) 578 549 { 579 550 if ( pen() != Qt::NoPen ) 580 551 { 581 painter->setPen( pen() ); 582 QwtPainter::drawLine( painter, rect.left(), rect.center().y(), 583 rect.right() - 1.0, rect.center().y() ); 584 } 585 } 552 QPen pn = pen(); 553 pn.setCapStyle( Qt::FlatCap ); 554 555 painter.setPen( pn ); 556 557 const double y = 0.5 * size.height(); 558 QwtPainter::drawLine( &painter, 0.0, y, size.width(), y ); 559 } 560 } 561 586 562 if ( d_data->legendAttributes & QwtPolarCurve::LegendShowSymbol ) 587 563 { 588 if ( d_data->symbol && 589 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) 590 { 591 QSize symbolSize = d_data->symbol->boundingSize(); 592 symbolSize -= QSize( 2, 2 ); 593 594 // scale the symbol size down if it doesn't fit into rect. 595 596 double xRatio = 1.0; 597 if ( rect.width() < symbolSize.width() ) 598 xRatio = rect.width() / symbolSize.width(); 599 double yRatio = 1.0; 600 if ( rect.height() < symbolSize.height() ) 601 yRatio = rect.height() / symbolSize.height(); 602 603 const double ratio = qMin( xRatio, yRatio ); 604 605 painter->save(); 606 painter->scale( ratio, ratio ); 607 608 d_data->symbol->drawSymbol( painter, rect.center() / ratio ); 609 610 painter->restore(); 611 } 612 } 564 if ( d_data->symbol ) 565 { 566 QRectF r( 0, 0, size.width(), size.height() ); 567 d_data->symbol->drawSymbol( &painter, r ); 568 } 569 } 570 571 return graphic; 613 572 } 614 573 … … 634 593 return QwtInterval(); 635 594 } 595 596
Note:
See TracChangeset
for help on using the changeset viewer.