Skip to content
Permalink
Browse files

Merge pull request #3851 from nirvn/raster_ui_improvements

Raster renderer UI improvements
  • Loading branch information
nirvn committed Dec 10, 2016
2 parents 8ec3eaf + ffb6ba7 commit fc8493f5d34f387cc63d915bc9590d783fc27d3e
@@ -20,12 +20,24 @@
#include "qgsrasterdataprovider.h"
#include "qgsrasterlayer.h"
#include "qgscolordialog.h"

#include <QColorDialog>
#include <QInputDialog>
#include <QMenu>

QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ): QgsRasterRendererWidget( layer, extent )
{
setupUi( this );

contextMenu = new QMenu( tr( "Options" ), this );
contextMenu->addAction( tr( "Change color" ), this, SLOT( changeColor() ) );

mTreeWidget->setColumnWidth( ColorColumn, 50 );
mTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
mTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
connect( mTreeWidget, &QTreeView::customContextMenuRequested, [=]( const QPoint& ) { contextMenu->exec( QCursor::pos() ); }
);

if ( mRasterLayer )
{
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
@@ -72,7 +84,7 @@ QgsRasterRenderer* QgsPalettedRendererWidget::renderer()

void QgsPalettedRendererWidget::on_mTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column )
{
if ( column == 1 && item ) //change item color
if ( column == ColorColumn && item ) //change item color
{
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QColor c = QgsColorDialog::getColor( item->background( column ).color(), nullptr );
@@ -82,15 +94,15 @@ void QgsPalettedRendererWidget::on_mTreeWidget_itemDoubleClicked( QTreeWidgetIte
emit widgetChanged();
}
}
else if ( column == 2 && item )
else if ( column == LabelColumn && item )
{
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
}
}

void QgsPalettedRendererWidget::on_mTreeWidget_itemChanged( QTreeWidgetItem * item, int column )
{
if ( column == 2 && item ) //palette label modified
if ( column == LabelColumn && item ) //palette label modified
{
emit widgetChanged();
}
@@ -133,3 +145,25 @@ void QgsPalettedRendererWidget::setFromRenderer( const QgsRasterRenderer* r )
}
}
}

void QgsPalettedRendererWidget::changeColor()
{
QList<QTreeWidgetItem *> itemList;
itemList = mTreeWidget->selectedItems();
if ( itemList.isEmpty() )
{
return;
}
QTreeWidgetItem* firstItem = itemList.first();

QColor newColor = QgsColorDialog::getColor( firstItem->background( ColorColumn ).color(), this, QStringLiteral( "Change color" ), true );
if ( newColor.isValid() )
{
Q_FOREACH ( QTreeWidgetItem *item, itemList )
{
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
item->setBackground( ColorColumn, QBrush( newColor ) );
}
emit widgetChanged();
}
}
@@ -31,6 +31,7 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
Q_OBJECT

public:

QgsPalettedRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent = QgsRectangle() );
static QgsRasterRendererWidget* create( QgsRasterLayer* layer, const QgsRectangle &theExtent ) { return new QgsPalettedRendererWidget( layer, theExtent ); }
~QgsPalettedRendererWidget();
@@ -39,9 +40,22 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv

void setFromRenderer( const QgsRasterRenderer* r );

private:

enum Column
{
ValueColumn = 0,
ColorColumn = 1,
LabelColumn = 2,
};

QMenu* contextMenu;

private slots:

void on_mTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column );
void on_mTreeWidget_itemChanged( QTreeWidgetItem * item, int column );
void changeColor();
};

#endif // QGSPALETTEDRENDERERWIDGET_H
@@ -29,11 +29,15 @@
#include "qgscolorrampbutton.h"
#include "qgscolordialog.h"

#include <QCursor>
#include <QPushButton>
#include <QInputDialog>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
#include <QTextStream>
#include <QTreeView>

QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent )
: QgsRasterRendererWidget( layer, extent )
@@ -44,7 +48,15 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(

setupUi( this );

contextMenu = new QMenu( tr( "Options" ), this );
contextMenu->addAction( tr( "Change color" ), this, SLOT( changeColor() ) );
contextMenu->addAction( tr( "Change transparency" ), this, SLOT( changeTransparency() ) );

mColormapTreeWidget->setColumnWidth( ColorColumn, 50 );
mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, [=]( const QPoint& ) { contextMenu->exec( QCursor::pos() ); }
);

QString defaultPalette = settings.value( QStringLiteral( "/Raster/defaultPalette" ), "" ).toString();
btnColorRamp->setColorRampFromName( defaultPalette );
@@ -303,10 +315,16 @@ void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_clicked()

void QgsSingleBandPseudoColorRendererWidget::on_mDeleteEntryButton_clicked()
{
QTreeWidgetItem* currentItem = mColormapTreeWidget->currentItem();
if ( currentItem )
QList<QTreeWidgetItem *> itemList;
itemList = mColormapTreeWidget->selectedItems();
if ( itemList.isEmpty() )
{
return;
}

Q_FOREACH ( QTreeWidgetItem *item, itemList )
{
delete currentItem;
delete item;
}
emit widgetChanged();
}
@@ -775,6 +793,7 @@ void QgsSingleBandPseudoColorRendererWidget::mColormapTreeWidget_itemEdited( QTr
{
// call autoLabel to fill when empty or gray out when same as autoLabel
autoLabel();
emit widgetChanged();
}
}

@@ -928,3 +947,51 @@ void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
mClassifyButton->setEnabled( false );
}
}

void QgsSingleBandPseudoColorRendererWidget::changeColor()
{
QList<QTreeWidgetItem *> itemList;
itemList = mColormapTreeWidget->selectedItems();
if ( itemList.isEmpty() )
{
return;
}
QTreeWidgetItem* firstItem = itemList.first();

QColor newColor = QgsColorDialog::getColor( firstItem->background( ColorColumn ).color(), this, QStringLiteral( "Change color" ), true );
if ( newColor.isValid() )
{
Q_FOREACH ( QTreeWidgetItem *item, itemList )
{
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
item->setBackground( ColorColumn, QBrush( newColor ) );
}
emit widgetChanged();
}
}

void QgsSingleBandPseudoColorRendererWidget::changeTransparency()
{
QList<QTreeWidgetItem *> itemList;
itemList = mColormapTreeWidget->selectedItems();
if ( itemList.isEmpty() )
{
return;
}
QTreeWidgetItem* firstItem = itemList.first();

bool ok;
double oldTransparency = firstItem->background( ColorColumn ).color().alpha() / 255 * 100;
double transparency = QInputDialog::getDouble( this, tr( "Transparency" ), tr( "Change symbol transparency [%]" ), oldTransparency, 0.0, 100.0, 0, &ok );
if ( ok )
{
int newTransparency = transparency / 100 * 255;
Q_FOREACH ( QTreeWidgetItem *item, itemList )
{
QColor newColor = item->background( ColorColumn ).color();
newColor.setAlpha( newTransparency );
item->setBackground( ColorColumn, QBrush( newColor ) );
}
emit widgetChanged();
}
}
@@ -72,6 +72,8 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void autoLabel();
void setUnitFromLabels();

QMenu* contextMenu;

private slots:

void applyColorRamp();
@@ -90,6 +92,8 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void on_mMinLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); mMinMaxOrigin = QgsRasterRenderer::MinMaxUser; showMinMaxOrigin(); }
void on_mMaxLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); mMinMaxOrigin = QgsRasterRenderer::MinMaxUser; showMinMaxOrigin(); }
void on_mClassificationModeComboBox_currentIndexChanged( int index );
void changeColor();
void changeTransparency();

private:

@@ -127,7 +127,7 @@
<item>
<widget class="QPushButton" name="mDeleteEntryButton">
<property name="toolTip">
<string>Remove selected row</string>
<string>Remove selected row(s)</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">

0 comments on commit fc8493f

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