32#include <QInputDialog>
39#include "moc_qgssinglebandpseudocolorrendererwidget.cpp"
48 mColorRampShaderWidget->initializeForUseWithRasterLayer();
50 connect( mMinLineEdit, &QLineEdit::textChanged,
this, &QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textChanged );
51 connect( mMaxLineEdit, &QLineEdit::textChanged,
this, &QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textChanged );
52 connect( mMinLineEdit, &QLineEdit::textEdited,
this, &QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textEdited );
53 connect( mMaxLineEdit, &QLineEdit::textEdited,
this, &QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textEdited );
71 mMinMaxWidget->setExtent( extent );
72 mMinMaxWidget->setMapCanvas(
mCanvas );
74 QHBoxLayout *layout =
new QHBoxLayout();
75 layout->setContentsMargins( 0, 0, 0, 0 );
76 mMinMaxContainerWidget->setLayout( layout );
77 layout->addWidget( mMinMaxWidget );
79 mColorRampShaderWidget->setRasterDataProvider( provider );
88 if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() )
94 mMinMaxWidget->setFromMinMaxOrigin( minMaxOrigin );
96 mMinMaxWidget->doComputations();
99 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
110 mColorRampShaderWidget->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
111 mColorRampShaderWidget->setExtent( mMinMaxWidget->extent() );
116 const int bandNumber = mBandComboBox->currentBand();
118 renderer->setClassificationMin( lineEditValue( mMinLineEdit ) );
119 renderer->setClassificationMax( lineEditValue( mMaxLineEdit ) );
120 renderer->setMinMaxOrigin( mMinMaxWidget->minMaxOrigin() );
126 mMinMaxWidget->doComputations();
134 mMinMaxWidget->setMapCanvas( canvas );
135 mColorRampShaderWidget->setExtent( mMinMaxWidget->extent() );
143 mBandComboBox->setBand( pr->
inputBand() );
144 mMinMaxWidget->setBands( QList<int>() << pr->
inputBand() );
145 mColorRampShaderWidget->setRasterBand( pr->
inputBand() );
151 mMinMaxWidget->setFromMinMaxOrigin( pr->
minMaxOrigin() );
157 if ( colorRampShader )
159 mColorRampShaderWidget->setFromShader( *colorRampShader );
165 mMinMaxWidget->setBands( QList<int>() << mBandComboBox->currentBand() );
166 mColorRampShaderWidget->setRasterBand( mBandComboBox->currentBand() );
170void QgsSingleBandPseudoColorRendererWidget::bandChanged()
173 bands.append( mBandComboBox->currentBand() );
175 mColorRampShaderWidget->setRasterBand( mBandComboBox->currentBand() );
176 mColorRampShaderWidget->classify();
181 QgsDebugMsgLevel( QStringLiteral(
"theBandNo = %1 min = %2 max = %3" ).arg( bandNo ).arg(
min ).arg(
max ), 2 );
183 const QString oldMinTextvalue = mMinLineEdit->text();
184 const QString oldMaxTextvalue = mMaxLineEdit->text();
186 if ( std::isnan(
min ) )
192 whileBlocking( mMinLineEdit )->setText( displayValueWithMaxPrecision(
min ) );
195 if ( std::isnan(
max ) )
201 whileBlocking( mMaxLineEdit )->setText( displayValueWithMaxPrecision(
max ) );
207 if ( mMinLineEdit->text() != oldMinTextvalue || mMaxLineEdit->text() != oldMaxTextvalue )
209 whileBlocking( mColorRampShaderWidget )->setRasterBand( bandNo );
217 whileBlocking( mMinLineEdit )->setText( displayValueWithMaxPrecision(
min ) );
218 whileBlocking( mMaxLineEdit )->setText( displayValueWithMaxPrecision(
max ) );
223void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit *lineEdit,
double value )
226 if ( !std::isnan( value ) )
228 s = displayValueWithMaxPrecision( value );
230 lineEdit->setText( s );
233double QgsSingleBandPseudoColorRendererWidget::lineEditValue(
const QLineEdit *lineEdit )
const
235 if ( lineEdit->text().isEmpty() )
237 return std::numeric_limits<double>::quiet_NaN();
243void QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textEdited(
const QString & )
246 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
250void QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textEdited(
const QString & )
253 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
257void QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textChanged(
const QString & )
259 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
263void QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textChanged(
const QString & )
265 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
270void QgsSingleBandPseudoColorRendererWidget::minMaxModified()
272 mMinMaxWidget->userHasSetManualMinMaxValues();
275QString QgsSingleBandPseudoColorRendererWidget::displayValueWithMaxPrecision(
const double value )
284 return QLocale().toString( value,
'g' );
290 mMinLineEdit->setText( value );
292 mColorRampShaderWidget->classify();
297 mMaxLineEdit->setText( value );
299 mColorRampShaderWidget->classify();
@ MinimumMaximum
Real min-max values.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
A custom validator which allows entry of doubles in a locale-tolerant way.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
Map canvas is a class for displaying all GIS data types on a canvas.
void bandChanged(int band)
Emitted when the currently selected band changes.
Base class for raster data providers.
Represents a raster layer.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
Describes the origin of minimum and maximum values in a raster.
void setLimits(Qgis::RasterRangeLimit limits)
Sets the limits.
Qgis::RasterRangeLimit limits() const
Returns the raster limits.
Raster renderer pipe that applies colors to a raster.
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
Interface for all raster shaders.
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
QgsRasterShaderFunction * rasterShaderFunction()
A rectangle specified with double values.
Stores settings for use within QGIS.
Raster renderer pipe for single band pseudocolor.
double classificationMin() const
QgsRasterShader * shader()
Returns the raster shader.
double classificationMax() const
int inputBand() const override
Returns the input band for the renderer, or -1 if no input band is available.
QString displayValueWithMaximumDecimals(const Qgis::DataType dataType, const double value, bool displayTrailingZeroes)
Returns a localized string representation of the value with the appropriate number of decimals suppor...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugMsgLevel(str, level)