QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
23 #include <QWindow>
24 
26  : QDialog( parent )
27  , mVectorLayer( vl )
28 {
29  setupUi( this );
30 
31  mFeatureSelection = new QgsGenericFeatureSelectionManager( mDualView );
32 
33  mDualView->setFeatureSelectionManager( mFeatureSelection );
34 
35  // TODO: Proper QgsDistanceArea, proper mapcanvas
36  mDualView->init( mVectorLayer, nullptr, QgsFeatureRequest(), context );
37 }
38 
40 {
41  return mFeatureSelection->selectedFeatureIds();
42 }
43 
45 {
46  mFeatureSelection->setSelectedFeatures( ids );
47 }
48 
49 void QgsFeatureSelectionDlg::showEvent( QShowEvent *event )
50 {
51 
52  QWindow *mainWindow = nullptr;
53  for ( const auto &w : QgsApplication::instance()->topLevelWindows() )
54  {
55  if ( w->objectName() == QStringLiteral( "QgisAppWindow" ) )
56  {
57  mainWindow = w;
58  break;
59  }
60  }
61 
62  if ( mainWindow )
63  {
64  QSize margins( size() - scrollAreaWidgetContents->size() );
65  QSize innerWinSize( mainWindow->width(), mainWindow->height() );
66  setMaximumSize( innerWinSize );
67  QSize minSize( scrollAreaWidgetContents->sizeHint() );
68  setMinimumSize( std::min( minSize.width() + margins.width( ), innerWinSize.width() ),
69  std::min( minSize.height() + margins.width( ), innerWinSize.height() ) );
70  }
71 
72  QDialog::showEvent( event );
73 }
74 
75 
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.