From 1450771081898dd66918f1f4313d2820593af902 Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 4 Apr 2018 16:55:59 +0000 Subject: [PATCH] diagram editor : undo/redo of a rotation is now animated git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5296 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/ui/dynamicelementtextmodel.cpp | 2 +- .../undocommand/rotateselectioncommand.cpp | 86 +++++++------------ sources/undocommand/rotateselectioncommand.h | 15 ++-- 3 files changed, 36 insertions(+), 67 deletions(-) diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index 9efe235e7..228b30821 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -542,7 +542,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup * if(group->rotation() != rotation) { QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo); - qpuc->enableAnimation(); + qpuc->setAnimated(true, false); } int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt(); diff --git a/sources/undocommand/rotateselectioncommand.cpp b/sources/undocommand/rotateselectioncommand.cpp index d1ece9a48..f98e55a9c 100644 --- a/sources/undocommand/rotateselectioncommand.cpp +++ b/sources/undocommand/rotateselectioncommand.cpp @@ -25,6 +25,7 @@ #include "diagram.h" #include "conductor.h" #include "qet.h" +#include "QPropertyUndoCommand/qpropertyundocommand.h" #include @@ -42,30 +43,40 @@ m_angle(angle) switch (item->type()) { case Element::Type: - m_element << static_cast(item); + m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this); break; case ConductorTextItem::Type: - m_text << static_cast(item); + { + m_cond_text << static_cast(item); + m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this); + } break; case IndependentTextItem::Type: - m_text << static_cast(item); + m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this); break; case DynamicElementTextItem::Type: + { if(item->parentItem() && !item->parentItem()->isSelected()) - m_text << static_cast(item); + m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this); + } break; case QGraphicsItemGroup::Type: + { if(ElementTextItemGroup *grp = dynamic_cast(item)) if(grp->parentElement() && !grp->parentElement()->isSelected()) - m_group << grp; + m_undo << new QPropertyUndoCommand(grp, "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this); + } break; case DiagramImageItem::Type: - m_image << static_cast(item); + m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this); break; default: break; } } + + for (QPropertyUndoCommand *undo : m_undo) + undo->setAnimated(true, false); } } @@ -75,33 +86,14 @@ m_angle(angle) void RotateSelectionCommand::undo() { m_diagram->showMe(); + QUndoCommand::undo(); - for(QPointer elmt : m_element) - if(elmt) - elmt.data()->setRotation(elmt.data()->rotation() - m_angle); - for(QPointer text : m_text) + for(QPointer cti : m_cond_text) { - if(text) - { - if(text.data()->type() == ConductorTextItem::Type) - { - ConductorTextItem *cti = static_cast(text.data()); - cti->forceRotateByUser(m_rotate_by_user.value(text.data())); - if(cti->wasRotateByUser()) - cti->setRotation(cti->rotation() - m_angle); - else - cti->parentConductor()->calculateTextItemPosition(); - } - else - text.data()->setRotation(text.data()->rotation() - m_angle); - } + cti->forceRotateByUser(m_rotate_by_user.value(cti.data())); + if(!cti->wasRotateByUser()) + cti->parentConductor()->calculateTextItemPosition(); } - for(QPointer image : m_image) - if(image) - image.data()->setRotation(image.data()->rotation() - m_angle); - for(QPointer group : m_group) - if(group) - group.data()->setRotation(group.data()->rotation() - m_angle); } /** @@ -110,29 +102,13 @@ void RotateSelectionCommand::undo() void RotateSelectionCommand::redo() { m_diagram->showMe(); + QUndoCommand::redo(); - for(QPointer elmt : m_element) - if(elmt) - elmt.data()->setRotation(elmt.data()->rotation() + m_angle); - for(QPointer text : m_text) - { - if(text) + for(QPointer cti : m_cond_text) { - if(text.data()->type() == ConductorTextItem::Type) - { - ConductorTextItem *cti = static_cast(text.data()); - m_rotate_by_user.insert(text.data(), cti->wasRotateByUser()); - cti->forceRotateByUser(true); - } - text.data()->setRotation(text.data()->rotation() + m_angle); + m_rotate_by_user.insert(cti, cti->wasRotateByUser()); + cti->forceRotateByUser(true); } - } - for(QPointer image : m_image) - if(image) - image.data()->setRotation(image.data()->rotation() + m_angle); - for(QPointer group : m_group) - if(group) - group.data()->setRotation(group.data()->rotation() + m_angle); } /** @@ -141,10 +117,8 @@ void RotateSelectionCommand::redo() */ bool RotateSelectionCommand::isValid() { - if(m_element.size()) return true; - if(m_image.size()) return true; - if(m_group.size()) return true; - if(m_text.size()) return true; - - return false; + if(childCount()) + return true; + else + return false; } diff --git a/sources/undocommand/rotateselectioncommand.h b/sources/undocommand/rotateselectioncommand.h index 4d1b18d68..b34210ab5 100644 --- a/sources/undocommand/rotateselectioncommand.h +++ b/sources/undocommand/rotateselectioncommand.h @@ -22,11 +22,8 @@ #include class Diagram; -class Element; -class QGraphicsObject; -class ElementTextItemGroup; -class DiagramTextItem; -class DiagramImageItem; +class ConductorTextItem; +class QPropertyUndoCommand; /** * @brief The RotateSelectionCommand class @@ -45,11 +42,9 @@ class RotateSelectionCommand : public QUndoCommand Diagram *m_diagram =nullptr; qreal m_angle; - QList> m_element; - QList> m_image; - QList> m_group; - QList> m_text; - QHash m_rotate_by_user; + QList> m_cond_text; + QHash m_rotate_by_user; + QList m_undo; };