Skip to content
Permalink
Browse files

duplicate feature default action if feature id given, then only copy …

…one feature otherwise all selected on layer
  • Loading branch information
signedav authored and m-kuhn committed Nov 1, 2017
1 parent adc884b commit 9c5ace096c907a2c5a9a4952774c429bce7ba0fa
Showing with 2 additions and 1 deletion.
  1. +2 −1 src/app/qgsattributeactiondialog.cpp
@@ -313,7 +313,8 @@ void QgsAttributeActionDialog::addDefaultActions()
insertRow( pos++, QgsAction::OpenUrl, tr( "Open file" ), QStringLiteral( "[% \"PATH\" %]" ), QLatin1String( "" ), false, tr( "Open file" ), QSet<QString>() << QStringLiteral( "Feature" ) << QStringLiteral( "Canvas" ), QString() );
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() );
insertRow( pos++, QgsAction::GenericPython, tr( "List feature ids" ), QStringLiteral( "from qgis.PyQt import QtWidgets\n\nlayer = QgsProject.instance().mapLayer('[% @layer_id %]')\nif layer.selectedFeatureCount():\n ids = layer.selectedFeatureIds()\nelse:\n ids = [f.id() for f in layer.getFeatures()]\n\nQtWidgets.QMessageBox.information(None, \"Feature ids\", ', '.join([str(id) for id in ids]))" ), QLatin1String( "" ), false, tr( "List feature ids" ), QSet<QString>() << QStringLiteral( "Layer" ), QString() );
insertRow( pos++, QgsAction::GenericPython, tr( "Duplicate selected feature" ), QStringLiteral( "from qgis.PyQt import QtWidgets\n\nproject = QgsProject.instance()\nlayer = QgsProject.instance().mapLayer(\"[% @layer_id %]\")\nlayer.startEditing()\nfeature_count=0\nchildren_info=\"\"\nfor f in layer.selectedFeatures():\n result=QgsVectorLayerUtils.duplicateFeature(layer, f, project, 0 );\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\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" ), QSet<QString>() << QStringLiteral( "Canvas" ) << QStringLiteral( "Layer" ), QString() );
insertRow( pos++, QgsAction::GenericPython, tr( "Duplicate 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=''\nfor f in features:\n result=QgsVectorLayerUtils.duplicateFeature(layer, f, project, 0 )\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() )\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" ), QSet<QString>() << QStringLiteral( "Canvas" ) << QStringLiteral( "Feature" ) << QStringLiteral( "Layer" ), QString() );

}

void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem *item )

0 comments on commit 9c5ace0

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