Skip to content

Commit 748d857

Browse files
committed
Improve multiband color widget
1 parent de15835 commit 748d857

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/gui/raster/qgsmultibandcolorrendererwidget.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer
5757
mRedBandComboBox->setCurrentIndex( mRedBandComboBox->findData( r->redBand() ) );
5858
mGreenBandComboBox->setCurrentIndex( mGreenBandComboBox->findData( r->greenBand() ) );
5959
mBlueBandComboBox->setCurrentIndex( mBlueBandComboBox->findData( r->blueBand() ) );
60+
61+
setMinMaxValue( r->redContrastEnhancement(), mRedMinLineEdit, mRedMaxLineEdit );
62+
setMinMaxValue( r->greenContrastEnhancement(), mGreenMinLineEdit, mGreenMaxLineEdit );
63+
setMinMaxValue( r->blueContrastEnhancement(), mBlueMinLineEdit, mBlueMaxLineEdit );
6064
}
6165
else
6266
{
@@ -176,3 +180,79 @@ void QgsMultiBandColorRendererWidget::setCustomMinMaxValues( QgsMultiBandColorRe
176180
r->setGreenContrastEnhancement( greenEnhancement );
177181
r->setBlueContrastEnhancement( blueEnhancement );
178182
}
183+
184+
void QgsMultiBandColorRendererWidget::on_mLoadPushButton_clicked()
185+
{
186+
int redBand = mRedBandComboBox->itemData( mRedBandComboBox->currentIndex() ).toInt();
187+
int greenBand = mGreenBandComboBox->itemData( mGreenBandComboBox->currentIndex() ).toInt();
188+
int blueBand = mBlueBandComboBox->itemData( mBlueBandComboBox->currentIndex() ).toInt();
189+
190+
loadMinMaxValueForBand( redBand, mRedMinLineEdit, mRedMaxLineEdit );
191+
loadMinMaxValueForBand( greenBand, mGreenMinLineEdit, mGreenMaxLineEdit );
192+
loadMinMaxValueForBand( blueBand, mBlueMinLineEdit, mBlueMaxLineEdit );
193+
}
194+
195+
void QgsMultiBandColorRendererWidget::setMinMaxValue( const QgsContrastEnhancement* ce, QLineEdit* minEdit, QLineEdit* maxEdit )
196+
{
197+
if ( !minEdit || !maxEdit )
198+
{
199+
return;
200+
}
201+
202+
if ( !ce )
203+
{
204+
minEdit->clear();
205+
maxEdit->clear();
206+
return;
207+
}
208+
209+
minEdit->setText( QString::number( ce->minimumValue() ) );
210+
maxEdit->setText( QString::number( ce->maximumValue() ) );
211+
mContrastEnhancementAlgorithmComboBox->setCurrentIndex( mContrastEnhancementAlgorithmComboBox->findData(
212+
( int )( ce->contrastEnhancementAlgorithm() ) ) );
213+
}
214+
215+
void QgsMultiBandColorRendererWidget::loadMinMaxValueForBand( int band, QLineEdit* minEdit, QLineEdit* maxEdit )
216+
{
217+
if ( !minEdit || !maxEdit || !mRasterLayer )
218+
{
219+
return;
220+
}
221+
222+
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
223+
if ( !provider )
224+
{
225+
return;
226+
}
227+
228+
if ( band < 0 )
229+
{
230+
minEdit->clear();
231+
maxEdit->clear();
232+
return;
233+
}
234+
235+
double minVal = 0;
236+
double maxVal = 0;
237+
if ( mEstimateRadioButton->isChecked() )
238+
{
239+
minVal = provider->minimumValue( band );
240+
maxVal = provider->maximumValue( band );
241+
}
242+
else if ( mActualRadioButton->isChecked() )
243+
{
244+
QgsRasterBandStats rasterBandStats = mRasterLayer->bandStatistics( band );
245+
minVal = rasterBandStats.minimumValue;
246+
maxVal = rasterBandStats.maximumValue;
247+
}
248+
else if ( mCurrentExtentRadioButton->isChecked() )
249+
{
250+
double minMax[2];
251+
mRasterLayer->computeMinimumMaximumFromLastExtent( band, minMax );
252+
minVal = minMax[0];
253+
maxVal = minMax[1];
254+
}
255+
256+
minEdit->setText( QString::number( minVal ) );
257+
maxEdit->setText( QString::number( maxVal ) );
258+
}

src/gui/raster/qgsmultibandcolorrendererwidget.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "qgsrasterrendererwidget.h"
2222
#include "ui_qgsmultibandcolorrendererwidgetbase.h"
2323

24+
class QgsContrastEnhancement;
25+
class QgsMultiBandColorRenderer;
2426
class QgsRasterDataProvider;
2527
class QgsRasterLayer;
26-
class QgsMultiBandColorRenderer;
28+
class QLineEdit;
2729

2830
class QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget, private Ui::QgsMultiBandColorRendererWidgetBase
2931
{
@@ -36,10 +38,16 @@ class QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget, private U
3638

3739
QgsRasterRenderer* renderer();
3840

41+
private slots:
42+
void on_mLoadPushButton_clicked();
43+
3944
private:
4045
void createValidators();
4146
void setCustomMinMaxValues( QgsMultiBandColorRenderer* r, const QgsRasterDataProvider* provider, int redBand, int GreenBand,
4247
int blueBand );
48+
/**Reads min/max values from contrast enhancement and fills values into the min/max line edits*/
49+
void setMinMaxValue( const QgsContrastEnhancement* ce, QLineEdit* minEdit, QLineEdit* maxEdit );
50+
void loadMinMaxValueForBand( int band, QLineEdit* minEdit, QLineEdit* maxEdit );
4351
};
4452

4553
#endif // QGSMULTIBANDCOLORRENDERERWIDGET_H

0 commit comments

Comments
 (0)