Navigation Menu

Skip to content

Commit

Permalink
Refine paletted raster renderer classification
Browse files Browse the repository at this point in the history
Change behaviour from clearing all existing values on classification
to instead keeping any existing values which do exist in the raster,
maintaining their current color and label.
  • Loading branch information
nyalldawson committed May 9, 2017
1 parent bccba30 commit 499a35d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/gui/raster/qgspalettedrendererwidget.cpp
Expand Up @@ -406,7 +406,7 @@ void QgsPalettedRendererWidget::classify()
return;
}

mGatherer = new QgsPalettedRendererClassGatherer( mRasterLayer, mBandComboBox->currentData().toInt(), btnColorRamp->colorRamp() );
mGatherer = new QgsPalettedRendererClassGatherer( mRasterLayer, mBandComboBox->currentData().toInt(), mModel->classData(), btnColorRamp->colorRamp() );

connect( mGatherer, &QgsPalettedRendererClassGatherer::progressChanged, mCalculatingProgressBar, &QProgressBar::setValue );
mCalculatingProgressBar->show();
Expand Down Expand Up @@ -450,7 +450,7 @@ void QgsPalettedRendererWidget::gathererThreadFinished()
{
mGatherer->deleteLater();
mGatherer = nullptr;
mClassifyButton->setText( tr( "Add Unique Values" ) );
mClassifyButton->setText( tr( "Populate Values" ) );
mClassifyButton->setEnabled( true );
mCalculatingProgressBar->hide();
mCancelButton->hide();
Expand Down
23 changes: 21 additions & 2 deletions src/gui/raster/qgspalettedrendererwidget.h
Expand Up @@ -38,10 +38,11 @@ class QgsPalettedRendererClassGatherer: public QThread
Q_OBJECT

public:
QgsPalettedRendererClassGatherer( QgsRasterLayer *layer, int bandNumber, QgsColorRamp *ramp = nullptr )
QgsPalettedRendererClassGatherer( QgsRasterLayer *layer, int bandNumber, const QgsPalettedRasterRenderer::ClassData &existingClasses, QgsColorRamp *ramp = nullptr )
: mLayer( layer )
, mBandNumber( bandNumber )
, mRamp( ramp )
, mClasses( existingClasses )
, mFeedback( nullptr )
, mWasCanceled( false )
{}
Expand All @@ -54,7 +55,25 @@ class QgsPalettedRendererClassGatherer: public QThread
mFeedback = new QgsRasterBlockFeedback();
connect( mFeedback, &QgsRasterBlockFeedback::progressChanged, this, &QgsPalettedRendererClassGatherer::progressChanged );

mClasses = QgsPalettedRasterRenderer::classDataFromRaster( mLayer->dataProvider(), mBandNumber, mRamp.get(), mFeedback );
QgsPalettedRasterRenderer::ClassData newClasses = QgsPalettedRasterRenderer::classDataFromRaster( mLayer->dataProvider(), mBandNumber, mRamp.get(), mFeedback );

// combine existing classes with new classes
QgsPalettedRasterRenderer::ClassData::iterator classIt = newClasses.begin();
for ( ; classIt != newClasses.end(); ++classIt )
{
// check if existing classes contains this same class
Q_FOREACH ( const QgsPalettedRasterRenderer::Class &existingClass, mClasses )
{
if ( existingClass.value == classIt->value )
{
classIt->color = existingClass.color;
classIt->label = existingClass.label;
break;
}
}
}
mClasses = newClasses;

// be overly cautious - it's *possible* stop() might be called between deleting mFeedback and nulling it
mFeedbackMutex.lock();
delete mFeedback;
Expand Down
5 changes: 4 additions & 1 deletion src/ui/qgspalettedrendererwidgetbase.ui
Expand Up @@ -43,8 +43,11 @@
</property>
<item>
<widget class="QPushButton" name="mClassifyButton">
<property name="toolTip">
<string>Adds all missing unique values from the raster</string>
</property>
<property name="text">
<string>Add Unique Values</string>
<string>Populate Values</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 499a35d

Please sign in to comment.