Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_intervalcurve.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_intervalcurve.cpp
r4271 r8127 13 13 #include "qwt_clipper.h" 14 14 #include "qwt_painter.h" 15 #include <string.h> 15 16 16 17 #include <qpainter.h> … … 24 25 25 26 const bool isOffScreen = ( y < yMin ) || ( y > yMax ) 26 || ( x1 < xMin && x2 < xMin ) || ( x1 > yMax && x2 > xMax );27 || ( x1 < xMin && x2 < xMin ) || ( x1 > xMax && x2 > xMax ); 27 28 28 29 return !isOffScreen; … … 46 47 public: 47 48 PrivateData(): 48 style( Tube ),49 style( QwtPlotIntervalCurve::Tube ), 49 50 symbol( NULL ), 50 51 pen( Qt::black ), … … 53 54 paintAttributes = QwtPlotIntervalCurve::ClipPolygons; 54 55 paintAttributes |= QwtPlotIntervalCurve::ClipSymbol; 55 56 56 57 pen.setCapStyle( Qt::FlatCap ); 57 58 } … … 62 63 } 63 64 64 CurveStyle style;65 QwtPlotIntervalCurve::CurveStyle style; 65 66 const QwtIntervalSymbol *symbol; 66 67 … … 76 77 */ 77 78 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ): 78 QwtPlotSeriesItem <QwtIntervalSample>( title )79 QwtPlotSeriesItem( title ) 79 80 { 80 81 init(); … … 86 87 */ 87 88 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ): 88 QwtPlotSeriesItem <QwtIntervalSample>( QwtText( title ) )89 QwtPlotSeriesItem( QwtText( title ) ) 89 90 { 90 91 init(); … … 104 105 105 106 d_data = new PrivateData; 106 d_series = new QwtIntervalSeriesData();107 setData( new QwtIntervalSeriesData() ); 107 108 108 109 setZ( 19.0 ); … … 122 123 \sa testPaintAttribute() 123 124 */ 124 void QwtPlotIntervalCurve::setPaintAttribute( 125 void QwtPlotIntervalCurve::setPaintAttribute( 125 126 PaintAttribute attribute, bool on ) 126 127 { … … 132 133 133 134 /*! 134 \ brief Return the current paint attributes135 \return True, when attribute is enabled 135 136 \sa PaintAttribute, setPaintAttribute() 136 137 */ 137 bool QwtPlotIntervalCurve::testPaintAttribute( 138 bool QwtPlotIntervalCurve::testPaintAttribute( 138 139 PaintAttribute attribute ) const 139 140 { … … 148 149 const QVector<QwtIntervalSample> &samples ) 149 150 { 150 delete d_series; 151 d_series = new QwtIntervalSeriesData( samples ); 152 itemChanged(); 151 setData( new QwtIntervalSeriesData( samples ) ); 152 } 153 154 /*! 155 Assign a series of samples 156 157 setSamples() is just a wrapper for setData() without any additional 158 value - beside that it is easier to find for the developer. 159 160 \param data Data 161 \warning The item takes ownership of the data object, deleting 162 it when its not used anymore. 163 */ 164 void QwtPlotIntervalCurve::setSamples( 165 QwtSeriesData<QwtIntervalSample> *data ) 166 { 167 setData( data ); 153 168 } 154 169 … … 164 179 { 165 180 d_data->style = style; 181 182 legendChanged(); 166 183 itemChanged(); 167 184 } … … 169 186 170 187 /*! 171 \ brief Return the current style188 \return Style of the curve 172 189 \sa setStyle() 173 190 */ … … 189 206 delete d_data->symbol; 190 207 d_data->symbol = symbol; 208 209 legendChanged(); 191 210 itemChanged(); 192 211 } … … 201 220 return d_data->symbol; 202 221 } 222 223 /*! 224 Build and assign a pen 225 226 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 227 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 228 to hide this incompatibility. 229 230 \param color Pen color 231 \param width Pen width 232 \param style Pen style 233 234 \sa pen(), brush() 235 */ 236 void QwtPlotIntervalCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style ) 237 { 238 setPen( QPen( color, width, style ) ); 239 } 203 240 204 241 /*! … … 212 249 { 213 250 d_data->pen = pen; 251 252 legendChanged(); 214 253 itemChanged(); 215 254 } … … 217 256 218 257 /*! 219 \ brief Return the pen used to draw the lines258 \return Pen used to draw the lines 220 259 \sa setPen(), brush() 221 260 */ … … 238 277 { 239 278 d_data->brush = brush; 279 280 legendChanged(); 240 281 itemChanged(); 241 282 } … … 257 298 QRectF QwtPlotIntervalCurve::boundingRect() const 258 299 { 259 QRectF rect = QwtPlotSeriesItem <QwtIntervalSample>::boundingRect();300 QRectF rect = QwtPlotSeriesItem::boundingRect(); 260 301 if ( rect.isValid() && orientation() == Qt::Vertical ) 261 302 rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() ); … … 270 311 \param xMap Maps x-values into pixel coordinates. 271 312 \param yMap Maps y-values into pixel coordinates. 272 \param canvasRect Contents rect of the canvas313 \param canvasRect Contents rectangle of the canvas 273 314 \param from Index of the first sample to be painted 274 315 \param to Index of the last sample to be painted. If to < 0 the … … 304 345 ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) 305 346 { 306 drawSymbols( painter, *d_data->symbol, 347 drawSymbols( painter, *d_data->symbol, 307 348 xMap, yMap, canvasRect, from, to ); 308 349 } … … 319 360 \param xMap Maps x-values into pixel coordinates. 320 361 \param yMap Maps y-values into pixel coordinates. 321 \param canvasRect Contents rect of the canvas362 \param canvasRect Contents rectangle of the canvas 322 363 \param from Index of the first sample to be painted 323 364 \param to Index of the last sample to be painted. If to < 0 the … … 388 429 { 389 430 const qreal m = 1.0; 390 const QPolygonF p = QwtClipper::clipPolygonF( 391 canvasRect.adjusted(-m, -m, m, m), polygon, true );431 const QPolygonF p = QwtClipper::clipPolygonF( 432 canvasRect.adjusted( -m, -m, m, m ), polygon, true ); 392 433 393 434 QwtPainter::drawPolygon( painter, p ); … … 406 447 if ( d_data->paintAttributes & ClipPolygons ) 407 448 { 408 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );409 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw);449 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() ); 450 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 410 451 411 452 QPolygonF p; 412 453 413 454 p.resize( size ); 414 qMemCopy( p.data(), points, size * sizeof( QPointF ) );415 p = QwtClipper::clipPolygonF( c anvasRect, p );455 ::memcpy( p.data(), points, size * sizeof( QPointF ) ); 456 p = QwtClipper::clipPolygonF( clipRect, p ); 416 457 QwtPainter::drawPolyline( painter, p ); 417 458 418 459 p.resize( size ); 419 qMemCopy( p.data(), points + size, size * sizeof( QPointF ) );420 p = QwtClipper::clipPolygonF( c anvasRect, p );460 ::memcpy( p.data(), points + size, size * sizeof( QPointF ) ); 461 p = QwtClipper::clipPolygonF( clipRect, p ); 421 462 QwtPainter::drawPolyline( painter, p ); 422 463 } … … 438 479 \param xMap x map 439 480 \param yMap y map 440 \param canvasRect Contents rect of the canvas481 \param canvasRect Contents rectangle of the canvas 441 482 \param from Index of the first sample to be painted 442 483 \param to Index of the last sample to be painted … … 457 498 painter->setBrush( symbol.brush() ); 458 499 459 const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect);500 const QRectF tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect ); 460 501 461 502 const double xMin = tr.left(); … … 464 505 const double yMax = tr.bottom(); 465 506 466 const bool doClip = d_data->paintAttributes & Clip Polygons;507 const bool doClip = d_data->paintAttributes & ClipSymbol; 467 508 468 509 for ( int i = from; i <= to; i++ ) … … 500 541 501 542 /*! 502 In case of Tibe stale() a plain rectangle is painted without a pen filled 503 the brush(). If a symbol is assigned it is painted cebtered into rect. 504 505 \param painter Painter 506 \param rect Bounding rectangle for the identifier 507 */ 508 509 void QwtPlotIntervalCurve::drawLegendIdentifier( 510 QPainter *painter, const QRectF &rect ) const 511 { 512 const double dim = qMin( rect.width(), rect.height() ); 513 514 QSizeF size( dim, dim ); 515 516 QRectF r( 0, 0, size.width(), size.height() ); 517 r.moveCenter( rect.center() ); 543 \return Icon for the legend 544 545 In case of Tube style() the icon is a plain rectangle filled with the brush(). 546 If a symbol is assigned it is scaled to size. 547 548 \param index Index of the legend entry 549 ( ignored as there is only one ) 550 \param size Icon size 551 552 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 553 */ 554 QwtGraphic QwtPlotIntervalCurve::legendIcon( 555 int index, const QSizeF &size ) const 556 { 557 Q_UNUSED( index ); 558 559 if ( size.isEmpty() ) 560 return QwtGraphic(); 561 562 QwtGraphic icon; 563 icon.setDefaultSize( size ); 564 icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 565 566 QPainter painter( &icon ); 567 painter.setRenderHint( QPainter::Antialiasing, 568 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 518 569 519 570 if ( d_data->style == Tube ) 520 571 { 521 painter->fillRect( r, d_data->brush ); 572 QRectF r( 0, 0, size.width(), size.height() ); 573 painter.fillRect( r, d_data->brush ); 522 574 } 523 575 … … 529 581 pen.setCapStyle( Qt::FlatCap ); 530 582 531 painter ->setPen( pen );532 painter ->setBrush( d_data->symbol->brush() );583 painter.setPen( pen ); 584 painter.setBrush( d_data->symbol->brush() ); 533 585 534 586 if ( orientation() == Qt::Vertical ) 535 587 { 536 d_data->symbol->draw( painter, orientation(), 537 QPointF( r.center().x(), r.top() ), 538 QPointF( r.center().x(), r.bottom() - 1 ) ); 588 const double x = 0.5 * size.width(); 589 590 d_data->symbol->draw( &painter, orientation(), 591 QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) ); 539 592 } 540 593 else 541 594 { 542 d_data->symbol->draw( painter, orientation(), 543 QPointF( r.left(), r.center().y() ), 544 QPointF( r.right() - 1, r.center().y() ) ); 545 } 546 } 547 } 595 const double y = 0.5 * size.height(); 596 597 d_data->symbol->draw( &painter, orientation(), 598 QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) ); 599 } 600 } 601 602 return icon; 603 }
Note:
See TracChangeset
for help on using the changeset viewer.