Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #33437 from elpaso/stored-expressions
[feature] Stored expressions
  • Loading branch information
elpaso committed Dec 17, 2019
2 parents 6d156d4 + fd6075e commit 89cacd7
Show file tree
Hide file tree
Showing 15 changed files with 804 additions and 198 deletions.
53 changes: 50 additions & 3 deletions python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in
Expand Up @@ -220,14 +220,38 @@ Registers a node item for the expression builder.

void saveToRecent( const QString &collection = "generic" );
%Docstring
Adds the current expression to the given collection.
Adds the current expression to the given ``collection``.
By default it is saved to the collection "generic".
%End

void loadRecent( const QString &collection = "generic" );
void loadRecent( const QString &collection = QStringLiteral( "generic" ) );
%Docstring
Loads the recent expressions from the given collection.
Loads the recent expressions from the given ``collection``.
By default it is loaded from the collection "generic".
%End

void loadUserExpressions( const QString &collection = QStringLiteral( "generic" ) );
%Docstring
Loads the user expressions from the given ``collection``.
By default it is loaded from the collection "generic".

.. versionadded:: 3.12
%End

void saveToUserExpressions( const QString &label, const QString expression, const QString &helpText, const QString &collection = QStringLiteral( "generic" ) );
%Docstring
Stores the user ``expression`` in the given ``collection`` with given ``label`` and ``helpText``.
By default it is saved to the collection "generic".

.. versionadded:: 3.12
%End

void removeFromUserExpressions( const QString &name, const QString &collection = QStringLiteral( "generic" ) );
%Docstring
Removes the expression ``name`` from the user stored expressions in the given ``collection``.
By default it is removed from the collection "generic".

.. versionadded:: 3.12
%End

void newFunctionFile( const QString &fileName = "scratch" );
Expand Down Expand Up @@ -323,6 +347,29 @@ when text changes.
:param enabled: ``True`` to enable auto saving.
%End

void storeCurrentUserExpression( );
%Docstring
Adds the current expressions to the stored user expressions.

.. versionadded:: 3.12
%End

void removeSelectedUserExpression( );
%Docstring
Removes the selected expression from the stored user expressions,
the selected expression must be a user stored expression.

.. versionadded:: 3.12
%End

const QList<QgsExpressionItem *> findExpressions( const QString &label );
%Docstring
Returns the list of expression items matching a ``label``.

.. versionadded:: 3.12
%End


signals:

void expressionParsed( bool isValid );
Expand Down
60 changes: 60 additions & 0 deletions python/gui/auto_generated/qgsexpressionstoredialog.sip.in
@@ -0,0 +1,60 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsexpressionstoredialog.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsExpressionStoreDialog : QDialog
{
%Docstring
A generic dialog for editing expression text, label and help text.

.. versionadded:: 3.12
%End

%TypeHeaderCode
#include "qgsexpressionstoredialog.h"
%End
public:

QgsExpressionStoreDialog( const QString &label,
const QString &expression,
const QString &helpText,
const QStringList &existingLabels,
QWidget *parent = 0 );
%Docstring
Creates a QgsExpressionStoreDialog with given ``label``, ``expression`` and ``helpText``.
``existingLabels`` is an optional list of existing labels for unique label validation,
``parent`` is the optional parent widget.
%End

QString expression( );
%Docstring
Returns the expression text
%End

QString label();
%Docstring
Returns the label text
%End

QString helpText();
%Docstring
Returns the help text
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsexpressionstoredialog.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -65,6 +65,7 @@
%Include auto_generated/qgsencodingfiledialog.sip
%Include auto_generated/qgserrordialog.sip
%Include auto_generated/qgsexpressionbuilderdialog.sip
%Include auto_generated/qgsexpressionstoredialog.sip
%Include auto_generated/qgsexpressionbuilderwidget.sip
%Include auto_generated/qgsexpressionhighlighter.sip
%Include auto_generated/qgsexpressionlineedit.sip
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsfieldcalculator.cpp
Expand Up @@ -153,6 +153,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer *vl, QWidget *parent )
mOnlyUpdateSelectedCheckBox->setText( tr( "Only update %1 selected features" ).arg( vl->selectedFeatureCount() ) );

builder->loadRecent( QStringLiteral( "fieldcalc" ) );
builder->loadUserExpressions( QStringLiteral( "fieldcalc" ) );

mInfoIcon->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) );

Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -292,6 +292,7 @@ SET(QGIS_GUI_SRCS
qgsexpressionhighlighter.cpp
qgsexpressionlineedit.cpp
qgsexpressionselectiondialog.cpp
qgsexpressionstoredialog.cpp
qgsextentgroupbox.cpp
qgsexternalresourcewidget.cpp
qgsfeatureselectiondlg.cpp
Expand Down Expand Up @@ -487,6 +488,7 @@ SET(QGIS_GUI_HDRS
qgsencodingfiledialog.h
qgserrordialog.h
qgsexpressionbuilderdialog.h
qgsexpressionstoredialog.h
qgsexpressionbuilderwidget.h
qgsexpressionhighlighter.h
qgsexpressionlineedit.h
Expand Down Expand Up @@ -919,6 +921,7 @@ SET(QGIS_GUI_UI_HDRS
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgscredentialdialog.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilderdialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionstoredialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilder.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionselectiondialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsfeaturefilterwidget.h
Expand Down
1 change: 1 addition & 0 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -861,6 +861,7 @@ void QgsDualView::modifySort()
expressionBuilder->setLayer( mLayer );
expressionBuilder->loadFieldNames();
expressionBuilder->loadRecent( QStringLiteral( "generic" ) );
expressionBuilder->loadUserExpressions( QStringLiteral( "generic" ) );
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );

sortingGroupBox->layout()->addWidget( expressionBuilder );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsexpressionbuilderdialog.cpp
Expand Up @@ -33,6 +33,7 @@ QgsExpressionBuilderDialog::QgsExpressionBuilderDialog( QgsVectorLayer *layer, c
builder->setExpressionText( startText );
builder->loadFieldNames();
builder->loadRecent( mRecentKey );
builder->loadUserExpressions( mRecentKey );

connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsExpressionBuilderDialog::showHelp );
}
Expand Down

0 comments on commit 89cacd7

Please sign in to comment.