Skip to content

Commit

Permalink
Merge pull request #3851 from nirvn/raster_ui_improvements
Browse files Browse the repository at this point in the history
Raster renderer UI improvements
  • Loading branch information
nirvn authored Dec 10, 2016
2 parents 8ec3eaf + ffb6ba7 commit fc8493f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 7 deletions.
40 changes: 37 additions & 3 deletions src/gui/raster/qgspalettedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
}
14 changes: 14 additions & 0 deletions src/gui/raster/qgspalettedrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
73 changes: 70 additions & 3 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 );
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void autoLabel();
void setUnitFromLabels();

QMenu* contextMenu;

private slots:

void applyColorRamp();
Expand All @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgssinglebandpseudocolorrendererwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit fc8493f

Please sign in to comment.