Skip to content

Commit 10aeba2

Browse files
committed
Move more modelling code to c++
1 parent e7f13f5 commit 10aeba2

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

python/core/processing/qgsprocessingmodelalgorithm.sip

+13
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,19 @@ Copies are protected to avoid slicing
785785
Sets the model's help ``contents`` (a free-form map of values describing the algorithm's
786786
use and metadata).
787787
.. seealso:: helpContent()
788+
%End
789+
790+
QString sourceFilePath() const;
791+
%Docstring
792+
Returns the source file path for the model, if available.
793+
.. seealso:: setSourceFilePath()
794+
:rtype: str
795+
%End
796+
797+
void setSourceFilePath( const QString &path );
798+
%Docstring
799+
Sets the source file ``path`` for the model, if available.
800+
.. seealso:: sourceFilePath()
788801
%End
789802

790803
protected:

python/plugins/processing/modeler/ModelerAlgorithm.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ class ModelerAlgorithm(QgsProcessingModelAlgorithm):
179179
def __init__(self):
180180
super().__init__()
181181

182-
self.descriptionFile = None
183-
184182
# Geoalgorithms in this model. A dict of Algorithm objects, with names as keys
185183
self.algs = {}
186184

@@ -229,7 +227,7 @@ def resolveValue(self, value, param):
229227
return param.evaluateForModeler(v, self)
230228

231229
def asPythonCommand(self, parameters, context):
232-
if self.descriptionFile:
230+
if self.sourceFilePath():
233231
return QgsProcessingAlgorithm.asPythonCommand(self, parameters, context)
234232
else:
235233
return None

python/plugins/processing/modeler/ModelerAlgorithmProvider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def loadFromFolder(self, folder):
108108
alg = ModelerAlgorithm()
109109
if alg.fromFile(fullpath):
110110
if alg.name():
111-
alg.descriptionFile = fullpath
111+
alg.setSourceFilePath(fullpath)
112112
self.algs.append(alg)
113113
else:
114114
QgsMessageLog.logMessage(self.tr('Could not load model {0}', 'ModelerAlgorithmProvider').format(descriptionFile),

python/plugins/processing/modeler/ModelerDialog.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ def saveModel(self, saveAs):
439439
return
440440
self.model.setName(str(self.textName.text()))
441441
self.model.setGroup(str(self.textGroup.text()))
442-
if self.model.descriptionFile is not None and not saveAs:
443-
filename = self.model.descriptionFile
442+
if self.model.sourceFilePath() is not None and not saveAs:
443+
filename = self.model.sourceFilePath()
444444
else:
445445
filename, filter = QFileDialog.getSaveFileName(self,
446446
self.tr('Save Model'),
@@ -449,7 +449,7 @@ def saveModel(self, saveAs):
449449
if filename:
450450
if not filename.endswith('.model3'):
451451
filename += '.model3'
452-
self.model.descriptionFile = filename
452+
self.model.setSourceFilePath(filename)
453453
if filename:
454454
if not self.model.toFile(filename):
455455
if saveAs:

src/core/processing/qgsprocessingmodelalgorithm.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
481481
return finalResults;
482482
}
483483

484+
QString QgsProcessingModelAlgorithm::sourceFilePath() const
485+
{
486+
return mSourceFile;
487+
}
488+
489+
void QgsProcessingModelAlgorithm::setSourceFilePath( const QString &sourceFile )
490+
{
491+
mSourceFile = sourceFile;
492+
}
493+
484494
QVariantMap QgsProcessingModelAlgorithm::helpContent() const
485495
{
486496
return mHelpContent;

src/core/processing/qgsprocessingmodelalgorithm.h

+15
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,18 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
780780
*/
781781
void setHelpContent( const QVariantMap &contents );
782782

783+
/**
784+
* Returns the source file path for the model, if available.
785+
* \see setSourceFilePath()
786+
*/
787+
QString sourceFilePath() const;
788+
789+
/**
790+
* Sets the source file \a path for the model, if available.
791+
* \see sourceFilePath()
792+
*/
793+
void setSourceFilePath( const QString &path );
794+
783795
protected:
784796

785797
QVariantMap processAlgorithm( const QVariantMap &parameters,
@@ -797,6 +809,9 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
797809

798810
QVariantMap mHelpContent;
799811

812+
//! Model source file
813+
QString mSourceFile;
814+
800815
void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
801816
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
802817

0 commit comments

Comments
 (0)