Skip to content
Permalink
Browse files

Make paletted raster widget behave more like vector categorized

renderer widget

Since they are basically counterparts to each other
  • Loading branch information
nyalldawson committed Jun 4, 2017
1 parent e977f1f commit c040469ca024f51d4a718d9e3d0223b705aa0c3c
@@ -40,10 +40,21 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
mCalculatingProgressBar->hide();
mCancelButton->hide();

contextMenu = new QMenu( tr( "Options" ), this );
contextMenu->addAction( tr( "Change color" ), this, SLOT( changeColor() ) );
contextMenu->addAction( tr( "Change opacity" ), this, SLOT( changeOpacity() ) );
contextMenu->addAction( tr( "Change label" ), this, SLOT( changeLabel() ) );
mContextMenu = new QMenu( tr( "Options" ), this );
mContextMenu->addAction( tr( "Change color" ), this, SLOT( changeColor() ) );
mContextMenu->addAction( tr( "Change opacity" ), this, SLOT( changeOpacity() ) );
mContextMenu->addAction( tr( "Change label" ), this, SLOT( changeLabel() ) );

mAdvancedMenu = new QMenu( tr( "Advanced options" ), this );
QAction *mLoadFromLayerAction = mAdvancedMenu->addAction( tr( "Load classes from layer" ) );
connect( mLoadFromLayerAction, &QAction::triggered, this, &QgsPalettedRendererWidget::loadFromLayer );
QAction *loadFromFile = mAdvancedMenu->addAction( trUtf8( "Load color map from file…" ) );
connect( loadFromFile, &QAction::triggered, this, &QgsPalettedRendererWidget::loadColorTable );
QAction *exportToFile = mAdvancedMenu->addAction( trUtf8( "Export color map to file…" ) );
connect( exportToFile, &QAction::triggered, this, &QgsPalettedRendererWidget::saveColorTable );


mButtonAdvanced->setMenu( mAdvancedMenu );

mModel = new QgsPalettedRendererModel( this );
mTreeView->setSortingEnabled( false );
@@ -65,7 +76,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
mTreeView->setSelectionBehavior( QAbstractItemView::SelectRows );
mTreeView->setDefaultDropAction( Qt::MoveAction );

connect( mTreeView, &QTreeView::customContextMenuRequested, [ = ]( const QPoint & ) { contextMenu->exec( QCursor::pos() ); }
connect( mTreeView, &QTreeView::customContextMenuRequested, [ = ]( const QPoint & ) { mContextMenu->exec( QCursor::pos() ); }
);

btnColorRamp->setShowRandomColorRamp( true );
@@ -87,20 +98,18 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, &QgsRasterRendererWidget::widgetChanged );
connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
connect( mDeleteEntryButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::deleteEntry );
connect( mButtonDeleteAll, &QPushButton::clicked, mModel, &QgsPalettedRendererModel::deleteAll );
connect( mAddEntryButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::addEntry );
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->currentBand() ).isEmpty() );
mLoadFromLayerAction->setEnabled( !provider->colorTable( mBandComboBox->currentBand() ).isEmpty() );
}
else
{
mButtonLoadFromLayer->setEnabled( false );
mLoadFromLayerAction->setEnabled( false );
}

connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( QgsMapLayer * ) >( &QgsProject::layerWillBeRemoved ), this, &QgsPalettedRendererWidget::layerWillBeRemoved );
@@ -444,7 +453,7 @@ void QgsPalettedRendererWidget::gathererThreadFinished()
{
mGatherer->deleteLater();
mGatherer = nullptr;
mClassifyButton->setText( tr( "Add Unique Values" ) );
mClassifyButton->setText( tr( "Classify" ) );
mClassifyButton->setEnabled( true );
mCalculatingProgressBar->hide();
mCancelButton->hide();
@@ -753,5 +762,13 @@ void QgsPalettedRendererModel::addEntry( const QColor &color )
setData( index( mData.count() - 1, 1 ), color );
}

void QgsPalettedRendererModel::deleteAll()
{
beginResetModel();
mData.clear();
endResetModel();
emit classesChanged();
}

///@endcond PRIVATE

@@ -162,6 +162,10 @@ class QgsPalettedRendererModel : public QAbstractItemModel

void addEntry( const QColor &color );

public slots:

void deleteAll();

signals:

void classesChanged();
@@ -194,7 +198,9 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv

private:

QMenu *contextMenu = nullptr;
QMenu *mContextMenu = nullptr;
QMenu *mAdvancedMenu = nullptr;
QAction *mLoadFromLayerAction = nullptr;
QgsPalettedRendererModel *mModel = nullptr;
QgsColorSwatchDelegate *mSwatchDelegate = nullptr;

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>293</width>
<width>277</width>
<height>459</height>
</rect>
</property>
@@ -26,41 +26,85 @@
<property name="bottomMargin">
<number>3</number>
</property>
<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="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="1,0,0,1,0">
<item>
<widget class="QPushButton" name="mClassifyButton">
<property name="toolTip">
<string>Adds all missing unique values from the raster</string>
</property>
<property name="text">
<string>Populate Values</string>
<string>Classify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mAddEntryButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Add values manually</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mDeleteEntryButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove selected row(s)</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonDeleteAll">
<property name="text">
<string>Delete all</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonLoadFromLayer">
<widget class="QToolButton" name="mButtonAdvanced">
<property name="toolTip">
<string>Advanced options</string>
</property>
<property name="text">
<string>Load from Layer</string>
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<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="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
@@ -139,67 +183,6 @@
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QPushButton" name="mDeleteEntryButton">
<property name="toolTip">
<string>Remove selected row(s)</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
</property>
</widget>
</item>
<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>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 row="0" column="0">
<widget class="QPushButton" name="mAddEntryButton">
<property name="toolTip">
<string>Add values manually</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="3">
<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>
</layout>
</item>
</layout>
</widget>
<customwidgets>
@@ -219,12 +202,11 @@
<tabstop>mBandComboBox</tabstop>
<tabstop>btnColorRamp</tabstop>
<tabstop>mTreeView</tabstop>
<tabstop>mClassifyButton</tabstop>
<tabstop>mAddEntryButton</tabstop>
<tabstop>mDeleteEntryButton</tabstop>
<tabstop>mLoadFromFileButton</tabstop>
<tabstop>mExportToFileButton</tabstop>
<tabstop>mClassifyButton</tabstop>
<tabstop>mButtonLoadFromLayer</tabstop>
<tabstop>mButtonDeleteAll</tabstop>
<tabstop>mButtonAdvanced</tabstop>
<tabstop>mCancelButton</tabstop>
</tabstops>
<resources>

0 comments on commit c040469

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