QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgsfeatureselectiondlg.cpp"
18
20#include "qgsdistancearea.h"
21#include "qgsfeaturerequest.h"
23#include "qgsapplication.h"
25#include "qgsmapcanvas.h"
26
27#include <QWindow>
28
30 : QDialog( parent, Qt::Window )
31 , mVectorLayer( vl )
32 , mContext( context )
33{
34 setupUi( this );
35
36 mFeatureSelection = new QgsVectorLayerSelectionManager( vl, mDualView );
37
38 mDualView->setFeatureSelectionManager( mFeatureSelection );
39
40 mDualView->init( mVectorLayer, context.mapCanvas(), QgsFeatureRequest(), context );
41 mDualView->setView( QgsDualView::AttributeEditor );
42
43 mFeatureFilterWidget->init( vl, context, mDualView, mMessageBar, 5 );
44 mFeatureFilterWidget->filterVisible();
45
46 connect( mActionExpressionSelect, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionExpressionSelect_triggered );
47 connect( mActionSelectAll, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionSelectAll_triggered );
48 connect( mActionInvertSelection, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionInvertSelection_triggered );
49 connect( mActionRemoveSelection, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionRemoveSelection_triggered );
50 connect( mActionSearchForm, &QAction::toggled, mDualView, &QgsDualView::toggleSearchMode );
51 connect( mActionSelectedToTop, &QAction::toggled, this, [this]( bool checked ) { mDualView->setSelectedOnTop( checked ); } );
52 connect( mActionZoomMapToSelectedRows, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionZoomMapToSelectedRows_triggered );
53 connect( mActionPanMapToSelectedRows, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionPanMapToSelectedRows_triggered );
54
56 connect( mDualView, &QgsDualView::formModeChanged, this, &QgsFeatureSelectionDlg::viewModeChanged );
57}
58
60{
61 // don't accept Enter key to accept the dialog, user could be editing a text field
62 if ( evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return )
63 return;
64 QDialog::keyPressEvent( evt );
65}
66
68{
69 return mFeatureSelection->selectedFeatureIds();
70}
71
73{
74 mFeatureSelection->setSelectedFeatures( ids );
75}
76
77void QgsFeatureSelectionDlg::showEvent( QShowEvent *event )
78{
79 QWindow *mainWindow = nullptr;
80 for ( const auto &w : QgsApplication::topLevelWindows() )
81 {
82 if ( w->objectName() == QLatin1String( "QgisAppWindow" ) )
83 {
84 mainWindow = w;
85 break;
86 }
87 }
88
89 if ( mainWindow )
90 {
91 const QSize margins( size() - scrollAreaWidgetContents->size() );
92 const QSize innerWinSize( mainWindow->width(), mainWindow->height() );
93 setMaximumSize( innerWinSize );
94 const QSize minSize( scrollAreaWidgetContents->sizeHint() );
95 setMinimumSize( std::min( minSize.width() + margins.width(), innerWinSize.width() ), std::min( minSize.height() + margins.width(), innerWinSize.height() ) );
96 }
97
98 QDialog::showEvent( event );
99}
100
101void QgsFeatureSelectionDlg::mActionExpressionSelect_triggered()
102{
104 dlg->setMessageBar( mMessageBar );
105 dlg->setAttribute( Qt::WA_DeleteOnClose );
106 dlg->show();
107}
108
109void QgsFeatureSelectionDlg::mActionInvertSelection_triggered()
110{
111 mVectorLayer->invertSelection();
112}
113
114void QgsFeatureSelectionDlg::mActionRemoveSelection_triggered()
115{
116 mVectorLayer->removeSelection();
117}
118
119void QgsFeatureSelectionDlg::mActionSelectAll_triggered()
120{
121 mVectorLayer->selectAll();
122}
123
124void QgsFeatureSelectionDlg::mActionZoomMapToSelectedRows_triggered()
125{
126 mContext.mapCanvas()->zoomToSelected( mVectorLayer );
127}
128
129void QgsFeatureSelectionDlg::mActionPanMapToSelectedRows_triggered()
130{
131 mContext.mapCanvas()->panToSelected( mVectorLayer );
132}
133
135{
136 mFeatureFilterWidget->setFilterExpression( filter, type, true );
137}
138
139void QgsFeatureSelectionDlg::viewModeChanged( QgsAttributeEditorContext::Mode mode )
140{
141 mActionSearchForm->setChecked( mode == QgsAttributeEditorContext::SearchMode );
142}
This class 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:67
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.
This class offers a dialog to change feature selections.
void setMessageBar(QgsMessageBar *messageBar)
Sets the message bar to display feedback from the dialog.
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.
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
void panToSelected(QgsMapLayer *layer=nullptr)
Pan to the selected features of current ayer keeping same extent.
void zoomToSelected(QgsMapLayer *layer=nullptr)
Zoom to the extent of the selected features of provided map layer.
void setSelectedFeatures(const QgsFeatureIds &ids) override
Change selection to the new set of features.
const QgsFeatureIds & selectedFeatureIds() const override
Returns reference to identifiers of selected features.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE void selectAll()
Select all the features.
Q_INVOKABLE void removeSelection()
Clear selection.
Q_INVOKABLE void invertSelection()
Selects not selected features and deselects selected ones.
QSet< QgsFeatureId > QgsFeatureIds