From fd6075e80b31bbf5d28eaa6a01e1ab1902c8db20 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Tue, 17 Dec 2019 17:10:43 +0100 Subject: [PATCH] Renamed stored expressions to user expressions --- .../qgsexpressionbuilderwidget.sip.in | 26 +++++------- .../qgsexpressionstoredialog.sip.in | 5 +-- src/app/qgsfieldcalculator.cpp | 2 +- src/gui/attributetable/qgsdualview.cpp | 2 +- src/gui/qgsexpressionbuilderdialog.cpp | 2 +- src/gui/qgsexpressionbuilderwidget.cpp | 42 +++++++++---------- src/gui/qgsexpressionbuilderwidget.h | 27 ++++++------ src/gui/qgsexpressionselectiondialog.cpp | 2 +- src/gui/qgsexpressionstoredialog.h | 4 +- .../python/test_qgsexpressionbuilderwidget.py | 6 +-- 10 files changed, 56 insertions(+), 62 deletions(-) diff --git a/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in b/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in index d66a25567ca..ae42cd0e258 100644 --- a/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in +++ b/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in @@ -227,25 +227,25 @@ Loads the recent expressions from the given ``collection``. By default it is loaded from the collection "generic". %End - void loadStored( const QString &collection = QStringLiteral( "generic" ) ); + void loadUserExpressions( const QString &collection = QStringLiteral( "generic" ) ); %Docstring -Loads the stored expressions from the given ``collection``. +Loads the user expressions from the given ``collection``. By default it is loaded from the collection "generic". .. versionadded:: 3.12 %End - void saveToStored( const QString &label, const QString expression, const QString &helpText, const QString &collection = QStringLiteral( "generic" ) ); + void saveToUserExpressions( const QString &label, const QString expression, const QString &helpText, const QString &collection = QStringLiteral( "generic" ) ); %Docstring -Stores the ``expression`` in the given ``collection`` with given ``label`` and ``helpText``. +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 removeFromStored( const QString &name, const QString &collection = QStringLiteral( "generic" ) ); + void removeFromUserExpressions( const QString &name, const QString &collection = QStringLiteral( "generic" ) ); %Docstring -Removes the expression ``name`` from the stored expressions in the given ``collection``. +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 @@ -344,17 +344,17 @@ when text changes. :param enabled: ``True`` to enable auto saving. %End - void storeCurrentExpression( ); + void storeCurrentUserExpression( ); %Docstring -Adds the current expressions to the stored expressions. +Adds the current expressions to the stored user expressions. .. versionadded:: 3.12 %End - void removeSelectedExpression( ); + void removeSelectedUserExpression( ); %Docstring -Removes the selected expression from the stored expressions, -the selected expression must be a stored expression. +Removes the selected expression from the stored user expressions, +the selected expression must be a user stored expression. .. versionadded:: 3.12 %End @@ -363,10 +363,6 @@ the selected expression must be a stored expression. %Docstring Returns the list of expression items matching a ``label``. -.. note:: - - this function is exposed for testing purposes only - .. versionadded:: 3.12 %End diff --git a/python/gui/auto_generated/qgsexpressionstoredialog.sip.in b/python/gui/auto_generated/qgsexpressionstoredialog.sip.in index b4d11f2d5c1..0a2112dc8b6 100644 --- a/python/gui/auto_generated/qgsexpressionstoredialog.sip.in +++ b/python/gui/auto_generated/qgsexpressionstoredialog.sip.in @@ -30,9 +30,8 @@ A generic dialog for editing expression text, label and help text. QWidget *parent = 0 ); %Docstring Creates a QgsExpressionStoreDialog with given ``label``, ``expression`` and ``helpText``. - -:param existingLabels: list of existing labels for unique label validation -:param parent: optional parent widget +``existingLabels`` is an optional list of existing labels for unique label validation, +``parent`` is the optional parent widget. %End QString expression( ); diff --git a/src/app/qgsfieldcalculator.cpp b/src/app/qgsfieldcalculator.cpp index 78dc2a82c7c..15332cf8441 100644 --- a/src/app/qgsfieldcalculator.cpp +++ b/src/app/qgsfieldcalculator.cpp @@ -153,7 +153,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer *vl, QWidget *parent ) mOnlyUpdateSelectedCheckBox->setText( tr( "Only update %1 selected features" ).arg( vl->selectedFeatureCount() ) ); builder->loadRecent( QStringLiteral( "fieldcalc" ) ); - builder->loadStored( QStringLiteral( "fieldcalc" ) ); + builder->loadUserExpressions( QStringLiteral( "fieldcalc" ) ); mInfoIcon->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) ); diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 9d6d36ec548..5350eaa1361 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -861,7 +861,7 @@ void QgsDualView::modifySort() expressionBuilder->setLayer( mLayer ); expressionBuilder->loadFieldNames(); expressionBuilder->loadRecent( QStringLiteral( "generic" ) ); - expressionBuilder->loadStored( QStringLiteral( "generic" ) ); + expressionBuilder->loadUserExpressions( QStringLiteral( "generic" ) ); expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() ); sortingGroupBox->layout()->addWidget( expressionBuilder ); diff --git a/src/gui/qgsexpressionbuilderdialog.cpp b/src/gui/qgsexpressionbuilderdialog.cpp index c44bb55db2e..8006877f0e6 100644 --- a/src/gui/qgsexpressionbuilderdialog.cpp +++ b/src/gui/qgsexpressionbuilderdialog.cpp @@ -33,7 +33,7 @@ QgsExpressionBuilderDialog::QgsExpressionBuilderDialog( QgsVectorLayer *layer, c builder->setExpressionText( startText ); builder->loadFieldNames(); builder->loadRecent( mRecentKey ); - builder->loadStored( mRecentKey ); + builder->loadUserExpressions( mRecentKey ); connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsExpressionBuilderDialog::showHelp ); } diff --git a/src/gui/qgsexpressionbuilderwidget.cpp b/src/gui/qgsexpressionbuilderwidget.cpp index 97b33ed60e4..bdfb21c0247 100644 --- a/src/gui/qgsexpressionbuilderwidget.cpp +++ b/src/gui/qgsexpressionbuilderwidget.cpp @@ -60,8 +60,8 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent ) connect( txtSearchEdit, &QgsFilterLineEdit::textChanged, this, &QgsExpressionBuilderWidget::txtSearchEdit_textChanged ); connect( lblPreview, &QLabel::linkActivated, this, &QgsExpressionBuilderWidget::lblPreview_linkActivated ); connect( mValuesListView, &QListView::doubleClicked, this, &QgsExpressionBuilderWidget::mValuesListView_doubleClicked ); - connect( btnSaveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::storeCurrentExpression ); - connect( btnRemoveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::removeSelectedExpression ); + connect( btnSaveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::storeCurrentUserExpression ); + connect( btnRemoveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::removeSelectedUserExpression ); connect( btnClearEditor, &QPushButton::pressed, txtExpressionString, &QgsCodeEditorExpression::clear ); txtHelpText->setOpenExternalLinks( true ); @@ -262,7 +262,7 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const txtHelpText->setText( help ); btnRemoveExpression->setEnabled( item->parent() && - item->parent()->text() == mStoredGroupName ); + item->parent()->text() == mUserExpressionsGroupName ); } @@ -286,7 +286,7 @@ void QgsExpressionBuilderWidget::runPythonCode( const QString &code ) updateFunctionTree(); loadFieldNames(); loadRecent( mRecentKey ); - loadStored( mRecentKey ); + loadUserExpressions( mRecentKey ); } void QgsExpressionBuilderWidget::saveFunctionFile( QString fileName ) @@ -606,15 +606,15 @@ void QgsExpressionBuilderWidget::loadRecent( const QString &collection ) } } -void QgsExpressionBuilderWidget::loadStored( const QString &collection ) +void QgsExpressionBuilderWidget::loadUserExpressions( const QString &collection ) { mRecentKey = collection; - mStoredGroupName = tr( "Stored (%1)" ).arg( collection ); + mUserExpressionsGroupName = tr( "User expressions (%1)" ).arg( collection ); // Cleanup - if ( mExpressionGroups.contains( mStoredGroupName ) ) + if ( mExpressionGroups.contains( mUserExpressionsGroupName ) ) { - QgsExpressionItem *node = mExpressionGroups.value( mStoredGroupName ); + QgsExpressionItem *node = mExpressionGroups.value( mUserExpressionsGroupName ); node->removeRows( 0, node->rowCount() ); } @@ -625,18 +625,18 @@ void QgsExpressionBuilderWidget::loadStored( const QString &collection ) QString helpText; QString expression; int i = 0; - mStoredLabels = settings.childGroups(); - for ( const auto &label : qgis::as_const( mStoredLabels ) ) + mUserExpressionLabels = settings.childGroups(); + for ( const auto &label : qgis::as_const( mUserExpressionLabels ) ) { settings.beginGroup( label ); expression = settings.value( QStringLiteral( "expression" ) ).toString(); helpText = settings.value( QStringLiteral( "helpText" ) ).toString(); - this->registerItem( mStoredGroupName, label, expression, helpText, QgsExpressionItem::ExpressionNode, false, i++ ); + this->registerItem( mUserExpressionsGroupName, label, expression, helpText, QgsExpressionItem::ExpressionNode, false, i++ ); settings.endGroup(); } } -void QgsExpressionBuilderWidget::saveToStored( const QString &label, const QString expression, const QString &helpText, const QString &collection ) +void QgsExpressionBuilderWidget::saveToUserExpressions( const QString &label, const QString expression, const QString &helpText, const QString &collection ) { QgsSettings settings; const QString location = QStringLiteral( "/expressions/stored/%1" ).arg( collection ); @@ -644,7 +644,7 @@ void QgsExpressionBuilderWidget::saveToStored( const QString &label, const QStri settings.beginGroup( label ); settings.setValue( QStringLiteral( "expression" ), expression ); settings.setValue( QStringLiteral( "helpText" ), helpText ); - loadStored( collection ); + loadUserExpressions( collection ); // Scroll const QModelIndexList idxs { expressionTree->model()->match( expressionTree->model()->index( 0, 0 ), Qt::DisplayRole, label, 1, @@ -655,13 +655,13 @@ void QgsExpressionBuilderWidget::saveToStored( const QString &label, const QStri } } -void QgsExpressionBuilderWidget::removeFromStored( const QString &name, const QString &collection ) +void QgsExpressionBuilderWidget::removeFromUserExpressions( const QString &name, const QString &collection ) { QgsSettings settings; QString location = QStringLiteral( "/expressions/stored/%1" ).arg( collection ); settings.beginGroup( location, QgsSettings::Section::Gui ); settings.remove( name ); - this->loadStored( collection ); + this->loadUserExpressions( collection ); } void QgsExpressionBuilderWidget::loadLayers() @@ -1226,17 +1226,17 @@ void QgsExpressionBuilderWidget::autosave() anim->start( QAbstractAnimation::DeleteWhenStopped ); } -void QgsExpressionBuilderWidget::storeCurrentExpression() +void QgsExpressionBuilderWidget::storeCurrentUserExpression() { const QString expression { this->expressionText() }; - QgsExpressionStoreDialog dlg { expression, expression, QString( ), mStoredLabels }; + QgsExpressionStoreDialog dlg { expression, expression, QString( ), mUserExpressionLabels }; if ( dlg.exec() == QDialog::DialogCode::Accepted ) { - saveToStored( dlg.label(), dlg.expression(), dlg.helpText(), mRecentKey ); + saveToUserExpressions( dlg.label(), dlg.expression(), dlg.helpText(), mRecentKey ); } } -void QgsExpressionBuilderWidget::removeSelectedExpression() +void QgsExpressionBuilderWidget::removeSelectedUserExpression() { // Get the item @@ -1248,14 +1248,14 @@ void QgsExpressionBuilderWidget::removeSelectedExpression() // Don't handle remove if we are on a header node or the parent // is not the stored group if ( item->getItemType() == QgsExpressionItem::Header || - ( item->parent() && item->parent()->text() != mStoredGroupName ) ) + ( item->parent() && item->parent()->text() != mUserExpressionsGroupName ) ) return; if ( QMessageBox::Yes == QMessageBox::question( this, tr( "Remove Stored Expression" ), tr( "Do you really want to remove stored expressions '%1'?" ).arg( item->text() ), QMessageBox::Yes | QMessageBox::No ) ) { - removeFromStored( item->text(), mRecentKey ); + removeFromUserExpressions( item->text(), mRecentKey ); } } diff --git a/src/gui/qgsexpressionbuilderwidget.h b/src/gui/qgsexpressionbuilderwidget.h index 9e31c12d9f6..ef2e666b5d8 100644 --- a/src/gui/qgsexpressionbuilderwidget.h +++ b/src/gui/qgsexpressionbuilderwidget.h @@ -237,25 +237,25 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp void loadRecent( const QString &collection = QStringLiteral( "generic" ) ); /** - * Loads the stored expressions from the given \a collection. + * Loads the user expressions from the given \a collection. * By default it is loaded from the collection "generic". * \since QGIS 3.12 */ - void loadStored( const QString &collection = QStringLiteral( "generic" ) ); + void loadUserExpressions( const QString &collection = QStringLiteral( "generic" ) ); /** - * Stores the \a expression in the given \a collection with given \a label and \a helpText. + * Stores the user \a expression in the given \a collection with given \a label and \a helpText. * By default it is saved to the collection "generic". * \since QGIS 3.12 */ - void saveToStored( const QString &label, const QString expression, const QString &helpText, const QString &collection = QStringLiteral( "generic" ) ); + void saveToUserExpressions( const QString &label, const QString expression, const QString &helpText, const QString &collection = QStringLiteral( "generic" ) ); /** - * Removes the expression \a name from the stored expressions in the given \a collection. + * Removes the expression \a name from the user stored expressions in the given \a collection. * By default it is removed from the collection "generic". * \since QGIS 3.12 */ - void removeFromStored( const QString &name, const QString &collection = QStringLiteral( "generic" ) ); + void removeFromUserExpressions( const QString &name, const QString &collection = QStringLiteral( "generic" ) ); /** * Create a new file in the function editor @@ -345,21 +345,20 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp void setAutoSave( bool enabled ) { mAutoSave = enabled; } /** - * Adds the current expressions to the stored expressions. + * Adds the current expressions to the stored user expressions. * \since QGIS 3.12 */ - void storeCurrentExpression( ); + void storeCurrentUserExpression( ); /** - * Removes the selected expression from the stored expressions, - * the selected expression must be a stored expression. + * Removes the selected expression from the stored user expressions, + * the selected expression must be a user stored expression. * \since QGIS 3.12 */ - void removeSelectedExpression( ); + void removeSelectedUserExpression( ); /** * Returns the list of expression items matching a \a label. - * \note this function is exposed for testing purposes only * \since QGIS 3.12 */ const QList findExpressions( const QString &label ); @@ -497,8 +496,8 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp QPointer< QgsProject > mProject; bool mEvalError = true; bool mParserError = true; - QString mStoredGroupName; - QStringList mStoredLabels; + QString mUserExpressionsGroupName; + QStringList mUserExpressionLabels; }; // clazy:excludeall=qstring-allocations diff --git a/src/gui/qgsexpressionselectiondialog.cpp b/src/gui/qgsexpressionselectiondialog.cpp index d14ff39c141..186abcb7773 100644 --- a/src/gui/qgsexpressionselectiondialog.cpp +++ b/src/gui/qgsexpressionselectiondialog.cpp @@ -59,7 +59,7 @@ QgsExpressionSelectionDialog::QgsExpressionSelectionDialog( QgsVectorLayer *laye mExpressionBuilder->setExpressionText( startText ); mExpressionBuilder->loadFieldNames(); mExpressionBuilder->loadRecent( QStringLiteral( "Selection" ) ); - mExpressionBuilder->loadStored( QStringLiteral( "Selection" ) ); + mExpressionBuilder->loadUserExpressions( QStringLiteral( "Selection" ) ); QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) ); mExpressionBuilder->setExpressionContext( context ); diff --git a/src/gui/qgsexpressionstoredialog.h b/src/gui/qgsexpressionstoredialog.h index 738ff9991d2..3d210640fe5 100644 --- a/src/gui/qgsexpressionstoredialog.h +++ b/src/gui/qgsexpressionstoredialog.h @@ -33,8 +33,8 @@ class GUI_EXPORT QgsExpressionStoreDialog : public QDialog, private Ui::QgsExpre /** * Creates a QgsExpressionStoreDialog with given \a label, \a expression and \a helpText. - * \param existingLabels list of existing labels for unique label validation - * \param parent optional parent widget + * \a existingLabels is an optional list of existing labels for unique label validation, + * \a parent is the optional parent widget. */ QgsExpressionStoreDialog( const QString &label, const QString &expression, diff --git a/tests/src/python/test_qgsexpressionbuilderwidget.py b/tests/src/python/test_qgsexpressionbuilderwidget.py index 2f05355ad31..90e97c6f152 100644 --- a/tests/src/python/test_qgsexpressionbuilderwidget.py +++ b/tests/src/python/test_qgsexpressionbuilderwidget.py @@ -169,14 +169,14 @@ class TestQgsExpressionBuilderWidget(unittest.TestCase): w = QgsExpressionBuilderWidget() - w.saveToStored('Stored Expression Number One', '"field_one" = 123', "An humble expression", "my_custom_collection") + w.saveToUserExpressions('Stored Expression Number One', '"field_one" = 123', "An humble expression", "my_custom_collection") items = w.findExpressions('Stored Expression Number One') self.assertEqual(len(items), 1) exp = items[0] self.assertEqual(exp.getExpressionText(), '"field_one" = 123') # Add another one with the same name (overwrite) - w.saveToStored('Stored Expression Number One', '"field_two" = 456', "An even more humble expression", "my_custom_collection") + w.saveToUserExpressions('Stored Expression Number One', '"field_two" = 456', "An even more humble expression", "my_custom_collection") items = w.findExpressions('Stored Expression Number One') self.assertEqual(len(items), 1) exp = items[0] @@ -187,7 +187,7 @@ class TestQgsExpressionBuilderWidget(unittest.TestCase): self.assertEqual(exp.getExpressionText(), '"field_two" = 456') # Test removal - w.removeFromStored('Stored Expression Number One', "my_custom_collection") + w.removeFromUserExpressions('Stored Expression Number One', "my_custom_collection") items = w.findExpressions('Stored Expression Number One') self.assertEqual(len(items), 0)