@@ -148,13 +148,19 @@ void QgsAttributeActionDialog::insertRow( int row, const QgsAction &action )
148
148
// Notification message
149
149
mAttributeActionTable ->setItem ( row, NotificationMessage, new QTableWidgetItem ( action.notificationMessage () ) );
150
150
151
+ // EnabledOnlyWhenEditable
152
+ item = new QTableWidgetItem ();
153
+ item->setFlags ( item->flags () & ~( Qt::ItemIsEditable ) );
154
+ item->setCheckState ( action.isEnabledOnlyWhenEditable () ? Qt::Checked : Qt::Unchecked );
155
+ mAttributeActionTable ->setItem ( row, EnabledOnlyWhenEditable, item );
156
+
151
157
updateButtons ();
152
158
}
153
159
154
- void QgsAttributeActionDialog::insertRow ( int row, QgsAction::ActionType type, const QString &name, const QString &actionText, const QString &iconPath, bool capture, const QString &shortTitle, const QSet<QString> &actionScopes, const QString ¬ificationMessage )
160
+ void QgsAttributeActionDialog::insertRow ( int row, QgsAction::ActionType type, const QString &name, const QString &actionText, const QString &iconPath, bool capture, const QString &shortTitle, const QSet<QString> &actionScopes, const QString ¬ificationMessage, bool isEnabledOnlyWhenEditable )
155
161
{
156
162
if ( uniqueName ( name ) == name )
157
- insertRow ( row, QgsAction ( type, name, actionText, iconPath, capture, shortTitle, actionScopes, notificationMessage ) );
163
+ insertRow ( row, QgsAction ( type, name, actionText, iconPath, capture, shortTitle, actionScopes, notificationMessage, isEnabledOnlyWhenEditable ) );
158
164
}
159
165
160
166
void QgsAttributeActionDialog::moveUp ()
@@ -223,7 +229,8 @@ QgsAction QgsAttributeActionDialog::rowToAction( int row ) const
223
229
mAttributeActionTable ->item ( row, Capture )->checkState () == Qt::Checked,
224
230
mAttributeActionTable ->item ( row, ShortTitle )->text (),
225
231
mAttributeActionTable ->item ( row, ActionScopes )->data ( Qt::UserRole ).value <QSet<QString>>(),
226
- mAttributeActionTable ->item ( row, NotificationMessage )->text ()
232
+ mAttributeActionTable ->item ( row, NotificationMessage )->text (),
233
+ mAttributeActionTable ->item ( row, EnabledOnlyWhenEditable )->checkState () == Qt::Checked
227
234
);
228
235
return action;
229
236
}
@@ -278,7 +285,7 @@ void QgsAttributeActionDialog::insert()
278
285
{
279
286
QString name = uniqueName ( dlg.description () );
280
287
281
- insertRow ( pos, dlg.type (), name, dlg.actionText (), dlg.iconPath (), dlg.capture (), dlg.shortTitle (), dlg.actionScopes (), dlg.notificationMessage () );
288
+ insertRow ( pos, dlg.type (), name, dlg.actionText (), dlg.iconPath (), dlg.capture (), dlg.shortTitle (), dlg.actionScopes (), dlg.notificationMessage (), dlg. isEnabledOnlyWhenEditable () );
282
289
}
283
290
}
284
291
@@ -313,7 +320,7 @@ void QgsAttributeActionDialog::addDefaultActions()
313
320
insertRow ( pos++, QgsAction::OpenUrl, tr ( " Open file" ), QStringLiteral ( " [% \" PATH\" %]" ), QLatin1String ( " " ), false , tr ( " Open file" ), QSet<QString>() << QStringLiteral ( " Feature" ) << QStringLiteral ( " Canvas" ), QString () );
314
321
insertRow ( pos++, QgsAction::OpenUrl, tr ( " Search on web based on attribute's value" ), QStringLiteral ( " http://www.google.com/search?q=[% \" ATTRIBUTE\" %]" ), QLatin1String ( " " ), false , tr ( " Search Web" ), QSet<QString>() << QStringLiteral ( " Field" ), QString () );
315
322
insertRow ( pos++, QgsAction::GenericPython, tr ( " List feature ids" ), QStringLiteral ( " from qgis.PyQt import QtWidgets\n\n layer = QgsProject.instance().mapLayer('[% @layer_id %]')\n if layer.selectedFeatureCount():\n ids = layer.selectedFeatureIds()\n else:\n ids = [f.id() for f in layer.getFeatures()]\n\n QtWidgets.QMessageBox.information(None, \" Feature ids\" , ', '.join([str(id) for id in ids]))" ), QLatin1String ( " " ), false , tr ( " List feature ids" ), QSet<QString>() << QStringLiteral ( " Layer" ), QString () );
316
- insertRow( pos++, QgsAction::GenericPython, tr( "Duplicate selected features" ), QStringLiteral( "project = QgsProject.instance()\nlayer = QgsProject.instance().mapLayer('[% @layer_id %]')\nlayer.startEditing()\nfeatures=[]\nif len('[% $id %]')>0:\n features.append( layer.getFeature( [% $id %] ) )\nelse:\n for x in layer.selectedFeatures():\n features.append( x )\nfeature_count=0\nchildren_info=''\nfeatureids=[]\nfor f in features:\n result=QgsVectorLayerUtils.duplicateFeature(layer, f, project, 0 )\n featureids.append( result[0].id() )\n feature_count+=1\n for ch_layer in result[1].layers():\n children_info+='{number_of_children} children on layer {children_layer}\\n'.format( number_of_children=str( len( result[1].duplicatedFeatures(ch_layer) ) ), children_layer=ch_layer.name() )\n ch_layer.selectByIds( result[1].duplicatedFeatures(ch_layer) )\nlayer.selectByIds( featureids )\nqgis.utils.iface.messageBar().pushMessage( '{number_of_features} features on layer {layer} duplicated with\\n{children_info}'.format( number_of_features=str( feature_count ), layer=layer.name(), children_info=children_info ) )" ), QLatin1String( "" ), false, tr( "Duplicate selected" ), QSet<QString>() << QStringLiteral( "Layer" ), QString() );
323
+ insertRow( pos++, QgsAction::GenericPython, tr( "Duplicate selected features" ), QStringLiteral( "project = QgsProject.instance()\nlayer = QgsProject.instance().mapLayer('[% @layer_id %]')\nif not layer.isEditable():\n qgis.utils.iface.messageBar().pushMessage( 'Cannot duplicate feature in not editable mode on layer {layer}'.format( layer=layer.name() ) )\nelse:\n features=[]\n if len('[% $id %]')>0:\n features.append( layer.getFeature( [% $id %] ) )\n else:\n for x in layer.selectedFeatures():\n features.append( x )\n feature_count=0\n children_info=''\n featureids=[]\n for f in features:\n result=QgsVectorLayerUtils.duplicateFeature(layer, f, project, 0 )\n featureids.append( result[0].id() )\n feature_count+=1\n for ch_layer in result[1].layers():\n children_info+='{number_of_children} children on layer {children_layer}\\n'.format( number_of_children=str( len( result[1].duplicatedFeatures(ch_layer) ) ), children_layer=ch_layer.name() )\n ch_layer.selectByIds( result[1].duplicatedFeatures(ch_layer) )\n layer.selectByIds( featureids )\n qgis.utils.iface.messageBar().pushMessage( '{number_of_features} features on layer {layer} duplicated with\\n{children_info}'.format( number_of_features=str( feature_count ), layer=layer.name(), children_info=children_info ) )" ), QLatin1String( "" ), false, tr( "Duplicate selected" ), QSet<QString>() << QStringLiteral( "Layer" ), QString(), true );
317
324
318
325
}
319
326
@@ -330,6 +337,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem *item )
330
337
mAttributeActionTable ->item ( row, Capture )->checkState () == Qt::Checked,
331
338
mAttributeActionTable ->item ( row, ActionScopes )->data ( Qt::UserRole ).value <QSet<QString>>(),
332
339
mAttributeActionTable ->item ( row, NotificationMessage )->text (),
340
+ mAttributeActionTable ->item ( row, EnabledOnlyWhenEditable )->checkState () == Qt::Checked,
333
341
mLayer
334
342
);
335
343
@@ -344,6 +352,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem *item )
344
352
mAttributeActionTable ->item ( row, ActionText )->setText ( actionProperties.actionText () );
345
353
mAttributeActionTable ->item ( row, Capture )->setCheckState ( actionProperties.capture () ? Qt::Checked : Qt::Unchecked );
346
354
mAttributeActionTable ->item ( row, NotificationMessage )->setText ( actionProperties.notificationMessage () );
355
+ mAttributeActionTable ->item ( row, EnabledOnlyWhenEditable )->setCheckState ( actionProperties.isEnabledOnlyWhenEditable () ? Qt::Checked : Qt::Unchecked );
347
356
348
357
QTableWidgetItem *item = mAttributeActionTable ->item ( row, ActionScopes );
349
358
QStringList actionScopes = actionProperties.actionScopes ().toList ();
0 commit comments