Navigation Menu

Skip to content

Commit

Permalink
Fix raster context menu "change transparency" actually changes opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 12, 2017
1 parent 48e876b commit f23d381
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/gui/raster/qgspalettedrendererwidget.cpp
Expand Up @@ -42,7 +42,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con

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

mModel = new QgsPalettedRendererModel( this );
Expand Down Expand Up @@ -239,19 +239,19 @@ void QgsPalettedRendererWidget::changeColor()
}
}

void QgsPalettedRendererWidget::changeTransparency()
void QgsPalettedRendererWidget::changeOpacity()
{
QItemSelection sel = mTreeView->selectionModel()->selection();

QModelIndex colorIndex = mModel->index( sel.first().top(), QgsPalettedRendererModel::ColorColumn );
QColor currentColor = mModel->data( colorIndex, Qt::DisplayRole ).value<QColor>();

bool ok;
double oldTransparency = ( currentColor.alpha() / 255.0 ) * 100.0;
double transparency = QInputDialog::getDouble( this, tr( "Transparency" ), tr( "Change color transparency [%]" ), oldTransparency, 0.0, 100.0, 0, &ok );
double oldOpacity = ( currentColor.alpha() / 255.0 ) * 100.0;
double opacity = QInputDialog::getDouble( this, tr( "Opacity" ), tr( "Change color opacity [%]" ), oldOpacity, 0.0, 100.0, 0, &ok );
if ( ok )
{
int newTransparency = transparency / 100 * 255;
int newOpacity = opacity / 100 * 255;

// don't want to emit widgetChanged multiple times
disconnect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
Expand All @@ -263,7 +263,7 @@ void QgsPalettedRendererWidget::changeTransparency()
colorIndex = mModel->index( index.row(), QgsPalettedRendererModel::ColorColumn );

QColor newColor = mModel->data( colorIndex, Qt::DisplayRole ).value<QColor>();
newColor.setAlpha( newTransparency );
newColor.setAlpha( newOpacity );
mModel->setData( colorIndex, newColor, Qt::EditRole );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgspalettedrendererwidget.h
Expand Up @@ -186,7 +186,7 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
void deleteEntry();
void addEntry();
void changeColor();
void changeTransparency();
void changeOpacity();
void changeLabel();
void applyColorRamp();
void loadColorTable();
Expand Down
12 changes: 6 additions & 6 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -51,7 +51,7 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(

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

mColormapTreeWidget->setColumnWidth( ColorColumn, 50 );
mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
Expand Down Expand Up @@ -818,7 +818,7 @@ void QgsSingleBandPseudoColorRendererWidget::changeColor()
}
}

void QgsSingleBandPseudoColorRendererWidget::changeTransparency()
void QgsSingleBandPseudoColorRendererWidget::changeOpacity()
{
QList<QTreeWidgetItem *> itemList;
itemList = mColormapTreeWidget->selectedItems();
Expand All @@ -829,15 +829,15 @@ void QgsSingleBandPseudoColorRendererWidget::changeTransparency()
QTreeWidgetItem *firstItem = itemList.first();

bool ok;
double oldTransparency = firstItem->background( ColorColumn ).color().alpha() / 255 * 100;
double transparency = QInputDialog::getDouble( this, tr( "Transparency" ), tr( "Change color transparency [%]" ), oldTransparency, 0.0, 100.0, 0, &ok );
double oldOpacity = firstItem->background( ColorColumn ).color().alpha() / 255 * 100;
double opacity = QInputDialog::getDouble( this, tr( "Opacity" ), tr( "Change color opacity [%]" ), oldOpacity, 0.0, 100.0, 0, &ok );
if ( ok )
{
int newTransparency = transparency / 100 * 255;
int newOpacity = opacity / 100 * 255;
Q_FOREACH ( QTreeWidgetItem *item, itemList )
{
QColor newColor = item->background( ColorColumn ).color();
newColor.setAlpha( newTransparency );
newColor.setAlpha( newOpacity );
item->setBackground( ColorColumn, QBrush( newColor ) );
}
emit widgetChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Expand Up @@ -96,7 +96,7 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void on_mMaxLineEdit_textEdited( const QString &text ) ;
void on_mClassificationModeComboBox_currentIndexChanged( int index );
void changeColor();
void changeTransparency();
void changeOpacity();

private:

Expand Down

0 comments on commit f23d381

Please sign in to comment.