Skip to content
Permalink
Browse files
[FEATURE] Add button to paletted renderer widget to allow loading
embedded color table

Only enabled for rasters which contain a color table
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent d03844d commit b9f1f0e427667491d4a4aa03cf3af8cba9806168
Showing with 73 additions and 41 deletions.
  1. +24 −7 src/gui/raster/qgspalettedrendererwidget.cpp
  2. +1 −0 src/gui/raster/qgspalettedrendererwidget.h
  3. +48 −34 src/ui/qgspalettedrendererwidgetbase.ui
@@ -94,6 +94,17 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
connect( mLoadFromFileButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::loadColorTable );
connect( mExportToFileButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::saveColorTable );
connect( mClassifyButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::classify );
connect( mButtonLoadFromLayer, &QPushButton::clicked, this, &QgsPalettedRendererWidget::loadFromLayer );

QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
if ( provider )
{
mButtonLoadFromLayer->setEnabled( !provider->colorTable( mBandComboBox->currentData().toInt() ).isEmpty() );
}
else
{
mButtonLoadFromLayer->setEnabled( false );
}
}

QgsRasterRenderer *QgsPalettedRendererWidget::renderer()
@@ -130,13 +141,7 @@ void QgsPalettedRendererWidget::setFromRenderer( const QgsRasterRenderer *r )
}
else
{
//read default palette settings from layer
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
if ( provider )
{
QgsPalettedRasterRenderer::ClassData classes = QgsPalettedRasterRenderer::colorTableToClassData( provider->colorTable( mBandComboBox->currentData().toInt() ) );
mModel->setClassData( classes );
}
loadFromLayer();
QgsSettings settings;
QString defaultPalette = settings.value( "/Raster/defaultPalette", "Spectral" ).toString();
whileBlocking( btnColorRamp )->setColorRampFromName( defaultPalette );
@@ -385,6 +390,18 @@ void QgsPalettedRendererWidget::classify()
}
}

void QgsPalettedRendererWidget::loadFromLayer()
{
//read default palette settings from layer
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
if ( provider )
{
QgsPalettedRasterRenderer::ClassData classes = QgsPalettedRasterRenderer::colorTableToClassData( provider->colorTable( mBandComboBox->currentData().toInt() ) );
mModel->setClassData( classes );
emit widgetChanged();
}
}

//
// QgsPalettedRendererModel
//
@@ -110,6 +110,7 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
void loadColorTable();
void saveColorTable();
void classify();
void loadFromLayer();

};

@@ -59,48 +59,54 @@
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="mClassifyButton">
<property name="text">
<string>Classify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mAddEntryButton">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QPushButton" name="mDeleteEntryButton">
<property name="toolTip">
<string>Add values manually</string>
<string>Remove selected row(s)</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mDeleteEntryButton">
<item row="0" column="6">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>48</width>
<height>28</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="mLoadFromFileButton">
<property name="toolTip">
<string>Remove selected row(s)</string>
<string>Load color map from file</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mLoadFromFileButton">
<item row="0" column="0">
<widget class="QPushButton" name="mAddEntryButton">
<property name="toolTip">
<string>Load color map from file</string>
<string>Add values manually</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
</widget>
</item>
<item>
<item row="0" column="3">
<widget class="QPushButton" name="mExportToFileButton">
<property name="toolTip">
<string>Export color map to file</string>
@@ -111,19 +117,6 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>48</width>
<height>28</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
@@ -146,6 +139,27 @@
</item>
</layout>
</item>
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="mClassifyButton">
<property name="text">
<string>Add Unique Values</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonLoadFromLayer">
<property name="text">
<string>Load from Layer</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>

0 comments on commit b9f1f0e

Please sign in to comment.