Skip to content

Commit

Permalink
Tweak logic relating to suppressing attribute form for new features
Browse files Browse the repository at this point in the history
For non-spatial layers, creating a new feature from the main
window now ALWAYS shows the attribute form for the new feature,
regardless of the user's "suppress form" setting. We do this because,
unlike for spatial layers, there's zero feedback given when adding
a new feature to a non spatial layer. (Spatial layers have instead
feedback even when the form is suppressed, because you see the
new feature appear on the map instantly)

But when a new feature is added from the attri bute table window,
then we never show the new feature's form -- because that's already
visible inside the attribute table dialog itself.
  • Loading branch information
nyalldawson committed Nov 12, 2018
1 parent 8caab49 commit d845f9d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -760,6 +760,7 @@ void QgsAttributeTableDialog::mActionAddFeature_triggered()

QgsFeature f;
QgsFeatureAction action( tr( "Geometryless feature added" ), f, mLayer, QString(), -1, this );
action.setForceSuppressFormPopup( true ); // we're already showing the table, allowing users to enter the new feature's attributes directly
if ( action.addFeature() )
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
Expand Down
25 changes: 23 additions & 2 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -200,8 +200,19 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
*mFeature = newFeature;

//show the dialog to enter attribute values
//only show if enabled in settings and layer has fields
bool isDisabledAttributeValuesDlg = ( fields.count() == 0 ) || settings.value( QStringLiteral( "qgis/digitizing/disable_enter_attribute_values_dialog" ), false ).toBool();
//only show if enabled in settings
bool isDisabledAttributeValuesDlg = settings.value( QStringLiteral( "qgis/digitizing/disable_enter_attribute_values_dialog" ), false ).toBool();

// override application-wide setting if layer is non-spatial -- BECAUSE it's bad UX if
// it appears that nothing happens when you click the add row button for a non-spatial layer. Unlike
// spatial layers, where you can SEE the newly created spatial object on the map, creating a new
// feature in a non-spatial layer otherwise seems to have no result.
if ( !mLayer->isSpatial() )
isDisabledAttributeValuesDlg = false;

// override application-wide setting if layer has no fields
if ( fields.count() == 0 )
isDisabledAttributeValuesDlg = true;

// override application-wide setting with any layer setting
switch ( mLayer->editFormConfig().suppress() )
Expand All @@ -215,6 +226,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
case QgsEditFormConfig::SuppressDefault:
break;
}

// finally, if this action has specifically forced suppression of the form, that overrides everything
if ( mForceSuppressFormPopup )
isDisabledAttributeValuesDlg = true;

if ( isDisabledAttributeValuesDlg )
{
mLayer->beginEditCommand( text() );
Expand Down Expand Up @@ -255,6 +271,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
return mFeatureSaved;
}

void QgsFeatureAction::setForceSuppressFormPopup( bool force )
{
mForceSuppressFormPopup = force;
}

void QgsFeatureAction::onFeatureSaved( const QgsFeature &feature )
{
QgsAttributeForm *form = qobject_cast<QgsAttributeForm *>( sender() );
Expand Down
9 changes: 9 additions & 0 deletions src/app/qgsfeatureaction.h
Expand Up @@ -54,6 +54,13 @@ class APP_EXPORT QgsFeatureAction : public QAction
*/
bool addFeature( const QgsAttributeMap &defaultAttributes = QgsAttributeMap(), bool showModal = true, QgsExpressionContextScope *scope = nullptr );

/**
* Sets whether to force suppression of the attribute form popup after creating a new feature.
* If \a force is true, then regardless of any user settings, form settings, etc, the attribute
* form will ALWAYS be suppressed.
*/
void setForceSuppressFormPopup( bool force );

private slots:
void onFeatureSaved( const QgsFeature &feature );

Expand All @@ -67,6 +74,8 @@ class APP_EXPORT QgsFeatureAction : public QAction

bool mFeatureSaved;

bool mForceSuppressFormPopup = false;

static QHash<QgsVectorLayer *, QgsAttributeMap> sLastUsedValues;
};

Expand Down

0 comments on commit d845f9d

Please sign in to comment.