Skip to content

Commit

Permalink
Make sure QgsFeatureSelectionDlg does not outgrow the window
Browse files Browse the repository at this point in the history
Fixes #20338 - Can not scroll through attribute list in dialog window when linking existing child features
  • Loading branch information
elpaso committed Nov 3, 2018
1 parent ec98dfc commit c962573
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsfeatureselectiondlg.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ Set the selected features
:param ids: The feature ids to select
%End

protected:

virtual void showEvent( QShowEvent *event );

%Docstring
Make sure the dialog does not grow too much
%End
};

/************************************************************************
Expand Down
27 changes: 27 additions & 0 deletions src/gui/qgsfeatureselectiondlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgsfeaturerequest.h"
#include "qgsattributeeditorcontext.h"

#include <QWindow>

QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer *vl, QgsAttributeEditorContext &context, QWidget *parent )
: QDialog( parent )
Expand All @@ -45,4 +46,30 @@ void QgsFeatureSelectionDlg::setSelectedFeatures( const QgsFeatureIds &ids )
mFeatureSelection->setSelectedFeatures( ids );
}

void QgsFeatureSelectionDlg::showEvent( QShowEvent *event )
{

QWindow *mainWindow = nullptr;
for ( const auto &w : QgsApplication::instance()->topLevelWindows() )
{
if ( w->objectName() == QStringLiteral( "QgisAppWindow" ) )
{
mainWindow = w;
break;
}
}

if ( mainWindow )
{
QSize margins( size() - scrollAreaWidgetContents->size() );
QSize innerWinSize( mainWindow->width(), mainWindow->height() );
setMaximumSize( innerWinSize );
QSize minSize( scrollAreaWidgetContents->sizeHint() );
setMinimumSize( std::min( minSize.width() + margins.width( ), innerWinSize.width() ),
std::min( minSize.height() + margins.width( ), innerWinSize.height() ) );
}

QDialog::showEvent( event );
}


6 changes: 6 additions & 0 deletions src/gui/qgsfeatureselectiondlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class GUI_EXPORT QgsFeatureSelectionDlg : public QDialog, private Ui::QgsFeature
private:
QgsGenericFeatureSelectionManager *mFeatureSelection = nullptr;
QgsVectorLayer *mVectorLayer = nullptr;

// QWidget interface
protected:

//! Make sure the dialog does not grow too much
void showEvent( QShowEvent *event ) override;
};

#endif // QGSFEATURESELECTIONDLG_H
25 changes: 22 additions & 3 deletions src/ui/qgsfeatureselectiondlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,28 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsDualView" name="mDualView">
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>444</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QgsDualView" name="mDualView">
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
Expand Down

0 comments on commit c962573

Please sign in to comment.