QGIS API Documentation  3.6.0-Noosa (5873452)
qgsfeatureselectiondlg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeatureselectiondlg.cpp
3  --------------------------------------
4  Date : 11.6.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsfeatureselectiondlg.h"
17 
19 #include "qgsdistancearea.h"
20 #include "qgsfeaturerequest.h"
22 #include "qgsapplication.h"
23 
24 #include <QWindow>
25 
27  : QDialog( parent )
28  , mVectorLayer( vl )
29 {
30  setupUi( this );
31 
32  mFeatureSelection = new QgsGenericFeatureSelectionManager( mDualView );
33 
34  mDualView->setFeatureSelectionManager( mFeatureSelection );
35 
36  // TODO: Proper QgsDistanceArea, proper mapcanvas
37  mDualView->init( mVectorLayer, nullptr, QgsFeatureRequest(), context );
38 }
39 
41 {
42  return mFeatureSelection->selectedFeatureIds();
43 }
44 
46 {
47  mFeatureSelection->setSelectedFeatures( ids );
48 }
49 
50 void QgsFeatureSelectionDlg::showEvent( QShowEvent *event )
51 {
52 
53  QWindow *mainWindow = nullptr;
54  for ( const auto &w : QgsApplication::instance()->topLevelWindows() )
55  {
56  if ( w->objectName() == QStringLiteral( "QgisAppWindow" ) )
57  {
58  mainWindow = w;
59  break;
60  }
61  }
62 
63  if ( mainWindow )
64  {
65  QSize margins( size() - scrollAreaWidgetContents->size() );
66  QSize innerWinSize( mainWindow->width(), mainWindow->height() );
67  setMaximumSize( innerWinSize );
68  QSize minSize( scrollAreaWidgetContents->sizeHint() );
69  setMinimumSize( std::min( minSize.width() + margins.width( ), innerWinSize.width() ),
70  std::min( minSize.height() + margins.width( ), innerWinSize.height() ) );
71  }
72 
73  QDialog::showEvent( event );
74 }
75 
76 
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
This class contains context information for attribute editor widgets.
void showEvent(QShowEvent *event) override
Make sure the dialog does not grow too much.
QgsFeatureSelectionDlg(QgsVectorLayer *vl, QgsAttributeEditorContext &context, QWidget *parent=nullptr)
Constructor for QgsFeatureSelectionDlg.
const QgsFeatureIds & selectedFeatures()
Gets the selected features.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setSelectedFeatures(const QgsFeatureIds &ids)
Set the selected features.
This selection manager synchronizes a local set of selected features with an attribute table...
void setSelectedFeatures(const QgsFeatureIds &ids) override
Change selection to the new set of features.
Represents a vector layer which manages a vector based data sets.
const QgsFeatureIds & selectedFeatureIds() const override
Returns reference to identifiers of selected features.