QGIS API Documentation  2.15.0-Master (972fc9f)
qgsexpressionselectiondialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgisexpressionselectiondialog.cpp
3  --------------------------------------
4  Date : 24.1.2013
5  Copyright : (C) 2013 by 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 #include "qgsapplication.h"
18 #include "qgsexpression.h"
19 
20 #include <QSettings>
21 
23  : QDialog( parent )
24  , mLayer( layer )
25 {
26  setupUi( this );
27 
28  setWindowTitle( QString( "Select by expression - %1" ).arg( layer->name() ) );
29 
30  mActionSelect->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
31  mActionAddToSelection->setIcon( QgsApplication::getThemeIcon( "/mIconSelectAdd.svg" ) );
32  mActionRemoveFromSelection->setIcon( QgsApplication::getThemeIcon( "/mIconSelectRemove.svg" ) );
33  mActionSelectIntersect->setIcon( QgsApplication::getThemeIcon( "/mIconSelectIntersect.svg" ) );
34 
35  mButtonSelect->addAction( mActionSelect );
36  mButtonSelect->addAction( mActionAddToSelection );
37  mButtonSelect->addAction( mActionRemoveFromSelection );
38  mButtonSelect->addAction( mActionSelectIntersect );
39  mButtonSelect->setDefaultAction( mActionSelect );
40 
41  mExpressionBuilder->setLayer( layer );
42  mExpressionBuilder->setExpressionText( startText );
43  mExpressionBuilder->loadFieldNames();
44  mExpressionBuilder->loadRecent( "Selection" );
45 
46  QgsExpressionContext context;
50  mExpressionBuilder->setExpressionContext( context );
51 
52  QSettings settings;
53  restoreGeometry( settings.value( "/Windows/ExpressionSelectionDialog/geometry" ).toByteArray() );
54 }
55 
57 {
58  return mExpressionBuilder;
59 }
60 
62 {
63  mExpressionBuilder->setExpressionText( text );
64 }
65 
67 {
68  return mExpressionBuilder->expressionText();
69 }
70 
72 {
73  // Store in child widget only.
74  mExpressionBuilder->setGeomCalculator( da );
75 }
76 
78 {
79  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
81  saveRecent();
82 }
83 
85 {
86  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
88  saveRecent();
89 }
90 
92 {
93  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
95  saveRecent();
96 }
97 
99 {
100  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
102  saveRecent();
103 }
104 
106 {
107  QDialog::closeEvent( closeEvent );
108 
109  QSettings settings;
110  settings.setValue( "/Windows/ExpressionSelectionDialog/geometry", saveGeometry() );
111 }
112 
114 {
115  close();
116 }
117 
119 {
120  QDialog::done( r );
121  close();
122 }
123 
124 void QgsExpressionSelectionDialog::saveRecent()
125 {
126  mExpressionBuilder->saveToRecent( "Selection" );
127 }
QByteArray toByteArray() const
bool close()
virtual void closeEvent(QCloseEvent *e)
void setupUi(QWidget *widget)
QString name() const
Get the display name of the layer.
Modify current selection to include only select features which match.
QString expressionText()
Returns the current expression text.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
QgsExpressionSelectionDialog(QgsVectorLayer *layer, const QString &startText=QString(), QWidget *parent=nullptr)
Creates a new selection dialog.
virtual void done(int r)
Set selection, removing any existing selection.
void selectByExpression(const QString &expression, SelectBehaviour behaviour=SetSelection)
Select matching features using an expression.
void setValue(const QString &key, const QVariant &value)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
bool restoreGeometry(const QByteArray &geometry)
void setGeomCalculator(const QgsDistanceArea &da)
Sets geometry calculator used in distance/area calculations.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void closeEvent(QCloseEvent *closeEvent) override
Implementation for closeEvent Saves the window geometry.
virtual void done(int r) override
Implementation for done (default behavior when pressing esc) Calls close, so the window geometry gets...
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
void setExpressionText(const QString &text)
Sets the current expression text.
General purpose distance and area calculator.
A reusable widget that can be used to build a expression string.
Add selection to current selection.
QVariant value(const QString &key, const QVariant &defaultValue) const
QByteArray saveGeometry() const
void setWindowTitle(const QString &)
Remove from current selection.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Represents a vector layer which manages a vector based data sets.