Skip to content
Permalink
Browse files
[FEATURE] Allow loading paletted color table from file
Supports standard GDAL/ESRI clr file format
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent d542a1a commit d0566f779243c37d2a18a6eaceb325334a65403e
Showing with 76 additions and 28 deletions.
  1. +25 −0 src/gui/raster/qgspalettedrendererwidget.cpp
  2. +1 −0 src/gui/raster/qgspalettedrendererwidget.h
  3. +50 −28 src/ui/qgspalettedrendererwidgetbase.ui
@@ -24,6 +24,8 @@

#include <QColorDialog>
#include <QInputDialog>
#include <QFileDialog>
#include <QMessageBox>
#include <QMenu>

#ifdef ENABLE_MODELTEST
@@ -89,6 +91,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
connect( mDeleteEntryButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::deleteEntry );
connect( mAddEntryButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::addEntry );
connect( mLoadFromFileButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::loadColorTable );
}

QgsRasterRenderer *QgsPalettedRendererWidget::renderer()
@@ -311,6 +314,28 @@ void QgsPalettedRendererWidget::applyColorRamp()
emit widgetChanged();
}

void QgsPalettedRendererWidget::loadColorTable()
{
QgsSettings settings;
QString lastDir = settings.value( QStringLiteral( "lastColorMapDir" ), QDir::homePath() ).toString();
QString fileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), lastDir );
if ( !fileName.isEmpty() )
{
QgsPalettedRasterRenderer::ClassData classes = QgsPalettedRasterRenderer::classDataFromFile( fileName );
if ( !classes.isEmpty() )
{
disconnect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
mModel->setClassData( classes );
emit widgetChanged();
connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
}
else
{
QMessageBox::critical( nullptr, tr( "Invalid file" ), tr( "Could not interpret file as a raster color table." ) );
}
}
}

//
// QgsPalettedRendererModel
//
@@ -107,6 +107,7 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
void changeTransparency();
void changeLabel();
void applyColorRamp();
void loadColorTable();
};

#endif // QGSPALETTEDRENDERERWIDGET_H
@@ -26,25 +26,15 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mBandLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Band</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mBandComboBox"/>
</item>
</layout>
<item row="2" column="0">
<widget class="QTreeView" name="mTreeView">
<property name="minimumSize">
<size>
<width>0</width>
<height>280</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QgsColorRampButton" name="btnColorRamp">
@@ -92,6 +82,28 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mLoadFromFileButton">
<property name="toolTip">
<string>Load color map from file</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mExportToFileButton">
<property name="toolTip">
<string>Export color map to file</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileSaveAs.svg</normaloff>:/images/themes/default/mActionFileSaveAs.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -107,15 +119,25 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QTreeView" name="mTreeView">
<property name="minimumSize">
<size>
<width>0</width>
<height>280</height>
</size>
</property>
</widget>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mBandLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Band</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mBandComboBox"/>
</item>
</layout>
</item>
</layout>
</widget>

0 comments on commit d0566f7

Please sign in to comment.