Skip to content
Permalink
Browse files

[BUG] Fix QgsColorRampShaderWidget (#35138)

Fixes issues related to the QgsColorRampShaderWidget in mesh/raster
fix #33882
fix #34962
  • Loading branch information
vcloarec committed Mar 20, 2020
1 parent 7b7c806 commit 02623cd09fef070184b450e12ffc1692be019dd4
Showing with 16 additions and 25 deletions.
  1. +16 −25 src/gui/raster/qgscolorrampshaderwidget.cpp
@@ -94,6 +94,7 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
resetClassifyButton();

connect( mClassificationModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorRampShaderWidget::classify );
connect( mColorInterpolationComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorRampShaderWidget::classify );
connect( mClassifyButton, &QPushButton::clicked, this, &QgsColorRampShaderWidget::classify );
connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsColorRampShaderWidget::applyColorRamp );
connect( mNumberOfEntriesSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsColorRampShaderWidget::classify );
@@ -265,7 +266,6 @@ void QgsColorRampShaderWidget::setUnitFromLabels()
}
}


void QgsColorRampShaderWidget::mAddEntryButton_clicked()
{
QgsTreeWidgetItemObject *newItem = new QgsTreeWidgetItemObject( mColormapTreeWidget );
@@ -337,6 +337,7 @@ void QgsColorRampShaderWidget::classify()
connect( newItem, &QgsTreeWidgetItemObject::itemEdited,
this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited );
}

mClipCheckBox->setChecked( colorRampShader->clip() );

autoLabel();
@@ -348,7 +349,6 @@ void QgsColorRampShaderWidget::mClassificationModeComboBox_currentIndexChanged(
QgsColorRampShader::ClassificationMode mode = static_cast< QgsColorRampShader::ClassificationMode >( mClassificationModeComboBox->itemData( index ).toInt() );
mNumberOfEntriesSpinBox->setEnabled( mode != QgsColorRampShader::Continuous );
emit classificationModeChanged( mode );

}

void QgsColorRampShaderWidget::applyColorRamp()
@@ -388,7 +388,7 @@ void QgsColorRampShaderWidget::applyColorRamp()

double value = currentItem->text( ValueColumn ).toDouble();
double position = ( value - mMin ) / ( mMax - mMin );
currentItem->setData( ColorColumn, Qt::EditRole, ramp->color( position ) );
whileBlocking( static_cast<QgsTreeWidgetItemObject *>( currentItem ) )->setData( ColorColumn, Qt::EditRole, ramp->color( position ) );
}

emit widgetChanged();
@@ -414,7 +414,6 @@ void QgsColorRampShaderWidget::populateColormapTreeWidget( const QList<QgsColorR
this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited );
}
setUnitFromLabels();
emit widgetChanged();
}

void QgsColorRampShaderWidget::mLoadFromBandButton_clicked()
@@ -645,9 +644,20 @@ void QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited( QTreeWidgetItem *

void QgsColorRampShaderWidget::setFromShader( const QgsColorRampShader &colorRampShader )
{
populateColormapTreeWidget( colorRampShader.colorRampItemList() );

// Those objects are connected to classify() the color ramp shader if they change, or call widget change
// need to block them to avoid to classify and to alter the color ramp, or to call duplicate widget change
whileBlocking( mClipCheckBox )->setChecked( colorRampShader.clip() );
whileBlocking( mColorInterpolationComboBox )->setCurrentIndex( mColorInterpolationComboBox->findData( colorRampShader.colorRampType() ) );
mColorInterpolationComboBox_currentIndexChanged( mColorInterpolationComboBox->currentIndex() );
whileBlocking( mClassificationModeComboBox )->setCurrentIndex( mClassificationModeComboBox->findData( colorRampShader.classificationMode() ) );
mClassificationModeComboBox_currentIndexChanged( mClassificationModeComboBox->currentIndex() );
whileBlocking( mNumberOfEntriesSpinBox )->setValue( colorRampShader.colorRampItemList().count() ); // some default

if ( colorRampShader.sourceColorRamp() )
{
btnColorRamp->setColorRamp( colorRampShader.sourceColorRamp() );
whileBlocking( btnColorRamp )->setColorRamp( colorRampShader.sourceColorRamp() );
}
else
{
@@ -656,26 +666,7 @@ void QgsColorRampShaderWidget::setFromShader( const QgsColorRampShader &colorRam
btnColorRamp->setColorRampFromName( defaultPalette );
}

mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( colorRampShader.colorRampType() ) );

mColormapTreeWidget->clear();
const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader.colorRampItemList();
QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
for ( ; it != colorRampItemList.end(); ++it )
{
QgsTreeWidgetItemObject *newItem = new QgsTreeWidgetItemObject( mColormapTreeWidget );
newItem->setText( ValueColumn, QString::number( it->value, 'g', 15 ) );
newItem->setData( ColorColumn, Qt::EditRole, it->color );
newItem->setText( LabelColumn, it->label );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
connect( newItem, &QgsTreeWidgetItemObject::itemEdited,
this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited );
}
setUnitFromLabels();

mClipCheckBox->setChecked( colorRampShader.clip() );
mClassificationModeComboBox->setCurrentIndex( mClassificationModeComboBox->findData( colorRampShader.classificationMode() ) );
mNumberOfEntriesSpinBox->setValue( colorRampShader.colorRampItemList().count() ); // some default
emit widgetChanged();
}

void QgsColorRampShaderWidget::mColorInterpolationComboBox_currentIndexChanged( int index )

0 comments on commit 02623cd

Please sign in to comment.
You can’t perform that action at this time.