Skip to content

Commit d40554b

Browse files
committed
Clarify what value means for single band psuedo color renderer
...by adapting the header text and tooltip as the interpolation mode is altered
1 parent c68eaeb commit d40554b

File tree

2 files changed

+58
-55
lines changed

2 files changed

+58
-55
lines changed

src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
115115
mBandComboBox->addItem( displayBandName( i ), i );
116116
}
117117

118-
mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 );
119-
mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 );
120-
mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 );
121-
mColorInterpolationComboBox->setCurrentIndex( 1 );
118+
mColorInterpolationComboBox->addItem( tr( "Discrete" ), QgsColorRampShader::DISCRETE );
119+
mColorInterpolationComboBox->addItem( tr( "Linear" ), QgsColorRampShader::INTERPOLATED );
120+
mColorInterpolationComboBox->addItem( tr( "Exact" ), QgsColorRampShader::EXACT );
121+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) );
122122
mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous );
123123
mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval );
124124
mClassificationModeComboBox->addItem( tr( "Quantile" ), Quantile );
@@ -178,18 +178,8 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
178178
qSort( colorRampItems );
179179
colorRampShader->setColorRampItemList( colorRampItems );
180180

181-
if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
182-
{
183-
colorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
184-
}
185-
else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
186-
{
187-
colorRampShader->setColorRampType( QgsColorRampShader::DISCRETE );
188-
}
189-
else
190-
{
191-
colorRampShader->setColorRampType( QgsColorRampShader::EXACT );
192-
}
181+
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
182+
colorRampShader->setColorRampType( interpolation );
193183
rasterShader->setRasterShaderFunction( colorRampShader );
194184

195185
int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
@@ -207,7 +197,8 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
207197
*/
208198
void QgsSingleBandPseudoColorRendererWidget::autoLabel()
209199
{
210-
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
200+
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
201+
bool discrete = interpolation == QgsColorRampShader::DISCRETE;
211202
QString unit = mUnitLineEdit->text();
212203
QString label;
213204
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
@@ -252,7 +243,8 @@ void QgsSingleBandPseudoColorRendererWidget::autoLabel()
252243
/** Extract the unit out of the current labels and set the unit field. */
253244
void QgsSingleBandPseudoColorRendererWidget::setUnitFromLabels()
254245
{
255-
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
246+
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
247+
bool discrete = interpolation == QgsColorRampShader::DISCRETE;
256248
QStringList allSuffixes;
257249
QString label;
258250
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
@@ -353,7 +345,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
353345
//QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
354346
int numberOfEntries;
355347

356-
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
348+
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
349+
bool discrete = interpolation == QgsColorRampShader::DISCRETE;
357350

358351
QList<double> entryValues;
359352
QVector<QColor> entryColors;
@@ -531,9 +524,10 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
531524

532525
void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index )
533526
{
534-
mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Continuous );
535-
mMinLineEdit->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Quantile );
536-
mMaxLineEdit->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Quantile );
527+
Mode mode = static_cast< Mode >( mClassificationModeComboBox->itemData( index ).toInt() );
528+
mNumberOfEntriesSpinBox->setEnabled( mode != Continuous );
529+
mMinLineEdit->setEnabled( mode != Quantile );
530+
mMaxLineEdit->setEnabled( mode != Quantile );
537531
}
538532

539533
void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index )
@@ -585,7 +579,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked()
585579
if ( !colorRampList.isEmpty() )
586580
{
587581
populateColormapTreeWidget( colorRampList );
588-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
582+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) );
589583
}
590584
else
591585
{
@@ -629,15 +623,15 @@ void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromFileButton_clicked()
629623
{
630624
if ( inputStringComponents[1].trimmed().toUpper().compare( "INTERPOLATED", Qt::CaseInsensitive ) == 0 )
631625
{
632-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
626+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) );
633627
}
634628
else if ( inputStringComponents[1].trimmed().toUpper().compare( "DISCRETE", Qt::CaseInsensitive ) == 0 )
635629
{
636-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
630+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::DISCRETE ) );
637631
}
638632
else
639633
{
640-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
634+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::EXACT ) );
641635
}
642636
}
643637
else
@@ -702,17 +696,18 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
702696
QTextStream outputStream( &outputFile );
703697
outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';
704698
outputStream << "INTERPOLATION:";
705-
if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
699+
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
700+
switch ( interpolation )
706701
{
707-
outputStream << "INTERPOLATED\n";
708-
}
709-
else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
710-
{
711-
outputStream << "DISCRETE\n";
712-
}
713-
else
714-
{
715-
outputStream << "EXACT\n";
702+
case QgsColorRampShader::INTERPOLATED:
703+
outputStream << "INTERPOLATED\n";
704+
break;
705+
case QgsColorRampShader::DISCRETE:
706+
outputStream << "DISCRETE\n";
707+
break;
708+
case QgsColorRampShader::EXACT:
709+
outputStream << "EXACT\n";
710+
break;
716711
}
717712

718713
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
@@ -750,10 +745,6 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
750745
}
751746
}
752747

753-
void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged()
754-
{
755-
}
756-
757748
void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
758749
{
759750
if ( !item )
@@ -812,18 +803,7 @@ void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRen
812803
const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
813804
if ( colorRampShader )
814805
{
815-
if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED )
816-
{
817-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
818-
}
819-
else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
820-
{
821-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
822-
}
823-
else
824-
{
825-
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
826-
}
806+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( colorRampShader->colorRampType() ) );
827807

828808
const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
829809
QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
@@ -857,8 +837,32 @@ void QgsSingleBandPseudoColorRendererWidget::on_mBandComboBox_currentIndexChange
857837

858838
void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged( int index )
859839
{
860-
Q_UNUSED( index );
861-
mClipCheckBox->setEnabled( mColorInterpolationComboBox->currentText() == tr( "Linear" ) );
840+
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( index ).toInt() );
841+
842+
mClipCheckBox->setEnabled( interpolation == QgsColorRampShader::INTERPOLATED );
843+
844+
QString valueLabel;
845+
QString valueToolTip;
846+
switch ( interpolation )
847+
{
848+
case QgsColorRampShader::INTERPOLATED:
849+
valueLabel = tr( "Value" );
850+
valueToolTip = tr( "Value for color stop" );
851+
break;
852+
case QgsColorRampShader::DISCRETE:
853+
valueLabel = tr( "Value <=" );
854+
valueToolTip = tr( "Maximum value for class" );
855+
break;
856+
case QgsColorRampShader::EXACT:
857+
valueLabel = tr( "Value =" );
858+
valueToolTip = tr( "Value for color" );
859+
break;
860+
}
861+
862+
QTreeWidgetItem* header = mColormapTreeWidget->headerItem();
863+
header->setText( ValueColumn, valueLabel );
864+
header->setToolTip( ValueColumn, valueToolTip );
865+
862866
autoLabel();
863867
}
864868

src/gui/raster/qgssinglebandpseudocolorrendererwidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
6767
void on_mLoadFromFileButton_clicked();
6868
void on_mExportToFileButton_clicked();
6969
void on_mUnitLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); autoLabel(); }
70-
void on_mColorInterpolationComboBox_currentIndexChanged();
7170
void on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column );
7271
void mColormapTreeWidget_itemEdited( QTreeWidgetItem* item, int column );
7372
void on_mBandComboBox_currentIndexChanged( int index );

0 commit comments

Comments
 (0)