Skip to content
Permalink
Browse files
Fix raster context menu "change transparency" actually changes opacity
  • Loading branch information
nyalldawson committed Apr 12, 2017
1 parent 48e876b commit f23d3814ae4774a04d944a952c8f4019ab85a659
@@ -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 );
@@ -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 );
@@ -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 );
}
}
@@ -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();
@@ -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 );
@@ -818,7 +818,7 @@ void QgsSingleBandPseudoColorRendererWidget::changeColor()
}
}

void QgsSingleBandPseudoColorRendererWidget::changeTransparency()
void QgsSingleBandPseudoColorRendererWidget::changeOpacity()
{
QList<QTreeWidgetItem *> itemList;
itemList = mColormapTreeWidget->selectedItems();
@@ -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();
@@ -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:

0 comments on commit f23d381

Please sign in to comment.