QGIS API Documentation  2.99.0-Master (6a61179)
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 #include "qgsvectorlayer.h"
20 
21 #include <QSettings>
22 
23 QgsExpressionSelectionDialog::QgsExpressionSelectionDialog( QgsVectorLayer* layer, const QString& startText, QWidget* parent )
24  : QDialog( parent )
25  , mLayer( layer )
26 {
27  setupUi( this );
28 
29  setWindowTitle( QStringLiteral( "Select by expression - %1" ).arg( layer->name() ) );
30 
31  mActionSelect->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconExpressionSelect.svg" ) ) );
32  mActionAddToSelection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconSelectAdd.svg" ) ) );
33  mActionRemoveFromSelection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconSelectRemove.svg" ) ) );
34  mActionSelectIntersect->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconSelectIntersect.svg" ) ) );
35 
36  mButtonSelect->addAction( mActionSelect );
37  mButtonSelect->addAction( mActionAddToSelection );
38  mButtonSelect->addAction( mActionRemoveFromSelection );
39  mButtonSelect->addAction( mActionSelectIntersect );
40  mButtonSelect->setDefaultAction( mActionSelect );
41 
42  mExpressionBuilder->setLayer( layer );
43  mExpressionBuilder->setExpressionText( startText );
44  mExpressionBuilder->loadFieldNames();
45  mExpressionBuilder->loadRecent( QStringLiteral( "Selection" ) );
46 
47  QgsExpressionContext context;
51  mExpressionBuilder->setExpressionContext( context );
52 
53  QSettings settings;
54  restoreGeometry( settings.value( QStringLiteral( "/Windows/ExpressionSelectionDialog/geometry" ) ).toByteArray() );
55 }
56 
58 {
59  return mExpressionBuilder;
60 }
61 
63 {
64  mExpressionBuilder->setExpressionText( text );
65 }
66 
68 {
69  return mExpressionBuilder->expressionText();
70 }
71 
73 {
74  // Store in child widget only.
75  mExpressionBuilder->setGeomCalculator( da );
76 }
77 
79 {
80  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
82  saveRecent();
83 }
84 
86 {
87  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
89  saveRecent();
90 }
91 
93 {
94  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
96  saveRecent();
97 }
98 
100 {
101  mLayer->selectByExpression( mExpressionBuilder->expressionText(),
103  saveRecent();
104 }
105 
107 {
108  QDialog::closeEvent( closeEvent );
109 
110  QSettings settings;
111  settings.setValue( QStringLiteral( "/Windows/ExpressionSelectionDialog/geometry" ), saveGeometry() );
112 }
113 
115 {
116  close();
117 }
118 
120 {
121  QDialog::done( r );
122  close();
123 }
124 
125 void QgsExpressionSelectionDialog::saveRecent()
126 {
127  mExpressionBuilder->saveToRecent( QStringLiteral( "Selection" ) );
128 }
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.
Set selection, removing any existing selection.
void selectByExpression(const QString &expression, SelectBehaviour behaviour=SetSelection)
Select matching features using an expression.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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.
Remove from current selection.
QString name
Read property of QString layerName.
Definition: qgsmaplayer.h:53
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.