From 34a8c8aab8b6b0a9a04be67d68057154f62d92b1 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 15 Aug 2017 03:56:32 +1000 Subject: [PATCH 1/5] Fix exception when running alg with no parameters from toolbox --- python/plugins/processing/gui/ProcessingToolbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/plugins/processing/gui/ProcessingToolbox.py b/python/plugins/processing/gui/ProcessingToolbox.py index fb0ca4a69a0..4272f66ed90 100644 --- a/python/plugins/processing/gui/ProcessingToolbox.py +++ b/python/plugins/processing/gui/ProcessingToolbox.py @@ -299,7 +299,7 @@ class ProcessingToolbox(BASE, WIDGET): context = dataobjects.createContext(feedback) parameters = {} ret, results = execute(alg, parameters, context, feedback) - handleAlgorithmResults(alg, parameters, context, feedback) + handleAlgorithmResults(alg, context, feedback) feedback.close() if isinstance(item, TreeActionItem): action = item.action From acbba3a387797a2b64ae3f857bd2648e3ddcdfd1 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 15 Aug 2017 16:59:16 +1000 Subject: [PATCH 2/5] Fix excepthook handling in standalone scripts --- python/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/utils.py b/python/utils.py index 241af1ed48e..04bcd0e9331 100644 --- a/python/utils.py +++ b/python/utils.py @@ -30,7 +30,7 @@ QGIS utilities module from qgis.PyQt.QtCore import QCoreApplication, QLocale, QThread from qgis.PyQt.QtWidgets import QPushButton, QApplication -from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes, QgsApplication +from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes from qgis.gui import QgsMessageBar import sys @@ -133,7 +133,7 @@ def show_message_log(pop_error=True): def open_stack_dialog(type, value, tb, msg, pop_error=True): - if pop_error: + if pop_error and iface is not None: iface.messageBar().popWidget() if msg is None: @@ -189,7 +189,7 @@ def open_stack_dialog(type, value, tb, msg, pop_error=True): def qgis_excepthook(type, value, tb): # detect if running in the main thread - in_main_thread = QThread.currentThread() == QgsApplication.instance().thread() + in_main_thread = QCoreApplication.instance() is None or QThread.currentThread() == QCoreApplication.instance().thread() # only use messagebar if running in main thread - otherwise it will crash! showException(type, value, tb, None, messagebar=in_main_thread) From 92e481e7c3fc8cb8e1e10d48f10ba171cfbc8051 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 22 Aug 2017 17:01:26 +1000 Subject: [PATCH 3/5] Fix creation of SAGA tests --- src/core/processing/qgsprocessingparameters.cpp | 4 ++-- tests/src/core/testqgsprocessing.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index ad0e645c36a..ed0621ca2f3 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -3071,11 +3071,11 @@ QString QgsProcessingParameterFileDestination::valueAsPythonString( const QVaria QgsProcessingOutputLayerDefinition fromVar = qvariant_cast( value ); if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty ) { - return QStringLiteral( "QgsProcessingOutputLayerDefinition('%1')" ).arg( fromVar.sink.staticValue().toString() ); + return QStringLiteral( "'%1'" ).arg( fromVar.sink.staticValue().toString() ); } else { - return QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('%1'))" ).arg( fromVar.sink.asExpression() ); + return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() ); } } diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index 360ca3391fd..9bf263e0e8a 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -3719,9 +3719,9 @@ void TestQgsProcessing::parameterVectorOut() QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp", &context ) ); QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromValue( "abc" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('\"abc\" || \"def\"'))" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "'abc'" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromValue( "abc" ) ) ), context ), QStringLiteral( "'abc'" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"abc\" || \"def\"')" ) ); QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); QCOMPARE( def->defaultFileExtension(), QStringLiteral( "shp" ) ); From f60d8885c90f3b21b6858244545ccffcffee1f16 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Wed, 13 Sep 2017 12:47:25 +0300 Subject: [PATCH 4/5] [processing] more fixes for tests creation --- src/core/processing/qgsprocessingparameters.cpp | 8 ++++---- tests/src/core/testqgsprocessing.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index ed0621ca2f3..634b8a43bb1 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -2993,11 +2993,11 @@ QString QgsProcessingParameterRasterDestination::valueAsPythonString( const QVar QgsProcessingOutputLayerDefinition fromVar = qvariant_cast( value ); if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty ) { - return QStringLiteral( "QgsProcessingOutputLayerDefinition('%1')" ).arg( fromVar.sink.staticValue().toString() ); + return QStringLiteral( "'%1'" ).arg( fromVar.sink.staticValue().toString() ); } else { - return QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('%1'))" ).arg( fromVar.sink.asExpression() ); + return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() ); } } @@ -3260,11 +3260,11 @@ QString QgsProcessingParameterVectorDestination::valueAsPythonString( const QVar QgsProcessingOutputLayerDefinition fromVar = qvariant_cast( value ); if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty ) { - return QStringLiteral( "QgsProcessingOutputLayerDefinition('%1')" ).arg( fromVar.sink.staticValue().toString() ); + return QStringLiteral( "'%1'" ).arg( fromVar.sink.staticValue().toString() ); } else { - return QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('%1'))" ).arg( fromVar.sink.asExpression() ); + return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() ); } } diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index 9bf263e0e8a..0279d49fa24 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -3830,9 +3830,9 @@ void TestQgsProcessing::parameterRasterOut() QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "test.tif" ) ); QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromValue( "abc" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('\"abc\" || \"def\"'))" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "'abc'" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromValue( "abc" ) ) ), context ), QStringLiteral( "'abc'" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"abc\" || \"def\"')" ) ); QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); QVariantMap map = def->toVariantMap(); @@ -3948,9 +3948,9 @@ void TestQgsProcessing::parameterFileOut() QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ), QStringLiteral( "test.txt" ) ); QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromValue( "abc" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition('abc')" ) ); - QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('\"abc\" || \"def\"'))" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( "abc" ) ), context ), QStringLiteral( "'abc'" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromValue( "abc" ) ) ), context ), QStringLiteral( "'abc'" ) ); + QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"abc\" || \"def\"')" ) ); QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); QVariantMap map = def->toVariantMap(); From afac940d37a8e568afe460a6fa6b3e27813d0d9f Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Wed, 13 Sep 2017 17:57:41 +0300 Subject: [PATCH 5/5] [processing] add band parameter support in test generator --- python/plugins/processing/gui/TestTools.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/plugins/processing/gui/TestTools.py b/python/plugins/processing/gui/TestTools.py index 720643b1c81..894e12228ec 100644 --- a/python/plugins/processing/gui/TestTools.py +++ b/python/plugins/processing/gui/TestTools.py @@ -44,6 +44,7 @@ from qgis.core import (QgsApplication, QgsProcessingParameterBoolean, QgsProcessingParameterNumber, QgsProcessingParameterFile, + QgsProcessingParameterBand, QgsProcessingParameterString, QgsProcessingParameterVectorLayer, QgsProcessingParameterFeatureSource, @@ -234,6 +235,8 @@ def createTest(text): params[param.name()] = [int(t) for t in token] else: params[param.name()] = int(token) + elif isinstance(param, QgsProcessingParameterBand): + params[param.name()] = int(token) elif token: if token[0] == '"': token = token[1:]