@@ -78,15 +78,18 @@ QgsMapLayerStyleManagerWidget::QgsMapLayerStyleManagerWidget( QgsMapLayer *layer
78
78
79
79
mModel ->clear ();
80
80
81
- Q_FOREACH ( const QString name, mLayer ->styleManager ()->styles () )
81
+ const QStringList styles = mLayer ->styleManager ()->styles ();
82
+ for ( const QString &styleName : styles )
82
83
{
83
- QString stylename = name ;
84
- QStandardItem * item = new QStandardItem ( stylename );
84
+ QStandardItem *item = new QStandardItem ( styleName ) ;
85
+ item-> setData ( styleName );
85
86
mModel ->appendRow ( item );
86
87
}
87
88
88
89
QString active = mLayer ->styleManager ()->currentStyle ();
89
90
currentStyleChanged ( active );
91
+
92
+ connect ( mModel , &QStandardItemModel::itemChanged, this , &QgsMapLayerStyleManagerWidget::renameStyle );
90
93
}
91
94
92
95
void QgsMapLayerStyleManagerWidget::styleClicked ( const QModelIndex &index )
@@ -113,6 +116,7 @@ void QgsMapLayerStyleManagerWidget::styleAdded( const QString &name )
113
116
{
114
117
QgsDebugMsg ( QStringLiteral ( " Style added" ) );
115
118
QStandardItem *item = new QStandardItem ( name );
119
+ item->setData ( name );
116
120
mModel ->appendRow ( item );
117
121
}
118
122
@@ -134,6 +138,7 @@ void QgsMapLayerStyleManagerWidget::styleRenamed( const QString &oldname, const
134
138
135
139
QStandardItem *item = items.at ( 0 );
136
140
item->setText ( newname );
141
+ item->setData ( newname );
137
142
}
138
143
139
144
void QgsMapLayerStyleManagerWidget::addStyle ()
@@ -176,6 +181,14 @@ void QgsMapLayerStyleManagerWidget::removeStyle()
176
181
177
182
}
178
183
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
+
179
192
void QgsMapLayerStyleManagerWidget::saveAsDefault ()
180
193
{
181
194
QString errorMsg;
0 commit comments