Skip to content

Commit

Permalink
[processing][FEATURE] After running a model through the model designer,
Browse files Browse the repository at this point in the history
show the obtained values for all child algorithm outputs within the designer
canvas

This gives users better tools for debugging models - they can see exactly
what values were output by the child algorithms and flowed into other
parts of their model
  • Loading branch information
nyalldawson committed Mar 31, 2020
1 parent cb990c6 commit 5963b90
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
Expand Up @@ -389,6 +389,11 @@ Ownership of ``child`` is transferred to the item.
virtual bool canDeleteComponent();


void setResults( const QVariantMap &results );
%Docstring
Sets the results obtained for this child algorithm for the last model execution through the dialog.
%End

protected:

virtual QColor fillColor( State state ) const;
Expand Down
Expand Up @@ -112,6 +112,11 @@ not correctly emit signals to allow the scene's model to update.
void setSelectedItem( QgsModelComponentGraphicItem *item );
%Docstring
Clears any selected items and sets ``item`` as the current selection.
%End

void setChildAlgorithmResults( const QVariantMap &results );
%Docstring
Sets the results for child algorithms for the last model execution.
%End

signals:
Expand Down Expand Up @@ -147,7 +152,7 @@ If ``None``, no item is selected.
Creates a new graphic item for a model parameter.
%End

virtual QgsModelComponentGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const /Factory/;
virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const /Factory/;
%Docstring
Creates a new graphic item for a model child algorithm.
%End
Expand Down
20 changes: 19 additions & 1 deletion src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Expand Up @@ -936,7 +936,15 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind
switch ( edge )
{
case Qt::BottomEdge:
return truncatedTextForItem( child->algorithm()->outputDefinitions().at( index )->description() );
{
const QgsProcessingOutputDefinition *output = child->algorithm()->outputDefinitions().at( index );
QString title = output->description();
if ( mResults.contains( output->name() ) )
{
title += QStringLiteral( ": %1" ).arg( mResults.value( output->name() ).toString() );
}
return truncatedTextForItem( title );
}

case Qt::TopEdge:
{
Expand Down Expand Up @@ -975,6 +983,16 @@ bool QgsModelChildAlgorithmGraphicItem::canDeleteComponent()
return false;
}

void QgsModelChildAlgorithmGraphicItem::setResults( const QVariantMap &results )
{
if ( mResults == results )
return;

mResults = results;
update();
emit updateArrowPaths();
}

void QgsModelChildAlgorithmGraphicItem::deleteComponent()
{
if ( const QgsProcessingModelChildAlgorithm *child = dynamic_cast< const QgsProcessingModelChildAlgorithm * >( component() ) )
Expand Down
6 changes: 6 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.h
Expand Up @@ -452,6 +452,11 @@ class GUI_EXPORT QgsModelChildAlgorithmGraphicItem : public QgsModelComponentGra
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
bool canDeleteComponent() override;

/**
* Sets the results obtained for this child algorithm for the last model execution through the dialog.
*/
void setResults( const QVariantMap &results );

protected:

QColor fillColor( State state ) const override;
Expand All @@ -475,6 +480,7 @@ class GUI_EXPORT QgsModelChildAlgorithmGraphicItem : public QgsModelComponentGra
private:
QPicture mPicture;
QPixmap mPixmap;
QVariantMap mResults;
};


Expand Down
3 changes: 3 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -356,6 +356,7 @@ void QgsModelDesignerDialog::setModelScene( QgsModelGraphicsScene *scene )

mScene = scene;
mScene->setParent( this );
mScene->setChildAlgorithmResults( mChildResults );

mView->setModelScene( mScene );

Expand Down Expand Up @@ -440,6 +441,8 @@ bool QgsModelDesignerDialog::checkForUnsavedChanges()
void QgsModelDesignerDialog::setLastRunChildAlgorithmResults( const QVariantMap &results )
{
mChildResults = results;
if ( mScene )
mScene->setChildAlgorithmResults( mChildResults );
}

void QgsModelDesignerDialog::zoomIn()
Expand Down
18 changes: 16 additions & 2 deletions src/gui/processing/models/qgsmodelgraphicsscene.cpp
Expand Up @@ -48,7 +48,7 @@ QgsModelComponentGraphicItem *QgsModelGraphicsScene::createParameterGraphicItem(
return new QgsModelParameterGraphicItem( param, model, nullptr );
}

QgsModelComponentGraphicItem *QgsModelGraphicsScene::createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const
QgsModelChildAlgorithmGraphicItem *QgsModelGraphicsScene::createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const
{
return new QgsModelChildAlgorithmGraphicItem( child, model, nullptr );
}
Expand Down Expand Up @@ -100,9 +100,10 @@ void QgsModelGraphicsScene::createItems( QgsProcessingModelAlgorithm *model, Qgs
const QMap<QString, QgsProcessingModelChildAlgorithm> childAlgs = model->childAlgorithms();
for ( auto it = childAlgs.constBegin(); it != childAlgs.constEnd(); ++it )
{
QgsModelComponentGraphicItem *item = createChildAlgGraphicItem( model, it.value().clone() );
QgsModelChildAlgorithmGraphicItem *item = createChildAlgGraphicItem( model, it.value().clone() );
addItem( item );
item->setPos( it.value().position().x(), it.value().position().y() );
item->setResults( mChildResults.value( it.value().childId() ).toMap() );
mChildAlgorithmItems.insert( it.value().childId(), item );
connect( item, &QgsModelComponentGraphicItem::requestModelRepaint, this, &QgsModelGraphicsScene::rebuildRequired );
connect( item, &QgsModelComponentGraphicItem::changed, this, &QgsModelGraphicsScene::componentChanged );
Expand Down Expand Up @@ -265,6 +266,19 @@ void QgsModelGraphicsScene::setSelectedItem( QgsModelComponentGraphicItem *item
emit selectedItemChanged( item );
}

void QgsModelGraphicsScene::setChildAlgorithmResults( const QVariantMap &results )
{
mChildResults = results;

for ( auto it = mChildResults.constBegin(); it != mChildResults.constEnd(); ++it )
{
if ( QgsModelChildAlgorithmGraphicItem *item = mChildAlgorithmItems.value( it.key() ) )
{
item->setResults( it.value().toMap() );
}
}
}

QList<QgsModelGraphicsScene::LinkSource> QgsModelGraphicsScene::linkSourcesForParameterValue( QgsProcessingModelAlgorithm *model, const QVariant &value, const QString &childId, QgsProcessingContext &context ) const
{
QList<QgsModelGraphicsScene::LinkSource> res;
Expand Down
11 changes: 9 additions & 2 deletions src/gui/processing/models/qgsmodelgraphicsscene.h
Expand Up @@ -28,6 +28,7 @@ class QgsProcessingModelChildAlgorithm;
class QgsProcessingModelOutput;
class QgsProcessingModelComponent;
class QgsProcessingModelComment;
class QgsModelChildAlgorithmGraphicItem;

///@cond NOT_STABLE

Expand Down Expand Up @@ -124,6 +125,11 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
*/
void setSelectedItem( QgsModelComponentGraphicItem *item );

/**
* Sets the results for child algorithms for the last model execution.
*/
void setChildAlgorithmResults( const QVariantMap &results );

signals:

/**
Expand Down Expand Up @@ -160,7 +166,7 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
/**
* Creates a new graphic item for a model child algorithm.
*/
virtual QgsModelComponentGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;
virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;

/**
* Creates a new graphic item for a model output.
Expand Down Expand Up @@ -189,8 +195,9 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
Flags mFlags = nullptr;

QMap< QString, QgsModelComponentGraphicItem * > mParameterItems;
QMap< QString, QgsModelComponentGraphicItem * > mChildAlgorithmItems;
QMap< QString, QgsModelChildAlgorithmGraphicItem * > mChildAlgorithmItems;
QMap< QString, QMap< QString, QgsModelComponentGraphicItem * > > mOutputItems;
QVariantMap mChildResults;

};

Expand Down

0 comments on commit 5963b90

Please sign in to comment.