QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
17
18#include "qgsapplication.h"
20#include "qgsdistancearea.h"
22#include "qgsfeaturerequest.h"
23#include "qgsgui.h"
24#include "qgsmapcanvas.h"
26
27#include <QString>
28#include <QWindow>
29
30#include "moc_qgsfeatureselectiondlg.cpp"
31
32using namespace Qt::StringLiterals;
33
35 : QDialog( parent, Qt::Window )
36 , mVectorLayer( vl )
37 , mContext( context )
38{
39 setupUi( this );
41
42 mFeatureSelection = new QgsVectorLayerSelectionManager( vl, mDualView );
43
44 mDualView->setFeatureSelectionManager( mFeatureSelection );
45
46 mDualView->init( mVectorLayer, context.mapCanvas(), QgsFeatureRequest(), context );
47 mDualView->setView( QgsDualView::AttributeEditor );
48
49 mFeatureFilterWidget->init( vl, context, mDualView, mMessageBar, 5 );
50 mFeatureFilterWidget->filterVisible();
51
52 connect( mActionExpressionSelect, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionExpressionSelect_triggered );
53 connect( mActionSelectAll, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionSelectAll_triggered );
54 connect( mActionInvertSelection, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionInvertSelection_triggered );
55 connect( mActionRemoveSelection, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionRemoveSelection_triggered );
56 connect( mActionSearchForm, &QAction::toggled, mDualView, &QgsDualView::toggleSearchMode );
57 connect( mActionSelectedToTop, &QAction::toggled, this, [this]( bool checked ) { mDualView->setSelectedOnTop( checked ); } );
58 connect( mActionZoomMapToSelectedRows, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionZoomMapToSelectedRows_triggered );
59 connect( mActionPanMapToSelectedRows, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionPanMapToSelectedRows_triggered );
60
62 connect( mDualView, &QgsDualView::formModeChanged, this, &QgsFeatureSelectionDlg::viewModeChanged );
63}
64
66{
67 // don't accept Enter key to accept the dialog, user could be editing a text field
68 if ( evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return )
69 return;
70 QDialog::keyPressEvent( evt );
71}
72
74{
75 return mFeatureSelection->selectedFeatureIds();
76}
77
79{
80 mFeatureSelection->setSelectedFeatures( ids );
81}
82
83void QgsFeatureSelectionDlg::showEvent( QShowEvent *event )
84{
85 QWindow *mainWindow = nullptr;
86 for ( const auto &w : QgsApplication::topLevelWindows() )
87 {
88 if ( w->objectName() == "QgisAppWindow"_L1 )
89 {
90 mainWindow = w;
91 break;
92 }
93 }
94
95 if ( mainWindow )
96 {
97 const QSize margins( size() - scrollAreaWidgetContents->size() );
98 const QSize innerWinSize( mainWindow->width(), mainWindow->height() );
99 setMaximumSize( innerWinSize );
100 const QSize minSize( scrollAreaWidgetContents->sizeHint() );
101 setMinimumSize( std::min( minSize.width() + margins.width(), innerWinSize.width() ), std::min( minSize.height() + margins.width(), innerWinSize.height() ) );
102 }
103
104 QDialog::showEvent( event );
105}
106
107void QgsFeatureSelectionDlg::mActionExpressionSelect_triggered()
108{
110 dlg->setMessageBar( mMessageBar );
111 dlg->setAttribute( Qt::WA_DeleteOnClose );
112 dlg->show();
113}
114
115void QgsFeatureSelectionDlg::mActionInvertSelection_triggered()
116{
117 mVectorLayer->invertSelection();
118}
119
120void QgsFeatureSelectionDlg::mActionRemoveSelection_triggered()
121{
122 mVectorLayer->removeSelection();
123}
124
125void QgsFeatureSelectionDlg::mActionSelectAll_triggered()
126{
127 mVectorLayer->selectAll();
128}
129
130void QgsFeatureSelectionDlg::mActionZoomMapToSelectedRows_triggered()
131{
132 mContext.mapCanvas()->zoomToSelected( mVectorLayer );
133}
134
135void QgsFeatureSelectionDlg::mActionPanMapToSelectedRows_triggered()
136{
137 mContext.mapCanvas()->panToSelected( mVectorLayer );
138}
139
141{
142 mFeatureFilterWidget->setFilterExpression( filter, type, true );
143}
144
145void QgsFeatureSelectionDlg::viewModeChanged( QgsAttributeEditorContext::Mode mode )
146{
147 mActionSearchForm->setChecked( mode == QgsAttributeEditorContext::SearchMode );
148}
Contains context information for attribute editor widgets.
QgsMapCanvas * mapCanvas() const
Returns the associated map canvas (e.g.
@ SearchMode
Form values are used for searching/filtering the layer.
FilterType
Filter types.
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition qgsdualview.h:69
void formModeChanged(QgsAttributeEditorContext::Mode mode)
Emitted when the form changes mode.
void filterExpressionSet(const QString &expression, QgsAttributeForm::FilterType type)
Emitted when a filter expression is set using the view.
void toggleSearchMode(bool enabled)
Toggles whether search mode should be enabled in the form.
A dialog for selecting features by expression.
void setMessageBar(QgsMessageBar *messageBar)
Sets the message bar to display feedback from the dialog.
Wraps a request for features to a vector layer (or directly its vector data provider).
void setSelectedFeatures(const QgsFeatureIds &ids)
Set the selected features.
const QgsFeatureIds & selectedFeatures()
Gets the selected features.
QgsFeatureSelectionDlg(QgsVectorLayer *vl, const QgsAttributeEditorContext &context, QWidget *parent=nullptr)
Constructor for QgsFeatureSelectionDlg.
void setFilterExpression(const QString &filter, QgsAttributeForm::FilterType type)
Set form filter expression.
void showEvent(QShowEvent *event) override
Make sure the dialog does not grow too much.
void keyPressEvent(QKeyEvent *evt) override
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:224
Represents a vector layer which manages a vector based dataset.
QSet< QgsFeatureId > QgsFeatureIds