Skip to content

Commit e6d86bb

Browse files
committed
[processing] Generalise modeler multi-step feedback proxy for use
outside of modeler This can be useful too for individual algorithms
1 parent 94a1e68 commit e6d86bb

7 files changed

+168
-110
lines changed

python/core/processing/models/qgsprocessingmodelalgorithm.sip

-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ Translated description of variable
374374
};
375375

376376

377-
378-
379377
/************************************************************************
380378
* This file has been generated automatically from *
381379
* *

python/core/processing/qgsprocessingfeedback.sip

+46
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,52 @@ class QgsProcessingFeedback : QgsFeedback
8080
};
8181

8282

83+
class QgsProcessingMultiStepFeedback : QgsProcessingFeedback
84+
{
85+
%Docstring
86+
87+
Processing feedback object for multi-step operations.
88+
89+
A processing feedback object which proxies its calls to an underlying
90+
feedback object, but scales overall progress reports to account
91+
for a number of child steps which each report their own feedback.
92+
93+
.. versionadded:: 3.0
94+
%End
95+
96+
%TypeHeaderCode
97+
#include "qgsprocessingfeedback.h"
98+
%End
99+
public:
100+
101+
QgsProcessingMultiStepFeedback( int steps, QgsProcessingFeedback *feedback );
102+
%Docstring
103+
Constructor for QgsProcessingMultiStepFeedback, for a process with the specified
104+
number of ``steps``. This feedback object will proxy calls
105+
to the specified ``feedback`` object.
106+
%End
107+
108+
void setCurrentStep( int step );
109+
%Docstring
110+
Sets the ``step`` which is being executed. This is used
111+
to scale the current progress to account for progress through the overall process.
112+
%End
113+
114+
virtual void setProgressText( const QString &text );
115+
116+
virtual void reportError( const QString &error );
117+
118+
virtual void pushInfo( const QString &info );
119+
120+
virtual void pushCommandInfo( const QString &info );
121+
122+
virtual void pushDebugInfo( const QString &info );
123+
124+
virtual void pushConsoleInfo( const QString &info );
125+
126+
127+
};
128+
83129

84130

85131
/************************************************************************

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ SET(QGIS_CORE_SRCS
100100

101101
processing/qgsprocessingalgorithm.cpp
102102
processing/qgsprocessingalgrunnertask.cpp
103+
processing/qgsprocessingfeedback.cpp
103104
processing/qgsprocessingoutputs.cpp
104105
processing/qgsprocessingparameters.cpp
105106
processing/qgsprocessingprovider.cpp

src/core/processing/models/qgsprocessingmodelalgorithm.cpp

+1-61
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
213213
QTime totalTime;
214214
totalTime.start();
215215

216-
QgsProcessingModelFeedback modelFeedback( toExecute.count(), feedback );
216+
QgsProcessingMultiStepFeedback modelFeedback( toExecute.count(), feedback );
217217
QgsExpressionContext baseContext = createExpressionContext( parameters, context );
218218

219219
QVariantMap childResults;
@@ -1146,65 +1146,5 @@ QgsProcessingAlgorithm *QgsProcessingModelAlgorithm::createInstance() const
11461146
return alg;
11471147
}
11481148

1149-
1150-
1151-
1152-
//
1153-
// QgsProcessingModelFeedback
1154-
//
1155-
1156-
QgsProcessingModelFeedback::QgsProcessingModelFeedback( int childAlgorithmCount, QgsProcessingFeedback *feedback )
1157-
: mChildSteps( childAlgorithmCount )
1158-
, mFeedback( feedback )
1159-
{
1160-
connect( mFeedback, &QgsFeedback::canceled, this, &QgsFeedback::cancel, Qt::DirectConnection );
1161-
connect( this, &QgsFeedback::progressChanged, this, &QgsProcessingModelFeedback::updateOverallProgress );
1162-
}
1163-
1164-
void QgsProcessingModelFeedback::setCurrentStep( int step )
1165-
{
1166-
mCurrentStep = step;
1167-
mFeedback->setProgress( 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps );
1168-
}
1169-
1170-
void QgsProcessingModelFeedback::setProgressText( const QString &text )
1171-
{
1172-
mFeedback->setProgressText( text );
1173-
}
1174-
1175-
void QgsProcessingModelFeedback::reportError( const QString &error )
1176-
{
1177-
mFeedback->reportError( error );
1178-
}
1179-
1180-
void QgsProcessingModelFeedback::pushInfo( const QString &info )
1181-
{
1182-
mFeedback->pushInfo( info );
1183-
}
1184-
1185-
void QgsProcessingModelFeedback::pushCommandInfo( const QString &info )
1186-
{
1187-
mFeedback->pushCommandInfo( info );
1188-
}
1189-
1190-
void QgsProcessingModelFeedback::pushDebugInfo( const QString &info )
1191-
{
1192-
mFeedback->pushDebugInfo( info );
1193-
}
1194-
1195-
void QgsProcessingModelFeedback::pushConsoleInfo( const QString &info )
1196-
{
1197-
mFeedback->pushConsoleInfo( info );
1198-
}
1199-
1200-
void QgsProcessingModelFeedback::updateOverallProgress( double progress )
1201-
{
1202-
double baseProgress = 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps;
1203-
double currentAlgorithmProgress = progress / mChildSteps;
1204-
mFeedback->setProgress( baseProgress + currentAlgorithmProgress );
1205-
}
1206-
1207-
1208-
12091149
///@endcond
12101150

src/core/processing/models/qgsprocessingmodelalgorithm.h

-47
Original file line numberDiff line numberDiff line change
@@ -403,53 +403,6 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
403403
friend class TestQgsProcessing;
404404
};
405405

406-
407-
#ifndef SIP_RUN
408-
409-
/**
410-
* Model algorithm feedback which proxies its calls to an underlying
411-
* feedback object, but scales overall progress reports to account
412-
* for the number of child steps in a model.
413-
*/
414-
class QgsProcessingModelFeedback : public QgsProcessingFeedback
415-
{
416-
Q_OBJECT
417-
418-
public:
419-
420-
/**
421-
* Constructor for QgsProcessingModelFeedback, for a model with the specified
422-
* number of active child algorithms. This feedback object will proxy calls
423-
* to the specified \a feedback object.
424-
*/
425-
QgsProcessingModelFeedback( int childAlgorithmCount, QgsProcessingFeedback *feedback );
426-
427-
/**
428-
* Sets the current child algorithm \a step which is being executed. This is used
429-
* to scale the overall progress to account for progress through the overall model.
430-
*/
431-
void setCurrentStep( int step );
432-
433-
void setProgressText( const QString &text ) override;
434-
void reportError( const QString &error ) override;
435-
void pushInfo( const QString &info ) override;
436-
void pushCommandInfo( const QString &info ) override;
437-
void pushDebugInfo( const QString &info ) override;
438-
void pushConsoleInfo( const QString &info ) override;
439-
440-
private slots:
441-
442-
void updateOverallProgress( double progress );
443-
444-
private:
445-
446-
int mChildSteps = 0;
447-
int mCurrentStep = 0;
448-
QgsProcessingFeedback *mFeedback = nullptr;
449-
};
450-
451-
#endif
452-
453406
///@endcond
454407

455408
#endif // QGSPROCESSINGMODELALGORITHM_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/***************************************************************************
2+
qgsprocessingfeedback.cpp
3+
-------------------------
4+
begin : June 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsprocessingfeedback.h"
19+
20+
QgsProcessingMultiStepFeedback::QgsProcessingMultiStepFeedback( int childAlgorithmCount, QgsProcessingFeedback *feedback )
21+
: mChildSteps( childAlgorithmCount )
22+
, mFeedback( feedback )
23+
{
24+
connect( mFeedback, &QgsFeedback::canceled, this, &QgsFeedback::cancel, Qt::DirectConnection );
25+
connect( this, &QgsFeedback::progressChanged, this, &QgsProcessingMultiStepFeedback::updateOverallProgress );
26+
}
27+
28+
void QgsProcessingMultiStepFeedback::setCurrentStep( int step )
29+
{
30+
mCurrentStep = step;
31+
mFeedback->setProgress( 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps );
32+
}
33+
34+
void QgsProcessingMultiStepFeedback::setProgressText( const QString &text )
35+
{
36+
mFeedback->setProgressText( text );
37+
}
38+
39+
void QgsProcessingMultiStepFeedback::reportError( const QString &error )
40+
{
41+
mFeedback->reportError( error );
42+
}
43+
44+
void QgsProcessingMultiStepFeedback::pushInfo( const QString &info )
45+
{
46+
mFeedback->pushInfo( info );
47+
}
48+
49+
void QgsProcessingMultiStepFeedback::pushCommandInfo( const QString &info )
50+
{
51+
mFeedback->pushCommandInfo( info );
52+
}
53+
54+
void QgsProcessingMultiStepFeedback::pushDebugInfo( const QString &info )
55+
{
56+
mFeedback->pushDebugInfo( info );
57+
}
58+
59+
void QgsProcessingMultiStepFeedback::pushConsoleInfo( const QString &info )
60+
{
61+
mFeedback->pushConsoleInfo( info );
62+
}
63+
64+
void QgsProcessingMultiStepFeedback::updateOverallProgress( double progress )
65+
{
66+
double baseProgress = 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps;
67+
double currentAlgorithmProgress = progress / mChildSteps;
68+
mFeedback->setProgress( baseProgress + currentAlgorithmProgress );
69+
}
70+
71+

src/core/processing/qgsprocessingfeedback.h

+49
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,55 @@ class CORE_EXPORT QgsProcessingFeedback : public QgsFeedback
9393
};
9494

9595

96+
/**
97+
* \class QgsProcessingMultiStepFeedback
98+
* \ingroup core
99+
*
100+
* Processing feedback object for multi-step operations.
101+
*
102+
* A processing feedback object which proxies its calls to an underlying
103+
* feedback object, but scales overall progress reports to account
104+
* for a number of child steps which each report their own feedback.
105+
*
106+
* \since QGIS 3.0
107+
*/
108+
class CORE_EXPORT QgsProcessingMultiStepFeedback : public QgsProcessingFeedback
109+
{
110+
Q_OBJECT
111+
112+
public:
113+
114+
/**
115+
* Constructor for QgsProcessingMultiStepFeedback, for a process with the specified
116+
* number of \a steps. This feedback object will proxy calls
117+
* to the specified \a feedback object.
118+
*/
119+
QgsProcessingMultiStepFeedback( int steps, QgsProcessingFeedback *feedback );
120+
121+
/**
122+
* Sets the \a step which is being executed. This is used
123+
* to scale the current progress to account for progress through the overall process.
124+
*/
125+
void setCurrentStep( int step );
126+
127+
void setProgressText( const QString &text ) override;
128+
void reportError( const QString &error ) override;
129+
void pushInfo( const QString &info ) override;
130+
void pushCommandInfo( const QString &info ) override;
131+
void pushDebugInfo( const QString &info ) override;
132+
void pushConsoleInfo( const QString &info ) override;
133+
134+
private slots:
135+
136+
void updateOverallProgress( double progress );
137+
138+
private:
139+
140+
int mChildSteps = 0;
141+
int mCurrentStep = 0;
142+
QgsProcessingFeedback *mFeedback = nullptr;
143+
};
144+
96145
#endif // QGSPROCESSINGFEEDBACK_H
97146

98147

0 commit comments

Comments
 (0)