QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <QWindow>
28
29#include "moc_qgsfeatureselectiondlg.cpp"
30
32 : QDialog( parent, Qt::Window )
33 , mVectorLayer( vl )
34 , mContext( context )
35{
36 setupUi( this );
38
39 mFeatureSelection = new QgsVectorLayerSelectionManager( vl, mDualView );
40
41 mDualView->setFeatureSelectionManager( mFeatureSelection );
42
43 mDualView->init( mVectorLayer, context.mapCanvas(), QgsFeatureRequest(), context );
44 mDualView->setView( QgsDualView::AttributeEditor );
45
46 mFeatureFilterWidget->init( vl, context, mDualView, mMessageBar, 5 );
47 mFeatureFilterWidget->filterVisible();
48
49 connect( mActionExpressionSelect, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionExpressionSelect_triggered );
50 connect( mActionSelectAll, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionSelectAll_triggered );
51 connect( mActionInvertSelection, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionInvertSelection_triggered );
52 connect( mActionRemoveSelection, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionRemoveSelection_triggered );
53 connect( mActionSearchForm, &QAction::toggled, mDualView, &QgsDualView::toggleSearchMode );
54 connect( mActionSelectedToTop, &QAction::toggled, this, [this]( bool checked ) { mDualView->setSelectedOnTop( checked ); } );
55 connect( mActionZoomMapToSelectedRows, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionZoomMapToSelectedRows_triggered );
56 connect( mActionPanMapToSelectedRows, &QAction::triggered, this, &QgsFeatureSelectionDlg::mActionPanMapToSelectedRows_triggered );
57
59 connect( mDualView, &QgsDualView::formModeChanged, this, &QgsFeatureSelectionDlg::viewModeChanged );
60}
61
63{
64 // don't accept Enter key to accept the dialog, user could be editing a text field
65 if ( evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return )
66 return;
67 QDialog::keyPressEvent( evt );
68}
69
71{
72 return mFeatureSelection->selectedFeatureIds();
73}
74
76{
77 mFeatureSelection->setSelectedFeatures( ids );
78}
79
80void QgsFeatureSelectionDlg::showEvent( QShowEvent *event )
81{
82 QWindow *mainWindow = nullptr;
83 for ( const auto &w : QgsApplication::topLevelWindows() )
84 {
85 if ( w->objectName() == QLatin1String( "QgisAppWindow" ) )
86 {
87 mainWindow = w;
88 break;
89 }
90 }
91
92 if ( mainWindow )
93 {
94 const QSize margins( size() - scrollAreaWidgetContents->size() );
95 const QSize innerWinSize( mainWindow->width(), mainWindow->height() );
96 setMaximumSize( innerWinSize );
97 const QSize minSize( scrollAreaWidgetContents->sizeHint() );
98 setMinimumSize( std::min( minSize.width() + margins.width(), innerWinSize.width() ), std::min( minSize.height() + margins.width(), innerWinSize.height() ) );
99 }
100
101 QDialog::showEvent( event );
102}
103
104void QgsFeatureSelectionDlg::mActionExpressionSelect_triggered()
105{
107 dlg->setMessageBar( mMessageBar );
108 dlg->setAttribute( Qt::WA_DeleteOnClose );
109 dlg->show();
110}
111
112void QgsFeatureSelectionDlg::mActionInvertSelection_triggered()
113{
114 mVectorLayer->invertSelection();
115}
116
117void QgsFeatureSelectionDlg::mActionRemoveSelection_triggered()
118{
119 mVectorLayer->removeSelection();
120}
121
122void QgsFeatureSelectionDlg::mActionSelectAll_triggered()
123{
124 mVectorLayer->selectAll();
125}
126
127void QgsFeatureSelectionDlg::mActionZoomMapToSelectedRows_triggered()
128{
129 mContext.mapCanvas()->zoomToSelected( mVectorLayer );
130}
131
132void QgsFeatureSelectionDlg::mActionPanMapToSelectedRows_triggered()
133{
134 mContext.mapCanvas()->panToSelected( mVectorLayer );
135}
136
138{
139 mFeatureFilterWidget->setFilterExpression( filter, type, true );
140}
141
142void QgsFeatureSelectionDlg::viewModeChanged( QgsAttributeEditorContext::Mode mode )
143{
144 mActionSearchForm->setChecked( mode == QgsAttributeEditorContext::SearchMode );
145}
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:70
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:221
Represents a vector layer which manages a vector based dataset.
QSet< QgsFeatureId > QgsFeatureIds