Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix output items placement when they are added after addition of the
algorithm item (fix #48132)
  • Loading branch information
alexbruy authored and nyalldawson committed Jun 18, 2022
1 parent d486358 commit f88419b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/gui/processing/models/qgsmodelgraphicsscene.cpp
Expand Up @@ -224,6 +224,11 @@ void QgsModelGraphicsScene::createItems( QgsProcessingModelAlgorithm *model, Qgs
const QMap<QString, QgsProcessingModelOutput> outputs = it.value().modelOutputs();
QMap< QString, QgsModelComponentGraphicItem * > outputItems;

// offsets from algorithm item needed to correctly place output items
// which does not have valid position assigned (https://github.com/qgis/QGIS/issues/48132)
double output_offset_x = mChildAlgorithmItems[it.value().childId()]->component()->size().width();
double output_offset_y = 1.5 * mChildAlgorithmItems[it.value().childId()]->component()->size().height();

for ( auto outputIt = outputs.constBegin(); outputIt != outputs.constEnd(); ++outputIt )
{
QgsModelComponentGraphicItem *item = createOutputGraphicItem( model, outputIt.value().clone() );
Expand All @@ -232,7 +237,15 @@ void QgsModelGraphicsScene::createItems( QgsProcessingModelAlgorithm *model, Qgs
connect( item, &QgsModelComponentGraphicItem::changed, this, &QgsModelGraphicsScene::componentChanged );
connect( item, &QgsModelComponentGraphicItem::aboutToChange, this, &QgsModelGraphicsScene::componentAboutToChange );

const QPointF pos = outputIt.value().position();
// if output added not at the same time as algorithm then it does not have
// valid position and will be placed at (0,0). We need to calculate better position.
// See https://github.com/qgis/QGIS/issues/48132.
QPointF pos = outputIt.value().position();
if ( pos.isNull() )
{
pos = mChildAlgorithmItems[it.value().childId()]->component()->position() + QPointF( output_offset_x, output_offset_y );
output_offset_y += 1.5 * outputIt.value().size().height();
}
int idx = -1;
int i = 0;
// find the actual index of the linked output from the child algorithm it comes from
Expand Down

0 comments on commit f88419b

Please sign in to comment.