31 #include <qwt_global.h>
32 #include <qwt_plot_canvas.h>
33 #include <qwt_legend.h>
35 #include <qwt_plot_curve.h>
36 #include <qwt_plot_grid.h>
37 #include <qwt_plot_marker.h>
38 #include <qwt_plot_picker.h>
39 #include <qwt_picker_machine.h>
40 #include <qwt_plot_zoomer.h>
41 #include <qwt_plot_layout.h>
42 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
43 #include <qwt_plot_renderer.h>
44 #include <qwt_plot_histogram.h>
60 , mRendererWidget( 0 )
67 mRendererName =
"singlebandgray";
74 mHistoMarkerMin = NULL;
75 mHistoMarkerMax = NULL;
78 mHistoShowMarkers = settings.
value(
"/Raster/histogram/showMarkers",
false ).
toBool();
80 mHistoZoomToMinMax = settings.
value(
"/Raster/histogram/zoomToMinMax",
false ).
toBool();
81 mHistoUpdateStyleToMinMax = settings.
value(
"/Raster/histogram/updateStyleToMinMax",
true ).
toBool();
82 mHistoDrawLines = settings.
value(
"/Raster/histogram/drawLines",
true ).
toBool();
84 mHistoShowBands = ShowAll;
90 int myBandCountInt = mRasterLayer->
bandCount();
91 for (
int myIteratorInt = 1;
92 myIteratorInt <= myBandCountInt;
95 cboHistoBand->addItem( mRasterLayer->
bandName( myIteratorInt ) );
111 connect( leHistoMin, SIGNAL( editingFinished() ),
this, SLOT( applyHistoMin() ) );
112 connect( leHistoMax, SIGNAL( editingFinished() ),
this, SLOT( applyHistoMax() ) );
118 btnHistoActions->setMenu( menu );
126 action =
new QAction(
tr(
"Min/Max options" ), group );
129 action =
new QAction(
tr(
"Always show min/max markers" ), group );
134 action =
new QAction(
tr(
"Zoom to min/max" ), group );
139 action =
new QAction(
tr(
"Update style to min/max" ), group );
142 action->
setChecked( mHistoUpdateStyleToMinMax );
149 action =
new QAction(
tr(
"Visibility" ), group );
155 action =
new QAction(
tr(
"Show all bands" ), group );
158 action->
setChecked( mHistoShowBands == ShowAll );
160 action =
new QAction(
tr(
"Show RGB/Gray band(s)" ), group );
163 action->
setChecked( mHistoShowBands == ShowRGB );
165 action =
new QAction(
tr(
"Show selected band" ), group );
168 action->
setChecked( mHistoShowBands == ShowSelected );
175 action =
new QAction(
tr(
"Display" ), group );
179 action =
new QAction(
"", group );
183 action->
setText(
tr(
"Draw as lines" ) );
189 action->
setText(
tr(
"Draw as lines (only int layers)" ) );
195 action =
new QAction(
tr(
"Actions" ), group );
203 action =
new QAction(
tr(
"Reset" ), group );
211 action =
new QAction(
tr(
"Load min/max" ), group );
214 action =
new QAction(
tr(
"Estimate (faster)" ), group );
217 action =
new QAction(
tr(
"Actual (slower)" ), group );
220 action =
new QAction(
tr(
"Current extent" ), group );
223 action =
new QAction(
tr(
"Use stddev (1.0)" ), group );
226 action =
new QAction(
tr(
"Use stddev (custom)" ), group );
229 action =
new QAction(
tr(
"Load for each band" ), group );
237 action =
new QAction(
tr(
"Recompute Histogram" ), group );
252 mRendererName =
name;
253 mRendererWidget = rendererWidget;
255 on_cboHistoBand_currentIndexChanged( -1 );
263 on_cboHistoBand_currentIndexChanged( -1 );
269 btnHistoMin->setChecked(
false );
270 btnHistoMax->setChecked(
false );
274 void QgsRasterHistogramWidget::on_btnHistoCompute_clicked()
290 int myBandCountInt = mRasterLayer->
bandCount();
293 if ( ! forceComputeFlag )
295 for (
int myIteratorInt = 1;
296 myIteratorInt <= myBandCountInt;
299 int sampleSize = 250000;
300 if ( !mRasterLayer->
dataProvider()->
hasHistogram( myIteratorInt, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
QgsRectangle(), sampleSize ) )
309 stackedWidget2->setCurrentIndex( 1 );
310 connect( mRasterLayer, SIGNAL( progressUpdate(
int ) ), mHistogramProgress, SLOT( setValue(
int ) ) );
313 for (
int myIteratorInt = 1;
314 myIteratorInt <= myBandCountInt;
317 int sampleSize = 250000;
318 mRasterLayer->
dataProvider()->
histogram( myIteratorInt, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
QgsRectangle(), sampleSize );
321 disconnect( mRasterLayer, SIGNAL( progressUpdate(
int ) ), mHistogramProgress, SLOT( setValue(
int ) ) );
323 stackedWidget2->setCurrentIndex( 0 );
341 int myBandCountInt = mRasterLayer->
bandCount();
348 stackedWidget2->setCurrentIndex( 2 );
353 mpPlot->detachItems();
356 mpPlot->setAutoDelete(
true );
357 mpPlot->setTitle(
QObject::tr(
"Raster Histogram" ) );
358 mpPlot->insertLegend(
new QwtLegend(), QwtPlot::BottomLegend );
360 mpPlot->setAxisTitle( QwtPlot::xBottom,
QObject::tr(
"Pixel Value" ) );
361 mpPlot->setAxisTitle( QwtPlot::yLeft,
QObject::tr(
"Frequency" ) );
362 mpPlot->setAxisAutoScale( QwtPlot::yLeft );
366 QwtPlotGrid * myGrid =
new QwtPlotGrid();
367 myGrid->attach( mpPlot );
370 mHistoColors.
clear();
371 mHistoColors << Qt::black;
373 myColors << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkYellow << Qt::cyan;
374 qsrand( myBandCountInt * 100 );
375 while ( myColors.
size() <= myBandCountInt )
378 QColor( 1 + (
int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ),
379 1 + (
int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ),
380 1 + (
int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ) );
383 qsrand( time( NULL ) );
388 if ( mRendererName ==
"singlebandgray" )
390 int myGrayBand = mySelectedBands[0];
391 for (
int i = 1; i <= myBandCountInt; i++ )
393 if ( i == myGrayBand )
395 mHistoColors << Qt::darkGray;
396 cboHistoBand->setItemData( i - 1,
QColor( Qt::darkGray ), Qt::ForegroundRole );
402 mHistoColors << myColors.
first();
407 mHistoColors << Qt::black;
409 cboHistoBand->setItemData( i - 1,
QColor( Qt::black ), Qt::ForegroundRole );
414 else if ( mRendererName ==
"multibandcolor" )
416 int myRedBand = mySelectedBands[0];
417 int myGreenBand = mySelectedBands[1];
418 int myBlueBand = mySelectedBands[2];
422 for (
int i = 1; i <= myBandCountInt; i++ )
425 if ( i == myRedBand )
427 else if ( i == myGreenBand )
429 else if ( i == myBlueBand )
435 myColor = myColors.
first();
442 cboHistoBand->setItemData( i - 1,
QColor( Qt::black ), Qt::ForegroundRole );
444 if ( i == myRedBand || i == myGreenBand || i == myBlueBand )
446 cboHistoBand->setItemData( i - 1, myColor, Qt::ForegroundRole );
448 mHistoColors << myColor;
453 mHistoColors << myColors;
468 bool myFirstIteration =
true;
470 mySelectedBands = histoSelectedBands();
471 double myBinXStep = 1;
474 for (
int myIteratorInt = 1;
475 myIteratorInt <= myBandCountInt;
479 if ( mHistoShowBands != ShowAll )
481 if ( ! mySelectedBands.
contains( myIteratorInt ) )
485 int sampleSize = 250000;
491 bool myDrawLines =
true;
492 if ( ! mHistoDrawLines &&
500 QwtPlotCurve * mypCurve = 0;
503 mypCurve =
new QwtPlotCurve(
tr(
"Band %1" ).arg( myIteratorInt ) );
505 mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased );
506 mypCurve->setPen(
QPen( mHistoColors.
at( myIteratorInt ) ) );
509 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
510 QwtPlotHistogram * mypHisto = 0;
513 mypHisto =
new QwtPlotHistogram(
tr(
"Band %1" ).arg( myIteratorInt ) );
514 mypHisto->setRenderHint( QwtPlotItem::RenderAntialiased );
516 mypHisto->setPen(
QPen( Qt::lightGray ) );
518 mypHisto->setBrush(
QBrush( mHistoColors.
at( myIteratorInt ) ) );
521 HistogramItem *mypHistoItem = 0;
524 mypHistoItem =
new HistogramItem(
tr(
"Band %1" ).arg( myIteratorInt ) );
525 mypHistoItem->setRenderHint( QwtPlotItem::RenderAntialiased );
526 mypHistoItem->setColor( mHistoColors.
at( myIteratorInt ) );
530 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
537 QwtArray<QwtDoubleInterval> intervalsHisto;
538 QwtArray<double> valuesHisto;
546 myBinX = myHistogram.
minimum + myBinXStep / 2.0;
554 for (
int myBin = 0; myBin < myHistogram.
binCount; myBin++ )
557 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
560 data <<
QPointF( myBinX, myBinValue );
564 dataHisto << QwtIntervalSample( myBinValue, myBinX - myBinXStep / 2.0, myBinX + myBinXStep / 2.0 );
569 myX2Data.
append(
double( myBinX ) );
570 myY2Data.
append(
double( myBinValue ) );
574 intervalsHisto.append( QwtDoubleInterval( myBinX - myBinXStep / 2.0, myBinX + myBinXStep / 2.0 ) );
575 valuesHisto.append(
double( myBinValue ) );
578 myBinX += myBinXStep;
581 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
584 mypCurve->setSamples( data );
585 mypCurve->attach( mpPlot );
589 mypHisto->setSamples( dataHisto );
590 mypHisto->attach( mpPlot );
595 mypCurve->setData( myX2Data, myY2Data );
596 mypCurve->attach( mpPlot );
600 mypHistoItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) );
601 mypHistoItem->attach( mpPlot );
605 if ( myFirstIteration || mHistoMin > myHistogram.
minimum )
607 mHistoMin = myHistogram.
minimum;
609 if ( myFirstIteration || mHistoMax < myHistogram.
maximum )
611 mHistoMax = myHistogram.
maximum;
613 QgsDebugMsg(
QString(
"computed histo min = %1 max = %2" ).arg( mHistoMin ).arg( mHistoMax ) );
614 myFirstIteration =
false;
617 if ( mHistoMin < mHistoMax )
623 mpPlot->setAxisScale( QwtPlot::xBottom,
624 mHistoMin - myBinXStep / 2,
625 mHistoMax + myBinXStep / 2 );
626 mpPlot->setEnabled(
true );
631 mHistoMarkerMin =
new QwtPlotMarker();
632 mHistoMarkerMin->attach( mpPlot );
633 mHistoMarkerMax =
new QwtPlotMarker();
634 mHistoMarkerMax->attach( mpPlot );
635 updateHistoMarkers();
640 mHistoPicker =
new QwtPlotPicker( mpPlot->canvas() );
642 mHistoPicker->setTrackerMode( QwtPicker::AlwaysOff );
643 mHistoPicker->setRubberBand( QwtPicker::VLineRubberBand );
644 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
645 mHistoPicker->setStateMachine(
new QwtPickerDragPointMachine );
646 connect( mHistoPicker, SIGNAL( selected(
const QPointF & ) ),
this, SLOT( histoPickerSelected(
const QPointF & ) ) );
648 mHistoPicker->setSelectionFlags( QwtPicker::PointSelection | QwtPicker::DragSelection );
649 connect( mHistoPicker, SIGNAL( selected(
const QwtDoublePoint & ) ),
this, SLOT( histoPickerSelectedQwt5(
const QwtDoublePoint & ) ) );
652 mHistoPicker->setEnabled(
false );
657 mHistoZoomer =
new QwtPlotZoomer( mpPlot->canvas() );
658 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
659 mHistoZoomer->setStateMachine(
new QwtPickerDragRectMachine );
661 mHistoZoomer->setSelectionFlags( QwtPicker::RectSelection | QwtPicker::DragSelection );
663 mHistoZoomer->setTrackerMode( QwtPicker::AlwaysOff );
665 mHistoZoomer->setEnabled(
true );
669 mpPlot->setDisabled(
true );
671 mHistoPicker->setEnabled(
false );
673 mHistoZoomer->setEnabled(
false );
676 disconnect( mRasterLayer, SIGNAL( progressUpdate(
int ) ), mHistogramProgress, SLOT( setValue(
int ) ) );
677 stackedWidget2->setCurrentIndex( 0 );
692 QFileInfo myInfo( myFileNameAndFilter.first );
700 int width,
int height,
int quality )
705 if ( ! myDir.exists() )
707 QgsDebugMsg(
QString(
"Error, directory %1 non-existent (theFilename = %2)" ).arg( myDir.absolutePath() ).arg( theFilename ) );
712 QPixmap myPixmap( width, height );
713 QRect myQRect( 5, 5, width - 10, height - 10 );
714 myPixmap.
fill( Qt::white );
716 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
717 QwtPlotRenderer myRenderer;
718 myRenderer.setDiscardFlags( QwtPlotRenderer::DiscardBackground |
719 QwtPlotRenderer::DiscardCanvasBackground );
720 myRenderer.setLayoutFlags( QwtPlotRenderer::FrameWithScales );
723 myPainter.
begin( &myPixmap );
724 myRenderer.render( mpPlot, &myPainter, myQRect );
727 QwtPlotPrintFilter myFilter;
728 int myOptions = QwtPlotPrintFilter::PrintAll;
729 myOptions &= ~QwtPlotPrintFilter::PrintBackground;
730 myOptions |= QwtPlotPrintFilter::PrintFrameWithScales;
731 myFilter.setOptions( myOptions );
734 myPainter.
begin( &myPixmap );
735 mpPlot->print( &myPainter, myQRect, myFilter );
745 myPixmap.
save( theFilename, 0, quality );
753 cboHistoBand->setCurrentIndex( theBandNo - 1 );
756 void QgsRasterHistogramWidget::on_cboHistoBand_currentIndexChanged(
int index )
758 if ( mHistoShowBands == ShowSelected )
762 index = cboHistoBand->currentIndex();
763 if ( mHistoPicker != NULL )
765 mHistoPicker->setEnabled(
false );
766 mHistoPicker->setRubberBandPen(
QPen( mHistoColors.
at( index + 1 ) ) );
768 if ( mHistoZoomer != NULL )
769 mHistoZoomer->setEnabled(
true );
770 btnHistoMin->setEnabled(
true );
771 btnHistoMax->setEnabled(
true );
774 leHistoMin->setText( myMinMax.first );
775 leHistoMax->setText( myMinMax.second );
781 void QgsRasterHistogramWidget::histoActionTriggered(
QAction* action )
790 if ( actionName ==
"" )
794 QgsDebugMsg(
QString(
"band = %1 action = %2" ).arg( cboHistoBand->currentIndex() + 1 ).arg( actionName ) );
797 if ( actionName ==
"Show markers" )
799 mHistoShowMarkers = actionFlag;
801 settings.
setValue(
"/Raster/histogram/showMarkers", mHistoShowMarkers );
802 updateHistoMarkers();
805 else if ( actionName ==
"Zoom min_max" )
807 mHistoZoomToMinMax = actionFlag;
809 settings.
setValue(
"/Raster/histogram/zoomToMinMax", mHistoZoomToMinMax );
812 else if ( actionName ==
"Update min_max" )
814 mHistoUpdateStyleToMinMax = actionFlag;
816 settings.
setValue(
"/Raster/histogram/updateStyleToMinMax", mHistoUpdateStyleToMinMax );
819 else if ( actionName ==
"Show all" )
821 mHistoShowBands = ShowAll;
826 else if ( actionName ==
"Show selected" )
828 mHistoShowBands = ShowSelected;
833 else if ( actionName ==
"Show RGB" )
835 mHistoShowBands = ShowRGB;
840 else if ( actionName ==
"Draw lines" )
842 mHistoDrawLines = actionFlag;
844 settings.
setValue(
"/Raster/histogram/drawLines", mHistoDrawLines );
845 on_btnHistoCompute_clicked();
849 else if ( actionName ==
"Load apply all" )
851 mHistoLoadApplyAll = actionFlag;
852 settings.setValue(
"/Raster/histogram/loadApplyAll", mHistoLoadApplyAll );
858 else if ( actionName.
left( 5 ) ==
"Load " && mRendererWidget )
864 double minMaxValues[2];
867 if ( mHistoLoadApplyAll )
869 int myBandCountInt = mRasterLayer->
bandCount();
870 for (
int i = 1; i <= myBandCountInt; i++ )
872 if ( i != cboHistoBand->currentIndex() + 1 )
879 myBands << cboHistoBand->currentIndex() + 1;
891 leHistoMin->blockSignals(
true );
892 leHistoMax->blockSignals(
true );
895 foreach (
int theBandNo, myBands )
899 if ( actionName ==
"Load actual" )
902 theBandNo, minMaxValues );
904 else if ( actionName ==
"Load estimate" )
907 theBandNo, minMaxValues );
909 else if ( actionName ==
"Load extent" )
912 theBandNo, minMaxValues );
914 else if ( actionName ==
"Load 1 stddev" ||
915 actionName ==
"Load stddev" )
917 ok = mRendererWidget->bandMinMaxFromStdDev( myStdDev, theBandNo, minMaxValues );
922 cboHistoBand->setCurrentIndex( theBandNo - 1 );
923 if ( !ok || actionName ==
"Load reset" )
945 leHistoMin->blockSignals(
false );
946 leHistoMax->blockSignals(
false );
947 updateHistoMarkers();
949 else if ( actionName ==
"Compute histogram" )
951 on_btnHistoCompute_clicked();
960 void QgsRasterHistogramWidget::applyHistoMin()
962 if ( ! mRendererWidget )
965 int theBandNo = cboHistoBand->currentIndex() + 1;
968 for (
int i = 0; i <= mySelectedBands.
size(); i++ )
972 min = leHistoMin->text();
973 if ( mHistoUpdateStyleToMinMax )
974 mRendererWidget->
setMin( min, i );
978 updateHistoMarkers();
980 if ( ! min.
isEmpty() && mHistoZoomToMinMax && mHistoZoomer )
984 mHistoZoomer->zoom( rect );
989 void QgsRasterHistogramWidget::applyHistoMax()
991 if ( ! mRendererWidget )
994 int theBandNo = cboHistoBand->currentIndex() + 1;
997 for (
int i = 0; i <= mySelectedBands.
size(); i++ )
1001 max = leHistoMax->text();
1002 if ( mHistoUpdateStyleToMinMax )
1003 mRendererWidget->
setMax( max, i );
1007 updateHistoMarkers();
1009 if ( ! max.
isEmpty() && mHistoZoomToMinMax && mHistoZoomer )
1011 QRectF rect = mHistoZoomer->zoomRect();
1013 mHistoZoomer->zoom( rect );
1017 void QgsRasterHistogramWidget::on_btnHistoMin_toggled()
1019 if ( mpPlot != NULL && mHistoPicker != NULL )
1023 if ( btnHistoMin->isChecked() )
1025 btnHistoMax->setChecked(
false );
1028 if ( mHistoZoomer != NULL )
1029 mHistoZoomer->setEnabled( ! btnHistoMin->isChecked() );
1030 mHistoPicker->setEnabled( btnHistoMin->isChecked() );
1032 updateHistoMarkers();
1035 void QgsRasterHistogramWidget::on_btnHistoMax_toggled()
1037 if ( mpPlot != NULL && mHistoPicker != NULL )
1041 if ( btnHistoMax->isChecked() )
1043 btnHistoMin->setChecked(
false );
1046 if ( mHistoZoomer != NULL )
1047 mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() );
1048 mHistoPicker->setEnabled( btnHistoMax->isChecked() );
1050 updateHistoMarkers();
1057 if ( !scale )
return "";
1061 double diff = ( minorTicks[1] - minorTicks[0] ) / div;
1062 double min = majorTicks[0] - diff;
1064 min -= ( majorTicks[1] - majorTicks[0] );
1065 #if defined(QWT_VERSION) && QWT_VERSION<0x050200
1066 double max = scale->hBound();
1068 double max = scale->upperBound();
1070 double closest = target;
1071 double current =
min;
1073 while ( current < max )
1076 if ( current > target )
1078 closest = ( qAbs( target - current + diff ) < qAbs( target - current ) ) ? current - diff : current;
1087 void QgsRasterHistogramWidget::histoPickerSelected(
const QPointF & pos )
1089 if ( btnHistoMin->isChecked() || btnHistoMax->isChecked() )
1091 #if defined(QWT_VERSION) && QWT_VERSION>=0x060100
1092 const QwtScaleDiv * scale = &mpPlot->axisScaleDiv( QwtPlot::xBottom );
1094 const QwtScaleDiv * scale = mpPlot->axisScaleDiv( QwtPlot::xBottom );
1097 if ( btnHistoMin->isChecked() )
1101 btnHistoMin->setChecked(
false );
1107 btnHistoMax->setChecked(
false );
1114 void QgsRasterHistogramWidget::histoPickerSelectedQwt5(
const QwtDoublePoint & pos )
1116 histoPickerSelected(
QPointF( pos.x(), pos.y() ) );
1119 void QgsRasterHistogramWidget::updateHistoMarkers()
1122 if ( leHistoMin->signalsBlocked() )
1125 if ( mpPlot == NULL || mHistoMarkerMin == NULL || mHistoMarkerMax == NULL )
1128 int theBandNo = cboHistoBand->currentIndex() + 1;
1131 if (( ! mHistoShowMarkers && ! btnHistoMin->isChecked() && ! btnHistoMax->isChecked() ) ||
1132 ( ! mySelectedBands.
isEmpty() && ! mySelectedBands.
contains( theBandNo ) ) )
1134 mHistoMarkerMin->hide();
1135 mHistoMarkerMax->hide();
1140 double minVal = mHistoMin;
1141 double maxVal = mHistoMax;
1142 QString minStr = leHistoMin->text();
1143 QString maxStr = leHistoMax->text();
1149 QPen linePen =
QPen( mHistoColors.
at( theBandNo ) );
1151 mHistoMarkerMin->setLineStyle( QwtPlotMarker::VLine );
1152 mHistoMarkerMin->setLinePen( linePen );
1153 mHistoMarkerMin->setXValue( minVal );
1154 mHistoMarkerMin->show();
1155 mHistoMarkerMax->setLineStyle( QwtPlotMarker::VLine );
1156 mHistoMarkerMax->setLinePen( linePen );
1157 mHistoMarkerMax->setXValue( maxVal );
1158 mHistoMarkerMax->show();
1164 QList< int > QgsRasterHistogramWidget::histoSelectedBands()
1168 if ( mHistoShowBands != ShowAll )
1170 if ( mHistoShowBands == ShowSelected )
1172 mySelectedBands << cboHistoBand->currentIndex() + 1;
1174 else if ( mHistoShowBands == ShowRGB )
1176 mySelectedBands = rendererSelectedBands();
1180 return mySelectedBands;
1183 QList< int > QgsRasterHistogramWidget::rendererSelectedBands()
1187 if ( ! mRendererWidget )
1189 mySelectedBands << -1 << -1 << -1;
1190 return mySelectedBands;
1193 if ( mRendererName ==
"singlebandgray" )
1197 else if ( mRendererName ==
"multibandcolor" )
1199 for (
int i = 0; i <= 2; i++ )
1205 return mySelectedBands;
1212 if ( ! mRendererWidget )
1215 if ( mRendererName ==
"singlebandgray" )
1219 myMinMax.first = mRendererWidget->
min();
1220 myMinMax.second = mRendererWidget->
max();
1223 else if ( mRendererName ==
"multibandcolor" )
1225 for (
int i = 0; i <= 2; i++ )
1229 myMinMax.first = mRendererWidget->
min( i );
1230 myMinMax.second = mRendererWidget->
max( i );
1246 if ( myMinMax.first.isEmpty() )
1248 if ( myMinMax.second.isEmpty() )
1251 QgsDebugMsg(
QString(
"bandNo %1 got min/max [%2] [%3]" ).arg( theBandNo ).arg( myMinMax.first ).
arg( myMinMax.second ) );
void setText(const QString &text)
A rectangle specified with double values.
void setStyle(Qt::PenStyle style)
void setSeparator(bool b)
void append(const T &value)
void fill(const QColor &color)
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
double minimum
The minimum histogram value.
static double maximumValuePossible(QGis::DataType)
Helper function that returns the maximum possible value for a GDAL data type.
double toDouble(bool *ok) const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap.
void setValue(const QString &key, const QVariant &value)
const char * name() const
QString number(int n, int base)
static double minimumValuePossible(QGis::DataType)
Helper function that returns the minimum possible value for a GDAL data type.
virtual bool hasHistogram(int theBandNo, int theBinCount, double theMinimum=std::numeric_limits< double >::quiet_NaN(), double theMaximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0, bool theIncludeOutOfRange=false)
Returns true if histogram is available (cached, already calculated), the parameters are the same as i...
bool save(const QString &fileName, const char *format, int quality) const
int bandCount() const
Get the number of bands in this layer.
virtual QGis::DataType srcDataType(int bandNo) const override=0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
void setOverrideCursor(const QCursor &cursor)
const QString bandName(int theBandNoInt)
Get the name of a band given its number.
void restoreOverrideCursor()
virtual QgsRasterHistogram histogram(int theBandNo, int theBinCount=0, double theMinimum=std::numeric_limits< double >::quiet_NaN(), double theMaximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0, bool theIncludeOutOfRange=false)
Get histogram.
void setData(const QVariant &userData)
double maximum
The maximum histogram value.
bool contains(const T &value) const
virtual QGis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
DataType
Raster data types.
QString left(int n) const
The QgsRasterHistogram is a container for histogram of a single raster band.
int binCount
Number of bins (intervals,buckets) in histogram.
QgsRasterDataProvider * dataProvider()
Returns the data provider.
HistogramVector histogramVector
Store the histogram for a given layer.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool begin(QPaintDevice *device)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QCursor * overrideCursor()
QPair< QString, QString > GUI_EXPORT getSaveAsImageName(QWidget *theParent, QString theMessage, QString defaultFilename)
A helper function to get an image name from the user.