Skip to content

Commit 64caa4c

Browse files
committedApr 29, 2020
[processing] Only show detailed logging messages when running a model
algorithm IF the model is being run through the model designer dialog If you run it from the toolbox (or as a sub-component in another model) then skip all the additional verbose debugging information that normally gets logged. This avoids a whole lot of unnecessary log noise when running models, unless you're actively working on changing the model.
1 parent 69e841a commit 64caa4c

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed
 

‎src/core/processing/models/qgsprocessingmodelalgorithm.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ QgsProcessingModelAlgorithm::QgsProcessingModelAlgorithm( const QString &name, c
4242

4343
void QgsProcessingModelAlgorithm::initAlgorithm( const QVariantMap & )
4444
{
45+
std::unique_ptr< QgsProcessingParameterBoolean > verboseLog = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( "VERBOSE_LOG" ), QObject::tr( "Verbose logging" ), false, true );
46+
verboseLog->setFlags( verboseLog->flags() | QgsProcessingParameterDefinition::FlagHidden );
47+
addParameter( verboseLog.release() );
4548
}
4649

4750
QString QgsProcessingModelAlgorithm::name() const
@@ -276,6 +279,8 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
276279
QVariantMap childResults;
277280
QVariantMap childInputs;
278281

282+
const bool verboseLog = parameterAsBool( parameters, QStringLiteral( "VERBOSE_LOG" ), context );
283+
279284
QVariantMap finalResults;
280285
QSet< QString > executed;
281286
bool executedAlg = true;
@@ -309,7 +314,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
309314
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms[ childId ];
310315
std::unique_ptr< QgsProcessingAlgorithm > childAlg( child.algorithm()->create( child.configuration() ) );
311316

312-
const bool skipGenericLogging = childAlg->flags() & QgsProcessingAlgorithm::FlagSkipGenericModelLogging;
317+
const bool skipGenericLogging = !verboseLog || childAlg->flags() & QgsProcessingAlgorithm::FlagSkipGenericModelLogging;
313318
if ( feedback && !skipGenericLogging )
314319
feedback->pushDebugInfo( QObject::tr( "Prepare algorithm: %1" ).arg( childId ) );
315320

@@ -1904,5 +1909,13 @@ void QgsProcessingModelAlgorithm::setVariables( const QVariantMap &variables )
19041909
mVariables = variables;
19051910
}
19061911

1912+
QVariantMap QgsProcessingModelAlgorithm::designerParameterValues() const
1913+
{
1914+
QVariantMap res = mDesignerParameterValues;
1915+
// when running through the designer, we show a detailed verbose log to aid in model debugging
1916+
res.insert( QStringLiteral( "VERBOSE_LOG" ), true );
1917+
return res;
1918+
}
1919+
19071920
///@endcond
19081921

‎src/core/processing/models/qgsprocessingmodelalgorithm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
489489
*
490490
* \since QGIS 3.14
491491
*/
492-
QVariantMap designerParameterValues() const { return mDesignerParameterValues; }
492+
QVariantMap designerParameterValues() const;
493493

494494
/**
495495
* Sets the parameter \a values to use as default values when running this model through the

‎tests/src/analysis/testqgsprocessing.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8596,6 +8596,9 @@ void TestQgsProcessing::modelerAlgorithm()
85968596
lastParams.insert( QStringLiteral( "a" ), 2 );
85978597
lastParams.insert( QStringLiteral( "b" ), 4 );
85988598
alg.setDesignerParameterValues( lastParams );
8599+
8600+
// we expect the result to add in some custom parameters -- namely the verbose log switch
8601+
lastParams.insert( QStringLiteral( "VERBOSE_LOG" ), true );
85998602
QCOMPARE( alg.designerParameterValues(), lastParams );
86008603

86018604
// child algorithms

‎tests/src/gui/testprocessinggui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ void TestProcessingGui::testModelUndo()
355355
// the last used parameter values setting should not be affected by undo stack changes
356356
QVariantMap params;
357357
params.insert( QStringLiteral( "a" ), 1 );
358+
params.insert( QStringLiteral( "VERBOSE_LOG" ), true );
358359
model.setDesignerParameterValues( params );
359360
command.undo();
360361
QCOMPARE( model.designerParameterValues(), params );

0 commit comments

Comments
 (0)
Please sign in to comment.