Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_barchart.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_barchart.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_barchart.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_map.h" 12 12 #include "qwt_column_symbol.h" 13 #include "qwt_painter.h" 13 #include "qwt_text.h" 14 #include "qwt_graphic.h" 15 #include "qwt_legend_data.h" 16 14 17 #include <qpainter.h> 15 18 16 19 class QwtPlotBarChart::PrivateData 17 20 { 18 public: 19 PrivateData() :20 symbol( NULL ) ,21 legendMode( QwtPlotBarChart::LegendChartTitle ) 21 public: 22 PrivateData() 23 : symbol( NULL ) 24 , legendMode( QwtPlotBarChart::LegendChartTitle ) 22 25 { 23 26 } … … 28 31 } 29 32 30 QwtColumnSymbol *symbol;33 QwtColumnSymbol* symbol; 31 34 QwtPlotBarChart::LegendMode legendMode; 32 35 }; 33 36 34 37 /*! 35 Constructor 36 \param title Title of the curve 37 */ 38 QwtPlotBarChart::QwtPlotBarChart( const QwtText &title ):39 QwtPlotAbstractBarChart( title ) 38 Constructor 39 \param title Title of the curve 40 */ 41 QwtPlotBarChart::QwtPlotBarChart( const QwtText& title ) 42 : QwtPlotAbstractBarChart( title ) 40 43 { 41 44 init(); … … 43 46 44 47 /*! 45 Constructor 46 \param title Title of the curve 47 */ 48 QwtPlotBarChart::QwtPlotBarChart( const QString &title ):49 QwtPlotAbstractBarChart( QwtText( title ) ) 48 Constructor 49 \param title Title of the curve 50 */ 51 QwtPlotBarChart::QwtPlotBarChart( const QString& title ) 52 : QwtPlotAbstractBarChart( QwtText( title ) ) 50 53 { 51 54 init(); … … 55 58 QwtPlotBarChart::~QwtPlotBarChart() 56 59 { 57 delete d_data;60 delete m_data; 58 61 } 59 62 60 63 void QwtPlotBarChart::init() 61 64 { 62 d_data = new PrivateData;65 m_data = new PrivateData; 63 66 setData( new QwtPointSeriesData() ); 64 67 } … … 71 74 72 75 /*! 73 Initialize data with an array of points 74 75 \param samples Vector of points 76 \note QVector is implicitly shared 77 \note QPolygonF is derived from QVector<QPointF> 78 */ 76 Initialize data with an array of points 77 78 \param samples Vector of points 79 \note QVector is implicitly shared 80 \note QPolygonF is derived from QVector<QPointF> 81 */ 79 82 void QwtPlotBarChart::setSamples( 80 const QVector<QPointF > &samples )83 const QVector< QPointF >& samples ) 81 84 { 82 85 setData( new QwtPointSeriesData( samples ) ); … … 84 87 85 88 /*! 86 Initialize data with an array of doubles 87 88 The indices in the array are taken as x coordinate, 89 while the doubles are interpreted as y values. 90 91 \param samples Vector of y coordinates 92 \note QVector is implicitly shared 93 */ 89 Initialize data with an array of doubles 90 91 The indices in the array are taken as x coordinate, 92 while the doubles are interpreted as y values. 93 94 \param samples Vector of y coordinates 95 \note QVector is implicitly shared 96 */ 94 97 void QwtPlotBarChart::setSamples( 95 const QVector<double> &samples ) 96 { 97 QVector<QPointF> points; 98 const QVector< double >& samples ) 99 { 100 QVector< QPointF > points; 101 points.reserve( samples.size() ); 102 98 103 for ( int i = 0; i < samples.size(); i++ ) 99 104 points += QPointF( i, samples[ i ] ); … … 103 108 104 109 /*! 105 Assign a series of samples 106 107 setSamples() is just a wrapper for setData() without any additional 108 value - beside that it is easier to find for the developer. 109 110 \param data Data 111 \warning The item takes ownership of the data object, deleting 110 Assign a series of samples 111 112 setSamples() is just a wrapper for setData() without any additional 113 value - beside that it is easier to find for the developer. 114 115 \param data Data 116 \warning The item takes ownership of the data object, deleting 112 117 it when its not used anymore. 113 */ 114 void QwtPlotBarChart::setSamples( QwtSeriesData<QPointF > *data )118 */ 119 void QwtPlotBarChart::setSamples( QwtSeriesData< QPointF >* data ) 115 120 { 116 121 setData( data ); … … 118 123 119 124 /*! 120 \brief Assign a symbol 121 122 The bar chart will take the ownership of the symbol, hence the previously 123 set symbol will be delete by setting a new one. If \p symbol is 124 \c NULL no symbol will be drawn. 125 126 \param symbol Symbol 127 \sa symbol() 128 */ 129 void QwtPlotBarChart::setSymbol( QwtColumnSymbol *symbol )130 { 131 if ( symbol != d_data->symbol )132 { 133 delete d_data->symbol;134 d_data->symbol = symbol;125 \brief Assign a symbol 126 127 The bar chart will take the ownership of the symbol, hence the previously 128 set symbol will be delete by setting a new one. If \p symbol is 129 \c NULL no symbol will be drawn. 130 131 \param symbol Symbol 132 \sa symbol() 133 */ 134 void QwtPlotBarChart::setSymbol( QwtColumnSymbol* symbol ) 135 { 136 if ( symbol != m_data->symbol ) 137 { 138 delete m_data->symbol; 139 m_data->symbol = symbol; 135 140 136 141 legendChanged(); … … 140 145 141 146 /*! 142 \return Current symbol or NULL, when no symbol has been assigned 143 \sa setSymbol() 144 */ 145 const QwtColumnSymbol *QwtPlotBarChart::symbol() const146 { 147 return d_data->symbol;148 } 149 150 /*! 151 Set the mode that decides what to display on the legend 152 153 In case of LegendBarTitles barTitle() needs to be overloaded 154 to return individual titles for each bar. 155 156 \param mode New mode 157 \sa legendMode(), legendData(), barTitle(), QwtPlotItem::ItemAttribute 147 \return Current symbol or NULL, when no symbol has been assigned 148 \sa setSymbol() 149 */ 150 const QwtColumnSymbol* QwtPlotBarChart::symbol() const 151 { 152 return m_data->symbol; 153 } 154 155 /*! 156 Set the mode that decides what to display on the legend 157 158 In case of LegendBarTitles barTitle() needs to be overloaded 159 to return individual titles for each bar. 160 161 \param mode New mode 162 \sa legendMode(), legendData(), barTitle(), QwtPlotItem::ItemAttribute 158 163 */ 159 164 void QwtPlotBarChart::setLegendMode( LegendMode mode ) 160 165 { 161 if ( mode != d_data->legendMode )162 { 163 d_data->legendMode = mode;166 if ( mode != m_data->legendMode ) 167 { 168 m_data->legendMode = mode; 164 169 legendChanged(); 165 170 } … … 167 172 168 173 /*! 169 \return Legend mode 170 \sa setLegendMode() 174 \return Legend mode 175 \sa setLegendMode() 171 176 */ 172 177 QwtPlotBarChart::LegendMode QwtPlotBarChart::legendMode() const 173 178 { 174 return d_data->legendMode;175 } 176 177 /*! 178 \return Bounding rectangle of all samples. 179 For an empty series the rectangle is invalid. 180 */ 179 return m_data->legendMode; 180 } 181 182 /*! 183 \return Bounding rectangle of all samples. 184 For an empty series the rectangle is invalid. 185 */ 181 186 QRectF QwtPlotBarChart::boundingRect() const 182 187 { … … 204 209 205 210 /*! 206 Draw an interval of the bar chart 207 208 \param painter Painter 209 \param xMap Maps x-values into pixel coordinates. 210 \param yMap Maps y-values into pixel coordinates. 211 \param canvasRect Contents rect of the canvas 212 \param from Index of the first point to be painted 213 \param to Index of the last point to be painted. If to < 0 the 211 Draw an interval of the bar chart 212 213 \param painter Painter 214 \param xMap Maps x-values into pixel coordinates. 215 \param yMap Maps y-values into pixel coordinates. 216 \param canvasRect Contents rect of the canvas 217 \param from Index of the first point to be painted 218 \param to Index of the last point to be painted. If to < 0 the 214 219 curve will be painted to its last point. 215 220 216 \sa drawSymbols() 217 */ 218 void QwtPlotBarChart::drawSeries( QPainter *painter,219 const QwtScaleMap &xMap, const QwtScaleMap&yMap,220 const QRectF &canvasRect, int from, int to ) const221 \sa drawSymbols() 222 */ 223 void QwtPlotBarChart::drawSeries( QPainter* painter, 224 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 225 const QRectF& canvasRect, int from, int to ) const 221 226 { 222 227 if ( to < 0 ) … … 238 243 { 239 244 drawSample( painter, xMap, yMap, 240 canvasRect, interval, i, sample( i ) );245 canvasRect, interval, i, sample( i ) ); 241 246 } 242 247 … … 245 250 246 251 /*! 247 Draw a sample 248 249 \param painter Painter 250 \param xMap x map 251 \param yMap y map 252 \param canvasRect Contents rect of the canvas 253 \param boundingInterval Bounding interval of sample values 254 \param index Index of the sample 255 \param sample Value of the sample 256 257 \sa drawSeries() 258 */ 259 void QwtPlotBarChart::drawSample( QPainter *painter, 260 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 261 const QRectF &canvasRect, const QwtInterval &boundingInterval, 262 int index, const QPointF &sample ) const 252 Calculate the geometry of a bar in widget coordinates 253 254 \param xMap x map 255 \param yMap y map 256 \param canvasRect Contents rect of the canvas 257 \param boundingInterval Bounding interval of sample values 258 \param sample Value of the sample 259 260 \return Geometry of the column 261 */ 262 QwtColumnRect QwtPlotBarChart::columnRect( 263 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 264 const QRectF& canvasRect, const QwtInterval& boundingInterval, 265 const QPointF& sample ) const 263 266 { 264 267 QwtColumnRect barRect; … … 301 304 } 302 305 306 return barRect; 307 } 308 309 /*! 310 Draw a sample 311 312 \param painter Painter 313 \param xMap x map 314 \param yMap y map 315 \param canvasRect Contents rect of the canvas 316 \param boundingInterval Bounding interval of sample values 317 \param index Index of the sample 318 \param sample Value of the sample 319 320 \sa drawSeries() 321 */ 322 void QwtPlotBarChart::drawSample( QPainter* painter, 323 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 324 const QRectF& canvasRect, const QwtInterval& boundingInterval, 325 int index, const QPointF& sample ) const 326 { 327 const QwtColumnRect barRect = columnRect( xMap, yMap, 328 canvasRect, boundingInterval, sample ); 329 303 330 drawBar( painter, index, sample, barRect ); 304 331 } 305 332 306 333 /*! 307 Draw a bar 308 309 \param painter Painter 310 \param sampleIndex Index of the sample represented by the bar 311 \param sample Value of the sample 312 \param rect Bounding rectangle of the bar 313 */ 314 void QwtPlotBarChart::drawBar( QPainter *painter,315 int sampleIndex, const QPointF &sample,316 const QwtColumnRect &rect ) const317 { 318 const QwtColumnSymbol *specialSym =334 Draw a bar 335 336 \param painter Painter 337 \param sampleIndex Index of the sample represented by the bar 338 \param sample Value of the sample 339 \param rect Bounding rectangle of the bar 340 */ 341 void QwtPlotBarChart::drawBar( QPainter* painter, 342 int sampleIndex, const QPointF& sample, 343 const QwtColumnRect& rect ) const 344 { 345 const QwtColumnSymbol* specialSym = 319 346 specialSymbol( sampleIndex, sample ); 320 347 321 const QwtColumnSymbol *sym = specialSym;348 const QwtColumnSymbol* sym = specialSym; 322 349 if ( sym == NULL ) 323 sym = d_data->symbol;350 sym = m_data->symbol; 324 351 325 352 if ( sym ) … … 340 367 341 368 /*! 342 Needs to be overloaded to return a 343 non default symbol for a specific sample 344 345 \param sampleIndex Index of the sample represented by the bar 346 \param sample Value of the sample 347 348 \return NULL, indicating to use the default symbol 349 */ 350 QwtColumnSymbol *QwtPlotBarChart::specialSymbol(351 int sampleIndex, const QPointF &sample ) const369 Needs to be overloaded to return a 370 non default symbol for a specific sample 371 372 \param sampleIndex Index of the sample represented by the bar 373 \param sample Value of the sample 374 375 \return NULL, indicating to use the default symbol 376 */ 377 QwtColumnSymbol* QwtPlotBarChart::specialSymbol( 378 int sampleIndex, const QPointF& sample ) const 352 379 { 353 380 Q_UNUSED( sampleIndex ); … … 358 385 359 386 /*! 360 \brief Return the title of a bar 361 362 In LegendBarTitles mode the title is displayed on 363 the legend entry corresponding to a bar. 364 365 The default implementation is a dummy, that is intended 366 to be overloaded. 367 368 \param sampleIndex Index of the bar 369 \return An empty text 370 \sa LegendBarTitles 387 \brief Return the title of a bar 388 389 In LegendBarTitles mode the title is displayed on 390 the legend entry corresponding to a bar. 391 392 The default implementation is a dummy, that is intended 393 to be overloaded. 394 395 \param sampleIndex Index of the bar 396 \return An empty text 397 \sa LegendBarTitles 371 398 */ 372 399 QwtText QwtPlotBarChart::barTitle( int sampleIndex ) const … … 387 414 \sa title(), setLegendMode(), barTitle(), QwtLegend, QwtPlotLegendItem 388 415 */ 389 QList<QwtLegendData> QwtPlotBarChart::legendData() const 390 { 391 QList<QwtLegendData> list; 392 393 if ( d_data->legendMode == LegendBarTitles )416 QList< QwtLegendData > QwtPlotBarChart::legendData() const 417 { 418 QList< QwtLegendData > list; 419 420 if ( m_data->legendMode == LegendBarTitles ) 394 421 { 395 422 const size_t numSamples = dataSize(); 423 list.reserve( numSamples ); 424 396 425 for ( size_t i = 0; i < numSamples; i++ ) 397 426 { 398 427 QwtLegendData data; 399 428 400 QVariant titleValue; 401 qVariantSetValue( titleValue, barTitle( i ) ); 402 data.setValue( QwtLegendData::TitleRole, titleValue ); 429 data.setValue( QwtLegendData::TitleRole, 430 QVariant::fromValue( barTitle( i ) ) ); 403 431 404 432 if ( !legendIconSize().isEmpty() ) 405 433 { 406 QVariant iconValue; 407 qVariantSetValue( iconValue, 408 legendIcon( i, legendIconSize() ) ); 409 410 data.setValue( QwtLegendData::IconRole, iconValue ); 434 data.setValue( QwtLegendData::IconRole, 435 QVariant::fromValue( legendIcon( i, legendIconSize() ) ) ); 411 436 } 412 437 … … 436 461 */ 437 462 QwtGraphic QwtPlotBarChart::legendIcon( 438 int index, const QSizeF &size ) const463 int index, const QSizeF& size ) const 439 464 { 440 465 QwtColumnRect column; … … 451 476 452 477 int barIndex = -1; 453 if ( d_data->legendMode == QwtPlotBarChart::LegendBarTitles )478 if ( m_data->legendMode == QwtPlotBarChart::LegendBarTitles ) 454 479 barIndex = index; 455 480
Note:
See TracChangeset
for help on using the changeset viewer.
