Skip to content

Commit

Permalink
Move another method to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 2, 2020
1 parent 1bf51a4 commit a38f0cb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
Expand Up @@ -78,6 +78,8 @@ Sets the ``font`` used to render text in the item.

virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent *event );

virtual QVariant itemChange( GraphicsItemChange change, const QVariant &value );


QRectF itemRect() const;
%Docstring
Expand Down
18 changes: 0 additions & 18 deletions python/plugins/processing/modeler/ModelerGraphicItem.py
Expand Up @@ -171,24 +171,6 @@ def getLinkPointForOutput(self, outputIndex):
else:
return QPointF(0, 0)

def itemChange(self, change, value):
if change == QGraphicsItem.ItemPositionHasChanged:
self.updateArrowPaths.emit()
self.component().setPosition(self.pos())

# also need to update the model's stored component's position
if isinstance(self.component(), QgsProcessingModelChildAlgorithm):
self.model().childAlgorithm(self.component().childId()).setPosition(self.pos())
elif isinstance(self.component(), QgsProcessingModelParameter):
self.model().parameterComponent(self.component().parameterName()).setPosition(self.pos())
elif isinstance(self.component(), QgsProcessingModelOutput):
self.model().childAlgorithm(self.component().childId()).modelOutput(
self.component().name()).setPosition(self.pos())
elif change == QGraphicsItem.ItemSelectedChange:
self.repaintArrows.emit()

return super().itemChange(change, value)


class ModelerInputGraphicItem(ModelerGraphicItem):

Expand Down
34 changes: 34 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsmodelgraphicsscene.h"
#include "qgsapplication.h"
#include "qgsmodelgraphicitem.h"
#include "qgsprocessingmodelalgorithm.h"
#include <QSvgRenderer>
#include <QPicture>
#include <QPainter>
Expand Down Expand Up @@ -109,6 +110,39 @@ void QgsModelComponentGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
}
}

QVariant QgsModelComponentGraphicItem::itemChange( QGraphicsItem::GraphicsItemChange change, const QVariant &value )
{
switch ( change )
{
case QGraphicsItem::ItemPositionHasChanged:
{
emit updateArrowPaths();
mComponent->setPosition( pos() );

// also need to update the model's stored component's position
// TODO - this is not so nice, consider moving this to model class
if ( QgsProcessingModelChildAlgorithm *child = dynamic_cast< QgsProcessingModelChildAlgorithm * >( mComponent.get() ) )
mModel->childAlgorithm( child->childId() ).setPosition( pos() );
else if ( QgsProcessingModelParameter *param = dynamic_cast< QgsProcessingModelParameter * >( mComponent.get() ) )
mModel->parameterComponent( param->parameterName() ).setPosition( pos() );
else if ( QgsProcessingModelOutput *output = dynamic_cast< QgsProcessingModelOutput * >( mComponent.get() ) )
mModel->childAlgorithm( output->childId() ).modelOutput( output->name() ).setPosition( pos() );

break;
}
case QGraphicsItem::ItemSelectedChange:
{
emit repaintArrows();
break;
}

default:
break;
}

return QGraphicsObject::itemChange( change, value );
}

QRectF QgsModelComponentGraphicItem::itemRect() const
{
return QRectF( -( mComponent->size().width() + 2 ) / 2.0,
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.h
Expand Up @@ -88,6 +88,7 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
void hoverEnterEvent( QGraphicsSceneHoverEvent *event ) override;
void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override;

/**
* Returns the rectangle representing the body of the item.
Expand Down

0 comments on commit a38f0cb

Please sign in to comment.