Skip to content
Permalink
Browse files

Return invalid feature instead of nullptr from QgsFеatureAction::feat…

…ure()
  • Loading branch information
suricactus committed Sep 10, 2020
1 parent 018ca92 commit 425733230678ffd1ddca9acfb497f26d573a535b
Showing with 9 additions and 5 deletions.
  1. +2 −2 src/app/qgsattributetabledialog.cpp
  2. +5 −0 src/app/qgsfeatureaction.cpp
  3. +2 −3 src/app/qgsfeatureaction.h
@@ -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() );
}
}

@@ -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() );
}
}

@@ -314,4 +314,9 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature &feature )
}
}

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

QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
@@ -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:

0 comments on commit 4257332

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