[qet] qet/qet: [5296] diagram editor : undo/redo of a rotation is now animated |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5296
Author: blacksun
Date: 2018-04-04 18:55:59 +0200 (Wed, 04 Apr 2018)
Log Message:
-----------
diagram editor : undo/redo of a rotation is now animated
Modified Paths:
--------------
trunk/sources/ui/dynamicelementtextmodel.cpp
trunk/sources/undocommand/rotateselectioncommand.cpp
trunk/sources/undocommand/rotateselectioncommand.h
Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp 2018-04-04 15:07:52 UTC (rev 5295)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp 2018-04-04 16:55:59 UTC (rev 5296)
@@ -542,7 +542,7 @@
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();
Modified: trunk/sources/undocommand/rotateselectioncommand.cpp
===================================================================
--- trunk/sources/undocommand/rotateselectioncommand.cpp 2018-04-04 15:07:52 UTC (rev 5295)
+++ trunk/sources/undocommand/rotateselectioncommand.cpp 2018-04-04 16:55:59 UTC (rev 5296)
@@ -25,6 +25,7 @@
#include "diagram.h"
#include "conductor.h"
#include "qet.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include <QGraphicsItem>
@@ -42,30 +43,40 @@
switch (item->type())
{
case Element::Type:
- m_element << static_cast<Element *>(item);
+ m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
break;
case ConductorTextItem::Type:
- m_text << static_cast<DiagramTextItem *>(item);
+ {
+ m_cond_text << static_cast<ConductorTextItem *>(item);
+ m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
+ }
break;
case IndependentTextItem::Type:
- m_text << static_cast<DiagramTextItem *>(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<DiagramTextItem *>(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<ElementTextItemGroup *>(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<DiagramImageItem *>(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 @@
void RotateSelectionCommand::undo()
{
m_diagram->showMe();
+ QUndoCommand::undo();
- for(QPointer<Element> elmt : m_element)
- if(elmt)
- elmt.data()->setRotation(elmt.data()->rotation() - m_angle);
- for(QPointer<DiagramTextItem> text : m_text)
+ for(QPointer<ConductorTextItem> cti : m_cond_text)
{
- if(text)
- {
- if(text.data()->type() == ConductorTextItem::Type)
- {
- ConductorTextItem *cti = static_cast<ConductorTextItem *>(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<DiagramImageItem> image : m_image)
- if(image)
- image.data()->setRotation(image.data()->rotation() - m_angle);
- for(QPointer<ElementTextItemGroup> group : m_group)
- if(group)
- group.data()->setRotation(group.data()->rotation() - m_angle);
}
/**
@@ -110,29 +102,13 @@
void RotateSelectionCommand::redo()
{
m_diagram->showMe();
+ QUndoCommand::redo();
- for(QPointer<Element> elmt : m_element)
- if(elmt)
- elmt.data()->setRotation(elmt.data()->rotation() + m_angle);
- for(QPointer<DiagramTextItem> text : m_text)
- {
- if(text)
+ for(QPointer<ConductorTextItem> cti : m_cond_text)
{
- if(text.data()->type() == ConductorTextItem::Type)
- {
- ConductorTextItem *cti = static_cast<ConductorTextItem *>(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<DiagramImageItem> image : m_image)
- if(image)
- image.data()->setRotation(image.data()->rotation() + m_angle);
- for(QPointer<ElementTextItemGroup> group : m_group)
- if(group)
- group.data()->setRotation(group.data()->rotation() + m_angle);
}
/**
@@ -141,10 +117,8 @@
*/
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;
}
Modified: trunk/sources/undocommand/rotateselectioncommand.h
===================================================================
--- trunk/sources/undocommand/rotateselectioncommand.h 2018-04-04 15:07:52 UTC (rev 5295)
+++ trunk/sources/undocommand/rotateselectioncommand.h 2018-04-04 16:55:59 UTC (rev 5296)
@@ -22,11 +22,8 @@
#include <QPointer>
class Diagram;
-class Element;
-class QGraphicsObject;
-class ElementTextItemGroup;
-class DiagramTextItem;
-class DiagramImageItem;
+class ConductorTextItem;
+class QPropertyUndoCommand;
/**
* @brief The RotateSelectionCommand class
@@ -45,11 +42,9 @@
Diagram *m_diagram =nullptr;
qreal m_angle;
- QList<QPointer<Element>> m_element;
- QList<QPointer<DiagramImageItem>> m_image;
- QList<QPointer<ElementTextItemGroup>> m_group;
- QList<QPointer<DiagramTextItem>> m_text;
- QHash<DiagramTextItem *, bool> m_rotate_by_user;
+ QList<QPointer<ConductorTextItem>> m_cond_text;
+ QHash<ConductorTextItem *, bool> m_rotate_by_user;
+ QList<QPropertyUndoCommand*> m_undo;
};