Skip to content
Permalink
Browse files

Move more modelling code to c++

  • Loading branch information
nyalldawson committed Jun 23, 2017
1 parent e7f13f5 commit 10aeba2e72169dcb527906ca4391172a4fc61178
@@ -785,6 +785,19 @@ Copies are protected to avoid slicing
Sets the model's help ``contents`` (a free-form map of values describing the algorithm's
use and metadata).
.. seealso:: helpContent()
%End

QString sourceFilePath() const;
%Docstring
Returns the source file path for the model, if available.
.. seealso:: setSourceFilePath()
:rtype: str
%End

void setSourceFilePath( const QString &path );
%Docstring
Sets the source file ``path`` for the model, if available.
.. seealso:: sourceFilePath()
%End

protected:
@@ -179,8 +179,6 @@ class ModelerAlgorithm(QgsProcessingModelAlgorithm):
def __init__(self):
super().__init__()

self.descriptionFile = None

# Geoalgorithms in this model. A dict of Algorithm objects, with names as keys
self.algs = {}

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

def asPythonCommand(self, parameters, context):
if self.descriptionFile:
if self.sourceFilePath():
return QgsProcessingAlgorithm.asPythonCommand(self, parameters, context)
else:
return None
@@ -108,7 +108,7 @@ def loadFromFolder(self, folder):
alg = ModelerAlgorithm()
if alg.fromFile(fullpath):
if alg.name():
alg.descriptionFile = fullpath
alg.setSourceFilePath(fullpath)
self.algs.append(alg)
else:
QgsMessageLog.logMessage(self.tr('Could not load model {0}', 'ModelerAlgorithmProvider').format(descriptionFile),
@@ -439,8 +439,8 @@ def saveModel(self, saveAs):
return
self.model.setName(str(self.textName.text()))
self.model.setGroup(str(self.textGroup.text()))
if self.model.descriptionFile is not None and not saveAs:
filename = self.model.descriptionFile
if self.model.sourceFilePath() is not None and not saveAs:
filename = self.model.sourceFilePath()
else:
filename, filter = QFileDialog.getSaveFileName(self,
self.tr('Save Model'),
@@ -449,7 +449,7 @@ def saveModel(self, saveAs):
if filename:
if not filename.endswith('.model3'):
filename += '.model3'
self.model.descriptionFile = filename
self.model.setSourceFilePath(filename)
if filename:
if not self.model.toFile(filename):
if saveAs:
@@ -481,6 +481,16 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
return finalResults;
}

QString QgsProcessingModelAlgorithm::sourceFilePath() const
{
return mSourceFile;
}

void QgsProcessingModelAlgorithm::setSourceFilePath( const QString &sourceFile )
{
mSourceFile = sourceFile;
}

QVariantMap QgsProcessingModelAlgorithm::helpContent() const
{
return mHelpContent;
@@ -780,6 +780,18 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
*/
void setHelpContent( const QVariantMap &contents );

/**
* Returns the source file path for the model, if available.
* \see setSourceFilePath()
*/
QString sourceFilePath() const;

/**
* Sets the source file \a path for the model, if available.
* \see sourceFilePath()
*/
void setSourceFilePath( const QString &path );

protected:

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

QVariantMap mHelpContent;

//! Model source file
QString mSourceFile;

void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;

0 comments on commit 10aeba2

Please sign in to comment.
You can’t perform that action at this time.