mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Port more model to c++
This commit is contained in:
parent
459244126f
commit
179a377da0
@ -541,6 +541,25 @@ Copies are protected to avoid slicing
|
||||
Returns true if the algorithm could be removed, or false
|
||||
if the algorithm could not be removed (e.g. due to other
|
||||
child algorithms depending on it).
|
||||
.. seealso:: deactivateChildAlgorithm()
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
void deactivateChildAlgorithm( const QString &id );
|
||||
%Docstring
|
||||
Deactivates the child algorithm with matching ``id``.
|
||||
All other child algorithms which depend on the child
|
||||
algorithm will also be deactivated.
|
||||
.. seealso:: removeChildAlgorithm()
|
||||
.. seealso:: activateChildAlgorithm()
|
||||
%End
|
||||
|
||||
bool activateChildAlgorithm( const QString &id );
|
||||
%Docstring
|
||||
Attempts to activate the child algorithm with matching ``id``.
|
||||
If any child algorithms on which the child depends are not active,
|
||||
then the child will not be activated and false will be returned.
|
||||
.. seealso:: deactivateChildAlgorithm()
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
|
@ -185,19 +185,6 @@ class ModelerAlgorithm(QgsProcessingModelAlgorithm):
|
||||
# Geoalgorithms in this model. A dict of Algorithm objects, with names as keys
|
||||
self.algs = {}
|
||||
|
||||
def updateAlgorithm(self, alg):
|
||||
alg.setPosition(self.childAlgorithm(alg.childId()).position())
|
||||
alg.setParametersCollapsed(self.childAlgorithm(alg.childId()).parametersCollapsed())
|
||||
alg.setOutputsCollapsed(self.childAlgorithm(alg.childId()).outputsCollapsed())
|
||||
self.setChildAlgorithm(alg)
|
||||
|
||||
from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
|
||||
for i, out in enumerate(alg.modelOutputs().keys()):
|
||||
alg.modelOutput(out).setPosition(alg.modelOutput(out).position() or
|
||||
alg.position() + QPointF(
|
||||
ModelerGraphicItem.BOX_WIDTH,
|
||||
(i + 1.5) * ModelerGraphicItem.BOX_HEIGHT))
|
||||
|
||||
def prepareAlgorithm(self, alg):
|
||||
algInstance = alg.algorithm()
|
||||
for param in algInstance.parameterDefinitions():
|
||||
@ -235,20 +222,6 @@ class ModelerAlgorithm(QgsProcessingModelAlgorithm):
|
||||
|
||||
return algInstance
|
||||
|
||||
def deactivateAlgorithm(self, algName):
|
||||
dependent = self.dependentChildAlgorithms(algName)
|
||||
for alg in dependent:
|
||||
self.algs[alg].setActive(False)
|
||||
self.algs[algName].setActive(False)
|
||||
|
||||
def activateAlgorithm(self, algName):
|
||||
parents = self.dependsOnChildAlgorithms(algName)
|
||||
for alg in parents:
|
||||
if not self.childAlgorithm(alg).isActive():
|
||||
return False
|
||||
self.childAlgorithm(algName).setActive(True)
|
||||
return True
|
||||
|
||||
def getSafeNameForOutput(self, algName, outName):
|
||||
return outName + '_ALG' + algName
|
||||
|
||||
@ -328,14 +301,6 @@ class ModelerAlgorithm(QgsProcessingModelAlgorithm):
|
||||
return str(self.helpContent['ALG_DESC'])
|
||||
return None
|
||||
|
||||
def getParameterDescriptions(self):
|
||||
descs = {}
|
||||
descriptions = self.helpContent
|
||||
for param in self.parameters:
|
||||
if param.name in descriptions:
|
||||
descs[param.name] = str(descriptions[param.name])
|
||||
return descs
|
||||
|
||||
def todict(self):
|
||||
keys = ["inputs", "_group", "_name", "algs", "helpContent"]
|
||||
return {k: v for k, v in list(self.__dict__.items()) if k in keys}
|
||||
|
@ -177,11 +177,11 @@ class ModelerGraphicItem(QGraphicsItem):
|
||||
popupmenu.exec_(event.screenPos())
|
||||
|
||||
def deactivateAlgorithm(self):
|
||||
self.model.deactivateAlgorithm(self.element.childId())
|
||||
self.model.deactivateChildAlgorithm(self.element.childId())
|
||||
self.scene.dialog.repaintModel()
|
||||
|
||||
def activateAlgorithm(self):
|
||||
if self.model.activateAlgorithm(self.element.childId()):
|
||||
if self.model.activateChildAlgorithm(self.element.childId()):
|
||||
self.scene.dialog.repaintModel()
|
||||
else:
|
||||
QMessageBox.warning(None, 'Could not activate Algorithm',
|
||||
@ -211,9 +211,21 @@ class ModelerGraphicItem(QGraphicsItem):
|
||||
dlg.exec_()
|
||||
if dlg.alg is not None:
|
||||
dlg.alg.setChildId(self.element.childId())
|
||||
self.model.updateAlgorithm(dlg.alg)
|
||||
self.updateAlgorithm(dlg.alg)
|
||||
self.scene.dialog.repaintModel()
|
||||
|
||||
def updateAlgorithm(self, alg):
|
||||
existing_child = self.model.childAlgorithm(alg.childId())
|
||||
alg.setPosition(existing_child.position())
|
||||
alg.setParametersCollapsed(existing_child.parametersCollapsed())
|
||||
alg.setOutputsCollapsed(existing_child.outputsCollapsed())
|
||||
for i, out in enumerate(alg.modelOutputs().keys()):
|
||||
alg.modelOutput(out).setPosition(alg.modelOutput(out).position() or
|
||||
alg.position() + QPointF(
|
||||
ModelerGraphicItem.BOX_WIDTH,
|
||||
(i + 1.5) * ModelerGraphicItem.BOX_HEIGHT))
|
||||
self.model.setChildAlgorithm(alg)
|
||||
|
||||
def removeElement(self):
|
||||
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
|
||||
if not self.model.removeModelParameter(self.element.parameterName()):
|
||||
|
@ -260,6 +260,26 @@ bool QgsProcessingModelAlgorithm::removeChildAlgorithm( const QString &id )
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsProcessingModelAlgorithm::deactivateChildAlgorithm( const QString &id )
|
||||
{
|
||||
Q_FOREACH ( const QString &child, dependentChildAlgorithms( id ) )
|
||||
{
|
||||
childAlgorithm( child ).setActive( false );
|
||||
}
|
||||
childAlgorithm( id ).setActive( false );
|
||||
}
|
||||
|
||||
bool QgsProcessingModelAlgorithm::activateChildAlgorithm( const QString &id )
|
||||
{
|
||||
Q_FOREACH ( const QString &child, dependsOnChildAlgorithms( id ) )
|
||||
{
|
||||
if ( !childAlgorithm( child ).isActive() )
|
||||
return false;
|
||||
}
|
||||
childAlgorithm( id ).setActive( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsProcessingModelAlgorithm::addModelParameter( QgsProcessingParameterDefinition *definition, const QgsProcessingModelAlgorithm::ModelParameter &component )
|
||||
{
|
||||
addParameter( definition );
|
||||
|
@ -547,9 +547,27 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
|
||||
* Returns true if the algorithm could be removed, or false
|
||||
* if the algorithm could not be removed (e.g. due to other
|
||||
* child algorithms depending on it).
|
||||
* \see deactivateChildAlgorithm()
|
||||
*/
|
||||
bool removeChildAlgorithm( const QString &id );
|
||||
|
||||
/**
|
||||
* Deactivates the child algorithm with matching \a id.
|
||||
* All other child algorithms which depend on the child
|
||||
* algorithm will also be deactivated.
|
||||
* \see removeChildAlgorithm()
|
||||
* \see activateChildAlgorithm()
|
||||
*/
|
||||
void deactivateChildAlgorithm( const QString &id );
|
||||
|
||||
/**
|
||||
* Attempts to activate the child algorithm with matching \a id.
|
||||
* If any child algorithms on which the child depends are not active,
|
||||
* then the child will not be activated and false will be returned.
|
||||
* \see deactivateChildAlgorithm()
|
||||
*/
|
||||
bool activateChildAlgorithm( const QString &id );
|
||||
|
||||
/**
|
||||
* Returns a list of the child algorithm IDs depending on the child
|
||||
* algorithm with the specified \a childId.
|
||||
|
@ -3226,6 +3226,49 @@ void TestQgsProcessing::modelerAlgorithm()
|
||||
QVERIFY( alg3.dependsOnChildAlgorithms( "c9" ).contains( "c7" ) );
|
||||
QVERIFY( alg3.dependsOnChildAlgorithms( "c9" ).contains( "c8" ) );
|
||||
|
||||
// (de)activate child algorithm
|
||||
alg3.deactivateChildAlgorithm( "c9" );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( alg3.activateChildAlgorithm( "c9" ) );
|
||||
QVERIFY( alg3.childAlgorithm( "c9" ).isActive() );
|
||||
alg3.deactivateChildAlgorithm( "c8" );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( !alg3.activateChildAlgorithm( "c9" ) );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( alg3.activateChildAlgorithm( "c8" ) );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( alg3.activateChildAlgorithm( "c9" ) );
|
||||
QVERIFY( alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c8" ).isActive() );
|
||||
alg3.deactivateChildAlgorithm( "c7" );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c7" ).isActive() );
|
||||
QVERIFY( !alg3.activateChildAlgorithm( "c9" ) );
|
||||
QVERIFY( !alg3.activateChildAlgorithm( "c8" ) );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c7" ).isActive() );
|
||||
QVERIFY( !alg3.activateChildAlgorithm( "c8" ) );
|
||||
QVERIFY( alg3.activateChildAlgorithm( "c7" ) );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( !alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c7" ).isActive() );
|
||||
QVERIFY( !alg3.activateChildAlgorithm( "c9" ) );
|
||||
QVERIFY( alg3.activateChildAlgorithm( "c8" ) );
|
||||
QVERIFY( !alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c7" ).isActive() );
|
||||
QVERIFY( alg3.activateChildAlgorithm( "c9" ) );
|
||||
QVERIFY( alg3.childAlgorithm( "c9" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c8" ).isActive() );
|
||||
QVERIFY( alg3.childAlgorithm( "c7" ).isActive() );
|
||||
|
||||
|
||||
|
||||
//remove child algorithm
|
||||
QVERIFY( !alg3.removeChildAlgorithm( "c7" ) );
|
||||
QVERIFY( !alg3.removeChildAlgorithm( "c8" ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user