Skip to content

Commit

Permalink
Return invalid feature instead of nullptr from QgsFеatureAction::feat…
Browse files Browse the repository at this point in the history
…ure()
  • Loading branch information
suricactus committed Sep 10, 2020
1 parent 018ca92 commit 4257332
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -623,7 +623,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered()
if ( action.addFeature() )
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature()->id() );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature().id() );
}
}

Expand All @@ -644,7 +644,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered()
if ( action.addFeature() )
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature()->id() );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature().id() );
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -314,4 +314,9 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature &feature )
}
}

QgsFeature QgsFeatureAction::feature() const
{
return mFeature ? *mFeature : QgsFeature();
}

QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
5 changes: 2 additions & 3 deletions src/app/qgsfeatureaction.h
Expand Up @@ -62,10 +62,9 @@ class APP_EXPORT QgsFeatureAction : public QAction
void setForceSuppressFormPopup( bool force );

/**
* Returns the current feature. It might be nullptr feature, so it's safe to use this method only
* right after`addFeature()` returned true.
* Returns the added feature or invalid feature in case addFeature() was not successful.
*/
QgsFeature *feature() const { return mFeature; }
QgsFeature feature() const;

signals:

Expand Down

0 comments on commit 4257332

Please sign in to comment.