Skip to content

Commit

Permalink
Also show child input values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 31, 2020
1 parent 5963b90 commit f268b09
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 1 deletion.
Expand Up @@ -392,6 +392,11 @@ Ownership of ``child`` is transferred to the item.
void setResults( const QVariantMap &results );
%Docstring
Sets the results obtained for this child algorithm for the last model execution through the dialog.
%End

void setInputs( const QVariantMap &inputs );
%Docstring
Sets the inputs used for this child algorithm for the last model execution through the dialog.
%End

protected:
Expand Down
Expand Up @@ -100,6 +100,11 @@ Returns ``False`` if the cancel option was selected
void setLastRunChildAlgorithmResults( const QVariantMap &results );
%Docstring
Sets the results of child algorithms for the last run of the model through the designer window.
%End

void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );
%Docstring
Sets the inputs for child algorithms for the last run of the model through the designer window.
%End

};
Expand Down
Expand Up @@ -117,6 +117,11 @@ Clears any selected items and sets ``item`` as the current selection.
void setChildAlgorithmResults( const QVariantMap &results );
%Docstring
Sets the results for child algorithms for the last model execution.
%End

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

signals:
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -122,6 +122,7 @@ def runModel(self):

def on_finished(successful, results):
self.setLastRunChildAlgorithmResults(dlg.results()['CHILD_RESULTS'])
self.setLastRunChildAlgorithmInputs(dlg.results()['CHILD_INPUTS'])

dlg = AlgorithmDialog(self.model().create(), parent=self)
dlg.setParameters(self.model().designerParameterValues())
Expand Down
4 changes: 4 additions & 0 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -253,6 +253,8 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
QgsExpressionContext baseContext = createExpressionContext( parameters, context );

QVariantMap childResults;
QVariantMap childInputs;

QVariantMap finalResults;
QSet< QString > executed;
bool executedAlg = true;
Expand Down Expand Up @@ -299,6 +301,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
if ( feedback && !skipGenericLogging )
feedback->setProgressText( QObject::tr( "Running %1 [%2/%3]" ).arg( child.description() ).arg( executed.count() + 1 ).arg( toExecute.count() ) );

childInputs.insert( childId, childParams );
QStringList params;
for ( auto childParamIt = childParams.constBegin(); childParamIt != childParams.constEnd(); ++childParamIt )
{
Expand Down Expand Up @@ -403,6 +406,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa

mResults = finalResults;
mResults.insert( QStringLiteral( "CHILD_RESULTS" ), childResults );
mResults.insert( QStringLiteral( "CHILD_INPUTS" ), childInputs );
return mResults;
}

Expand Down
16 changes: 15 additions & 1 deletion src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Expand Up @@ -954,7 +954,11 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind
return param->flags() & QgsProcessingParameterDefinition::FlagHidden || param->isDestination();
} ), params.end() );

return truncatedTextForItem( params.at( index )->description() );

QString title = params.at( index )->description();
if ( !mInputs.value( params.at( index )->name() ).toString().isEmpty() )
title += QStringLiteral( ": %1" ).arg( mInputs.value( params.at( index )->name() ).toString() );
return truncatedTextForItem( title );
}

case Qt::LeftEdge:
Expand Down Expand Up @@ -993,6 +997,16 @@ void QgsModelChildAlgorithmGraphicItem::setResults( const QVariantMap &results )
emit updateArrowPaths();
}

void QgsModelChildAlgorithmGraphicItem::setInputs( const QVariantMap &inputs )
{
if ( mInputs == inputs )
return;

mInputs = inputs;
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 @@ -457,6 +457,11 @@ class GUI_EXPORT QgsModelChildAlgorithmGraphicItem : public QgsModelComponentGra
*/
void setResults( const QVariantMap &results );

/**
* Sets the inputs used for this child algorithm for the last model execution through the dialog.
*/
void setInputs( const QVariantMap &inputs );

protected:

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


Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -445,6 +445,13 @@ void QgsModelDesignerDialog::setLastRunChildAlgorithmResults( const QVariantMap
mScene->setChildAlgorithmResults( mChildResults );
}

void QgsModelDesignerDialog::setLastRunChildAlgorithmInputs( const QVariantMap &inputs )
{
mChildInputs = inputs;
if ( mScene )
mScene->setChildAlgorithmInputs( mChildInputs );
}

void QgsModelDesignerDialog::zoomIn()
{
mView->setTransformationAnchor( QGraphicsView::NoAnchor );
Expand Down
6 changes: 6 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.h
Expand Up @@ -125,6 +125,11 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
*/
void setLastRunChildAlgorithmResults( const QVariantMap &results );

/**
* Sets the inputs for child algorithms for the last run of the model through the designer window.
*/
void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );

private slots:
void zoomIn();
void zoomOut();
Expand Down Expand Up @@ -170,6 +175,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
int mBlockRepaints = 0;

QVariantMap mChildResults;
QVariantMap mChildInputs;

bool isDirty() const;

Expand Down
14 changes: 14 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.cpp
Expand Up @@ -104,6 +104,7 @@ void QgsModelGraphicsScene::createItems( QgsProcessingModelAlgorithm *model, Qgs
addItem( item );
item->setPos( it.value().position().x(), it.value().position().y() );
item->setResults( mChildResults.value( it.value().childId() ).toMap() );
item->setInputs( mChildInputs.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 @@ -279,6 +280,19 @@ void QgsModelGraphicsScene::setChildAlgorithmResults( const QVariantMap &results
}
}

void QgsModelGraphicsScene::setChildAlgorithmInputs( const QVariantMap &inputs )
{
mChildInputs = inputs;

for ( auto it = mChildInputs.constBegin(); it != mChildInputs.constEnd(); ++it )
{
if ( QgsModelChildAlgorithmGraphicItem *item = mChildAlgorithmItems.value( it.key() ) )
{
item->setInputs( 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
6 changes: 6 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.h
Expand Up @@ -130,6 +130,11 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
*/
void setChildAlgorithmResults( const QVariantMap &results );

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

signals:

/**
Expand Down Expand Up @@ -198,6 +203,7 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
QMap< QString, QgsModelChildAlgorithmGraphicItem * > mChildAlgorithmItems;
QMap< QString, QMap< QString, QgsModelComponentGraphicItem * > > mOutputItems;
QVariantMap mChildResults;
QVariantMap mChildInputs;

};

Expand Down

0 comments on commit f268b09

Please sign in to comment.