Skip to content

Commit

Permalink
Expose changed attributes in QgsFeatureAction and QgsVectorLayerTools
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 30, 2015
1 parent 66b9b0d commit d2b506c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions python/gui/qgsvectorlayertools.sip
Expand Up @@ -13,8 +13,7 @@ class QgsVectorLayerTools
* @param defaultGeometry A default geometry to add to the feature
* @return True in case of success, False if the operation failed/was aborted
*/
virtual bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) const = 0;

virtual bool addFeature( QgsVectorLayer* laye, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry(), QgsFeature* feature /Out/ = 0 ) const = 0;

/**
* This will be called, whenever a vector layer should be switched to edit mode. Check the providers
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -218,6 +218,9 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
Q_UNUSED( form ) // only used for Q_ASSERT
Q_ASSERT( form );

// Assign provider generated values
mFeature = feature;

mFeatureSaved = true;

QSettings settings;
Expand Down
17 changes: 12 additions & 5 deletions src/app/qgsguivectorlayertools.cpp
Expand Up @@ -32,12 +32,19 @@ QgsGuiVectorLayerTools::QgsGuiVectorLayerTools()
: QObject( NULL )
{}

bool QgsGuiVectorLayerTools::addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues, const QgsGeometry& defaultGeometry ) const
bool QgsGuiVectorLayerTools::addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues, const QgsGeometry& defaultGeometry, QgsFeature* feat ) const
{
QgsFeature f;
f.setGeometry( defaultGeometry );
QgsFeatureAction a( tr( "Add feature" ), f, layer );
return a.addFeature( defaultValues );
QgsFeature* f = feat;
if ( !feat )
f = new QgsFeature();

feat->setGeometry( defaultGeometry );
QgsFeatureAction a( tr( "Add feature" ), *f, layer );
bool added = a.addFeature( defaultValues );
if ( !feat )
delete f;

return added;
}

bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer ) const
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsguivectorlayertools.h
Expand Up @@ -39,7 +39,7 @@ class QgsGuiVectorLayerTools : public QObject, public QgsVectorLayerTools
*
* @return True in case of success, False if the operation failed/was aborted
*/
bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap& defaultValues, const QgsGeometry &defaultGeometry ) const override;
bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap& defaultValues, const QgsGeometry &defaultGeometry, QgsFeature* feat = 0 ) const override;

/**
* This should be called, whenever a vector layer should be switched to edit mode. If successful
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsvectorlayertools.h
Expand Up @@ -45,10 +45,10 @@ class GUI_EXPORT QgsVectorLayerTools
* @param layer The layer to which the feature should be added
* @param defaultValues Default values for the feature to add
* @param defaultGeometry A default geometry to add to the feature
* @param feature Updated feature after adding will be written back to this
* @return True in case of success, False if the operation failed/was aborted
*/
virtual bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) const = 0;

virtual bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry(), QgsFeature* feature = 0 ) const = 0;

/**
* This will be called, whenever a vector layer should be switched to edit mode. Check the providers
Expand Down

0 comments on commit d2b506c

Please sign in to comment.