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

Also add keyboard shortcut (F3) to open select by form
dialog
This commit is contained in:
Nyall Dawson 2016-06-09 14:04:45 +10:00
parent ce7d79e495
commit fe26d33e29
11 changed files with 359 additions and 3 deletions

View File

@ -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>

View 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>

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -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.

View File

@ -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

View File

@ -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 );

View File

@ -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();

View File

@ -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 );
}

View File

@ -0,0 +1,64 @@
/***************************************************************************
qgsselectbyformdialog.h
----------------------
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. *
* *
***************************************************************************/
#ifndef QGSSELECTBYFORMDIALOG_H
#define QGSSELECTBYFORMDIALOG_H
#include <QDialog>
#include "qgsattributeeditorcontext.h"
class QgsAttributeForm;
class QgsMessageBar;
class QgsVectorLayer;
/** \ingroup app
* \class QgsSelectByFormDialog
* A dialog for selecting features from a layer, using a form based off the layer's editor widgets.
* @note introduced in QGIS 2.16
*/
class APP_EXPORT QgsSelectByFormDialog : public QDialog
{
Q_OBJECT
public:
/** Constructor for QgsSelectByFormDialog
* @param layer vector layer to select from
* @param context editor context
* @param parent parent widget
* @param fl window flags
*/
QgsSelectByFormDialog( QgsVectorLayer* layer,
const QgsAttributeEditorContext& context = QgsAttributeEditorContext(),
QWidget* parent = nullptr, Qt::WindowFlags fl = nullptr );
~QgsSelectByFormDialog();
/** 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 );
private:
QgsAttributeForm* mForm;
};
#endif // QGSSELECTBYFORMDIALOG_H

View File

@ -51,6 +51,7 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &featur
: QWidget( parent )
, mLayer( vl )
, mMessageBar( nullptr )
, mOwnsMessageBar( true )
, mMultiEditUnsavedMessageBarItem( nullptr )
, mMultiEditMessageBarItem( nullptr )
, mInvalidConstraintMessage( nullptr )
@ -1296,7 +1297,7 @@ void QgsAttributeForm::init()
else
{
QPushButton* closeButton = new QPushButton( tr( "Close" ), mSearchButtonBox );
connect( closeButton, SIGNAL( clicked( bool ) ), this, SLOT( close() ) );
connect( closeButton, SIGNAL( clicked( bool ) ), this, SIGNAL( closed() ) );
closeButton->setShortcut( Qt::Key_Escape );
boxLayout->addWidget( closeButton );
}
@ -1804,6 +1805,14 @@ void QgsAttributeForm::setMultiEditFeatureIds( const QgsFeatureIds& fids )
mIsSettingMultiEditFeatures = false;
}
void QgsAttributeForm::setMessageBar( QgsMessageBar* messageBar )
{
if ( mOwnsMessageBar )
delete mMessageBar;
mOwnsMessageBar = false;
mMessageBar = messageBar;
}
int QgsAttributeForm::messageTimeout()
{
QSettings settings;

View File

@ -147,6 +147,13 @@ class GUI_EXPORT QgsAttributeForm : public 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
@ -183,6 +190,11 @@ class GUI_EXPORT QgsAttributeForm : public 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.
@ -317,6 +329,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
QgsVectorLayer* mLayer;
QgsFeature mFeature;
QgsMessageBar* mMessageBar;
bool mOwnsMessageBar;
QgsMessageBarItem* mMultiEditUnsavedMessageBarItem;
QgsMessageBarItem* mMultiEditMessageBarItem;
QLabel* mInvalidConstraintMessage;

View File

@ -71,6 +71,7 @@
<addaction name="mActionSelectFreehand"/>
<addaction name="mActionSelectRadius"/>
<addaction name="mActionSelectByExpression"/>
<addaction name="mActionSelectByForm"/>
<addaction name="mActionDeselectAll"/>
<addaction name="mActionSelectAll"/>
<addaction name="mActionInvertSelection"/>
@ -2502,7 +2503,7 @@ Acts on currently active editable layer</string>
<string>Modify the Attributes of all Selected Features Simultaneously</string>
</property>
</action>
<action name="mActionAddAmsLayer">
<action name="mActionAddAmsLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionAddAmsLayer.svg</normaloff>:/images/themes/default/mActionAddAmsLayer.svg</iconset>
@ -2526,6 +2527,21 @@ Acts on currently active editable layer</string>
<string>Add ArcGIS FeatureServer Layer</string>
</property>
</action>
<action name="mActionSelectByForm">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mIconFormSelect.svg</normaloff>:/images/themes/default/mIconFormSelect.svg</iconset>
</property>
<property name="text">
<string>Select Features by Form...</string>
</property>
<property name="toolTip">
<string>Select Features By Form</string>
</property>
<property name="shortcut">
<string>F3</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>