Skip to content

Commit

Permalink
Move more modelling code to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 23, 2017
1 parent e7f13f5 commit 10aeba2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
13 changes: 13 additions & 0 deletions python/core/processing/qgsprocessingmodelalgorithm.sip
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -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'),
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/core/processing/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/core/processing/qgsprocessingmodelalgorithm.h
Expand Up @@ -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,
Expand All @@ -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;

Expand Down

0 comments on commit 10aeba2

Please sign in to comment.