Skip to content

Commit

Permalink
Clarify what value means for single band psuedo color renderer
Browse files Browse the repository at this point in the history
...by adapting the header text and tooltip as the interpolation
mode is altered
  • Loading branch information
nyalldawson committed Jun 2, 2016
1 parent c68eaeb commit d40554b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 55 deletions.
112 changes: 58 additions & 54 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -115,10 +115,10 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
mBandComboBox->addItem( displayBandName( i ), i ); mBandComboBox->addItem( displayBandName( i ), i );
} }


mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 ); mColorInterpolationComboBox->addItem( tr( "Discrete" ), QgsColorRampShader::DISCRETE );
mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 ); mColorInterpolationComboBox->addItem( tr( "Linear" ), QgsColorRampShader::INTERPOLATED );
mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 ); mColorInterpolationComboBox->addItem( tr( "Exact" ), QgsColorRampShader::EXACT );
mColorInterpolationComboBox->setCurrentIndex( 1 ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) );
mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous ); mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous );
mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval ); mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval );
mClassificationModeComboBox->addItem( tr( "Quantile" ), Quantile ); mClassificationModeComboBox->addItem( tr( "Quantile" ), Quantile );
Expand Down Expand Up @@ -178,18 +178,8 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
qSort( colorRampItems ); qSort( colorRampItems );
colorRampShader->setColorRampItemList( colorRampItems ); colorRampShader->setColorRampItemList( colorRampItems );


if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) ) QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
{ colorRampShader->setColorRampType( interpolation );
colorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
}
else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
{
colorRampShader->setColorRampType( QgsColorRampShader::DISCRETE );
}
else
{
colorRampShader->setColorRampType( QgsColorRampShader::EXACT );
}
rasterShader->setRasterShaderFunction( colorRampShader ); rasterShader->setRasterShaderFunction( colorRampShader );


int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt(); int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
Expand All @@ -207,7 +197,8 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
*/ */
void QgsSingleBandPseudoColorRendererWidget::autoLabel() void QgsSingleBandPseudoColorRendererWidget::autoLabel()
{ {
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" ); QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
bool discrete = interpolation == QgsColorRampShader::DISCRETE;
QString unit = mUnitLineEdit->text(); QString unit = mUnitLineEdit->text();
QString label; QString label;
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount(); int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
Expand Down Expand Up @@ -252,7 +243,8 @@ void QgsSingleBandPseudoColorRendererWidget::autoLabel()
/** Extract the unit out of the current labels and set the unit field. */ /** Extract the unit out of the current labels and set the unit field. */
void QgsSingleBandPseudoColorRendererWidget::setUnitFromLabels() void QgsSingleBandPseudoColorRendererWidget::setUnitFromLabels()
{ {
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" ); QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
bool discrete = interpolation == QgsColorRampShader::DISCRETE;
QStringList allSuffixes; QStringList allSuffixes;
QString label; QString label;
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount(); int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
Expand Down Expand Up @@ -353,7 +345,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
//QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr ); //QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
int numberOfEntries; int numberOfEntries;


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


QList<double> entryValues; QList<double> entryValues;
QVector<QColor> entryColors; QVector<QColor> entryColors;
Expand Down Expand Up @@ -531,9 +524,10 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()


void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index ) void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index )
{ {
mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Continuous ); Mode mode = static_cast< Mode >( mClassificationModeComboBox->itemData( index ).toInt() );
mMinLineEdit->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Quantile ); mNumberOfEntriesSpinBox->setEnabled( mode != Continuous );
mMaxLineEdit->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Quantile ); mMinLineEdit->setEnabled( mode != Quantile );
mMaxLineEdit->setEnabled( mode != Quantile );
} }


void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index ) void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index )
Expand Down Expand Up @@ -585,7 +579,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked()
if ( !colorRampList.isEmpty() ) if ( !colorRampList.isEmpty() )
{ {
populateColormapTreeWidget( colorRampList ); populateColormapTreeWidget( colorRampList );
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) );
} }
else else
{ {
Expand Down Expand Up @@ -629,15 +623,15 @@ void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromFileButton_clicked()
{ {
if ( inputStringComponents[1].trimmed().toUpper().compare( "INTERPOLATED", Qt::CaseInsensitive ) == 0 ) if ( inputStringComponents[1].trimmed().toUpper().compare( "INTERPOLATED", Qt::CaseInsensitive ) == 0 )
{ {
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) );
} }
else if ( inputStringComponents[1].trimmed().toUpper().compare( "DISCRETE", Qt::CaseInsensitive ) == 0 ) else if ( inputStringComponents[1].trimmed().toUpper().compare( "DISCRETE", Qt::CaseInsensitive ) == 0 )
{ {
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::DISCRETE ) );
} }
else else
{ {
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::EXACT ) );
} }
} }
else else
Expand Down Expand Up @@ -702,17 +696,18 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
QTextStream outputStream( &outputFile ); QTextStream outputStream( &outputFile );
outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n'; outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';
outputStream << "INTERPOLATION:"; outputStream << "INTERPOLATION:";
if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) ) QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
switch ( interpolation )
{ {
outputStream << "INTERPOLATED\n"; case QgsColorRampShader::INTERPOLATED:
} outputStream << "INTERPOLATED\n";
else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) ) break;
{ case QgsColorRampShader::DISCRETE:
outputStream << "DISCRETE\n"; outputStream << "DISCRETE\n";
} break;
else case QgsColorRampShader::EXACT:
{ outputStream << "EXACT\n";
outputStream << "EXACT\n"; break;
} }


int topLevelItemCount = mColormapTreeWidget->topLevelItemCount(); int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
Expand Down Expand Up @@ -750,10 +745,6 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
} }
} }


void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged()
{
}

void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column ) void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
{ {
if ( !item ) if ( !item )
Expand Down Expand Up @@ -812,18 +803,7 @@ void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRen
const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() ); const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
if ( colorRampShader ) if ( colorRampShader )
{ {
if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED ) mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( colorRampShader->colorRampType() ) );
{
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
}
else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
{
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
}
else
{
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
}


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


void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged( int index ) void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged( int index )
{ {
Q_UNUSED( index ); QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( index ).toInt() );
mClipCheckBox->setEnabled( mColorInterpolationComboBox->currentText() == tr( "Linear" ) );
mClipCheckBox->setEnabled( interpolation == QgsColorRampShader::INTERPOLATED );

QString valueLabel;
QString valueToolTip;
switch ( interpolation )
{
case QgsColorRampShader::INTERPOLATED:
valueLabel = tr( "Value" );
valueToolTip = tr( "Value for color stop" );
break;
case QgsColorRampShader::DISCRETE:
valueLabel = tr( "Value <=" );
valueToolTip = tr( "Maximum value for class" );
break;
case QgsColorRampShader::EXACT:
valueLabel = tr( "Value =" );
valueToolTip = tr( "Value for color" );
break;
}

QTreeWidgetItem* header = mColormapTreeWidget->headerItem();
header->setText( ValueColumn, valueLabel );
header->setToolTip( ValueColumn, valueToolTip );

autoLabel(); autoLabel();
} }


Expand Down
1 change: 0 additions & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Expand Up @@ -67,7 +67,6 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void on_mLoadFromFileButton_clicked(); void on_mLoadFromFileButton_clicked();
void on_mExportToFileButton_clicked(); void on_mExportToFileButton_clicked();
void on_mUnitLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); autoLabel(); } void on_mUnitLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); autoLabel(); }
void on_mColorInterpolationComboBox_currentIndexChanged();
void on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column ); void on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column );
void mColormapTreeWidget_itemEdited( QTreeWidgetItem* item, int column ); void mColormapTreeWidget_itemEdited( QTreeWidgetItem* item, int column );
void on_mBandComboBox_currentIndexChanged( int index ); void on_mBandComboBox_currentIndexChanged( int index );
Expand Down

0 comments on commit d40554b

Please sign in to comment.