From ae97c333d693d3e85cb92d2dfbb50abbb44b0e36 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 15 May 2017 10:24:38 +1000 Subject: [PATCH] Revert "Port algorithm countVisibleParameters to c++" This reverts commit c3c694f8ccfbe0b64df14365f950f5895968a66a. --- python/core/processing/qgsprocessingalgorithm.sip | 7 ------- python/plugins/processing/core/GeoAlgorithm.py | 9 +++++++++ python/plugins/processing/core/Processing.py | 2 +- python/plugins/processing/gui/BatchPanel.py | 2 +- python/plugins/processing/gui/ProcessingToolbox.py | 2 +- python/plugins/processing/gui/menus.py | 2 +- src/core/processing/qgsprocessingalgorithm.cpp | 11 ----------- src/core/processing/qgsprocessingalgorithm.h | 6 ------ tests/src/core/testqgsprocessing.cpp | 9 --------- 9 files changed, 13 insertions(+), 37 deletions(-) diff --git a/python/core/processing/qgsprocessingalgorithm.sip b/python/core/processing/qgsprocessingalgorithm.sip index 24af9ec107d..5e7896d1ca6 100644 --- a/python/core/processing/qgsprocessingalgorithm.sip +++ b/python/core/processing/qgsprocessingalgorithm.sip @@ -128,13 +128,6 @@ class QgsProcessingAlgorithm :rtype: QgsProcessingParameterDefinition %End - int countVisibleParameters() const; -%Docstring - Returns the number of visible (non-hidden) parameters defined by this - algorithm. - :rtype: int -%End - virtual QVariantMap run( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const; %Docstring diff --git a/python/plugins/processing/core/GeoAlgorithm.py b/python/plugins/processing/core/GeoAlgorithm.py index 02165f1764f..31a04303478 100755 --- a/python/plugins/processing/core/GeoAlgorithm.py +++ b/python/plugins/processing/core/GeoAlgorithm.py @@ -430,6 +430,15 @@ class GeoAlgorithm(QgsProcessingAlgorithm): i += 1 return i + def getVisibleParametersCount(self): + """Returns the number of non-hidden parameters. + """ + i = 0 + for param in self.parameters: + if not param.hidden: + i += 1 + return i + def getHTMLOutputsCount(self): """Returns the number of HTML outputs. """ diff --git a/python/plugins/processing/core/Processing.py b/python/plugins/processing/core/Processing.py index 3dcf0a3dc9e..6d4efc8a5c8 100755 --- a/python/plugins/processing/core/Processing.py +++ b/python/plugins/processing/core/Processing.py @@ -170,7 +170,7 @@ class Processing(object): Processing.tr("Processing")) return else: - if len(args) != alg.countVisibleParameters() + alg.getVisibleOutputsCount(): + if len(args) != alg.getVisibleParametersCount() + alg.getVisibleOutputsCount(): # fix_print_with_import print('Error: Wrong number of parameters') QgsMessageLog.logMessage(Processing.tr('Error: Wrong number of parameters'), diff --git a/python/plugins/processing/gui/BatchPanel.py b/python/plugins/processing/gui/BatchPanel.py index 2de1d910f88..c293eec8990 100644 --- a/python/plugins/processing/gui/BatchPanel.py +++ b/python/plugins/processing/gui/BatchPanel.py @@ -102,7 +102,7 @@ class BatchPanel(BASE, WIDGET): nOutputs = 0 self.tblParameters.setColumnCount( - self.alg.countVisibleParameters() + nOutputs) + self.alg.getVisibleParametersCount() + nOutputs) # Table headers column = 0 diff --git a/python/plugins/processing/gui/ProcessingToolbox.py b/python/plugins/processing/gui/ProcessingToolbox.py index 5cbde9ee24d..e2445abcbbe 100644 --- a/python/plugins/processing/gui/ProcessingToolbox.py +++ b/python/plugins/processing/gui/ProcessingToolbox.py @@ -275,7 +275,7 @@ class ProcessingToolbox(BASE, WIDGET): alg = alg.getCopy() alg.setProvider(provider) - if (alg.countVisibleParameters() + alg.getVisibleOutputsCount()) > 0: + if (alg.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0: dlg = alg.getCustomParametersDialog() if not dlg: dlg = AlgorithmDialog(alg) diff --git a/python/plugins/processing/gui/menus.py b/python/plugins/processing/gui/menus.py index 8834650989e..d5b2e067d4b 100644 --- a/python/plugins/processing/gui/menus.py +++ b/python/plugins/processing/gui/menus.py @@ -210,7 +210,7 @@ def _executeAlgorithm(alg): alg.setProvider(provider) context = dataobjects.createContext() - if (alg.countVisibleParameters() + alg.getVisibleOutputsCount()) > 0: + if (alg.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0: dlg = alg.getCustomParametersDialog() if not dlg: dlg = AlgorithmDialog(alg) diff --git a/src/core/processing/qgsprocessingalgorithm.cpp b/src/core/processing/qgsprocessingalgorithm.cpp index 9f6d7a06a5d..d02b9745acd 100644 --- a/src/core/processing/qgsprocessingalgorithm.cpp +++ b/src/core/processing/qgsprocessingalgorithm.cpp @@ -87,17 +87,6 @@ const QgsProcessingParameterDefinition *QgsProcessingAlgorithm::parameterDefinit return nullptr; } -int QgsProcessingAlgorithm::countVisibleParameters() const -{ - int count = 0; - Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters ) - { - if ( !( def->flags() & QgsProcessingParameterDefinition::FlagHidden ) ) - count++; - } - return count; -} - QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const { return QgsProcessingParameters::parameterAsString( parameterDefinition( name ), parameters, name, context ); diff --git a/src/core/processing/qgsprocessingalgorithm.h b/src/core/processing/qgsprocessingalgorithm.h index 1aea65da5a2..7283d8925b3 100644 --- a/src/core/processing/qgsprocessingalgorithm.h +++ b/src/core/processing/qgsprocessingalgorithm.h @@ -142,12 +142,6 @@ class CORE_EXPORT QgsProcessingAlgorithm */ const QgsProcessingParameterDefinition *parameterDefinition( const QString &name ) const; - /** - * Returns the number of visible (non-hidden) parameters defined by this - * algorithm. - */ - int countVisibleParameters() const; - /** * Runs the algorithm using the specified \a parameters. Algorithms should implement * their custom processing logic here. diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index debfa4f2f56..d0cc8ba2a6a 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -62,15 +62,6 @@ class DummyAlgorithm : public QgsProcessingAlgorithm // parameterDefinition should be case insensitive QCOMPARE( parameterDefinition( "P1" ), parameterDefinitions().at( 0 ) ); QVERIFY( !parameterDefinition( "invalid" ) ); - - QCOMPARE( countVisibleParameters(), 1 ); - QgsProcessingParameterBoolean *p3 = new QgsProcessingParameterBoolean( "p3" ); - QVERIFY( addParameter( p3 ) ); - QCOMPARE( countVisibleParameters(), 2 ); - QgsProcessingParameterBoolean *p4 = new QgsProcessingParameterBoolean( "p4" ); - p4->setFlags( QgsProcessingParameterDefinition::FlagHidden ); - QVERIFY( addParameter( p4 ) ); - QCOMPARE( countVisibleParameters(), 2 ); } };