Skip to content
Permalink
Browse files

Bit more Python to c++ porting

  • Loading branch information
nyalldawson committed Mar 5, 2020
1 parent 889563e commit 64868ce8f22d1153660733f1737bed52db7b18fd
@@ -35,6 +35,16 @@ should be set to a QgsProcessingAlgorithm algorithm ID.
virtual QgsProcessingModelChildAlgorithm *clone() const /Factory/;


void copyNonDefinitionPropertiesFromModel( QgsProcessingModelAlgorithm *model );
%Docstring
Copies all non-specific definition properties from the the matching component from a ``model``.

This includes properties like the size and position of the component, but not properties
like the specific algorithm or input details.

.. versionadded:: 3.14
%End

QString childId() const;
%Docstring
Returns the child algorithm's unique ID string, used the identify
@@ -134,6 +134,16 @@ Saves the component properties to a QVariantMap.
Restores the component properties from a QVariantMap.

.. seealso:: :py:func:`saveCommonProperties`
%End

void copyNonDefinitionProperties( const QgsProcessingModelComponent &other );
%Docstring
Copies all non-specific definition properties from the ``other`` component definition.

This includes properties like the size and position of the component, but not properties
like the specific algorithm or input details.

.. versionadded:: 3.14
%End

};
@@ -29,8 +29,7 @@
QgsProcessingParameterWidgetContext,
QgsModelParameterGraphicItem,
QgsModelChildAlgorithmGraphicItem,
QgsModelOutputGraphicItem,
QgsModelCommentGraphicItem
QgsModelOutputGraphicItem
)
from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
@@ -129,7 +128,8 @@ def edit(self, edit_comment=False):
if dlg.exec_():
alg = dlg.createAlgorithm()
alg.setChildId(self.component().childId())
self.updateAlgorithm(alg)
alg.copyNonDefinitionPropertiesFromModel(self.model())
self.model().setChildAlgorithm(alg)
self.requestModelRepaint.emit()
self.changed.emit()

@@ -139,27 +139,6 @@ def editComponent(self):
def editComment(self):
self.edit(edit_comment=True)

def updateAlgorithm(self, alg):
existing_child = self.model().childAlgorithm(alg.childId())
alg.setPosition(existing_child.position())
alg.setLinksCollapsed(Qt.TopEdge, existing_child.linksCollapsed(Qt.TopEdge))
alg.setLinksCollapsed(Qt.BottomEdge, existing_child.linksCollapsed(Qt.BottomEdge))
alg.comment().setPosition(existing_child.comment().position()
or alg.position() + QPointF(
self.component().size().width(),
-1.5 * self.component().size().height())
)
alg.comment().setSize(existing_child.comment().size())
for i, out in enumerate(alg.modelOutputs().keys()):
alg.modelOutput(out).setPosition(existing_child.modelOutput(out).position()
or alg.position() + QPointF(
self.component().size().width(),
(i + 1.5) * self.component().size().height()))
alg.modelOutput(out).comment().setDescription(existing_child.modelOutput(out).comment().description())
alg.modelOutput(out).comment().setSize(existing_child.modelOutput(out).comment().size())
alg.modelOutput(out).comment().setPosition(existing_child.modelOutput(out).comment().position())
self.model().setChildAlgorithm(alg)


class ModelerOutputGraphicItem(QgsModelOutputGraphicItem):
"""
@@ -59,6 +59,32 @@ QgsProcessingModelChildAlgorithm *QgsProcessingModelChildAlgorithm::clone() cons
return new QgsProcessingModelChildAlgorithm( *this );
}

void QgsProcessingModelChildAlgorithm::copyNonDefinitionPropertiesFromModel( QgsProcessingModelAlgorithm *model )
{
const QgsProcessingModelChildAlgorithm existingChild = model->childAlgorithm( mId );
copyNonDefinitionProperties( existingChild );

int i = 0;
for ( auto it = mModelOutputs.begin(); it != mModelOutputs.end(); ++it )
{
if ( !existingChild.modelOutputs().value( it.key() ).position().isNull() )
it.value().setPosition( existingChild.modelOutputs().value( it.key() ).position() );
else
it.value().setPosition( position() + QPointF( size().width(), ( i + 1.5 ) * size().height() ) );

if ( QgsProcessingModelComment *comment = it.value().comment() )
{
if ( const QgsProcessingModelComment *existingComment = existingChild.modelOutputs().value( it.key() ).comment() )
{
comment->setDescription( existingComment->description() );
comment->setSize( existingComment->size() );
comment->setPosition( existingComment->position() );
}
}
i++;
}
}

const QgsProcessingAlgorithm *QgsProcessingModelChildAlgorithm::algorithm() const
{
return mAlgorithm.get();
@@ -51,6 +51,16 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo

QgsProcessingModelChildAlgorithm *clone() const override SIP_FACTORY;

/**
* Copies all non-specific definition properties from the the matching component from a \a model.
*
* This includes properties like the size and position of the component, but not properties
* like the specific algorithm or input details.
*
* \since QGIS 3.14
*/
void copyNonDefinitionPropertiesFromModel( QgsProcessingModelAlgorithm *model );

/**
* Returns the child algorithm's unique ID string, used the identify
* this child algorithm within its parent model.
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsprocessingmodelcomponent.h"
#include "qgsprocessingmodelcomment.h"

///@cond NOT_STABLE

@@ -117,4 +118,19 @@ void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &ma
mBottomEdgeLinksCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();
}

void QgsProcessingModelComponent::copyNonDefinitionProperties( const QgsProcessingModelComponent &other )
{
setPosition( other.position() );
setLinksCollapsed( Qt::TopEdge, other.linksCollapsed( Qt::TopEdge ) );
setLinksCollapsed( Qt::BottomEdge, other.linksCollapsed( Qt::BottomEdge ) );
if ( comment() && other.comment() )
{
if ( !other.comment()->position().isNull() )
comment()->setPosition( other.comment()->position() );
else
comment()->setPosition( other.position() + QPointF( size().width(), -1.5 * size().height() ) );
comment()->setSize( other.comment()->size() );
}
}

///@endcond
@@ -137,6 +137,16 @@ class CORE_EXPORT QgsProcessingModelComponent
*/
void restoreCommonProperties( const QVariantMap &map );

/**
* Copies all non-specific definition properties from the \a other component definition.
*
* This includes properties like the size and position of the component, but not properties
* like the specific algorithm or input details.
*
* \since QGIS 3.14
*/
void copyNonDefinitionProperties( const QgsProcessingModelComponent &other );

private:

static constexpr double DEFAULT_COMPONENT_WIDTH = 200;

0 comments on commit 64868ce

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