Skip to content

Commit d845f9d

Browse files
committed
Tweak logic relating to suppressing attribute form for new features
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.
1 parent 8caab49 commit d845f9d

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/app/qgsattributetabledialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ void QgsAttributeTableDialog::mActionAddFeature_triggered()
760760

761761
QgsFeature f;
762762
QgsFeatureAction action( tr( "Geometryless feature added" ), f, mLayer, QString(), -1, this );
763+
action.setForceSuppressFormPopup( true ); // we're already showing the table, allowing users to enter the new feature's attributes directly
763764
if ( action.addFeature() )
764765
{
765766
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );

src/app/qgsfeatureaction.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,19 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
200200
*mFeature = newFeature;
201201

202202
//show the dialog to enter attribute values
203-
//only show if enabled in settings and layer has fields
204-
bool isDisabledAttributeValuesDlg = ( fields.count() == 0 ) || settings.value( QStringLiteral( "qgis/digitizing/disable_enter_attribute_values_dialog" ), false ).toBool();
203+
//only show if enabled in settings
204+
bool isDisabledAttributeValuesDlg = settings.value( QStringLiteral( "qgis/digitizing/disable_enter_attribute_values_dialog" ), false ).toBool();
205+
206+
// override application-wide setting if layer is non-spatial -- BECAUSE it's bad UX if
207+
// it appears that nothing happens when you click the add row button for a non-spatial layer. Unlike
208+
// spatial layers, where you can SEE the newly created spatial object on the map, creating a new
209+
// feature in a non-spatial layer otherwise seems to have no result.
210+
if ( !mLayer->isSpatial() )
211+
isDisabledAttributeValuesDlg = false;
212+
213+
// override application-wide setting if layer has no fields
214+
if ( fields.count() == 0 )
215+
isDisabledAttributeValuesDlg = true;
205216

206217
// override application-wide setting with any layer setting
207218
switch ( mLayer->editFormConfig().suppress() )
@@ -215,6 +226,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
215226
case QgsEditFormConfig::SuppressDefault:
216227
break;
217228
}
229+
230+
// finally, if this action has specifically forced suppression of the form, that overrides everything
231+
if ( mForceSuppressFormPopup )
232+
isDisabledAttributeValuesDlg = true;
233+
218234
if ( isDisabledAttributeValuesDlg )
219235
{
220236
mLayer->beginEditCommand( text() );
@@ -255,6 +271,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
255271
return mFeatureSaved;
256272
}
257273

274+
void QgsFeatureAction::setForceSuppressFormPopup( bool force )
275+
{
276+
mForceSuppressFormPopup = force;
277+
}
278+
258279
void QgsFeatureAction::onFeatureSaved( const QgsFeature &feature )
259280
{
260281
QgsAttributeForm *form = qobject_cast<QgsAttributeForm *>( sender() );

src/app/qgsfeatureaction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ class APP_EXPORT QgsFeatureAction : public QAction
5454
*/
5555
bool addFeature( const QgsAttributeMap &defaultAttributes = QgsAttributeMap(), bool showModal = true, QgsExpressionContextScope *scope = nullptr );
5656

57+
/**
58+
* Sets whether to force suppression of the attribute form popup after creating a new feature.
59+
* If \a force is true, then regardless of any user settings, form settings, etc, the attribute
60+
* form will ALWAYS be suppressed.
61+
*/
62+
void setForceSuppressFormPopup( bool force );
63+
5764
private slots:
5865
void onFeatureSaved( const QgsFeature &feature );
5966

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

6875
bool mFeatureSaved;
6976

77+
bool mForceSuppressFormPopup = false;
78+
7079
static QHash<QgsVectorLayer *, QgsAttributeMap> sLastUsedValues;
7180
};
7281

0 commit comments

Comments
 (0)