Skip to content
Permalink
Browse files

Move another method to c++

  • Loading branch information
nyalldawson committed Mar 2, 2020
1 parent 1bf51a4 commit a38f0cbbd49fa92d1fccb4fadf93fba6c2fa9612
@@ -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
@@ -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):

@@ -21,6 +21,7 @@
#include "qgsmodelgraphicsscene.h"
#include "qgsapplication.h"
#include "qgsmodelgraphicitem.h"
#include "qgsprocessingmodelalgorithm.h"
#include <QSvgRenderer>
#include <QPicture>
#include <QPainter>
@@ -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,
@@ -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.

0 comments on commit a38f0cb

Please sign in to comment.
You can’t perform that action at this time.