Skip to content

Commit

Permalink
Fix missing color cell in color ramp shader widget for non-default theme
Browse files Browse the repository at this point in the history
(fixes #15913)
  • Loading branch information
nirvn committed Dec 28, 2018
1 parent 4ea6c9c commit 314c399
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/gui/raster/qgscolorrampshaderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
contextMenu->addAction( tr( "Change Color…" ), this, SLOT( changeColor() ) );
contextMenu->addAction( tr( "Change Opacity…" ), this, SLOT( changeOpacity() ) );

mSwatchDelegate = new QgsColorSwatchDelegate( this );
mColormapTreeWidget->setItemDelegateForColumn( ColorColumn, mSwatchDelegate );
mColormapTreeWidget->setColumnWidth( ColorColumn, 50 );
mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
Expand Down Expand Up @@ -135,7 +137,7 @@ QgsColorRampShader QgsColorRampShaderWidget::shader() const
}
QgsColorRampShader::ColorRampItem newColorRampItem;
newColorRampItem.value = currentItem->text( ValueColumn ).toDouble();
newColorRampItem.color = currentItem->background( ColorColumn ).color();
newColorRampItem.color = currentItem->data( ColorColumn, Qt::EditRole ).value<QColor>();
newColorRampItem.label = currentItem->text( LabelColumn );
colorRampItems.append( newColorRampItem );
}
Expand Down Expand Up @@ -264,7 +266,7 @@ void QgsColorRampShaderWidget::mAddEntryButton_clicked()
{
QgsTreeWidgetItemObject *newItem = new QgsTreeWidgetItemObject( mColormapTreeWidget );
newItem->setText( ValueColumn, QStringLiteral( "0" ) );
newItem->setBackground( ColorColumn, QBrush( QColor( Qt::magenta ) ) );
newItem->setData( ColorColumn, Qt::EditRole, QColor( Qt::magenta ) );
newItem->setText( LabelColumn, QString() );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
connect( newItem, &QgsTreeWidgetItemObject::itemEdited,
Expand Down Expand Up @@ -325,7 +327,7 @@ void QgsColorRampShaderWidget::classify()
{
QgsTreeWidgetItemObject *newItem = new QgsTreeWidgetItemObject( mColormapTreeWidget );
newItem->setText( ValueColumn, QString::number( it->value, 'g', 15 ) );
newItem->setBackground( ColorColumn, QBrush( it->color ) );
newItem->setData( ColorColumn, Qt::EditRole, it->color );
newItem->setText( LabelColumn, it->label );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
connect( newItem, &QgsTreeWidgetItemObject::itemEdited,
Expand Down Expand Up @@ -379,7 +381,7 @@ void QgsColorRampShaderWidget::populateColormapTreeWidget( const QList<QgsColorR
{
QgsTreeWidgetItemObject *newItem = new QgsTreeWidgetItemObject( mColormapTreeWidget );
newItem->setText( ValueColumn, QString::number( it->value, 'g', 15 ) );
newItem->setBackground( ColorColumn, QBrush( it->color ) );
newItem->setData( ColorColumn, Qt::EditRole, it->color );
newItem->setText( LabelColumn, it->label );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
connect( newItem, &QgsTreeWidgetItemObject::itemEdited,
Expand Down Expand Up @@ -545,7 +547,7 @@ void QgsColorRampShaderWidget::mExportToFileButton_clicked()
{
continue;
}
color = currentItem->background( ColorColumn ).color();
color = currentItem->data( ColorColumn, Qt::EditRole ).value<QColor>();
outputStream << currentItem->text( ValueColumn ).toDouble() << ',';
outputStream << color.red() << ',' << color.green() << ',' << color.blue() << ',' << color.alpha() << ',';
if ( currentItem->text( LabelColumn ).isEmpty() )
Expand Down Expand Up @@ -580,10 +582,10 @@ void QgsColorRampShaderWidget::mColormapTreeWidget_itemDoubleClicked( QTreeWidge
if ( column == ColorColumn )
{
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QColor newColor = QgsColorDialog::getColor( item->background( column ).color(), this, QStringLiteral( "Change Color" ), true );
QColor newColor = QgsColorDialog::getColor( item->data( column, Qt::EditRole ).value<QColor>(), this, QStringLiteral( "Change Color" ), true );
if ( newColor.isValid() )
{
item->setBackground( ColorColumn, QBrush( newColor ) );
item->setData( ColorColumn, Qt::EditRole, newColor );
loadMinimumMaximumFromTree();
emit widgetChanged();
}
Expand Down Expand Up @@ -642,7 +644,7 @@ void QgsColorRampShaderWidget::setFromShader( const QgsColorRampShader &colorRam
{
QgsTreeWidgetItemObject *newItem = new QgsTreeWidgetItemObject( mColormapTreeWidget );
newItem->setText( ValueColumn, QString::number( it->value, 'g', 15 ) );
newItem->setBackground( ColorColumn, QBrush( it->color ) );
newItem->setData( ColorColumn, Qt::EditRole, it->color );
newItem->setText( LabelColumn, it->label );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
connect( newItem, &QgsTreeWidgetItemObject::itemEdited,
Expand Down Expand Up @@ -753,13 +755,13 @@ void QgsColorRampShaderWidget::changeColor()
}
QTreeWidgetItem *firstItem = itemList.first();

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

loadMinimumMaximumFromTree();
Expand All @@ -778,16 +780,16 @@ void QgsColorRampShaderWidget::changeOpacity()
QTreeWidgetItem *firstItem = itemList.first();

bool ok;
double oldOpacity = firstItem->background( ColorColumn ).color().alpha() / 255 * 100;
double oldOpacity = firstItem->data( ColorColumn, Qt::EditRole ).value<QColor>().alpha() / 255 * 100;
double opacity = QInputDialog::getDouble( this, tr( "Opacity" ), tr( "Change color opacity [%]" ), oldOpacity, 0.0, 100.0, 0, &ok );
if ( ok )
{
int newOpacity = static_cast<int>( opacity / 100 * 255 );
Q_FOREACH ( QTreeWidgetItem *item, itemList )
{
QColor newColor = item->background( ColorColumn ).color();
QColor newColor = item->data( ColorColumn, Qt::EditRole ).value<QColor>();
newColor.setAlpha( newOpacity );
item->setBackground( ColorColumn, QBrush( newColor ) );
item->setData( ColorColumn, Qt::EditRole, newColor );
}

loadMinimumMaximumFromTree();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/raster/qgscolorrampshaderwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgis_sip.h"
#include "qgscolorrampshader.h"
#include "qgsrasterrenderer.h"
#include "qgscolorschemelist.h"
#include "ui_qgscolorrampshaderwidgetbase.h"
#include "qgis_gui.h"
#include "qgsrasterrendererwidget.h"
Expand Down Expand Up @@ -144,6 +145,8 @@ class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColo
double lineEditValue( const QLineEdit *lineEdit ) const;
void resetClassifyButton();

QgsColorSwatchDelegate *mSwatchDelegate = nullptr;

double mMin = std::numeric_limits<double>::quiet_NaN();
double mMax = std::numeric_limits<double>::quiet_NaN();

Expand Down

0 comments on commit 314c399

Please sign in to comment.