Skip to content

Commit

Permalink
Unit tests for model copy/paste functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 14, 2020
1 parent 0bea126 commit 5f91b06
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsview.cpp
Expand Up @@ -645,6 +645,8 @@ void QgsModelGraphicsView::pasteItems( QgsModelGraphicsView::PasteMode mode )

pastedGroups << box;

modelScene()->model()->addGroupBox( box );

if ( !pastedBounds.isValid( ) )
pastedBounds = QRectF( box.position() - QPointF( box.size().width() / 2.0, box.size().height() / 2.0 ), box.size() );
else
Expand Down
62 changes: 59 additions & 3 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -8407,9 +8407,65 @@ void TestProcessingGui::testModelGraphicsView()
QCOMPARE( dynamic_cast< QgsProcessingModelGroupBox * >( groupItem->component() )->description(), QStringLiteral( "group" ) );





QgsModelGraphicsView view;
view.setModelScene( &scene );

// copy some items
view.copyItems( QList< QgsModelComponentGraphicItem * >() << layerItem << algItem << groupItem, QgsModelGraphicsView::ClipboardCopy );


// second view to paste into
QgsProcessingModelAlgorithm algDest;
QVERIFY( algDest.childAlgorithms().empty() );
QVERIFY( algDest.parameterComponents().empty() );
QVERIFY( algDest.groupBoxes().empty() );
QgsModelGraphicsScene sceneDest;
sceneDest.setModel( &algDest );
QgsModelGraphicsView viewDest;
viewDest.setModelScene( &sceneDest );
viewDest.pasteItems( QgsModelGraphicsView::PasteModeInPlace );

QCOMPARE( algDest.parameterComponents().size(), 1 );
QCOMPARE( algDest.parameterComponents().value( QStringLiteral( "LAYER" ) ).parameterName(), QStringLiteral( "LAYER" ) );
// comment should not be copied, was not selected
QCOMPARE( algDest.parameterComponents().value( QStringLiteral( "LAYER" ) ).comment()->description(), QString() );
QCOMPARE( algDest.childAlgorithms().size(), 1 );
QCOMPARE( algDest.childAlgorithms().keys().at( 0 ), QStringLiteral( "native:buffer_1" ) );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_1" ) ).algorithmId(), QStringLiteral( "native:buffer" ) );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_1" ) ).comment()->description(), QString() );
// output was not selected
QVERIFY( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_1" ) ).modelOutputs().empty() );
QCOMPARE( algDest.groupBoxes().size(), 1 );
QCOMPARE( algDest.groupBoxes().at( 0 ).description(), QStringLiteral( "group" ) );

// copy comments and output (not output comment though!)
view.copyItems( QList< QgsModelComponentGraphicItem * >() << layerItem << layerCommentItem << algItem << algCommentItem << outputItem << groupItem, QgsModelGraphicsView::ClipboardCopy );
viewDest.pasteItems( QgsModelGraphicsView::PasteModeInPlace );

QCOMPARE( algDest.parameterComponents().size(), 2 );
QCOMPARE( algDest.parameterComponents().value( QStringLiteral( "LAYER" ) ).parameterName(), QStringLiteral( "LAYER" ) );
QCOMPARE( algDest.parameterComponents().value( QStringLiteral( "LAYER (2)" ) ).parameterName(), QStringLiteral( "LAYER (2)" ) );
QCOMPARE( algDest.parameterComponents().value( QStringLiteral( "LAYER" ) ).comment()->description(), QString() );
QCOMPARE( algDest.parameterComponents().value( QStringLiteral( "LAYER (2)" ) ).comment()->description(), QStringLiteral( "input comment" ) );
QCOMPARE( algDest.childAlgorithms().size(), 2 );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_1" ) ).algorithmId(), QStringLiteral( "native:buffer" ) );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_1" ) ).comment()->description(), QString() );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_2" ) ).algorithmId(), QStringLiteral( "native:buffer" ) );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_2" ) ).comment()->description(), QStringLiteral( "alg comment" ) );
QVERIFY( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_1" ) ).modelOutputs().empty() );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_2" ) ).modelOutputs().size(), 1 );
// output comment wasn't selected
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_2" ) ).modelOutputs().value( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_2" ) ).modelOutputs().keys().at( 0 ) ).comment()->description(), QString() );
QCOMPARE( algDest.groupBoxes().size(), 2 );
QCOMPARE( algDest.groupBoxes().at( 0 ).description(), QStringLiteral( "group" ) );
QCOMPARE( algDest.groupBoxes().at( 1 ).description(), QStringLiteral( "group" ) );

// output and output comment
view.copyItems( QList< QgsModelComponentGraphicItem * >() << algItem << outputItem << outputCommentItem, QgsModelGraphicsView::ClipboardCopy );
viewDest.pasteItems( QgsModelGraphicsView::PasteModeInPlace );
QCOMPARE( algDest.childAlgorithms().size(), 3 );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_3" ) ).modelOutputs().size(), 1 );
QCOMPARE( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_3" ) ).modelOutputs().value( algDest.childAlgorithms().value( QStringLiteral( "native:buffer_3" ) ).modelOutputs().keys().at( 0 ) ).comment()->description(), QStringLiteral( "output comm" ) );
}

void TestProcessingGui::cleanupTempDir()
Expand Down

0 comments on commit 5f91b06

Please sign in to comment.