Skip to content

Commit

Permalink
Some tests for model scene
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 14, 2020
1 parent d24ae53 commit 0bea126
Showing 1 changed file with 164 additions and 0 deletions.
164 changes: 164 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -80,6 +80,9 @@
#include "qgsprocessingfeaturesourceoptionswidget.h"
#include "qgsextentwidget.h"
#include "qgsrasterbandcombobox.h"
#include "qgsmodelgraphicsscene.h"
#include "qgsmodelgraphicsview.h"
#include "qgsmodelcomponentgraphicitem.h"

class TestParamType : public QgsProcessingParameterDefinition
{
Expand Down Expand Up @@ -234,6 +237,7 @@ class TestProcessingGui : public QObject
void testRasterOutWrapper();
void testFileOutWrapper();
void testFolderOutWrapper();
void testModelGraphicsView();

private:

Expand Down Expand Up @@ -8246,6 +8250,166 @@ void TestProcessingGui::testFolderOutWrapper()

// modeler wrapper
testWrapper( QgsProcessingGui::Modeler );
}

void TestProcessingGui::testModelGraphicsView()
{
// test model
QgsProcessingModelAlgorithm model1;

QgsProcessingModelChildAlgorithm algc1;
algc1.setChildId( "buffer" );
algc1.setAlgorithmId( "native:buffer" );
QgsProcessingModelParameter param;
param.setParameterName( QStringLiteral( "LAYER" ) );
param.setSize( QSizeF( 500, 400 ) );
param.setPosition( QPointF( 101, 102 ) );
param.comment()->setDescription( QStringLiteral( "input comment" ) );
model1.addModelParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "LAYER" ) ), param );
algc1.addParameterSources( QStringLiteral( "INPUT" ), QList< QgsProcessingModelChildParameterSource >() << QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "LAYER" ) ) );
algc1.comment()->setDescription( QStringLiteral( "alg comment" ) );
algc1.comment()->setSize( QSizeF( 300, 200 ) );
algc1.comment()->setPosition( QPointF( 201, 202 ) );

QgsProcessingModelOutput modelOut;
modelOut.setChildId( algc1.childId() );
modelOut.setChildOutputName( QStringLiteral( "my_output" ) );
modelOut.comment()->setDescription( QStringLiteral( "output comm" ) );
QMap< QString, QgsProcessingModelOutput > outs;
outs.insert( QStringLiteral( "OUTPUT" ), modelOut );
algc1.setModelOutputs( outs );
model1.addChildAlgorithm( algc1 );

QgsProcessingModelGroupBox groupBox;
groupBox.setDescription( QStringLiteral( "group" ) );
model1.addGroupBox( groupBox );

// hiding comments
QgsProcessingContext context;
QgsModelGraphicsScene scene2;
scene2.setModel( &model1 );
scene2.setFlags( QgsModelGraphicsScene::FlagHideComments );
scene2.createItems( &model1, context );
QList< QGraphicsItem * > items = scene2.items();
QgsModelParameterGraphicItem *layerItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelParameterGraphicItem *param = dynamic_cast< QgsModelParameterGraphicItem * >( item ) )
{
layerItem = param;
break;
}
}
QVERIFY( layerItem );
QgsModelCommentGraphicItem *layerCommentItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelCommentGraphicItem *comment = dynamic_cast< QgsModelCommentGraphicItem * >( item ) )
{
layerCommentItem = comment;
break;
}
}
// should not exist
QVERIFY( !layerCommentItem );


QgsModelGraphicsScene scene;
QVERIFY( !scene.model() );
scene.setModel( &model1 );
QCOMPARE( scene.model(), &model1 );

QVERIFY( scene.items().empty() );
scene.createItems( &model1, context );
items = scene.items();
layerItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelParameterGraphicItem *param = dynamic_cast< QgsModelParameterGraphicItem * >( item ) )
{
layerItem = param;

}
}
QVERIFY( layerItem );
QCOMPARE( dynamic_cast< QgsProcessingModelParameter * >( layerItem->component() )->parameterName(), QStringLiteral( "LAYER" ) );
QCOMPARE( layerItem->itemRect().size(), QSizeF( 500, 400 ) );
QCOMPARE( layerItem->scenePos(), QPointF( 101, 102 ) );

QgsModelChildAlgorithmGraphicItem *algItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelChildAlgorithmGraphicItem *param = dynamic_cast< QgsModelChildAlgorithmGraphicItem * >( item ) )
{
algItem = param;
break;
}
}
QVERIFY( algItem );
QCOMPARE( dynamic_cast< QgsProcessingModelChildAlgorithm * >( algItem->component() )->algorithmId(), QStringLiteral( "native:buffer" ) );

QgsModelOutputGraphicItem *outputItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelOutputGraphicItem *comment = dynamic_cast< QgsModelOutputGraphicItem * >( item ) )
{
outputItem = comment;
break;
}
}
QVERIFY( outputItem );
QCOMPARE( dynamic_cast< QgsProcessingModelOutput * >( outputItem->component() )->childOutputName(), QStringLiteral( "my_output" ) );


layerCommentItem = nullptr;
QgsModelCommentGraphicItem *algCommentItem = nullptr;
QgsModelCommentGraphicItem *outputCommentItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelCommentGraphicItem *comment = dynamic_cast< QgsModelCommentGraphicItem * >( item ) )
{
if ( comment->parentComponentItem() == layerItem )
{
layerCommentItem = comment;
}
else if ( comment->parentComponentItem() == algItem )
{
algCommentItem = comment;
}
else if ( comment->parentComponentItem() == outputItem )
{
outputCommentItem = comment;
}
}
}

QVERIFY( algCommentItem );
QCOMPARE( algCommentItem->component()->description(), QStringLiteral( "alg comment" ) );
QCOMPARE( algCommentItem->itemRect().size(), QSizeF( 300, 200 ) );
QCOMPARE( algCommentItem->scenePos(), QPointF( 201, 202 ) );

QVERIFY( layerCommentItem );
QCOMPARE( layerCommentItem->component()->description(), QStringLiteral( "input comment" ) );

QVERIFY( outputCommentItem );
QCOMPARE( outputCommentItem->component()->description(), QStringLiteral( "output comm" ) );

QgsModelGroupBoxGraphicItem *groupItem = nullptr;
for ( QGraphicsItem *item : items )
{
if ( QgsModelGroupBoxGraphicItem *comment = dynamic_cast< QgsModelGroupBoxGraphicItem * >( item ) )
{
groupItem = comment;
break;
}
}
QVERIFY( groupItem );
QCOMPARE( dynamic_cast< QgsProcessingModelGroupBox * >( groupItem->component() )->description(), QStringLiteral( "group" ) );





}

void TestProcessingGui::cleanupTempDir()
Expand Down

0 comments on commit 0bea126

Please sign in to comment.