Skip to content
Permalink
Browse files

Make link point collapsing handling more generic

  • Loading branch information
nyalldawson committed Mar 2, 2020
1 parent 919088c commit d8111e102529950d3354829502c2a1f9133e2b1a
@@ -199,46 +199,6 @@ algorithm is dependent. The list should contain the id() of the
dependent algorithms.

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

bool parametersCollapsed() const;
%Docstring
Returns ``True`` if the list of parameters for this algorithm should be collapsed
in the graphical modeler.

.. seealso:: :py:func:`setParametersCollapsed`

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

void setParametersCollapsed( bool collapsed );
%Docstring
Sets whether the list of parameters for this algorithm should be collapsed
in the graphical modeler.

.. seealso:: :py:func:`parametersCollapsed`

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

bool outputsCollapsed() const;
%Docstring
Returns ``True`` if the list of outputs for this algorithm should be collapsed
in the graphical modeler.

.. seealso:: :py:func:`setParametersCollapsed`

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

void setOutputsCollapsed( bool collapsed );
%Docstring
Sets whether the list of outputs for this algorithm should be collapsed
in the graphical modeler.

.. seealso:: :py:func:`outputsCollapsed`

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

QMap<QString, QgsProcessingModelOutput> modelOutputs() const;
@@ -69,6 +69,21 @@ Sets the ``size`` of the model component within the graphical modeler.
.. seealso:: :py:func:`size`

.. versionadded:: 3.14
%End

bool linksCollapsed( Qt::Edge edge ) const;
%Docstring
Returns ``True`` if the link points for the specified ``edge`` should be shown collapsed or not.

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

void setLinksCollapsed( Qt::Edge edge, bool collapsed );
%Docstring
Sets whether the link points for the specified ``edge`` for this component should be shown collapsed
in the graphical modeler.

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

virtual QgsProcessingModelComponent *clone() = 0 /Factory/;
@@ -35,8 +35,6 @@ QgsProcessingModelChildAlgorithm::QgsProcessingModelChildAlgorithm( const QgsPro
, mModelOutputs( other.mModelOutputs )
, mActive( other.mActive )
, mDependencies( other.mDependencies )
, mParametersCollapsed( other.mParametersCollapsed )
, mOutputsCollapsed( other.mOutputsCollapsed )
{
setAlgorithmId( other.algorithmId() );
}
@@ -51,8 +49,6 @@ QgsProcessingModelChildAlgorithm &QgsProcessingModelChildAlgorithm::operator=( c
mModelOutputs = other.mModelOutputs;
mActive = other.mActive;
mDependencies = other.mDependencies;
mParametersCollapsed = other.mParametersCollapsed;
mOutputsCollapsed = other.mOutputsCollapsed;
return *this;
}

@@ -93,8 +89,6 @@ QVariant QgsProcessingModelChildAlgorithm::toVariant() const
map.insert( QStringLiteral( "alg_config" ), mConfiguration );
map.insert( QStringLiteral( "active" ), mActive );
map.insert( QStringLiteral( "dependencies" ), mDependencies );
map.insert( QStringLiteral( "parameters_collapsed" ), mParametersCollapsed );
map.insert( QStringLiteral( "outputs_collapsed" ), mOutputsCollapsed );

saveCommonProperties( map );

@@ -132,8 +126,6 @@ bool QgsProcessingModelChildAlgorithm::loadVariant( const QVariant &child )
setAlgorithmId( map.value( QStringLiteral( "alg_id" ) ).toString() );
mActive = map.value( QStringLiteral( "active" ) ).toBool();
mDependencies = map.value( QStringLiteral( "dependencies" ) ).toStringList();
mParametersCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool();
mOutputsCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();

restoreCommonProperties( map );

@@ -193,38 +193,6 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo
*/
void setDependencies( const QStringList &dependencies ) { mDependencies = dependencies; }

/**
* Returns TRUE if the list of parameters for this algorithm should be collapsed
* in the graphical modeler.
* \see setParametersCollapsed()
* \see outputsCollapsed()
*/
bool parametersCollapsed() const { return mParametersCollapsed; }

/**
* Sets whether the list of parameters for this algorithm should be collapsed
* in the graphical modeler.
* \see parametersCollapsed()
* \see setOutputsCollapsed()
*/
void setParametersCollapsed( bool collapsed ) { mParametersCollapsed = collapsed; }

/**
* Returns TRUE if the list of outputs for this algorithm should be collapsed
* in the graphical modeler.
* \see setParametersCollapsed()
* \see parametersCollapsed()
*/
bool outputsCollapsed() const { return mOutputsCollapsed; }

/**
* Sets whether the list of outputs for this algorithm should be collapsed
* in the graphical modeler.
* \see outputsCollapsed()
* \see setParametersCollapsed()
*/
void setOutputsCollapsed( bool collapsed ) { mOutputsCollapsed = collapsed; }

/**
* Returns the map of final model outputs which are generated by this child algorithm.
* The keys are the output names from this child algorithm. Only outputs which are
@@ -313,11 +281,6 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo
//! List of child algorithms from the parent model on which this algorithm is dependent
QStringList mDependencies;

//! Whether list of parameters should be collapsed in the graphical modeler
bool mParametersCollapsed = true;
//! Whether list of outputs should be collapsed in the graphical modeler
bool mOutputsCollapsed = true;

friend class TestQgsProcessing;

};
@@ -53,13 +53,50 @@ void QgsProcessingModelComponent::setSize( QSizeF size )
mSize = size;
}

bool QgsProcessingModelComponent::linksCollapsed( Qt::Edge edge ) const
{
switch ( edge )
{
case Qt::TopEdge:
return mTopEdgeLinksCollapsed;

case Qt::BottomEdge:
return mBottomEdgeLinksCollapsed;

case Qt::LeftEdge:
case Qt::RightEdge:
return false;
}
return false;
}

void QgsProcessingModelComponent::setLinksCollapsed( Qt::Edge edge, bool collapsed )
{
switch ( edge )
{
case Qt::TopEdge:
mTopEdgeLinksCollapsed = collapsed;
break;

case Qt::BottomEdge:
mBottomEdgeLinksCollapsed = collapsed;
break;

case Qt::LeftEdge:
case Qt::RightEdge:
break;
}
}

void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const
{
map.insert( QStringLiteral( "component_pos_x" ), mPosition.x() );
map.insert( QStringLiteral( "component_pos_y" ), mPosition.y() );
map.insert( QStringLiteral( "component_description" ), mDescription );
map.insert( QStringLiteral( "component_width" ), mSize.width() );
map.insert( QStringLiteral( "component_height" ), mSize.height() );
map.insert( QStringLiteral( "parameters_collapsed" ), mTopEdgeLinksCollapsed );
map.insert( QStringLiteral( "outputs_collapsed" ), mBottomEdgeLinksCollapsed );
}

void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &map )
@@ -71,6 +108,8 @@ void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &ma
mDescription = map.value( QStringLiteral( "component_description" ) ).toString();
mSize.setWidth( map.value( QStringLiteral( "component_width" ), QString::number( DEFAULT_COMPONENT_WIDTH ) ).toDouble() );
mSize.setHeight( map.value( QStringLiteral( "component_height" ), QString::number( DEFAULT_COMPONENT_HEIGHT ) ).toDouble() );
mTopEdgeLinksCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool();
mBottomEdgeLinksCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();
}

///@endcond
@@ -74,6 +74,19 @@ class CORE_EXPORT QgsProcessingModelComponent
*/
void setSize( QSizeF size );

/**
* Returns TRUE if the link points for the specified \a edge should be shown collapsed or not.
* \see setLinksCollapsed()
*/
bool linksCollapsed( Qt::Edge edge ) const;

/**
* Sets whether the link points for the specified \a edge for this component should be shown collapsed
* in the graphical modeler.
* \see linksCollapsed()
*/
void setLinksCollapsed( Qt::Edge edge, bool collapsed );

/**
* Clones the component.
*
@@ -116,6 +129,9 @@ class CORE_EXPORT QgsProcessingModelComponent

QSizeF mSize = QSizeF( DEFAULT_COMPONENT_WIDTH, DEFAULT_COMPONENT_HEIGHT );

bool mTopEdgeLinksCollapsed = true;
bool mBottomEdgeLinksCollapsed = true;

};

///@endcond
@@ -7682,12 +7682,12 @@ void TestQgsProcessing::modelerAlgorithm()
QCOMPARE( child.position(), QPointF( 1, 2 ) );
child.setSize( QSizeF( 3, 4 ) );
QCOMPARE( child.size(), QSizeF( 3, 4 ) );
QVERIFY( child.parametersCollapsed() );
child.setParametersCollapsed( false );
QVERIFY( !child.parametersCollapsed() );
QVERIFY( child.outputsCollapsed() );
child.setOutputsCollapsed( false );
QVERIFY( !child.outputsCollapsed() );
QVERIFY( child.linksCollapsed( Qt::TopEdge ) );
child.setLinksCollapsed( Qt::TopEdge, false );
QVERIFY( !child.linksCollapsed( Qt::TopEdge ) );
QVERIFY( child.linksCollapsed( Qt::BottomEdge ) );
child.setLinksCollapsed( Qt::BottomEdge, false );
QVERIFY( !child.linksCollapsed( Qt::BottomEdge ) );

child.setChildId( QStringLiteral( "my_id" ) );
QCOMPARE( child.childId(), QStringLiteral( "my_id" ) );
@@ -8086,8 +8086,8 @@ void TestQgsProcessing::modelerAlgorithm()
<< QgsProcessingModelChildParameterSource::fromExpression( "1+2" )
<< QgsProcessingModelChildParameterSource::fromStaticValue( QgsProperty::fromExpression( "1+8" ) ) );
alg5c1.setActive( true );
alg5c1.setOutputsCollapsed( true );
alg5c1.setParametersCollapsed( true );
alg5c1.setLinksCollapsed( Qt::BottomEdge, true );
alg5c1.setLinksCollapsed( Qt::TopEdge, true );
alg5c1.setDescription( "child 1" );
alg5c1.setPosition( QPointF( 1, 2 ) );
alg5c1.setSize( QSizeF( 11, 21 ) );
@@ -8103,8 +8103,8 @@ void TestQgsProcessing::modelerAlgorithm()
QgsProcessingModelChildAlgorithm alg5c2;
alg5c2.setChildId( "cx2" );
alg5c2.setActive( false );
alg5c2.setOutputsCollapsed( false );
alg5c2.setParametersCollapsed( false );
alg5c2.setLinksCollapsed( Qt::BottomEdge, false );
alg5c2.setLinksCollapsed( Qt::TopEdge, false );
alg5c2.setDependencies( QStringList() << "a" << "b" );
alg5.addChildAlgorithm( alg5c2 );

@@ -8129,8 +8129,8 @@ void TestQgsProcessing::modelerAlgorithm()
QCOMPARE( alg6c1.algorithmId(), QStringLiteral( "buffer" ) );
QCOMPARE( alg6c1.configuration(), myConfig );
QVERIFY( alg6c1.isActive() );
QVERIFY( alg6c1.outputsCollapsed() );
QVERIFY( alg6c1.parametersCollapsed() );
QVERIFY( alg6c1.linksCollapsed( Qt::BottomEdge ) );
QVERIFY( alg6c1.linksCollapsed( Qt::TopEdge ) );
QCOMPARE( alg6c1.description(), QStringLiteral( "child 1" ) );
QCOMPARE( alg6c1.position().x(), 1.0 );
QCOMPARE( alg6c1.position().y(), 2.0 );
@@ -8171,8 +8171,8 @@ void TestQgsProcessing::modelerAlgorithm()
QgsProcessingModelChildAlgorithm alg6c2 = alg6.childAlgorithm( "cx2" );
QCOMPARE( alg6c2.childId(), QStringLiteral( "cx2" ) );
QVERIFY( !alg6c2.isActive() );
QVERIFY( !alg6c2.outputsCollapsed() );
QVERIFY( !alg6c2.parametersCollapsed() );
QVERIFY( !alg6c2.linksCollapsed( Qt::BottomEdge ) );
QVERIFY( !alg6c2.linksCollapsed( Qt::TopEdge ) );
QCOMPARE( alg6c2.dependencies(), QStringList() << "a" << "b" );

QCOMPARE( alg6.parameterComponents().count(), 1 );

0 comments on commit d8111e1

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