Skip to content

Commit

Permalink
Fix multi item moves, avoid unnecessary scene rebuilds
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent 5149f0b commit b7b4ef2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
Expand Up @@ -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 );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Expand Up @@ -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() )
Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.h
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -271,7 +271,9 @@ void QgsModelDesignerDialog::endUndoCommand()
return;

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

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

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

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

updateWindowTitle();
}
Expand Down
26 changes: 9 additions & 17 deletions src/gui/processing/models/qgsmodelgraphicsview.cpp
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit b7b4ef2

Please sign in to comment.