Move another method to c++

This commit is contained in:
Nyall Dawson 2020-03-02 13:04:41 +10:00
parent 1bf51a4fbb
commit a38f0cbbd4
4 changed files with 37 additions and 18 deletions

View File

@ -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

View File

@ -171,24 +171,6 @@ class ModelerGraphicItem(QgsModelComponentGraphicItem):
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):

View File

@ -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,

View File

@ -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.