Expose changed attributes in QgsFeatureAction and QgsVectorLayerTools

This commit is contained in:
Matthias Kuhn 2015-11-30 14:16:45 +01:00
parent 66b9b0dd10
commit d2b506cccc
5 changed files with 19 additions and 10 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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