Merge pull request #8407 from elpaso/bugfix-20338-qgsfeatureselectiondlg-sizing

Make sure QgsFeatureSelectionDlg does not outgrow the window
This commit is contained in:
Alessandro Pasotti 2018-11-05 09:55:33 +01:00 committed by GitHub
commit ceb33f0156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 3 deletions

View File

@ -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
};
/************************************************************************

View File

@ -20,6 +20,7 @@
#include "qgsfeaturerequest.h"
#include "qgsattributeeditorcontext.h"
#include <QWindow>
QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer *vl, QgsAttributeEditorContext &context, QWidget *parent )
: QDialog( parent )
@ -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 );
}

View File

@ -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

View File

@ -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>