Skip to content
Permalink
Browse files
Allow changing label for multiple values at once in paletted renderer…
… widget
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 64084ae commit 40027abcd273a3a8692c2bb29ee4d0e40beab448
Showing with 30 additions and 0 deletions.
  1. +29 −0 src/gui/raster/qgspalettedrendererwidget.cpp
  2. +1 −0 src/gui/raster/qgspalettedrendererwidget.h
@@ -32,6 +32,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 label" ), this, SLOT( changeLabel() ) );

mModel = new QgsPalettedRendererModel( this );
mTreeView->setSortingEnabled( false );
@@ -202,6 +203,34 @@ void QgsPalettedRendererWidget::changeTransparency()
}
}

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

QModelIndex labelIndex = mModel->index( sel.first().top(), QgsPalettedRendererModel::LabelColumn );
QString currentLabel = mModel->data( labelIndex, Qt::DisplayRole ).toString();

bool ok;
QString newLabel = QInputDialog::getText( this, tr( "Label" ), tr( "Change label" ), QLineEdit::Normal, currentLabel, &ok );
if ( ok )
{
// don't want to emit widgetChanged multiple times
disconnect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );

Q_FOREACH ( const QItemSelectionRange &range, sel )
{
Q_FOREACH ( const QModelIndex &index, range.indexes() )
{
labelIndex = mModel->index( index.row(), QgsPalettedRendererModel::LabelColumn );
mModel->setData( labelIndex, newLabel, Qt::EditRole );
}
}
connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );

emit widgetChanged();
}
}

//
// QgsPalettedRendererModel
//
@@ -97,6 +97,7 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
void addEntry();
void changeColor();
void changeTransparency();
void changeLabel();
};

#endif // QGSPALETTEDRENDERERWIDGET_H

0 comments on commit 40027ab

Please sign in to comment.