Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_multi_barchart.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (2 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_multi_barchart.cpp (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_multi_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" 14 #include <qpainter.h> 15 #include <qpalette.h> 13 #include "qwt_text.h" 14 #include "qwt_graphic.h" 15 #include "qwt_legend_data.h" 16 #include "qwt_math.h" 17 16 18 #include <qmap.h> 17 19 18 20 inline static bool qwtIsIncreasing( 19 const QwtScaleMap &map, const QVector<double> &values )21 const QwtScaleMap& map, const QVector< double >& values ) 20 22 { 21 23 bool isInverting = map.isInverting(); … … 33 35 class QwtPlotMultiBarChart::PrivateData 34 36 { 35 public: 36 PrivateData() :37 style( QwtPlotMultiBarChart::Grouped ) 37 public: 38 PrivateData() 39 : style( QwtPlotMultiBarChart::Grouped ) 38 40 { 39 41 } 40 42 41 43 QwtPlotMultiBarChart::ChartStyle style; 42 QList< QwtText> barTitles;43 QMap<int, QwtColumnSymbol *> symbolMap;44 QList< QwtText > barTitles; 45 QMap< int, QwtColumnSymbol* > symbolMap; 44 46 }; 45 47 46 48 /*! 47 Constructor 48 \param title Title of the chart 49 */ 50 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QwtText &title ):51 QwtPlotAbstractBarChart( title ) 49 Constructor 50 \param title Title of the chart 51 */ 52 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QwtText& title ) 53 : QwtPlotAbstractBarChart( title ) 52 54 { 53 55 init(); … … 55 57 56 58 /*! 57 Constructor 58 \param title Title of the chart 59 */ 60 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QString &title ):61 QwtPlotAbstractBarChart( QwtText( title ) ) 59 Constructor 60 \param title Title of the chart 61 */ 62 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QString& title ) 63 : QwtPlotAbstractBarChart( QwtText( title ) ) 62 64 { 63 65 init(); … … 68 70 { 69 71 resetSymbolMap(); 70 delete d_data;72 delete m_data; 71 73 } 72 74 73 75 void QwtPlotMultiBarChart::init() 74 76 { 75 d_data = new PrivateData;77 m_data = new PrivateData; 76 78 setData( new QwtSetSeriesData() ); 77 79 } … … 84 86 85 87 /*! 86 Initialize data with an array of samples. 87 \param samples Vector of points 88 */ 88 Initialize data with an array of samples. 89 \param samples Vector of points 90 */ 89 91 void QwtPlotMultiBarChart::setSamples( 90 const QVector<QwtSetSample > &samples )92 const QVector< QwtSetSample >& samples ) 91 93 { 92 94 setData( new QwtSetSeriesData( samples ) ); … … 94 96 95 97 /*! 96 Initialize data with an array of samples. 97 \param samples Vector of points 98 */ 98 Initialize data with an array of samples. 99 \param samples Vector of points 100 */ 99 101 void QwtPlotMultiBarChart::setSamples( 100 const QVector< QVector<double> > &samples ) 101 { 102 QVector<QwtSetSample> s; 102 const QVector< QVector< double > >& samples ) 103 { 104 QVector< QwtSetSample > s; 105 s.reserve( samples.size() ); 106 103 107 for ( int i = 0; i < samples.size(); i++ ) 104 108 s += QwtSetSample( i, samples[ i ] ); … … 108 112 109 113 /*! 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 114 Assign a series of samples 115 116 setSamples() is just a wrapper for setData() without any additional 117 value - beside that it is easier to find for the developer. 118 119 \param data Data 120 \warning The item takes ownership of the data object, deleting 117 121 it when its not used anymore. 118 */ 122 */ 119 123 void QwtPlotMultiBarChart::setSamples( 120 QwtSeriesData<QwtSetSample > *data )124 QwtSeriesData< QwtSetSample >* data ) 121 125 { 122 126 setData( data ); … … 124 128 125 129 /*! 126 \brief Set the titles for the bars 127 128 The titles are used for the legend. 129 130 \param titles Bar titles 131 132 \sa barTitles(), legendData() 133 */ 134 void QwtPlotMultiBarChart::setBarTitles( const QList<QwtText > &titles )135 { 136 d_data->barTitles = titles;130 \brief Set the titles for the bars 131 132 The titles are used for the legend. 133 134 \param titles Bar titles 135 136 \sa barTitles(), legendData() 137 */ 138 void QwtPlotMultiBarChart::setBarTitles( const QList< QwtText >& titles ) 139 { 140 m_data->barTitles = titles; 137 141 itemChanged(); 138 142 } 139 143 140 144 /*! 141 \return Bar titles 142 \sa setBarTitles(), legendData() 143 */ 144 QList< QwtText> QwtPlotMultiBarChart::barTitles() const145 { 146 return d_data->barTitles;147 } 148 149 /*! 150 \brief Add a symbol to the symbol map 151 152 Assign a default symbol for drawing the bar representing all values 153 with the same index in a set. 154 155 \param valueIndex Index of a value in a set 156 \param symbol Symbol used for drawing a bar 157 158 \sa symbol(), resetSymbolMap(), specialSymbol() 159 */ 160 void QwtPlotMultiBarChart::setSymbol( int valueIndex, QwtColumnSymbol *symbol )145 \return Bar titles 146 \sa setBarTitles(), legendData() 147 */ 148 QList< QwtText > QwtPlotMultiBarChart::barTitles() const 149 { 150 return m_data->barTitles; 151 } 152 153 /*! 154 \brief Add a symbol to the symbol map 155 156 Assign a default symbol for drawing the bar representing all values 157 with the same index in a set. 158 159 \param valueIndex Index of a value in a set 160 \param symbol Symbol used for drawing a bar 161 162 \sa symbol(), resetSymbolMap(), specialSymbol() 163 */ 164 void QwtPlotMultiBarChart::setSymbol( int valueIndex, QwtColumnSymbol* symbol ) 161 165 { 162 166 if ( valueIndex < 0 ) 163 167 return; 164 168 165 QMap<int, QwtColumnSymbol *>::iterator it =166 d_data->symbolMap.find(valueIndex);167 if ( it == d_data->symbolMap.end() )169 QMap< int, QwtColumnSymbol* >::iterator it = 170 m_data->symbolMap.find(valueIndex); 171 if ( it == m_data->symbolMap.end() ) 168 172 { 169 173 if ( symbol != NULL ) 170 174 { 171 d_data->symbolMap.insert( valueIndex, symbol );175 m_data->symbolMap.insert( valueIndex, symbol ); 172 176 173 177 legendChanged(); … … 183 187 if ( symbol == NULL ) 184 188 { 185 d_data->symbolMap.remove( valueIndex );189 m_data->symbolMap.remove( valueIndex ); 186 190 } 187 191 else … … 197 201 198 202 /*! 199 Find a symbol in the symbol map 200 201 \param valueIndex Index of a value in a set 202 \return The symbol, that had been set by setSymbol() or NULL. 203 204 \sa setSymbol(), specialSymbol(), drawBar() 205 */ 206 const QwtColumnSymbol *QwtPlotMultiBarChart::symbol( int valueIndex ) const207 { 208 QMap<int, QwtColumnSymbol *>::const_iterator it =209 d_data->symbolMap.constFind( valueIndex );210 211 return ( it == d_data->symbolMap.constEnd() ) ? NULL : it.value();212 } 213 214 /*! 215 Find a symbol in the symbol map 216 217 \param valueIndex Index of a value in a set 218 \return The symbol, that had been set by setSymbol() or NULL. 219 220 \sa setSymbol(), specialSymbol(), drawBar() 221 */ 222 QwtColumnSymbol *QwtPlotMultiBarChart::symbol( int valueIndex )223 { 224 QMap<int, QwtColumnSymbol *>::const_iterator it =225 d_data->symbolMap.constFind( valueIndex );226 227 return ( it == d_data->symbolMap.constEnd() ) ? NULL : it.value();228 } 229 230 /*! 231 Remove all symbols from the symbol map 203 Find a symbol in the symbol map 204 205 \param valueIndex Index of a value in a set 206 \return The symbol, that had been set by setSymbol() or NULL. 207 208 \sa setSymbol(), specialSymbol(), drawBar() 209 */ 210 const QwtColumnSymbol* QwtPlotMultiBarChart::symbol( int valueIndex ) const 211 { 212 QMap< int, QwtColumnSymbol* >::const_iterator it = 213 m_data->symbolMap.constFind( valueIndex ); 214 215 return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value(); 216 } 217 218 /*! 219 Find a symbol in the symbol map 220 221 \param valueIndex Index of a value in a set 222 \return The symbol, that had been set by setSymbol() or NULL. 223 224 \sa setSymbol(), specialSymbol(), drawBar() 225 */ 226 QwtColumnSymbol* QwtPlotMultiBarChart::symbol( int valueIndex ) 227 { 228 QMap< int, QwtColumnSymbol* >::const_iterator it = 229 m_data->symbolMap.constFind( valueIndex ); 230 231 return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value(); 232 } 233 234 /*! 235 Remove all symbols from the symbol map 232 236 */ 233 237 void QwtPlotMultiBarChart::resetSymbolMap() 234 238 { 235 qDeleteAll( d_data->symbolMap );236 d_data->symbolMap.clear();237 } 238 239 /*! 240 \brief Create a symbol for special values 241 242 Usually the symbols for displaying a bar are set by setSymbols() and 243 common for all sets. By overloading specialSymbol() it is possible to 244 create a temporary symbol() for displaying a special value. 245 246 The symbol has to be created by new each time specialSymbol() is 247 called. As soon as the symbol is painted this symbol gets deleted. 248 249 When no symbol ( NULL ) is returned, the value will be displayed 250 with the standard symbol that is used for all symbols with the same 251 valueIndex. 252 253 \param sampleIndex Index of the sample 254 \param valueIndex Index of the value in the set 255 256 \return NULL, meaning that the value is not special 257 258 */ 259 QwtColumnSymbol *QwtPlotMultiBarChart::specialSymbol(239 qDeleteAll( m_data->symbolMap ); 240 m_data->symbolMap.clear(); 241 } 242 243 /*! 244 \brief Create a symbol for special values 245 246 Usually the symbols for displaying a bar are set by setSymbols() and 247 common for all sets. By overloading specialSymbol() it is possible to 248 create a temporary symbol() for displaying a special value. 249 250 The symbol has to be created by new each time specialSymbol() is 251 called. As soon as the symbol is painted this symbol gets deleted. 252 253 When no symbol ( NULL ) is returned, the value will be displayed 254 with the standard symbol that is used for all symbols with the same 255 valueIndex. 256 257 \param sampleIndex Index of the sample 258 \param valueIndex Index of the value in the set 259 260 \return NULL, meaning that the value is not special 261 262 */ 263 QwtColumnSymbol* QwtPlotMultiBarChart::specialSymbol( 260 264 int sampleIndex, int valueIndex ) const 261 265 { … … 267 271 268 272 /*! 269 Set the style of the chart 270 271 \param style Chart style 272 \sa style() 273 Set the style of the chart 274 275 \param style Chart style 276 \sa style() 273 277 */ 274 278 void QwtPlotMultiBarChart::setStyle( ChartStyle style ) 275 279 { 276 if ( style != d_data->style )277 { 278 d_data->style = style;280 if ( style != m_data->style ) 281 { 282 m_data->style = style; 279 283 280 284 legendChanged(); … … 284 288 285 289 /*! 286 \return Style of the chart 287 \sa setStyle() 290 \return Style of the chart 291 \sa setStyle() 288 292 */ 289 293 QwtPlotMultiBarChart::ChartStyle QwtPlotMultiBarChart::style() const 290 294 { 291 return d_data->style;292 } 293 294 /*! 295 \return Bounding rectangle of all samples. 296 For an empty series the rectangle is invalid. 297 */ 295 return m_data->style; 296 } 297 298 /*! 299 \return Bounding rectangle of all samples. 300 For an empty series the rectangle is invalid. 301 */ 298 302 QRectF QwtPlotMultiBarChart::boundingRect() const 299 303 { … … 307 311 QRectF rect; 308 312 309 if ( d_data->style != QwtPlotMultiBarChart::Stacked )313 if ( m_data->style != QwtPlotMultiBarChart::Stacked ) 310 314 { 311 315 rect = QwtPlotSeriesItem::boundingRect(); … … 326 330 yMin = yMax = baseLine; 327 331 328 const QwtSeriesData<QwtSetSample > *series = data();332 const QwtSeriesData< QwtSetSample >* series = data(); 329 333 330 334 for ( size_t i = 0; i < numSamples; i++ ) … … 337 341 else 338 342 { 339 xMin = q Min( xMin, sample.value );340 xMax = q Max( xMax, sample.value );343 xMin = qwtMinF( xMin, sample.value ); 344 xMax = qwtMaxF( xMax, sample.value ); 341 345 } 342 346 343 347 const double y = baseLine + sample.added(); 344 348 345 yMin = q Min( yMin, y );346 yMax = q Max( yMax, y );349 yMin = qwtMinF( yMin, y ); 350 yMax = qwtMaxF( yMax, y ); 347 351 } 348 352 rect.setRect( xMin, yMin, xMax - xMin, yMax - yMin ); … … 356 360 357 361 /*! 358 Draw an interval of the bar chart 359 360 \param painter Painter 361 \param xMap Maps x-values into pixel coordinates. 362 \param yMap Maps y-values into pixel coordinates. 363 \param canvasRect Contents rectangle of the canvas 364 \param from Index of the first point to be painted 365 \param to Index of the last point to be painted. If to < 0 the 362 Draw an interval of the bar chart 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 canvasRect Contents rectangle of the canvas 368 \param from Index of the first point to be painted 369 \param to Index of the last point to be painted. If to < 0 the 366 370 curve will be painted to its last point. 367 371 368 \sa drawSymbols() 369 */ 370 void QwtPlotMultiBarChart::drawSeries( QPainter *painter,371 const QwtScaleMap &xMap, const QwtScaleMap&yMap,372 const QRectF &canvasRect, int from, int to ) const372 \sa drawSymbols() 373 */ 374 void QwtPlotMultiBarChart::drawSeries( QPainter* painter, 375 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 376 const QRectF& canvasRect, int from, int to ) const 373 377 { 374 378 if ( to < 0 ) … … 397 401 398 402 /*! 399 Draw a sample 400 401 \param painter Painter 402 \param xMap x map 403 \param yMap y map 404 \param canvasRect Contents rectangle of the canvas 405 \param boundingInterval Bounding interval of sample values 406 \param index Index of the sample to be painted 407 \param sample Sample value 408 409 \sa drawSeries() 410 */ 411 void QwtPlotMultiBarChart::drawSample( QPainter *painter,412 const QwtScaleMap &xMap, const QwtScaleMap&yMap,413 const QRectF &canvasRect, const QwtInterval&boundingInterval,403 Draw a sample 404 405 \param painter Painter 406 \param xMap x map 407 \param yMap y map 408 \param canvasRect Contents rectangle of the canvas 409 \param boundingInterval Bounding interval of sample values 410 \param index Index of the sample to be painted 411 \param sample Sample value 412 413 \sa drawSeries() 414 */ 415 void QwtPlotMultiBarChart::drawSample( QPainter* painter, 416 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 417 const QRectF& canvasRect, const QwtInterval& boundingInterval, 414 418 int index, const QwtSetSample& sample ) const 415 419 { … … 430 434 } 431 435 432 if ( d_data->style == Stacked )436 if ( m_data->style == Stacked ) 433 437 { 434 438 drawStackedBars( painter, xMap, yMap, … … 443 447 444 448 /*! 445 Draw a grouped sample 446 447 \param painter Painter 448 \param xMap x map 449 \param yMap y map 450 \param canvasRect Contents rectangle of the canvas 451 \param index Index of the sample to be painted 452 \param sampleWidth Boundng width for all bars of the s maple453 \param sample Sample 454 455 \sa drawSeries(), sampleWidth() 456 */ 457 void QwtPlotMultiBarChart::drawGroupedBars( QPainter *painter,458 const QwtScaleMap &xMap, const QwtScaleMap&yMap,459 const QRectF &canvasRect, int index, double sampleWidth,449 Draw a grouped sample 450 451 \param painter Painter 452 \param xMap x map 453 \param yMap y map 454 \param canvasRect Contents rectangle of the canvas 455 \param index Index of the sample to be painted 456 \param sampleWidth Bounding width for all bars of the sample 457 \param sample Sample 458 459 \sa drawSeries(), sampleWidth() 460 */ 461 void QwtPlotMultiBarChart::drawGroupedBars( QPainter* painter, 462 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 463 const QRectF& canvasRect, int index, double sampleWidth, 460 464 const QwtSetSample& sample ) const 461 465 { … … 523 527 524 528 /*! 525 Draw a stacked sample 526 527 \param painter Painter 528 \param xMap x map 529 \param yMap y map 530 \param canvasRect Contents rectangle of the canvas 531 \param index Index of the sample to be painted 532 \param sampleWidth Width of the bars 533 \param sample Sample 534 535 \sa drawSeries(), sampleWidth() 536 */ 537 void QwtPlotMultiBarChart::drawStackedBars( QPainter *painter,538 const QwtScaleMap &xMap, const QwtScaleMap&yMap,539 const QRectF &canvasRect, int index,529 Draw a stacked sample 530 531 \param painter Painter 532 \param xMap x map 533 \param yMap y map 534 \param canvasRect Contents rectangle of the canvas 535 \param index Index of the sample to be painted 536 \param sampleWidth Width of the bars 537 \param sample Sample 538 539 \sa drawSeries(), sampleWidth() 540 */ 541 void QwtPlotMultiBarChart::drawStackedBars( QPainter* painter, 542 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 543 const QRectF& canvasRect, int index, 540 544 double sampleWidth, const QwtSetSample& sample ) const 541 545 { … … 636 640 637 641 /*! 638 Draw a bar 639 640 \param painter Painter 641 \param sampleIndex Index of the sample - might be -1 when the 642 Draw a bar 643 644 \param painter Painter 645 \param sampleIndex Index of the sample - might be -1 when the 642 646 bar is painted for the legend 643 \param valueIndex Index of a value in a set 644 \param rect Directed target rectangle for the bar 645 646 \sa drawSeries() 647 */ 648 void QwtPlotMultiBarChart::drawBar( QPainter *painter,649 int sampleIndex, int valueIndex, const QwtColumnRect &rect ) const650 { 651 const QwtColumnSymbol *specialSym = NULL;647 \param valueIndex Index of a value in a set 648 \param rect Directed target rectangle for the bar 649 650 \sa drawSeries() 651 */ 652 void QwtPlotMultiBarChart::drawBar( QPainter* painter, 653 int sampleIndex, int valueIndex, const QwtColumnRect& rect ) const 654 { 655 const QwtColumnSymbol* specialSym = NULL; 652 656 if ( sampleIndex >= 0 ) 653 657 specialSym = specialSymbol( sampleIndex, valueIndex ); 654 658 655 const QwtColumnSymbol *sym = specialSym;659 const QwtColumnSymbol* sym = specialSym; 656 660 if ( sym == NULL ) 657 661 sym = symbol( valueIndex ); … … 674 678 675 679 /*! 676 \return Information to be displayed on the legend 677 678 The chart is represented by a list of entries - one for each bar title. 679 Each element contains a bar title and an icon showing its corresponding bar. 680 681 \sa barTitles(), legendIcon(), legendIconSize() 682 */ 683 QList<QwtLegendData> QwtPlotMultiBarChart::legendData() const 684 { 685 QList<QwtLegendData> list; 686 687 for ( int i = 0; i < d_data->barTitles.size(); i++ ) 680 \return Information to be displayed on the legend 681 682 The chart is represented by a list of entries - one for each bar title. 683 Each element contains a bar title and an icon showing its corresponding bar. 684 685 \sa barTitles(), legendIcon(), legendIconSize() 686 */ 687 QList< QwtLegendData > QwtPlotMultiBarChart::legendData() const 688 { 689 QList< QwtLegendData > list; 690 list.reserve( m_data->barTitles.size() ); 691 692 for ( int i = 0; i < m_data->barTitles.size(); i++ ) 688 693 { 689 694 QwtLegendData data; 690 695 691 QVariant titleValue; 692 qVariantSetValue( titleValue, d_data->barTitles[i] ); 693 data.setValue( QwtLegendData::TitleRole, titleValue ); 696 data.setValue( QwtLegendData::TitleRole, 697 QVariant::fromValue( m_data->barTitles[i] ) ); 694 698 695 699 if ( !legendIconSize().isEmpty() ) 696 700 { 697 QVariant iconValue; 698 qVariantSetValue( iconValue, 699 legendIcon( i, legendIconSize() ) ); 700 701 data.setValue( QwtLegendData::IconRole, iconValue ); 701 data.setValue( QwtLegendData::IconRole, 702 QVariant::fromValue( legendIcon( i, legendIconSize() ) ) ); 702 703 } 703 704 … … 709 710 710 711 /*! 711 \return Icon for representing a bar on the legend 712 713 \param index Index of the bar 714 \param size Icon size 715 716 \return An icon showing a bar 717 \sa drawBar(), legendData() 712 \return Icon for representing a bar on the legend 713 714 \param index Index of the bar 715 \param size Icon size 716 717 \return An icon showing a bar 718 \sa drawBar(), legendData() 718 719 */ 719 720 QwtGraphic QwtPlotMultiBarChart::legendIcon( int index, 720 const QSizeF &size ) const721 const QSizeF& size ) const 721 722 { 722 723 QwtColumnRect column;
Note:
See TracChangeset
for help on using the changeset viewer.
