Skip to content

Commit fe26d33

Browse files
committed
[needs-docs] Add shortcut to Select by Form to toolbar and menu
Also add keyboard shortcut (F3) to open select by form dialog
1 parent ce7d79e commit fe26d33

11 files changed

+359
-3
lines changed

images/images.qrc

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@
596596
<file>themes/default/mIconAms.svg</file>
597597
<file>themes/default/mActionAddAmsLayer.svg</file>
598598
<file>themes/default/mActionAddAfsLayer.svg</file>
599+
<file>themes/default/mIconFormSelect.svg</file>
599600
</qresource>
600601
<qresource prefix="/images/tips">
601602
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
+148
Loading

python/gui/qgsattributeform.sip

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ class QgsAttributeForm : QWidget
125125
*/
126126
void setMultiEditFeatureIds( const QgsFeatureIds& fids );
127127

128+
/** Sets the message bar to display feedback from the form in. This is used in the search/filter
129+
* mode to display the count of selected features.
130+
* @param messageBar target message bar
131+
* @note added in QGIS 2.16
132+
*/
133+
void setMessageBar( QgsMessageBar* messageBar );
134+
128135
signals:
129136
/**
130137
* Notifies about changes of attributes
@@ -161,6 +168,11 @@ class QgsAttributeForm : QWidget
161168
*/
162169
void modeChanged( QgsAttributeForm::Mode mode );
163170

171+
/** Emitted when the user selects the close option from the form's button bar.
172+
* @note added in QGIS 2.16
173+
*/
174+
void closed();
175+
164176
public slots:
165177
/**
166178
* Call this to change the content of a given attribute. Will update the editor(s) related to this field.

src/app/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ SET(QGIS_APP_SRCS
113113
qgsrasterlayerproperties.cpp
114114
qgsrelationmanagerdialog.cpp
115115
qgsrelationadddlg.cpp
116+
qgsselectbyformdialog.cpp
116117
qgsstatisticalsummarydockwidget.cpp
117118
qgstextannotationdialog.cpp
118119
qgssnappingdialog.cpp
@@ -287,6 +288,7 @@ SET (QGIS_APP_MOC_HDRS
287288
qgsrasterlayerproperties.h
288289
qgsrelationmanagerdialog.h
289290
qgsrelationadddlg.h
291+
qgsselectbyformdialog.h
290292
qgssnappingdialog.h
291293
qgssponsors.h
292294
qgsstatisticalsummarydockwidget.h

src/app/qgisapp.cpp

+35-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
#include "qgsrectangle.h"
211211
#include "qgsscalevisibilitydialog.h"
212212
#include "qgsgroupwmsdatadialog.h"
213+
#include "qgsselectbyformdialog.h"
213214
#include "qgsshortcutsmanager.h"
214215
#include "qgssinglebandgrayrenderer.h"
215216
#include "qgssnappingdialog.h"
@@ -1514,6 +1515,7 @@ void QgisApp::createActions()
15141515
connect( mActionSelectAll, SIGNAL( triggered() ), this, SLOT( selectAll() ) );
15151516
connect( mActionInvertSelection, SIGNAL( triggered() ), this, SLOT( invertSelection() ) );
15161517
connect( mActionSelectByExpression, SIGNAL( triggered() ), this, SLOT( selectByExpression() ) );
1518+
connect( mActionSelectByForm, SIGNAL( triggered() ), this, SLOT( selectByForm() ) );
15171519
connect( mActionIdentify, SIGNAL( triggered() ), this, SLOT( identify() ) );
15181520
connect( mActionFeatureAction, SIGNAL( triggered() ), this, SLOT( doFeatureAction() ) );
15191521
connect( mActionMeasure, SIGNAL( triggered() ), this, SLOT( measure() ) );
@@ -1988,7 +1990,7 @@ void QgisApp::createToolBars()
19881990
QToolButton *bt = new QToolButton( mAttributesToolBar );
19891991
bt->setPopupMode( QToolButton::MenuButtonPopup );
19901992
QList<QAction*> selectActions;
1991-
selectActions << mActionSelectByExpression << mActionSelectAll
1993+
selectActions << mActionSelectByExpression << mActionSelectByForm << mActionSelectAll
19921994
<< mActionInvertSelection;
19931995
bt->addActions( selectActions );
19941996
bt->setDefaultAction( mActionSelectByExpression );
@@ -2550,6 +2552,7 @@ void QgisApp::setTheme( const QString& theThemeName )
25502552
mActionSelectAll->setIcon( QgsApplication::getThemeIcon( "/mActionSelectAll.svg" ) );
25512553
mActionInvertSelection->setIcon( QgsApplication::getThemeIcon( "/mActionInvertSelection.svg" ) );
25522554
mActionSelectByExpression->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
2555+
mActionSelectByForm->setIcon( QgsApplication::getThemeIcon( "/mIconFormSelect.svg" ) );
25532556
mActionOpenTable->setIcon( QgsApplication::getThemeIcon( "/mActionOpenTable.svg" ) );
25542557
mActionOpenFieldCalc->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) );
25552558
mActionMeasure->setIcon( QgsApplication::getThemeIcon( "/mActionMeasure.png" ) );
@@ -7211,6 +7214,34 @@ void QgisApp::selectByExpression()
72117214
dlg->show();
72127215
}
72137216

7217+
void QgisApp::selectByForm()
7218+
{
7219+
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
7220+
if ( !vlayer )
7221+
{
7222+
messageBar()->pushMessage(
7223+
tr( "No active vector layer" ),
7224+
tr( "To select features, choose a vector layer in the legend" ),
7225+
QgsMessageBar::INFO,
7226+
messageTimeout() );
7227+
return;
7228+
}
7229+
QgsDistanceArea myDa;
7230+
7231+
myDa.setSourceCrs( vlayer->crs().srsid() );
7232+
myDa.setEllipsoidalMode( mMapCanvas->mapSettings().hasCrsTransformEnabled() );
7233+
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
7234+
7235+
QgsAttributeEditorContext context;
7236+
context.setDistanceArea( myDa );
7237+
context.setVectorLayerTools( mVectorLayerTools );
7238+
7239+
QgsSelectByFormDialog* dlg = new QgsSelectByFormDialog( vlayer, context, this );
7240+
dlg->setMessageBar( messageBar() );
7241+
dlg->setAttribute( Qt::WA_DeleteOnClose );
7242+
dlg->show();
7243+
}
7244+
72147245
void QgisApp::addRing()
72157246
{
72167247
mMapCanvas->setMapTool( mMapTools.mAddRing );
@@ -10315,6 +10346,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1031510346
mActionSelectRadius->setEnabled( false );
1031610347
mActionIdentify->setEnabled( QSettings().value( "/Map/identifyMode", 0 ).toInt() != 0 );
1031710348
mActionSelectByExpression->setEnabled( false );
10349+
mActionSelectByForm->setEnabled( false );
1031810350
mActionLabeling->setEnabled( false );
1031910351
mActionOpenTable->setEnabled( false );
1032010352
mActionSelectAll->setEnabled( false );
@@ -10419,6 +10451,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1041910451
mActionSelectRadius->setEnabled( true );
1042010452
mActionIdentify->setEnabled( true );
1042110453
mActionSelectByExpression->setEnabled( true );
10454+
mActionSelectByForm->setEnabled( true );
1042210455
mActionOpenTable->setEnabled( true );
1042310456
mActionSelectAll->setEnabled( true );
1042410457
mActionInvertSelection->setEnabled( true );
@@ -10606,6 +10639,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1060610639
mActionSelectAll->setEnabled( false );
1060710640
mActionInvertSelection->setEnabled( false );
1060810641
mActionSelectByExpression->setEnabled( false );
10642+
mActionSelectByForm->setEnabled( false );
1060910643
mActionOpenFieldCalc->setEnabled( false );
1061010644
mActionToggleEditing->setEnabled( false );
1061110645
mActionToggleEditing->setChecked( false );

src/app/qgisapp.h

+3
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
10891089
//! select features by expression
10901090
void selectByExpression();
10911091

1092+
//! select features by form
1093+
void selectByForm();
1094+
10921095
//! refresh map canvas
10931096
void refreshMapCanvas();
10941097

src/app/qgsselectbyformdialog.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
qgsselectbyformdialog.cpp
3+
------------------------
4+
Date : June 2016
5+
Copyright : (C) 2016 nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
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 "qgsselectbyformdialog.h"
17+
#include "qgsattributeform.h"
18+
#include <QLayout>
19+
#include <QSettings>
20+
21+
QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer* layer, const QgsAttributeEditorContext& context, QWidget* parent, Qt::WindowFlags fl )
22+
: QDialog( parent, fl )
23+
{
24+
QgsAttributeEditorContext dlgContext = context;
25+
dlgContext.setFormMode( QgsAttributeEditorContext::StandaloneDialog );
26+
27+
mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this );
28+
mForm->setMode( QgsAttributeForm::SearchMode );
29+
30+
QVBoxLayout* vLayout = new QVBoxLayout();
31+
vLayout->setMargin( 0 );
32+
vLayout->setContentsMargins( 0, 0, 0, 0 );
33+
setLayout( vLayout );
34+
35+
vLayout->addWidget( mForm );
36+
37+
connect( mForm, SIGNAL( closed() ), this, SLOT( close() ) );
38+
39+
QSettings settings;
40+
restoreGeometry( settings.value( "/Windows/SelectByForm/geometry" ).toByteArray() );
41+
42+
setWindowTitle( tr( "Select matching features" ) );
43+
}
44+
45+
QgsSelectByFormDialog::~QgsSelectByFormDialog()
46+
{
47+
QSettings settings;
48+
settings.setValue( "/Windows/SelectByForm/geometry", saveGeometry() );
49+
}
50+
51+
void QgsSelectByFormDialog::setMessageBar( QgsMessageBar* messageBar )
52+
{
53+
mForm->setMessageBar( messageBar );
54+
}

0 commit comments

Comments
 (0)