Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_histogram.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (9 days ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_histogram.cpp (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_histogram.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot_histogram.h" 11 #include "qwt_plot.h"12 11 #include "qwt_painter.h" 13 12 #include "qwt_column_symbol.h" 14 13 #include "qwt_scale_map.h" 14 #include "qwt_graphic.h" 15 15 16 #include <qstring.h> 16 17 #include <qpainter.h> 17 18 18 static inline bool qwtIsCombinable( const QwtInterval &d1,19 const QwtInterval &d2 )19 static inline bool qwtIsCombinable( const QwtInterval& d1, 20 const QwtInterval& d2 ) 20 21 { 21 22 if ( d1.isValid() && d2.isValid() ) … … 36 37 class QwtPlotHistogram::PrivateData 37 38 { 38 public: 39 PrivateData() :40 baseline( 0.0 ) ,41 style( Columns ) ,42 symbol( NULL ) 39 public: 40 PrivateData() 41 : baseline( 0.0 ) 42 , style( Columns ) 43 , symbol( NULL ) 43 44 { 44 45 } … … 54 55 QBrush brush; 55 56 QwtPlotHistogram::HistogramStyle style; 56 const QwtColumnSymbol *symbol;57 const QwtColumnSymbol* symbol; 57 58 }; 58 59 59 60 /*! 60 Constructor 61 \param title Title of the histogram. 62 */ 63 QwtPlotHistogram::QwtPlotHistogram( const QwtText &title ):64 QwtPlotSeriesItem( title ) 61 Constructor 62 \param title Title of the histogram. 63 */ 64 QwtPlotHistogram::QwtPlotHistogram( const QwtText& title ) 65 : QwtPlotSeriesItem( title ) 65 66 { 66 67 init(); … … 68 69 69 70 /*! 70 Constructor 71 \param title Title of the histogram. 72 */ 73 QwtPlotHistogram::QwtPlotHistogram( const QString &title ):74 QwtPlotSeriesItem( title ) 71 Constructor 72 \param title Title of the histogram. 73 */ 74 QwtPlotHistogram::QwtPlotHistogram( const QString& title ) 75 : QwtPlotSeriesItem( title ) 75 76 { 76 77 init(); … … 80 81 QwtPlotHistogram::~QwtPlotHistogram() 81 82 { 82 delete d_data;83 delete m_data; 83 84 } 84 85 … … 86 87 void QwtPlotHistogram::init() 87 88 { 88 d_data = new PrivateData();89 m_data = new PrivateData(); 89 90 setData( new QwtIntervalSeriesData() ); 90 91 … … 96 97 97 98 /*! 98 Set the histogram's drawing style 99 100 \param style Histogram style 101 \sa HistogramStyle, style() 102 */ 99 Set the histogram's drawing style 100 101 \param style Histogram style 102 \sa HistogramStyle, style() 103 */ 103 104 void QwtPlotHistogram::setStyle( HistogramStyle style ) 104 105 { 105 if ( style != d_data->style )106 { 107 d_data->style = style;106 if ( style != m_data->style ) 107 { 108 m_data->style = style; 108 109 109 110 legendChanged(); … … 115 116 \return Style of the histogram 116 117 \sa HistogramStyle, setStyle() 117 */ 118 */ 118 119 QwtPlotHistogram::HistogramStyle QwtPlotHistogram::style() const 119 120 { 120 return d_data->style;121 } 122 123 /*! 124 Build and assign a pen 125 126 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 127 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 128 to hide this incompatibility. 129 130 \param color Pen color 131 \param width Pen width 132 \param style Pen style 133 134 \sa pen(), brush() 135 */ 136 void QwtPlotHistogram::setPen( const QColor &color, qreal width, Qt::PenStyle style )121 return m_data->style; 122 } 123 124 /*! 125 Build and assign a pen 126 127 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 128 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 129 to hide this incompatibility. 130 131 \param color Pen color 132 \param width Pen width 133 \param style Pen style 134 135 \sa pen(), brush() 136 */ 137 void QwtPlotHistogram::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 137 138 { 138 139 setPen( QPen( color, width, style ) ); … … 140 141 141 142 /*! 142 Assign a pen, that is used in a style() depending way. 143 144 \param pen New pen 145 \sa pen(), brush() 146 */ 147 void QwtPlotHistogram::setPen( const QPen &pen )148 { 149 if ( pen != d_data->pen )150 { 151 d_data->pen = pen;143 Assign a pen, that is used in a style() depending way. 144 145 \param pen New pen 146 \sa pen(), brush() 147 */ 148 void QwtPlotHistogram::setPen( const QPen& pen ) 149 { 150 if ( pen != m_data->pen ) 151 { 152 m_data->pen = pen; 152 153 153 154 legendChanged(); … … 157 158 158 159 /*! 159 \return Pen used in a style() depending way. 160 \sa setPen(), brush() 161 */ 162 const QPen &QwtPlotHistogram::pen() const163 { 164 return d_data->pen;165 } 166 167 /*! 168 Assign a brush, that is used in a style() depending way. 169 170 \param brush New brush 171 \sa pen(), brush() 172 */ 173 void QwtPlotHistogram::setBrush( const QBrush &brush )174 { 175 if ( brush != d_data->brush )176 { 177 d_data->brush = brush;160 \return Pen used in a style() depending way. 161 \sa setPen(), brush() 162 */ 163 const QPen& QwtPlotHistogram::pen() const 164 { 165 return m_data->pen; 166 } 167 168 /*! 169 Assign a brush, that is used in a style() depending way. 170 171 \param brush New brush 172 \sa pen(), brush() 173 */ 174 void QwtPlotHistogram::setBrush( const QBrush& brush ) 175 { 176 if ( brush != m_data->brush ) 177 { 178 m_data->brush = brush; 178 179 179 180 legendChanged(); … … 183 184 184 185 /*! 185 \return Brush used in a style() depending way. 186 \sa setPen(), brush() 187 */ 188 const QBrush &QwtPlotHistogram::brush() const189 { 190 return d_data->brush;191 } 192 193 /*! 194 \brief Assign a symbol 195 196 In Column style an optional symbol can be assigned, that is responsible 197 for displaying the rectangle that is defined by the interval and 198 the distance between baseline() and value. When no symbol has been 199 defined the area is displayed as plain rectangle using pen() and brush(). 200 201 \sa style(), symbol(), drawColumn(), pen(), brush() 202 203 \note In applications, where different intervals need to be displayed 186 \return Brush used in a style() depending way. 187 \sa setPen(), brush() 188 */ 189 const QBrush& QwtPlotHistogram::brush() const 190 { 191 return m_data->brush; 192 } 193 194 /*! 195 \brief Assign a symbol 196 197 In Column style an optional symbol can be assigned, that is responsible 198 for displaying the rectangle that is defined by the interval and 199 the distance between baseline() and value. When no symbol has been 200 defined the area is displayed as plain rectangle using pen() and brush(). 201 202 \sa style(), symbol(), drawColumn(), pen(), brush() 203 204 \note In applications, where different intervals need to be displayed 204 205 in a different way ( f.e different colors or even using different symbols) 205 206 it is recommended to overload drawColumn(). 206 */ 207 void QwtPlotHistogram::setSymbol( const QwtColumnSymbol *symbol )208 { 209 if ( symbol != d_data->symbol )210 { 211 delete d_data->symbol;212 d_data->symbol = symbol;207 */ 208 void QwtPlotHistogram::setSymbol( const QwtColumnSymbol* symbol ) 209 { 210 if ( symbol != m_data->symbol ) 211 { 212 delete m_data->symbol; 213 m_data->symbol = symbol; 213 214 214 215 legendChanged(); … … 218 219 219 220 /*! 220 \return Current symbol or NULL, when no symbol has been assigned 221 \sa setSymbol() 222 */ 223 const QwtColumnSymbol *QwtPlotHistogram::symbol() const224 { 225 return d_data->symbol;226 } 227 228 /*! 229 \brief Set the value of the baseline 230 231 Each column representing an QwtIntervalSample is defined by its 232 interval and the interval between baseline and the value of the sample. 233 234 The default value of the baseline is 0.0. 235 236 \param value Value of the baseline 237 \sa baseline() 238 */ 221 \return Current symbol or NULL, when no symbol has been assigned 222 \sa setSymbol() 223 */ 224 const QwtColumnSymbol* QwtPlotHistogram::symbol() const 225 { 226 return m_data->symbol; 227 } 228 229 /*! 230 \brief Set the value of the baseline 231 232 Each column representing an QwtIntervalSample is defined by its 233 interval and the interval between baseline and the value of the sample. 234 235 The default value of the baseline is 0.0. 236 237 \param value Value of the baseline 238 \sa baseline() 239 */ 239 240 void QwtPlotHistogram::setBaseline( double value ) 240 241 { 241 if ( d_data->baseline != value )242 { 243 d_data->baseline = value;242 if ( m_data->baseline != value ) 243 { 244 m_data->baseline = value; 244 245 itemChanged(); 245 246 } … … 247 248 248 249 /*! 249 \return Value of the baseline 250 \sa setBaseline() 251 */ 250 \return Value of the baseline 251 \sa setBaseline() 252 */ 252 253 double QwtPlotHistogram::baseline() const 253 254 { 254 return d_data->baseline;255 } 256 257 /*! 258 \return Bounding rectangle of all samples. 259 For an empty series the rectangle is invalid. 260 */ 255 return m_data->baseline; 256 } 257 258 /*! 259 \return Bounding rectangle of all samples. 260 For an empty series the rectangle is invalid. 261 */ 261 262 QRectF QwtPlotHistogram::boundingRect() const 262 263 { … … 270 271 rect.height(), rect.width() ); 271 272 272 if ( rect.left() > d_data->baseline )273 rect.setLeft( d_data->baseline );274 else if ( rect.right() < d_data->baseline )275 rect.setRight( d_data->baseline );273 if ( rect.left() > m_data->baseline ) 274 rect.setLeft( m_data->baseline ); 275 else if ( rect.right() < m_data->baseline ) 276 rect.setRight( m_data->baseline ); 276 277 } 277 278 else 278 279 { 279 if ( rect.bottom() < d_data->baseline )280 rect.setBottom( d_data->baseline );281 else if ( rect.top() > d_data->baseline )282 rect.setTop( d_data->baseline );280 if ( rect.bottom() < m_data->baseline ) 281 rect.setBottom( m_data->baseline ); 282 else if ( rect.top() > m_data->baseline ) 283 rect.setTop( m_data->baseline ); 283 284 } 284 285 … … 293 294 294 295 /*! 295 Initialize data with an array of samples. 296 \param samples Vector of points 297 */ 296 Initialize data with an array of samples. 297 \param samples Vector of points 298 */ 298 299 void QwtPlotHistogram::setSamples( 299 const QVector<QwtIntervalSample > &samples )300 const QVector< QwtIntervalSample >& samples ) 300 301 { 301 302 setData( new QwtIntervalSeriesData( samples ) ); … … 303 304 304 305 /*! 305 Assign a series of samples 306 307 setSamples() is just a wrapper for setData() without any additional 308 value - beside that it is easier to find for the developer. 309 310 \param data Data 311 \warning The item takes ownership of the data object, deleting 306 Assign a series of samples 307 308 setSamples() is just a wrapper for setData() without any additional 309 value - beside that it is easier to find for the developer. 310 311 \param data Data 312 \warning The item takes ownership of the data object, deleting 312 313 it when its not used anymore. 313 */ 314 */ 314 315 void QwtPlotHistogram::setSamples( 315 QwtSeriesData<QwtIntervalSample > *data )316 QwtSeriesData< QwtIntervalSample >* data ) 316 317 { 317 318 setData( data ); … … 319 320 320 321 /*! 321 Draw a subset of the histogram samples 322 323 \param painter Painter 324 \param xMap Maps x-values into pixel coordinates. 325 \param yMap Maps y-values into pixel coordinates. 326 \param canvasRect Contents rectangle of the canvas 327 \param from Index of the first sample to be painted 328 \param to Index of the last sample to be painted. If to < 0 the 322 Draw a subset of the histogram samples 323 324 \param painter Painter 325 \param xMap Maps x-values into pixel coordinates. 326 \param yMap Maps y-values into pixel coordinates. 327 \param canvasRect Contents rectangle of the canvas 328 \param from Index of the first sample to be painted 329 \param to Index of the last sample to be painted. If to < 0 the 329 330 series will be painted to its last sample. 330 331 331 \sa drawOutline(), drawLines(), drawColumns 332 */ 333 void QwtPlotHistogram::drawSeries( QPainter *painter,334 const QwtScaleMap &xMap, const QwtScaleMap&yMap,335 const QRectF &canvasRect, int from, int to ) const332 \sa drawOutline(), drawLines(), drawColumns 333 */ 334 void QwtPlotHistogram::drawSeries( QPainter* painter, 335 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 336 const QRectF& canvasRect, int from, int to ) const 336 337 { 337 338 Q_UNUSED( canvasRect ) … … 343 344 to = dataSize() - 1; 344 345 345 switch ( d_data->style )346 switch ( m_data->style ) 346 347 { 347 348 case Outline: … … 360 361 361 362 /*! 362 Draw a histogram in Outline style() 363 364 \param painter Painter 365 \param xMap Maps x-values into pixel coordinates. 366 \param yMap Maps y-values into pixel coordinates. 367 \param from Index of the first sample to be painted 368 \param to Index of the last sample to be painted. If to < 0 the 363 Draw a histogram in Outline style() 364 365 \param painter Painter 366 \param xMap Maps x-values into pixel coordinates. 367 \param yMap Maps y-values into pixel coordinates. 368 \param from Index of the first sample to be painted 369 \param to Index of the last sample to be painted. If to < 0 the 369 370 histogram will be painted to its last point. 370 371 371 \sa setStyle(), style() 372 \warning The outline style requires, that the intervals are in increasing 372 \sa setStyle(), style() 373 \warning The outline style requires, that the intervals are in increasing 373 374 order and not overlapping. 374 */ 375 void QwtPlotHistogram::drawOutline( QPainter *painter,376 const QwtScaleMap &xMap, const QwtScaleMap&yMap,375 */ 376 void QwtPlotHistogram::drawOutline( QPainter* painter, 377 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 377 378 int from, int to ) const 378 379 { … … 447 448 448 449 /*! 449 Draw a histogram in Columns style() 450 451 \param painter Painter 452 \param xMap Maps x-values into pixel coordinates. 453 \param yMap Maps y-values into pixel coordinates. 454 \param from Index of the first sample to be painted 455 \param to Index of the last sample to be painted. If to < 0 the 450 Draw a histogram in Columns style() 451 452 \param painter Painter 453 \param xMap Maps x-values into pixel coordinates. 454 \param yMap Maps y-values into pixel coordinates. 455 \param from Index of the first sample to be painted 456 \param to Index of the last sample to be painted. If to < 0 the 456 457 histogram will be painted to its last point. 457 458 458 \sa setStyle(), style(), setSymbol(), drawColumn() 459 */ 460 void QwtPlotHistogram::drawColumns( QPainter *painter,461 const QwtScaleMap &xMap, const QwtScaleMap&yMap,459 \sa setStyle(), style(), setSymbol(), drawColumn() 460 */ 461 void QwtPlotHistogram::drawColumns( QPainter* painter, 462 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 462 463 int from, int to ) const 463 464 { 464 painter->setPen( d_data->pen );465 painter->setBrush( d_data->brush );466 467 const QwtSeriesData<QwtIntervalSample > *series = data();465 painter->setPen( m_data->pen ); 466 painter->setBrush( m_data->brush ); 467 468 const QwtSeriesData< QwtIntervalSample >* series = data(); 468 469 469 470 for ( int i = from; i <= to; i++ ) … … 479 480 480 481 /*! 481 Draw a histogram in Lines style() 482 483 \param painter Painter 484 \param xMap Maps x-values into pixel coordinates. 485 \param yMap Maps y-values into pixel coordinates. 486 \param from Index of the first sample to be painted 487 \param to Index of the last sample to be painted. If to < 0 the 482 Draw a histogram in Lines style() 483 484 \param painter Painter 485 \param xMap Maps x-values into pixel coordinates. 486 \param yMap Maps y-values into pixel coordinates. 487 \param from Index of the first sample to be painted 488 \param to Index of the last sample to be painted. If to < 0 the 488 489 histogram will be painted to its last point. 489 490 490 \sa setStyle(), style(), setPen() 491 */ 492 void QwtPlotHistogram::drawLines( QPainter *painter,493 const QwtScaleMap &xMap, const QwtScaleMap&yMap,491 \sa setStyle(), style(), setPen() 492 */ 493 void QwtPlotHistogram::drawLines( QPainter* painter, 494 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 494 495 int from, int to ) const 495 496 { 496 497 const bool doAlign = QwtPainter::roundingAlignment( painter ); 497 498 498 painter->setPen( d_data->pen );499 painter->setPen( m_data->pen ); 499 500 painter->setBrush( Qt::NoBrush ); 500 501 501 const QwtSeriesData<QwtIntervalSample > *series = data();502 const QwtSeriesData< QwtIntervalSample >* series = data(); 502 503 503 504 for ( int i = from; i <= to; i++ ) … … 549 550 550 551 //! Internal, used by the Outline style. 551 void QwtPlotHistogram::flushPolygon( QPainter *painter,552 double baseLine, QPolygonF &polygon ) const552 void QwtPlotHistogram::flushPolygon( QPainter* painter, 553 double baseLine, QPolygonF& polygon ) const 553 554 { 554 555 if ( polygon.size() == 0 ) … … 560 561 polygon += QPointF( polygon.last().x(), baseLine ); 561 562 562 if ( d_data->brush.style() != Qt::NoBrush )563 if ( m_data->brush.style() != Qt::NoBrush ) 563 564 { 564 565 painter->setPen( Qt::NoPen ); 565 painter->setBrush( d_data->brush );566 painter->setBrush( m_data->brush ); 566 567 567 568 if ( orientation() == Qt::Horizontal ) … … 581 582 polygon.pop_back(); 582 583 } 583 if ( d_data->pen.style() != Qt::NoPen )584 if ( m_data->pen.style() != Qt::NoPen ) 584 585 { 585 586 painter->setBrush( Qt::NoBrush ); 586 painter->setPen( d_data->pen );587 painter->setPen( m_data->pen ); 587 588 QwtPainter::drawPolyline( painter, polygon ); 588 589 } … … 591 592 592 593 /*! 593 Calculate the area that is covered by a sample 594 595 \param sample Sample 596 \param xMap Maps x-values into pixel coordinates. 597 \param yMap Maps y-values into pixel coordinates. 598 599 \return Rectangle, that is covered by a sample 600 */ 601 QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample &sample,602 const QwtScaleMap &xMap, const QwtScaleMap&yMap ) const594 Calculate the area that is covered by a sample 595 596 \param sample Sample 597 \param xMap Maps x-values into pixel coordinates. 598 \param yMap Maps y-values into pixel coordinates. 599 600 \return Rectangle, that is covered by a sample 601 */ 602 QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample& sample, 603 const QwtScaleMap& xMap, const QwtScaleMap& yMap ) const 603 604 { 604 605 QwtColumnRect rect; 605 606 606 const QwtInterval &iv = sample.interval;607 const QwtInterval& iv = sample.interval; 607 608 if ( !iv.isValid() ) 608 609 return rect; … … 611 612 { 612 613 const double x0 = xMap.transform( baseline() ); 613 const double x = xMap.transform( sample.value );614 const double x = xMap.transform( sample.value ); 614 615 const double y1 = yMap.transform( iv.minValue() ); 615 616 const double y2 = yMap.transform( iv.maxValue() ); … … 618 619 rect.vInterval.setInterval( y1, y2, iv.borderFlags() ); 619 620 rect.direction = ( x < x0 ) ? QwtColumnRect::RightToLeft : 620 QwtColumnRect::LeftToRight;621 QwtColumnRect::LeftToRight; 621 622 } 622 623 else … … 637 638 638 639 /*! 639 Draw a column for a sample in Columns style(). 640 641 When a symbol() has been set the symbol is used otherwise the 642 column is displayed as plain rectangle using pen() and brush(). 643 644 \param painter Painter 645 \param rect Rectangle where to paint the column in paint device coordinates 646 \param sample Sample to be displayed 647 648 \note In applications, where different intervals need to be displayed 640 Draw a column for a sample in Columns style(). 641 642 When a symbol() has been set the symbol is used otherwise the 643 column is displayed as plain rectangle using pen() and brush(). 644 645 \param painter Painter 646 \param rect Rectangle where to paint the column in paint device coordinates 647 \param sample Sample to be displayed 648 649 \note In applications, where different intervals need to be displayed 649 650 in a different way ( f.e different colors or even using different symbols) 650 651 it is recommended to overload drawColumn(). 651 */ 652 void QwtPlotHistogram::drawColumn( QPainter *painter,653 const QwtColumnRect &rect, const QwtIntervalSample&sample ) const652 */ 653 void QwtPlotHistogram::drawColumn( QPainter* painter, 654 const QwtColumnRect& rect, const QwtIntervalSample& sample ) const 654 655 { 655 656 Q_UNUSED( sample ); 656 657 657 if ( d_data->symbol &&658 ( d_data->symbol->style() != QwtColumnSymbol::NoStyle ) )659 { 660 d_data->symbol->draw( painter, rect );658 if ( m_data->symbol && 659 ( m_data->symbol->style() != QwtColumnSymbol::NoStyle ) ) 660 { 661 m_data->symbol->draw( painter, rect ); 661 662 } 662 663 else … … 676 677 677 678 /*! 678 A plain rectangle without pen using the brush() 679 680 \param index Index of the legend entry 679 A plain rectangle without pen using the brush() 680 681 \param index Index of the legend entry 681 682 ( ignored as there is only one ) 682 \param size Icon size 683 \return A graphic displaying the icon 684 685 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 686 */ 687 QwtGraphic QwtPlotHistogram::legendIcon( int index, 688 const QSizeF &size ) const 683 \param size Icon size 684 \return A graphic displaying the icon 685 686 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 687 */ 688 QwtGraphic QwtPlotHistogram::legendIcon( int index, const QSizeF& size ) const 689 689 { 690 690 Q_UNUSED( index ); 691 return defaultIcon( d_data->brush, size );692 } 691 return defaultIcon( m_data->brush, size ); 692 }
Note:
See TracChangeset
for help on using the changeset viewer.
