Skip to content

Commit

Permalink
[ui] When the color ramp shader widget list of values has been
Browse files Browse the repository at this point in the history
customized, maintain those values when modifying the color ramp
(fixes #30345)
  • Loading branch information
nirvn committed Jun 24, 2019
1 parent 94ec2dc commit 9910fd6
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/gui/raster/qgscolorrampshaderwidget.cpp
Expand Up @@ -66,8 +66,7 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
mColormapTreeWidget->setColumnWidth( ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, this, [ = ]( QPoint ) { contextMenu->exec( QCursor::pos() ); }
);
connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, this, [ = ]( QPoint ) { contextMenu->exec( QCursor::pos() ); } );

QString defaultPalette = settings.value( QStringLiteral( "Raster/defaultPalette" ), "" ).toString();
btnColorRamp->setColorRampFromName( defaultPalette );
Expand All @@ -89,7 +88,7 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
resetClassifyButton();

connect( mClassificationModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorRampShaderWidget::classify );
connect( mClassifyButton, &QPushButton::clicked, this, &QgsColorRampShaderWidget::applyColorRamp );
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 );
connect( mClipCheckBox, &QAbstractButton::toggled, this, &QgsColorRampShaderWidget::widgetChanged );
Expand Down Expand Up @@ -319,7 +318,6 @@ void QgsColorRampShaderWidget::classify()
mRasterDataProvider );
colorRampShader->setClip( mClipCheckBox->isChecked() );


mColormapTreeWidget->clear();

const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
Expand All @@ -336,7 +334,6 @@ void QgsColorRampShaderWidget::classify()
}
mClipCheckBox->setChecked( colorRampShader->clip() );


autoLabel();
emit widgetChanged();
}
Expand Down Expand Up @@ -371,7 +368,30 @@ void QgsColorRampShaderWidget::applyColorRamp()
mClassificationModeComboBox->setCurrentIndex( mClassificationModeComboBox->findData( QgsColorRampShader::EqualInterval ) );
}

classify();
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
if ( topLevelItemCount > 0 )
{
// if the list values has been customized, maintain pre-existing values
QTreeWidgetItem *currentItem = nullptr;
for ( int i = 0; i < topLevelItemCount; ++i )
{
currentItem = mColormapTreeWidget->topLevelItem( i );
if ( !currentItem )
{
continue;
}

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

emit widgetChanged();
}
else
{
classify();
}
}

void QgsColorRampShaderWidget::populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem> &colorRampItems )
Expand Down Expand Up @@ -409,7 +429,6 @@ void QgsColorRampShaderWidget::mLoadFromBandButton_clicked()
{
QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries." ).arg( mBand ) );
}

loadMinimumMaximumFromTree();
emit widgetChanged();
}
Expand Down

0 comments on commit 9910fd6

Please sign in to comment.