Skip to content
Permalink
Browse files
[editor widgets] Provide a show first feature setting to avoid UI fre…
…eze of attribute form containing a large number of embedded relations
  • Loading branch information
nirvn committed Nov 4, 2021
1 parent 0ab1bf4 commit 9684c1ac7e1c1f4fb61302008a504ced247d7a97
@@ -55,7 +55,7 @@ Constructor
QgsMapCanvas *mapCanvas,
const QgsFeatureRequest &request = QgsFeatureRequest(),
const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
bool loadFeatures = true );
bool loadFeatures = true, bool showFirstFeature = true );
%Docstring
Has to be called to initialize the dual view.

@@ -66,6 +66,7 @@ Has to be called to initialize the dual view.
:param context: The context in which this view is shown
:param loadFeatures: whether to initially load all features into the view. If set to
``False``, limited features can later be loaded using :py:func:`~QgsDualView.setFilterMode`
:param showFirstFeature: whether to initially show the first feature form upon initializing the dual view
%End

void setView( ViewMode view );
@@ -119,7 +119,7 @@ QgsDualView::~QgsDualView()
}

void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request,
const QgsAttributeEditorContext &context, bool loadFeatures )
const QgsAttributeEditorContext &context, bool loadFeatures, bool showFirstFeature )
{
if ( !layer )
return;
@@ -162,9 +162,8 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg
// This slows down load of the attribute table heaps and uses loads of memory.
//mTableView->resizeColumnsToContents();

if ( mFeatureListModel->rowCount( ) > 0 )
if ( showFirstFeature && mFeatureListModel->rowCount( ) > 0 )
mFeatureListView->setEditSelection( QgsFeatureIds() << mFeatureListModel->data( mFeatureListModel->index( 0, 0 ), QgsFeatureListModel::Role::FeatureRole ).value<QgsFeature>().id() );

}

void QgsDualView::initAttributeForm( const QgsFeature &feature )
@@ -96,12 +96,13 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
* \param context The context in which this view is shown
* \param loadFeatures whether to initially load all features into the view. If set to
* FALSE, limited features can later be loaded using setFilterMode()
* \param showFirstFeature whether to initially show the first feature form upon initializing the dual view
*/
void init( QgsVectorLayer *layer,
QgsMapCanvas *mapCanvas,
const QgsFeatureRequest &request = QgsFeatureRequest(),
const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
bool loadFeatures = true );
bool loadFeatures = true, bool showFirstFeature = true );

/**
* Change the current view mode.
@@ -97,6 +97,7 @@ void QgsFilteredSelectionManager::onSelectionChanged( const QgsFeatureIds &selec
QgsRelationEditorWidget::QgsRelationEditorWidget( const QVariantMap &config, QWidget *parent )
: QgsAbstractRelationEditorWidget( config, parent )
, mButtonsVisibility( qgsFlagKeysToValue( config.value( QStringLiteral( "buttons" ) ).toString(), QgsRelationEditorWidget::Button::AllButtons ) )
, mShowFirstFeature( config.value( QStringLiteral( "show_first_feature" ), true ).toBool() )
{
QVBoxLayout *rootLayout = new QVBoxLayout( this );
rootLayout->setContentsMargins( 0, 9, 0, 0 );
@@ -226,7 +227,7 @@ void QgsRelationEditorWidget::initDualView( QgsVectorLayer *layer, const QgsFeat
{
QgsAttributeEditorContext ctx { mEditorContext };
ctx.setParentFormFeature( mFeature );
mDualView->init( layer, mEditorContext.mapCanvas(), request, ctx );
mDualView->init( layer, mEditorContext.mapCanvas(), request, ctx, true, mShowFirstFeature );
mFeatureSelectionMgr = new QgsFilteredSelectionManager( layer, request, mDualView );
mDualView->setFeatureSelectionManager( mFeatureSelectionMgr );

@@ -489,12 +490,14 @@ void QgsRelationEditorWidget::mapToolDeactivated()

QVariantMap QgsRelationEditorWidget::config() const
{
return QVariantMap( {{"buttons", qgsFlagValueToKeys( visibleButtons() )}} );
return QVariantMap( {{"buttons", qgsFlagValueToKeys( visibleButtons() )},
{"show_first_feature", mShowFirstFeature}} );
}

void QgsRelationEditorWidget::setConfig( const QVariantMap &config )
{
mButtonsVisibility = qgsFlagKeysToValue( config.value( QStringLiteral( "buttons" ) ).toString(), QgsRelationEditorWidget::Button::AllButtons );
mShowFirstFeature = config.value( QStringLiteral( "show_first_feature" ), true ).toBool();
updateButtons();
}

@@ -623,6 +626,7 @@ QVariantMap QgsRelationEditorConfigWidget::config()
return QVariantMap(
{
{"buttons", qgsFlagValueToKeys( buttons )},
{"show_first_feature", mShowFirstFeature->isChecked()}
} );
}

@@ -637,6 +641,7 @@ void QgsRelationEditorConfigWidget::setConfig( const QVariantMap &config )
mRelationShowZoomToFeatureCheckBox->setChecked( buttons.testFlag( QgsRelationEditorWidget::Button::ZoomToChildFeature ) );
mRelationDeleteChildFeatureCheckBox->setChecked( buttons.testFlag( QgsRelationEditorWidget::Button::DeleteChildFeature ) );
mRelationShowSaveChildEditsCheckBox->setChecked( buttons.testFlag( QgsRelationEditorWidget::Button::SaveChildEdits ) );
mShowFirstFeature->setChecked( config.value( QStringLiteral( "show_first_feature" ), true ).toBool() );
}


@@ -232,6 +232,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;

Buttons mButtonsVisibility = Button::AllButtons;
bool mShowFirstFeature = true;
};


@@ -15,52 +15,74 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="mRelationShowLinkCheckBox">
<widget class="QCheckBox" name="mShowFirstFeature">
<property name="text">
<string>Show link button</string>
<string>Automatically show first child feature</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowUnlinkCheckBox">
<property name="text">
<string>Show unlink button</string>
<widget class="QGroupBox" name="mButtonsVisibility">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowSaveChildEditsCheckBox">
<property name="text">
<string>Show save child layer edits button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowAddChildCheckBox">
<property name="text">
<string>Add child feature</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowDuplicateChildFeatureCheckBox">
<property name="text">
<string>Duplicate child feature</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationDeleteChildFeatureCheckBox">
<property name="text">
<string>Delete child feature</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowZoomToFeatureCheckBox">
<property name="text">
<string>Zoom to child feature</string>
<property name="title">
<string>Toolbar settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="mRelationShowLinkCheckBox">
<property name="text">
<string>Show link button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowUnlinkCheckBox">
<property name="text">
<string>Show unlink button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowSaveChildEditsCheckBox">
<property name="text">
<string>Show save child layer edits button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowAddChildCheckBox">
<property name="text">
<string>Add child feature button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowDuplicateChildFeatureCheckBox">
<property name="text">
<string>Duplicate child feature button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationDeleteChildFeatureCheckBox">
<property name="text">
<string>Delete child feature button</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowZoomToFeatureCheckBox">
<property name="text">
<string>Zoom to child feature button</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>

0 comments on commit 9684c1a

Please sign in to comment.