Skip to content

Commit ef97dba

Browse files
authoredJan 31, 2019
fix #17652 Impossible to rename a layer style from the Styling Panel (#9041)
fix #17652 Impossible to rename a layer style from the Styling Panel
1 parent 95e45a3 commit ef97dba

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed
 

‎src/gui/qgsmaplayerstylemanagerwidget.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ QgsMapLayerStyleManagerWidget::QgsMapLayerStyleManagerWidget( QgsMapLayer *layer
7878

7979
mModel->clear();
8080

81-
Q_FOREACH ( const QString name, mLayer->styleManager()->styles() )
81+
const QStringList styles = mLayer->styleManager()->styles();
82+
for ( const QString &styleName : styles )
8283
{
83-
QString stylename = name;
84-
QStandardItem *item = new QStandardItem( stylename );
84+
QStandardItem *item = new QStandardItem( styleName );
85+
item->setData( styleName );
8586
mModel->appendRow( item );
8687
}
8788

8889
QString active = mLayer->styleManager()->currentStyle();
8990
currentStyleChanged( active );
91+
92+
connect( mModel, &QStandardItemModel::itemChanged, this, &QgsMapLayerStyleManagerWidget::renameStyle );
9093
}
9194

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

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

135139
QStandardItem *item = items.at( 0 );
136140
item->setText( newname );
141+
item->setData( newname );
137142
}
138143

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

177182
}
178183

184+
void QgsMapLayerStyleManagerWidget::renameStyle( QStandardItem *item )
185+
{
186+
const QString oldName = item->data().toString();
187+
const QString newName = item->text();
188+
item->setData( newName );
189+
whileBlocking( this )->mLayer->styleManager()->renameStyle( oldName, newName );
190+
}
191+
179192
void QgsMapLayerStyleManagerWidget::saveAsDefault()
180193
{
181194
QString errorMsg;

‎src/gui/qgsmaplayerstylemanagerwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class GUI_EXPORT QgsMapLayerStyleManagerWidget : public QgsMapLayerConfigWidget
5555
void styleRenamed( const QString &oldname, const QString &newname );
5656
void addStyle();
5757
void removeStyle();
58+
void renameStyle( QStandardItem *item );
5859
void saveAsDefault();
5960
void loadDefault();
6061
void saveStyle();

0 commit comments

Comments
 (0)
Please sign in to comment.