Skip to content
Permalink
Browse files

Fix multi item moves, avoid unnecessary scene rebuilds

  • Loading branch information
nyalldawson committed Mar 10, 2020
1 parent 5149f0b commit b7b4ef232a76b39139d10c0563b5e272be5d973a
@@ -90,6 +90,15 @@ Sets the ``font`` used to render text in the item.
.. seealso:: :py:func:`font`
%End

void moveComponentBy( qreal dx, qreal dy );
%Docstring
Moves the component by the specified ``dx`` and ``dy``.

.. warning::

Call this method, not QGraphicsItem.moveBy!
%End

virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event );

virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent *event );
@@ -111,6 +111,13 @@ void QgsModelComponentGraphicItem::setFont( const QFont &font )
update();
}

void QgsModelComponentGraphicItem::moveComponentBy( qreal dx, qreal dy )
{
mIsMoving = true;
moveBy( dx, dy );
mIsMoving = false;
}

void QgsModelComponentGraphicItem::mouseDoubleClickEvent( QGraphicsSceneMouseEvent * )
{
if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
@@ -113,6 +113,13 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
void setFont( const QFont &font );

/**
* Moves the component by the specified \a dx and \a dy.
*
* \warning Call this method, not QGraphicsItem::moveBy!
*/
void moveComponentBy( qreal dx, qreal dy );

void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
void hoverEnterEvent( QGraphicsSceneHoverEvent *event ) override;
@@ -271,7 +271,9 @@ void QgsModelDesignerDialog::endUndoCommand()
return;

mActiveCommand->saveAfterState();
mIgnoreUndoStackChanges++;
mUndoStack->push( mActiveCommand.release() );
mIgnoreUndoStackChanges--;
setDirty( true );
}

@@ -291,7 +293,10 @@ void QgsModelDesignerDialog::setModel( QgsProcessingModelAlgorithm *model )

mView->centerOn( 0, 0 );
setDirty( false );

mIgnoreUndoStackChanges++;
mUndoStack->clear();
mIgnoreUndoStackChanges--;

updateWindowTitle();
}
@@ -341,25 +341,17 @@ void QgsModelGraphicsView::keyPressEvent( QKeyEvent *event )
{
QgsModelGraphicsScene *s = modelScene();
const QList<QgsModelComponentGraphicItem *> itemList = s->selectedComponentItems();

QPointF delta = deltaForKeyEvent( event );

#if 0
l->undoStack()->beginMacro( tr( "Move Item" ) );
#endif
for ( QgsModelComponentGraphicItem *item : itemList )
if ( !itemList.empty() )
{
#if 0
l->undoStack()->beginCommand( item, tr( "Move Item" ), QgsLayoutItem::UndoIncrementalMove );
#endif
item->moveBy( delta.x(), delta.y() );
#if 0
l->undoStack()->endCommand();
#endif
QPointF delta = deltaForKeyEvent( event );

itemList.at( 0 )->aboutToChange( tr( "Move Items" ) );
for ( QgsModelComponentGraphicItem *item : itemList )
{
item->moveComponentBy( delta.x(), delta.y() );
}
itemList.at( 0 )->changed();
}
#if 0
l->undoStack()->endMacro();
#endif
event->accept();
}
}

0 comments on commit b7b4ef2

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