Skip to content
Permalink
Browse files

fix #17652 Impossible to rename a layer style from the Styling Panel

  • Loading branch information
PeterPetrik committed Jan 31, 2019
1 parent 4f6df29 commit 44c4e8cca07176eb6665a8ae74a7448f968fde3a
Showing with 17 additions and 3 deletions.
  1. +16 −3 src/gui/qgsmaplayerstylemanagerwidget.cpp
  2. +1 −0 src/gui/qgsmaplayerstylemanagerwidget.h
@@ -78,15 +78,18 @@ QgsMapLayerStyleManagerWidget::QgsMapLayerStyleManagerWidget( QgsMapLayer *layer

mModel->clear();

Q_FOREACH ( const QString name, mLayer->styleManager()->styles() )
const QStringList styles = mLayer->styleManager()->styles();
for ( const QString &styleName : styles )
{
QString stylename = name;
QStandardItem *item = new QStandardItem( stylename );
QStandardItem *item = new QStandardItem( styleName );
item->setData( styleName );
mModel->appendRow( item );
}

QString active = mLayer->styleManager()->currentStyle();
currentStyleChanged( active );

connect( mModel, &QStandardItemModel::itemChanged, this, &QgsMapLayerStyleManagerWidget::renameStyle );
}

void QgsMapLayerStyleManagerWidget::styleClicked( const QModelIndex &index )
@@ -113,6 +116,7 @@ void QgsMapLayerStyleManagerWidget::styleAdded( const QString &name )
{
QgsDebugMsg( QStringLiteral( "Style added" ) );
QStandardItem *item = new QStandardItem( name );
item->setData( name );
mModel->appendRow( item );
}

@@ -134,6 +138,7 @@ void QgsMapLayerStyleManagerWidget::styleRenamed( const QString &oldname, const

QStandardItem *item = items.at( 0 );
item->setText( newname );
item->setData( newname );
}

void QgsMapLayerStyleManagerWidget::addStyle()
@@ -176,6 +181,14 @@ void QgsMapLayerStyleManagerWidget::removeStyle()

}

void QgsMapLayerStyleManagerWidget::renameStyle( QStandardItem *item )
{
const QString oldName = item->data().toString();
const QString newName = item->text();
item->setData( newName );
whileBlocking( this )->mLayer->styleManager()->renameStyle( oldName, newName );
}

void QgsMapLayerStyleManagerWidget::saveAsDefault()
{
QString errorMsg;
@@ -55,6 +55,7 @@ class GUI_EXPORT QgsMapLayerStyleManagerWidget : public QgsMapLayerConfigWidget
void styleRenamed( const QString &oldname, const QString &newname );
void addStyle();
void removeStyle();
void renameStyle( QStandardItem *item );
void saveAsDefault();
void loadDefault();
void saveStyle();

0 comments on commit 44c4e8c

Please sign in to comment.
You can’t perform that action at this time.