mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
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
This commit is contained in:
@@ -542,7 +542,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup *
|
|||||||
if(group->rotation() != rotation)
|
if(group->rotation() != rotation)
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
|
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();
|
int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
@@ -42,30 +43,40 @@ m_angle(angle)
|
|||||||
switch (item->type())
|
switch (item->type())
|
||||||
{
|
{
|
||||||
case Element::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;
|
break;
|
||||||
case ConductorTextItem::Type:
|
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;
|
break;
|
||||||
case IndependentTextItem::Type:
|
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;
|
break;
|
||||||
case DynamicElementTextItem::Type:
|
case DynamicElementTextItem::Type:
|
||||||
|
{
|
||||||
if(item->parentItem() && !item->parentItem()->isSelected())
|
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;
|
break;
|
||||||
case QGraphicsItemGroup::Type:
|
case QGraphicsItemGroup::Type:
|
||||||
|
{
|
||||||
if(ElementTextItemGroup *grp = dynamic_cast<ElementTextItemGroup *>(item))
|
if(ElementTextItemGroup *grp = dynamic_cast<ElementTextItemGroup *>(item))
|
||||||
if(grp->parentElement() && !grp->parentElement()->isSelected())
|
if(grp->parentElement() && !grp->parentElement()->isSelected())
|
||||||
m_group << grp;
|
m_undo << new QPropertyUndoCommand(grp, "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DiagramImageItem::Type:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (QPropertyUndoCommand *undo : m_undo)
|
||||||
|
undo->setAnimated(true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,33 +86,14 @@ m_angle(angle)
|
|||||||
void RotateSelectionCommand::undo()
|
void RotateSelectionCommand::undo()
|
||||||
{
|
{
|
||||||
m_diagram->showMe();
|
m_diagram->showMe();
|
||||||
|
QUndoCommand::undo();
|
||||||
|
|
||||||
for(QPointer<Element> elmt : m_element)
|
for(QPointer<ConductorTextItem> cti : m_cond_text)
|
||||||
if(elmt)
|
|
||||||
elmt.data()->setRotation(elmt.data()->rotation() - m_angle);
|
|
||||||
for(QPointer<DiagramTextItem> text : m_text)
|
|
||||||
{
|
{
|
||||||
if(text)
|
cti->forceRotateByUser(m_rotate_by_user.value(cti.data()));
|
||||||
{
|
if(!cti->wasRotateByUser())
|
||||||
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();
|
cti->parentConductor()->calculateTextItemPosition();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
text.data()->setRotation(text.data()->rotation() - m_angle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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::undo()
|
|||||||
void RotateSelectionCommand::redo()
|
void RotateSelectionCommand::redo()
|
||||||
{
|
{
|
||||||
m_diagram->showMe();
|
m_diagram->showMe();
|
||||||
|
QUndoCommand::redo();
|
||||||
|
|
||||||
for(QPointer<Element> elmt : m_element)
|
for(QPointer<ConductorTextItem> cti : m_cond_text)
|
||||||
if(elmt)
|
|
||||||
elmt.data()->setRotation(elmt.data()->rotation() + m_angle);
|
|
||||||
for(QPointer<DiagramTextItem> text : m_text)
|
|
||||||
{
|
{
|
||||||
if(text)
|
m_rotate_by_user.insert(cti, cti->wasRotateByUser());
|
||||||
{
|
|
||||||
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);
|
cti->forceRotateByUser(true);
|
||||||
}
|
}
|
||||||
text.data()->setRotation(text.data()->rotation() + m_angle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 @@ void RotateSelectionCommand::redo()
|
|||||||
*/
|
*/
|
||||||
bool RotateSelectionCommand::isValid()
|
bool RotateSelectionCommand::isValid()
|
||||||
{
|
{
|
||||||
if(m_element.size()) return true;
|
if(childCount())
|
||||||
if(m_image.size()) return true;
|
return true;
|
||||||
if(m_group.size()) return true;
|
else
|
||||||
if(m_text.size()) return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,8 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class Element;
|
class ConductorTextItem;
|
||||||
class QGraphicsObject;
|
class QPropertyUndoCommand;
|
||||||
class ElementTextItemGroup;
|
|
||||||
class DiagramTextItem;
|
|
||||||
class DiagramImageItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The RotateSelectionCommand class
|
* @brief The RotateSelectionCommand class
|
||||||
@@ -45,11 +42,9 @@ class RotateSelectionCommand : public QUndoCommand
|
|||||||
Diagram *m_diagram =nullptr;
|
Diagram *m_diagram =nullptr;
|
||||||
qreal m_angle;
|
qreal m_angle;
|
||||||
|
|
||||||
QList<QPointer<Element>> m_element;
|
QList<QPointer<ConductorTextItem>> m_cond_text;
|
||||||
QList<QPointer<DiagramImageItem>> m_image;
|
QHash<ConductorTextItem *, bool> m_rotate_by_user;
|
||||||
QList<QPointer<ElementTextItemGroup>> m_group;
|
QList<QPropertyUndoCommand*> m_undo;
|
||||||
QList<QPointer<DiagramTextItem>> m_text;
|
|
||||||
QHash<DiagramTextItem *, bool> m_rotate_by_user;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user