Skip to content

Commit

Permalink
[editor widgets] Provide a show first feature setting to avoid UI fre…
Browse files Browse the repository at this point in the history
…eze of attribute form containing a large number of embedded relations
  • Loading branch information
nirvn committed Nov 4, 2021
1 parent 0ab1bf4 commit 9684c1a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 46 deletions.
3 changes: 2 additions & 1 deletion python/gui/auto_generated/attributetable/qgsdualview.sip.in
Expand Up @@ -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.

Expand All @@ -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 );
Expand Down
5 changes: 2 additions & 3 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/attributetable/qgsdualview.h
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

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

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

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


Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -232,6 +232,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;

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


Expand Down
100 changes: 61 additions & 39 deletions src/ui/qgsrelationeditorconfigwidgetbase.ui
Expand Up @@ -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>
Expand Down

0 comments on commit 9684c1a

Please sign in to comment.