Skip to content
Permalink
Browse files

[needs-docs] Add shortcut to Select by Form to toolbar and menu

Also add keyboard shortcut (F3) to open select by form
dialog
  • Loading branch information
nyalldawson committed Jun 9, 2016
1 parent ce7d79e commit fe26d33e29e3bc7a719e2ddff4da65d32cdbc730
@@ -596,6 +596,7 @@
<file>themes/default/mIconAms.svg</file>
<file>themes/default/mActionAddAmsLayer.svg</file>
<file>themes/default/mActionAddAfsLayer.svg</file>
<file>themes/default/mIconFormSelect.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
id="svg5692"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="mIconFormSelect.svg"
inkscape:export-filename="/mnt/home1/robert/svn/graphics/trunk/toolbar-icons/24x24/expression-select.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90"
style="display:inline">
<title
id="title2967">expression editor select</title>
<defs
id="defs5694" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="21.095352"
inkscape:cx="6.2423369"
inkscape:cy="9.4260791"
inkscape:current-layer="layer4"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
borderlayer="false"
inkscape:window-width="1855"
inkscape:window-height="1056"
inkscape:window-x="1345"
inkscape:window-y="24"
inkscape:window-maximized="1"
showguides="true"
inkscape:guide-bbox="true"
inkscape:snap-bbox="true"
inkscape:snap-object-midpoints="true"
inkscape:snap-nodes="true"
inkscape:snap-to-guides="false"
inkscape:snap-global="true">
<inkscape:grid
type="xygrid"
id="grid5700"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
dotted="false"
originx="0"
originy="0"
spacingx="1px"
spacingy="1px" />
</sodipodi:namedview>
<metadata
id="metadata5697">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>expression editor select</dc:title>
<dc:date>2013-01-30</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>Robert Szczepanek</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>Robert Szczepanek</dc:title>
</cc:Agent>
</dc:rights>
<dc:subject>
<rdf:Bag>
<rdf:li>expression editor select</rdf:li>
</rdf:Bag>
</dc:subject>
<dc:coverage>GIS icons 0.2</dc:coverage>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/3.0/" />
<dc:description />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/3.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer4"
inkscape:label="1"
style="display:inline"
transform="translate(0,-8)">
<rect
style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:#fce94f;stroke:#c4a000;stroke-width:1.07692313;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate"
id="rect2902"
width="14.92308"
height="12.923077"
x="6.5384603"
y="16.538462" />
<rect
style="opacity:1;fill:#d8e2e8;fill-opacity:1;stroke:#959595;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.99215686"
id="rect4283"
width="14"
height="13"
x="3.5"
y="11.5" />
<rect
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#959595;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.99215686"
id="rect4288"
width="10.500001"
height="3"
x="5.250001"
y="13.499998" />
<rect
style="display:inline;opacity:1;fill:#ffffff;fill-opacity:1;stroke:#959595;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.99215686"
id="rect4288-8"
width="10.500001"
height="3"
x="5.2500005"
y="18.499998" />
</g>
</svg>
@@ -125,6 +125,13 @@ class QgsAttributeForm : QWidget
*/
void setMultiEditFeatureIds( const QgsFeatureIds& fids );

/** Sets the message bar to display feedback from the form in. This is used in the search/filter
* mode to display the count of selected features.
* @param messageBar target message bar
* @note added in QGIS 2.16
*/
void setMessageBar( QgsMessageBar* messageBar );

signals:
/**
* Notifies about changes of attributes
@@ -161,6 +168,11 @@ class QgsAttributeForm : QWidget
*/
void modeChanged( QgsAttributeForm::Mode mode );

/** Emitted when the user selects the close option from the form's button bar.
* @note added in QGIS 2.16
*/
void closed();

public slots:
/**
* Call this to change the content of a given attribute. Will update the editor(s) related to this field.
@@ -113,6 +113,7 @@ SET(QGIS_APP_SRCS
qgsrasterlayerproperties.cpp
qgsrelationmanagerdialog.cpp
qgsrelationadddlg.cpp
qgsselectbyformdialog.cpp
qgsstatisticalsummarydockwidget.cpp
qgstextannotationdialog.cpp
qgssnappingdialog.cpp
@@ -287,6 +288,7 @@ SET (QGIS_APP_MOC_HDRS
qgsrasterlayerproperties.h
qgsrelationmanagerdialog.h
qgsrelationadddlg.h
qgsselectbyformdialog.h
qgssnappingdialog.h
qgssponsors.h
qgsstatisticalsummarydockwidget.h
@@ -210,6 +210,7 @@
#include "qgsrectangle.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsgroupwmsdatadialog.h"
#include "qgsselectbyformdialog.h"
#include "qgsshortcutsmanager.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgssnappingdialog.h"
@@ -1514,6 +1515,7 @@ void QgisApp::createActions()
connect( mActionSelectAll, SIGNAL( triggered() ), this, SLOT( selectAll() ) );
connect( mActionInvertSelection, SIGNAL( triggered() ), this, SLOT( invertSelection() ) );
connect( mActionSelectByExpression, SIGNAL( triggered() ), this, SLOT( selectByExpression() ) );
connect( mActionSelectByForm, SIGNAL( triggered() ), this, SLOT( selectByForm() ) );
connect( mActionIdentify, SIGNAL( triggered() ), this, SLOT( identify() ) );
connect( mActionFeatureAction, SIGNAL( triggered() ), this, SLOT( doFeatureAction() ) );
connect( mActionMeasure, SIGNAL( triggered() ), this, SLOT( measure() ) );
@@ -1988,7 +1990,7 @@ void QgisApp::createToolBars()
QToolButton *bt = new QToolButton( mAttributesToolBar );
bt->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction*> selectActions;
selectActions << mActionSelectByExpression << mActionSelectAll
selectActions << mActionSelectByExpression << mActionSelectByForm << mActionSelectAll
<< mActionInvertSelection;
bt->addActions( selectActions );
bt->setDefaultAction( mActionSelectByExpression );
@@ -2550,6 +2552,7 @@ void QgisApp::setTheme( const QString& theThemeName )
mActionSelectAll->setIcon( QgsApplication::getThemeIcon( "/mActionSelectAll.svg" ) );
mActionInvertSelection->setIcon( QgsApplication::getThemeIcon( "/mActionInvertSelection.svg" ) );
mActionSelectByExpression->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
mActionSelectByForm->setIcon( QgsApplication::getThemeIcon( "/mIconFormSelect.svg" ) );
mActionOpenTable->setIcon( QgsApplication::getThemeIcon( "/mActionOpenTable.svg" ) );
mActionOpenFieldCalc->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) );
mActionMeasure->setIcon( QgsApplication::getThemeIcon( "/mActionMeasure.png" ) );
@@ -7211,6 +7214,34 @@ void QgisApp::selectByExpression()
dlg->show();
}

void QgisApp::selectByForm()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( !vlayer )
{
messageBar()->pushMessage(
tr( "No active vector layer" ),
tr( "To select features, choose a vector layer in the legend" ),
QgsMessageBar::INFO,
messageTimeout() );
return;
}
QgsDistanceArea myDa;

myDa.setSourceCrs( vlayer->crs().srsid() );
myDa.setEllipsoidalMode( mMapCanvas->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

QgsAttributeEditorContext context;
context.setDistanceArea( myDa );
context.setVectorLayerTools( mVectorLayerTools );

QgsSelectByFormDialog* dlg = new QgsSelectByFormDialog( vlayer, context, this );
dlg->setMessageBar( messageBar() );
dlg->setAttribute( Qt::WA_DeleteOnClose );
dlg->show();
}

void QgisApp::addRing()
{
mMapCanvas->setMapTool( mMapTools.mAddRing );
@@ -10315,6 +10346,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectRadius->setEnabled( false );
mActionIdentify->setEnabled( QSettings().value( "/Map/identifyMode", 0 ).toInt() != 0 );
mActionSelectByExpression->setEnabled( false );
mActionSelectByForm->setEnabled( false );
mActionLabeling->setEnabled( false );
mActionOpenTable->setEnabled( false );
mActionSelectAll->setEnabled( false );
@@ -10419,6 +10451,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectRadius->setEnabled( true );
mActionIdentify->setEnabled( true );
mActionSelectByExpression->setEnabled( true );
mActionSelectByForm->setEnabled( true );
mActionOpenTable->setEnabled( true );
mActionSelectAll->setEnabled( true );
mActionInvertSelection->setEnabled( true );
@@ -10606,6 +10639,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectAll->setEnabled( false );
mActionInvertSelection->setEnabled( false );
mActionSelectByExpression->setEnabled( false );
mActionSelectByForm->setEnabled( false );
mActionOpenFieldCalc->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
@@ -1089,6 +1089,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! select features by expression
void selectByExpression();

//! select features by form
void selectByForm();

//! refresh map canvas
void refreshMapCanvas();

@@ -0,0 +1,54 @@
/***************************************************************************
qgsselectbyformdialog.cpp
------------------------
Date : June 2016
Copyright : (C) 2016 nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsselectbyformdialog.h"
#include "qgsattributeform.h"
#include <QLayout>
#include <QSettings>

QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer* layer, const QgsAttributeEditorContext& context, QWidget* parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
QgsAttributeEditorContext dlgContext = context;
dlgContext.setFormMode( QgsAttributeEditorContext::StandaloneDialog );

mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this );
mForm->setMode( QgsAttributeForm::SearchMode );

QVBoxLayout* vLayout = new QVBoxLayout();
vLayout->setMargin( 0 );
vLayout->setContentsMargins( 0, 0, 0, 0 );
setLayout( vLayout );

vLayout->addWidget( mForm );

connect( mForm, SIGNAL( closed() ), this, SLOT( close() ) );

QSettings settings;
restoreGeometry( settings.value( "/Windows/SelectByForm/geometry" ).toByteArray() );

setWindowTitle( tr( "Select matching features" ) );
}

QgsSelectByFormDialog::~QgsSelectByFormDialog()
{
QSettings settings;
settings.setValue( "/Windows/SelectByForm/geometry", saveGeometry() );
}

void QgsSelectByFormDialog::setMessageBar( QgsMessageBar* messageBar )
{
mForm->setMessageBar( messageBar );
}

0 comments on commit fe26d33

Please sign in to comment.
You can’t perform that action at this time.