Skip to content

Commit

Permalink
[needs-docs] Add shortcut to Select by Form to toolbar and menu
Browse files Browse the repository at this point in the history
Also add keyboard shortcut (F3) to open select by form
dialog
  • Loading branch information
nyalldawson committed Jun 9, 2016
1 parent ce7d79e commit fe26d33
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 3 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
148 changes: 148 additions & 0 deletions images/themes/default/mIconFormSelect.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions python/gui/qgsattributeform.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SET(QGIS_APP_SRCS
qgsrasterlayerproperties.cpp
qgsrelationmanagerdialog.cpp
qgsrelationadddlg.cpp
qgsselectbyformdialog.cpp
qgsstatisticalsummarydockwidget.cpp
qgstextannotationdialog.cpp
qgssnappingdialog.cpp
Expand Down Expand Up @@ -287,6 +288,7 @@ SET (QGIS_APP_MOC_HDRS
qgsrasterlayerproperties.h
qgsrelationmanagerdialog.h
qgsrelationadddlg.h
qgsselectbyformdialog.h
qgssnappingdialog.h
qgssponsors.h
qgsstatisticalsummarydockwidget.h
Expand Down
36 changes: 35 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
54 changes: 54 additions & 0 deletions src/app/qgsselectbyformdialog.cpp
Original file line number Diff line number Diff line change
@@ -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.