42
42
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
43
43
#include < qwt_plot_renderer.h>
44
44
#include < qwt_plot_histogram.h>
45
+ #else
46
+ #include " qwt5_histogram_item.h"
45
47
#endif
46
48
47
49
// this has been removed, now we let the provider/raster interface decide
@@ -165,12 +167,8 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
165
167
action = new QAction ( tr ( " Draw as lines" ), group );
166
168
action->setData ( QVariant ( " Draw lines" ) );
167
169
action->setCheckable ( true );
168
- #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
169
- // should we plot as histogram instead of line plot? (QWT>=6 and byte data only)
170
+ // should we plot as histogram instead of line plot? (int data only)
170
171
action->setChecked ( mHistoDrawLines );
171
- #else
172
- action->setDisabled ( true );
173
- #endif
174
172
menu->addAction ( action );
175
173
176
174
// actions
@@ -331,11 +329,9 @@ void QgsRasterHistogramWidget::refreshHistogram()
331
329
return ;
332
330
}
333
331
334
- # if defined(QWT_VERSION) && QWT_VERSION>=0x060000
332
+ // clear plot
335
333
mpPlot->detachItems ();
336
- #else
337
- mpPlot->clear ();
338
- #endif
334
+
339
335
// ensure all children get removed
340
336
mpPlot->setAutoDelete ( true );
341
337
mpPlot->setTitle ( QObject::tr ( " Raster Histogram" ) );
@@ -469,19 +465,44 @@ void QgsRasterHistogramWidget::refreshHistogram()
469
465
470
466
QgsDebugMsg ( QString ( " got raster histo for band %1 : min=%2 max=%3 count=%4" ).arg ( myIteratorInt ).arg ( myHistogram.minimum ).arg ( myHistogram.maximum ).arg ( myHistogram.binCount ) );
471
467
468
+ QGis::DataType mySrcDataType = mRasterLayer ->dataProvider ()->srcDataType ( myIteratorInt );
472
469
bool myDrawLines = true ;
470
+ if ( ! mHistoDrawLines &&
471
+ ( mySrcDataType == QGis::Byte ||
472
+ mySrcDataType == QGis::Int16 || mySrcDataType == QGis::Int32 ||
473
+ mySrcDataType == QGis::UInt16 || mySrcDataType == QGis::UInt32 ) )
474
+ {
475
+ myDrawLines = false ;
476
+ }
473
477
474
- QwtPlotCurve * mypCurve = new QwtPlotCurve ( tr ( " Band %1" ).arg ( myIteratorInt ) );
475
- // mypCurve->setCurveAttribute( QwtPlotCurve::Fitted );
476
- mypCurve->setRenderHint ( QwtPlotItem::RenderAntialiased );
477
- mypCurve->setPen ( QPen ( mHistoColors .at ( myIteratorInt ) ) );
478
+ QwtPlotCurve * mypCurve = 0 ;
479
+ if ( myDrawLines )
480
+ {
481
+ mypCurve = new QwtPlotCurve ( tr ( " Band %1" ).arg ( myIteratorInt ) );
482
+ // mypCurve->setCurveAttribute( QwtPlotCurve::Fitted );
483
+ mypCurve->setRenderHint ( QwtPlotItem::RenderAntialiased );
484
+ mypCurve->setPen ( QPen ( mHistoColors .at ( myIteratorInt ) ) );
485
+ }
478
486
479
487
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
480
- QwtPlotHistogram * mypHisto = new QwtPlotHistogram ( tr ( " Band %1" ).arg ( myIteratorInt ) );
481
- // mypHisto->setPen( QPen( mHistoColors.at( myIteratorInt ) ) );
482
- // this is needed in order to see the colors in the legend
483
- mypHisto->setPen ( QPen ( Qt::black ) );
484
- mypHisto->setBrush ( QBrush ( mHistoColors .at ( myIteratorInt ) ) );
488
+ QwtPlotHistogram * mypHisto = 0 ;
489
+ if ( ! myDrawLines )
490
+ {
491
+ mypHisto = new QwtPlotHistogram ( tr ( " Band %1" ).arg ( myIteratorInt ) );
492
+ mypHisto->setRenderHint ( QwtPlotItem::RenderAntialiased );
493
+ // mypHisto->setPen( QPen( mHistoColors.at( myIteratorInt ) ) );
494
+ // this is needed in order to see the colors in the legend
495
+ mypHisto->setPen ( QPen ( Qt::black ) );
496
+ mypHisto->setBrush ( QBrush ( mHistoColors .at ( myIteratorInt ) ) );
497
+ }
498
+ #else
499
+ HistogramItem *mypHistoItem = 0 ;
500
+ if ( ! myDrawLines )
501
+ {
502
+ mypHistoItem = new HistogramItem ( tr ( " Band %1" ).arg ( myIteratorInt ) );
503
+ mypHistoItem->setRenderHint ( QwtPlotItem::RenderAntialiased );
504
+ mypHistoItem->setColor ( mHistoColors .at ( myIteratorInt ) );
505
+ }
485
506
#endif
486
507
487
508
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
@@ -490,10 +511,13 @@ void QgsRasterHistogramWidget::refreshHistogram()
490
511
#else
491
512
QVector<double > myX2Data;
492
513
QVector<double > myY2Data;
514
+ // we safely assume that QT>=4.0 (min version is 4.7), therefore QwtArray is a QVector, so don't set size here
515
+ QwtArray<QwtDoubleInterval> intervalsHisto;
516
+ QwtArray<double > valuesHisto;
517
+
493
518
#endif
494
519
495
520
// calculate first bin x value and bin step size if not Byte data
496
- QGis::DataType mySrcDataType = mRasterLayer ->dataProvider ()->srcDataType ( myIteratorInt );
497
521
if ( mySrcDataType != QGis::Byte )
498
522
{
499
523
myBinXStep = ( myHistogram.maximum - myHistogram.minimum ) / myHistogram.binCount ;
@@ -504,15 +528,6 @@ void QgsRasterHistogramWidget::refreshHistogram()
504
528
myBinXStep = 1 ;
505
529
myBinX = 0 ;
506
530
}
507
- #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
508
- if ( ! mHistoDrawLines &&
509
- ( mySrcDataType == QGis::Byte ||
510
- mySrcDataType == QGis::Int16 || mySrcDataType == QGis::Int32 ||
511
- mySrcDataType == QGis::UInt16 || mySrcDataType == QGis::UInt32 ) )
512
- {
513
- myDrawLines = false ;
514
- }
515
- #endif
516
531
517
532
for ( int myBin = 0 ; myBin < myHistogram.binCount ; myBin++ )
518
533
{
@@ -527,8 +542,16 @@ void QgsRasterHistogramWidget::refreshHistogram()
527
542
dataHisto << QwtIntervalSample ( myBinValue, myBinX - myBinXStep / 2.0 , myBinX + myBinXStep / 2.0 );
528
543
}
529
544
#else
530
- myX2Data.append ( double ( myBinX ) );
531
- myY2Data.append ( double ( myBinValue ) );
545
+ if ( myDrawLines )
546
+ {
547
+ myX2Data.append ( double ( myBinX ) );
548
+ myY2Data.append ( double ( myBinValue ) );
549
+ }
550
+ else
551
+ {
552
+ intervalsHisto.append ( QwtDoubleInterval ( myBinX - myBinXStep / 2.0 , myBinX + myBinXStep / 2.0 ) );
553
+ valuesHisto.append ( double ( myBinValue ) );
554
+ }
532
555
#endif
533
556
myBinX += myBinXStep;
534
557
}
@@ -545,8 +568,16 @@ void QgsRasterHistogramWidget::refreshHistogram()
545
568
mypHisto->attach ( mpPlot );
546
569
}
547
570
#else
548
- mypCurve->setData ( myX2Data, myY2Data );
549
- mypCurve->attach ( mpPlot );
571
+ if ( myDrawLines )
572
+ {
573
+ mypCurve->setData ( myX2Data, myY2Data );
574
+ mypCurve->attach ( mpPlot );
575
+ }
576
+ else
577
+ {
578
+ mypHistoItem->setData ( QwtIntervalData ( intervalsHisto, valuesHisto ) );
579
+ mypHistoItem->attach ( mpPlot );
580
+ }
550
581
#endif
551
582
552
583
if ( myFirstIteration || mHistoMin > myHistogram.minimum )
0 commit comments