File tree 4 files changed +59
-7
lines changed
python/core/auto_generated/processing/models
src/core/processing/models
4 files changed +59
-7
lines changed Original file line number Diff line number Diff line change @@ -71,14 +71,32 @@ Returns the underlying child algorithm's ID.
71
71
.. seealso:: :py:func:`setAlgorithmId`
72
72
%End
73
73
74
- void setAlgorithmId( const QString &algorithmId );
74
+ bool setAlgorithmId( const QString &algorithmId );
75
75
%Docstring
76
76
Sets the underlying child algorithm's ID. This
77
77
should be set to an existing QgsProcessingAlgorithm algorithm ID.
78
78
79
+ Returns true if the algorithm was successfully set.
80
+
81
+ .. seealso:: :py:func:`reattach`
82
+
79
83
.. seealso:: :py:func:`algorithm`
80
84
81
85
.. seealso:: :py:func:`algorithmId`
86
+ %End
87
+
88
+ bool reattach() const;
89
+ %Docstring
90
+ Attempts to re-attach the child to the algorithm specified by ``algorithmId``().
91
+
92
+ This can be run to relink the child to algorithms from providers which were not
93
+ originally available for the model to link to.
94
+
95
+ Returns true if the algorithm was successfully reattached.
96
+
97
+ .. seealso:: :py:func:`algorithm`
98
+
99
+ .. seealso:: :py:func:`setAlgorithmId`
82
100
%End
83
101
84
102
QVariantMap configuration() const;
@@ -110,6 +128,8 @@ to adjust their behavior at run time according to some user configuration.
110
128
Returns the underlying child algorithm, or a None
111
129
if a matching algorithm is not available.
112
130
131
+ .. seealso:: :py:func:`reattach`
132
+
113
133
.. seealso:: :py:func:`algorithmId`
114
134
%End
115
135
Original file line number Diff line number Diff line change @@ -222,10 +222,16 @@ void QgsProcessingModelChildAlgorithm::generateChildId( const QgsProcessingModel
222
222
mId = id;
223
223
}
224
224
225
- void QgsProcessingModelChildAlgorithm::setAlgorithmId ( const QString &algorithmId )
225
+ bool QgsProcessingModelChildAlgorithm::setAlgorithmId ( const QString &algorithmId )
226
226
{
227
227
mAlgorithmId = algorithmId;
228
228
mAlgorithm .reset ( QgsApplication::processingRegistry ()->createAlgorithmById ( mAlgorithmId , mConfiguration ) );
229
+ return static_cast < bool >( mAlgorithm .get () );
230
+ }
231
+
232
+ bool QgsProcessingModelChildAlgorithm::reattach () const
233
+ {
234
+ return const_cast < QgsProcessingModelChildAlgorithm * >( this )->setAlgorithmId ( mAlgorithmId );
229
235
}
230
236
231
237
// /@endcond
Original file line number Diff line number Diff line change @@ -82,10 +82,27 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo
82
82
/* *
83
83
* Sets the underlying child algorithm's ID. This
84
84
* should be set to an existing QgsProcessingAlgorithm algorithm ID.
85
+ *
86
+ * Returns true if the algorithm was successfully set.
87
+ *
88
+ * \see reattach()
85
89
* \see algorithm()
86
90
* \see algorithmId()
87
91
*/
88
- void setAlgorithmId ( const QString &algorithmId );
92
+ bool setAlgorithmId ( const QString &algorithmId );
93
+
94
+ /* *
95
+ * Attempts to re-attach the child to the algorithm specified by \a algorithmId().
96
+ *
97
+ * This can be run to relink the child to algorithms from providers which were not
98
+ * originally available for the model to link to.
99
+ *
100
+ * Returns true if the algorithm was successfully reattached.
101
+ *
102
+ * \see algorithm()
103
+ * \see setAlgorithmId()
104
+ */
105
+ bool reattach () const ;
89
106
90
107
/* *
91
108
* Returns the child algorithm's configuration map.
@@ -114,6 +131,7 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo
114
131
/* *
115
132
* Returns the underlying child algorithm, or a nullptr
116
133
* if a matching algorithm is not available.
134
+ * \see reattach()
117
135
* \see algorithmId()
118
136
*/
119
137
const QgsProcessingAlgorithm *algorithm () const ;
@@ -289,6 +307,8 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo
289
307
// ! Whether list of outputs should be collapsed in the graphical modeler
290
308
bool mOutputsCollapsed = true ;
291
309
310
+ friend class TestQgsProcessing ;
311
+
292
312
};
293
313
294
314
// /@endcond
Original file line number Diff line number Diff line change @@ -5539,15 +5539,21 @@ void TestQgsProcessing::modelerAlgorithm()
5539
5539
QgsProcessingModelChildParameterSource::fromStaticValue( QStringLiteral( "b" ) ) );
5540
5540
5541
5541
5542
-
5543
-
5544
-
5545
5542
QgsProcessingModelChildAlgorithm child( QStringLiteral( "some_id" ) );
5546
5543
QCOMPARE( child.algorithmId(), QStringLiteral( "some_id" ) );
5547
5544
QVERIFY( !child.algorithm() );
5548
- child.setAlgorithmId( QStringLiteral( "native:centroids" ) );
5545
+ QVERIFY( !child.setAlgorithmId( QStringLiteral( "blah" ) ) );
5546
+ QVERIFY( !child.reattach() );
5547
+ QVERIFY( child.setAlgorithmId( QStringLiteral( "native:centroids" ) ) );
5549
5548
QVERIFY( child.algorithm() );
5550
5549
QCOMPARE( child.algorithm()->id(), QStringLiteral( "native:centroids" ) );
5550
+ // bit of a hack -- but try to simulate an algorithm not originally available!
5551
+ child.mAlgorithm.reset();
5552
+ QVERIFY( !child.algorithm() );
5553
+ QVERIFY( child.reattach() );
5554
+ QVERIFY( child.algorithm() );
5555
+ QCOMPARE( child.algorithm()->id(), QStringLiteral( "native:centroids" ) );
5556
+
5551
5557
QVariantMap myConfig;
5552
5558
myConfig.insert( QStringLiteral( "some_key" ), 11 );
5553
5559
child.setConfiguration( myConfig );
You can’t perform that action at this time.
0 commit comments