32#include <QInputDialog>
40#include "moc_qgssinglebandpseudocolorrendererwidget.cpp"
42using namespace Qt::StringLiterals;
51 mColorRampShaderWidget->initializeForUseWithRasterLayer();
53 connect( mMinLineEdit, &QLineEdit::textChanged,
this, &QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textChanged );
54 connect( mMaxLineEdit, &QLineEdit::textChanged,
this, &QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textChanged );
55 connect( mMinLineEdit, &QLineEdit::textEdited,
this, &QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textEdited );
56 connect( mMaxLineEdit, &QLineEdit::textEdited,
this, &QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textEdited );
74 mMinMaxWidget->setExtent( extent );
75 mMinMaxWidget->setMapCanvas(
mCanvas );
77 QHBoxLayout *layout =
new QHBoxLayout();
78 layout->setContentsMargins( 0, 0, 0, 0 );
79 mMinMaxContainerWidget->setLayout( layout );
80 layout->addWidget( mMinMaxWidget );
82 mColorRampShaderWidget->setRasterDataProvider( provider );
91 if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() )
97 mMinMaxWidget->setFromMinMaxOrigin( minMaxOrigin );
99 mMinMaxWidget->doComputations();
102 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
113 mColorRampShaderWidget->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
114 mColorRampShaderWidget->setExtent( mMinMaxWidget->extent() );
119 const int bandNumber = mBandComboBox->currentBand();
121 renderer->setClassificationMin( lineEditValue( mMinLineEdit ) );
122 renderer->setClassificationMax( lineEditValue( mMaxLineEdit ) );
123 renderer->setMinMaxOrigin( mMinMaxWidget->minMaxOrigin() );
129 mMinMaxWidget->doComputations();
134 return mMinMaxWidget;
140 mMinMaxWidget->setMapCanvas( canvas );
141 mColorRampShaderWidget->setExtent( mMinMaxWidget->extent() );
146 bool hasSetColorRampShader =
false;
149 mBandComboBox->setBand( pr->inputBand() );
150 mMinMaxWidget->setBands( QList<int>() << pr->inputBand() );
151 mColorRampShaderWidget->setRasterBand( pr->inputBand() );
155 setLineEditValue( mMinLineEdit, pr->classificationMin() );
156 setLineEditValue( mMaxLineEdit, pr->classificationMax() );
157 mMinMaxWidget->setFromMinMaxOrigin( pr->minMaxOrigin() );
161 if (
const auto *colorRampShader =
dynamic_cast<const QgsColorRampShader *
>( rasterShader->rasterShaderFunction() ) )
163 mColorRampShaderWidget->setFromShader( *colorRampShader );
164 hasSetColorRampShader =
true;
170 mMinMaxWidget->setBands( QList<int>() << mBandComboBox->currentBand() );
171 mColorRampShaderWidget->setRasterBand( mBandComboBox->currentBand() );
174 if ( !hasSetColorRampShader )
182void QgsSingleBandPseudoColorRendererWidget::bandChanged()
185 bands.append( mBandComboBox->currentBand() );
187 mColorRampShaderWidget->setRasterBand( mBandComboBox->currentBand() );
188 mColorRampShaderWidget->classify();
195 const QString oldMinTextvalue = mMinLineEdit->text();
196 const QString oldMaxTextvalue = mMaxLineEdit->text();
198 if ( std::isnan(
min ) )
204 whileBlocking( mMinLineEdit )->setText( displayValueWithMaxPrecision(
min ) );
207 if ( std::isnan(
max ) )
213 whileBlocking( mMaxLineEdit )->setText( displayValueWithMaxPrecision(
max ) );
219 if ( mMinLineEdit->text() != oldMinTextvalue || mMaxLineEdit->text() != oldMaxTextvalue )
221 whileBlocking( mColorRampShaderWidget )->setRasterBand( bandNo );
229 whileBlocking( mMinLineEdit )->setText( displayValueWithMaxPrecision(
min ) );
230 whileBlocking( mMaxLineEdit )->setText( displayValueWithMaxPrecision(
max ) );
235void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit *lineEdit,
double value )
238 if ( !std::isnan( value ) )
240 s = displayValueWithMaxPrecision( value );
242 lineEdit->setText( s );
245double QgsSingleBandPseudoColorRendererWidget::lineEditValue(
const QLineEdit *lineEdit )
const
247 if ( lineEdit->text().isEmpty() )
249 return std::numeric_limits<double>::quiet_NaN();
255void QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textEdited(
const QString & )
258 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
262void QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textEdited(
const QString & )
265 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
269void QgsSingleBandPseudoColorRendererWidget::mMinLineEdit_textChanged(
const QString & )
271 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
275void QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textChanged(
const QString & )
277 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( lineEditValue( mMinLineEdit ), lineEditValue( mMaxLineEdit ) );
282void QgsSingleBandPseudoColorRendererWidget::minMaxModified()
284 mMinMaxWidget->userHasSetManualMinMaxValues();
287QString QgsSingleBandPseudoColorRendererWidget::displayValueWithMaxPrecision(
const double value )
296 return QLocale().toString( value,
'g' );
302 mMinLineEdit->setText( value );
304 mColorRampShaderWidget->classify();
309 mMaxLineEdit->setText( value );
311 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.
Interface for all raster shaders.
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
A rectangle specified with double values.
Stores settings for use within QGIS.
Raster renderer pipe for single band pseudocolor.
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)