QGIS API Documentation  2.99.0-Master (a411669)
qgsexpressionbuilderdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgisexpressionbuilderdialog.h - A generic expression string builder dialog.
3  --------------------------------------
4  Date : 29-May-2011
5  Copyright : (C) 2011 by Nathan Woodrow
6  Email : woodrow.nathan at gmail dot com
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 "qgssettings.h"
18 
19 QgsExpressionBuilderDialog::QgsExpressionBuilderDialog( QgsVectorLayer *layer, const QString &startText, QWidget *parent, const QString &key, const QgsExpressionContext &context )
20  : QDialog( parent )
21  , mRecentKey( key )
22 {
23  setupUi( this );
24 
25  QPushButton *okButton = buttonBox->button( QDialogButtonBox::Ok );
26  connect( builder, &QgsExpressionBuilderWidget::expressionParsed, okButton, &QWidget::setEnabled );
27 
28  builder->setExpressionContext( context );
29  builder->setLayer( layer );
30  builder->setExpressionText( startText );
31  builder->loadFieldNames();
32  builder->loadRecent( mRecentKey );
33 
34  QgsSettings settings;
35  restoreGeometry( settings.value( QStringLiteral( "Windows/ExpressionBuilderDialog/geometry" ) ).toByteArray() );
36 
37  connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsExpressionBuilderDialog::showHelp );
38 }
39 
41 {
42  return builder;
43 }
44 
46 {
47  builder->setExpressionText( text );
48 }
49 
51 {
52  return builder->expressionText();
53 }
54 
56 {
57  return builder->expressionContext();
58 }
59 
61 {
62  builder->setExpressionContext( context );
63 }
64 
66 {
67  QDialog::done( r );
68 
69  QgsSettings settings;
70  settings.setValue( QStringLiteral( "Windows/ExpressionBuilderDialog/geometry" ), saveGeometry() );
71 }
72 
74 {
75  builder->saveToRecent( mRecentKey );
76  QDialog::accept();
77 }
78 
80 {
81  // Store in child widget only.
82  builder->setGeomCalculator( da );
83 }
84 
85 void QgsExpressionBuilderDialog::showHelp()
86 {
87  QgsHelp::openHelp( QStringLiteral( "working_with_vector/expression.html" ) );
88 }
void setExpressionText(const QString &text)
QgsExpressionBuilderDialog(QgsVectorLayer *layer, const QString &startText=QString(), QWidget *parent SIP_TRANSFERTHIS=nullptr, const QString &key="generic", const QgsExpressionContext &context=QgsExpressionContext())
This class is a composition of two QSettings instances:
Definition: qgssettings.h:55
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
QgsExpressionContext expressionContext() const
Returns the expression context for the dialog.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context for the dialog.
void setGeomCalculator(const QgsDistanceArea &da)
Sets geometry calculator used in distance/area calculations.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
A reusable widget that can be used to build a expression string.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
virtual void done(int r) override
Is called when the dialog get accepted or rejected Used to save geometry.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:34
Represents a vector layer which manages a vector based data sets.
void expressionParsed(bool isValid)
Emitted when the user changes the expression in the widget.