mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Element texts group is fully managed by the undo stack
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5124 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -3,4 +3,5 @@ LinkElementCommand = 2
|
|||||||
ItemResizerCommand = 3
|
ItemResizerCommand = 3
|
||||||
ChangeShapeStyleCommand = 4
|
ChangeShapeStyleCommand = 4
|
||||||
QetShapeGeometryCommand = 5
|
QetShapeGeometryCommand = 5
|
||||||
|
AlignmentTextsGroupCommand = 6
|
||||||
QPropertyUndoCommand = 10 000
|
QPropertyUndoCommand = 10 000
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
|
#include "elementtextitemgroup.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementTextsMover::ElementTextsMover
|
* @brief ElementTextsMover::ElementTextsMover
|
||||||
@@ -44,26 +46,54 @@ bool ElementTextsMover::isReady() const {
|
|||||||
*/
|
*/
|
||||||
int ElementTextsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_item)
|
int ElementTextsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_item)
|
||||||
{
|
{
|
||||||
if (m_movement_running || !diagram) return(-1);
|
if (m_movement_running || !diagram)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
m_diagram = diagram;
|
m_diagram = diagram;
|
||||||
m_movement_driver = driver_item;
|
m_movement_driver = driver_item;
|
||||||
m_texts_item_H.clear();
|
m_last_pos = driver_item->pos();
|
||||||
|
m_items_hash.clear();
|
||||||
|
m_text_count = m_group_count =0;
|
||||||
|
// m_texts_hash.clear();
|
||||||
|
// m_grps_hash.clear();
|
||||||
|
|
||||||
|
// for(QGraphicsItem *item : diagram->selectedItems())
|
||||||
|
// {
|
||||||
|
// if (item->type() == ElementTextItem::Type || item->type() == DynamicElementTextItem::Type)
|
||||||
|
// {
|
||||||
|
// DiagramTextItem *dti = static_cast<DiagramTextItem *> (item);
|
||||||
|
// m_texts_hash.insert(dti, dti->pos());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
for(QGraphicsItem *item : diagram->selectedItems())
|
for(QGraphicsItem *item : diagram->selectedItems())
|
||||||
{
|
{
|
||||||
if (item->type() == ElementTextItem::Type || item->type() == DynamicElementTextItem::Type)
|
if(item->type() == ElementTextItem::Type || item->type() == DynamicElementTextItem::Type)
|
||||||
{
|
{
|
||||||
DiagramTextItem *dti = static_cast<DiagramTextItem *> (item);
|
m_items_hash.insert(item, item->pos());
|
||||||
m_texts_item_H.insert(dti, dti->pos());
|
m_text_count++;
|
||||||
}
|
}
|
||||||
|
else if(item->type() == QGraphicsItemGroup::Type)
|
||||||
|
{
|
||||||
|
if(dynamic_cast<ElementTextItemGroup *>(item))
|
||||||
|
{
|
||||||
|
m_items_hash.insert(item, item->pos());
|
||||||
|
m_group_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_texts_item_H.size()) return(-1);
|
// if (!m_texts_hash.size())
|
||||||
|
// return(-1);
|
||||||
|
|
||||||
|
if(m_items_hash.isEmpty())
|
||||||
|
return -1;
|
||||||
|
|
||||||
m_movement_running = true;
|
m_movement_running = true;
|
||||||
|
|
||||||
return(m_texts_item_H.size());
|
return m_items_hash.size();
|
||||||
|
|
||||||
|
// return(m_texts_hash.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,15 +104,28 @@ int ElementTextsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_ite
|
|||||||
*/
|
*/
|
||||||
void ElementTextsMover::continueMovement(const QPointF &movement)
|
void ElementTextsMover::continueMovement(const QPointF &movement)
|
||||||
{
|
{
|
||||||
if (!m_movement_running || movement.isNull()) return;
|
if (!m_movement_running || movement.isNull())
|
||||||
|
return;
|
||||||
|
|
||||||
for(DiagramTextItem *text_item : m_texts_item_H.keys())
|
QPointF move = m_movement_driver->pos() - m_last_pos;
|
||||||
|
m_last_pos = m_movement_driver->pos();
|
||||||
|
|
||||||
|
for(QGraphicsItem *qgi : m_items_hash.keys())
|
||||||
{
|
{
|
||||||
if (text_item == m_movement_driver)
|
if(qgi == m_movement_driver)
|
||||||
continue;
|
continue;
|
||||||
QPointF applied_movement = text_item->mapMovementToParent(text_item->mapMovementFromScene(movement));
|
|
||||||
text_item->setPos(text_item->pos() + applied_movement);
|
qgi->setPos(qgi->pos() + move);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for(DiagramTextItem *text_item : m_texts_hash.keys())
|
||||||
|
// {
|
||||||
|
// if (text_item == m_movement_driver)
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
// QPointF applied_movement = text_item->mapMovementToParent(text_item->mapMovementFromScene(movement));
|
||||||
|
// text_item->setPos(text_item->pos() + applied_movement);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,26 +134,70 @@ void ElementTextsMover::continueMovement(const QPointF &movement)
|
|||||||
*/
|
*/
|
||||||
void ElementTextsMover::endMovement()
|
void ElementTextsMover::endMovement()
|
||||||
{
|
{
|
||||||
//No movement running, or no text to move
|
// //No movement running, or no text to move
|
||||||
if (!m_movement_running || m_texts_item_H.isEmpty())
|
// if (!m_movement_running || m_texts_hash.isEmpty())
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
|
// //Movement is null
|
||||||
|
// DiagramTextItem *dti = m_texts_hash.keys().first();
|
||||||
|
// if (dti->pos() == m_texts_hash.value(dti))
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// QUndoCommand *undo = new QUndoCommand(m_texts_hash.size() == 1 ? QString(QObject::tr("Déplacer un texte d'élément")) :
|
||||||
|
// QString(QObject::tr("Déplacer %1 textes d'élément").arg(m_texts_hash.size())));
|
||||||
|
|
||||||
|
// for (DiagramTextItem *dti : m_texts_hash.keys())
|
||||||
|
// {
|
||||||
|
// QPropertyUndoCommand *child_undo = new QPropertyUndoCommand(dti, "pos", m_texts_hash.value(dti), dti->pos(), undo);
|
||||||
|
// child_undo->enableAnimation();
|
||||||
|
// }
|
||||||
|
|
||||||
|
//No movement or no items to move
|
||||||
|
if(!m_movement_running || m_items_hash.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
//Movement is null
|
//Movement is null
|
||||||
DiagramTextItem *dti = m_texts_item_H.keys().first();
|
QGraphicsItem *qgi = m_items_hash.keys().first();
|
||||||
if (dti->pos() == m_texts_item_H.value(dti))
|
if(qgi->pos() == m_items_hash.value(qgi))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
QUndoCommand *undo = new QUndoCommand(undoText());
|
||||||
|
|
||||||
QUndoCommand *undo = new QUndoCommand(m_texts_item_H.size() == 1 ? QString(QObject::tr("Déplacer un texte d'élément")) :
|
for (QGraphicsItem *qgi : m_items_hash.keys())
|
||||||
QString(QObject::tr("Déplacer %1 textes d'élément").arg(m_texts_item_H.size())));
|
|
||||||
|
|
||||||
for (DiagramTextItem *dti : m_texts_item_H.keys())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *child_undo = new QPropertyUndoCommand(dti, "pos", m_texts_item_H.value(dti), dti->pos(), undo);
|
if(QObject *object = dynamic_cast<QObject *>(qgi))
|
||||||
child_undo->enableAnimation();
|
{
|
||||||
|
QPropertyUndoCommand *child_undo = new QPropertyUndoCommand(object, "pos", m_items_hash.value(qgi), qgi->pos(), undo);
|
||||||
|
child_undo->enableAnimation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_diagram->undoStack().push(undo);
|
m_diagram->undoStack().push(undo);
|
||||||
|
|
||||||
m_movement_running = false;
|
m_movement_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ElementTextsMover::undoText() const
|
||||||
|
{
|
||||||
|
QString undo_text;
|
||||||
|
|
||||||
|
if(m_text_count == 1)
|
||||||
|
undo_text.append(QObject::tr("Déplacer un texte d'élément"));
|
||||||
|
else if(m_text_count > 1)
|
||||||
|
undo_text.append(QObject::tr("Déplacer %1 textes d'élément").arg(m_items_hash.size()));
|
||||||
|
|
||||||
|
if(m_group_count >= 1)
|
||||||
|
{
|
||||||
|
if(undo_text.isEmpty())
|
||||||
|
undo_text.append(QObject::tr("Déplacer"));
|
||||||
|
else
|
||||||
|
undo_text.append(QObject::tr(" et"));
|
||||||
|
|
||||||
|
if(m_group_count == 1)
|
||||||
|
undo_text.append(QObject::tr(" un groupe de texte"));
|
||||||
|
else
|
||||||
|
undo_text.append(QObject::tr((" %1 groupes de textes")).arg(m_group_count));
|
||||||
|
}
|
||||||
|
|
||||||
|
return undo_text;
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
class QGraphicsItem;
|
class QGraphicsItem;
|
||||||
class DiagramTextItem;
|
class DiagramTextItem;
|
||||||
class Diagram;
|
class Diagram;
|
||||||
|
class QGraphicsItemGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class manages the interactive movement of element text items on a
|
This class manages the interactive movement of element text items on a
|
||||||
@@ -41,11 +42,19 @@ class ElementTextsMover
|
|||||||
int beginMovement(Diagram *diagram, QGraphicsItem *driver_item = nullptr);
|
int beginMovement(Diagram *diagram, QGraphicsItem *driver_item = nullptr);
|
||||||
void continueMovement(const QPointF &);
|
void continueMovement(const QPointF &);
|
||||||
void endMovement();
|
void endMovement();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString undoText() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_movement_running = false;
|
bool m_movement_running = false;
|
||||||
Diagram *m_diagram = nullptr;
|
Diagram *m_diagram = nullptr;
|
||||||
QGraphicsItem *m_movement_driver = nullptr;
|
QGraphicsItem *m_movement_driver = nullptr;
|
||||||
QHash <DiagramTextItem *, QPointF> m_texts_item_H;
|
QHash <DiagramTextItem *, QPointF> m_texts_hash;
|
||||||
|
QHash <QGraphicsItemGroup *, QPointF> m_grps_hash;
|
||||||
|
QHash <QGraphicsItem *, QPointF> m_items_hash;
|
||||||
|
QPointF m_last_pos;
|
||||||
|
int m_text_count = 0,
|
||||||
|
m_group_count = 0;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -727,7 +727,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
//Set the alignment to top, because top is not used by groupand so,
|
//Set the alignment to top, because top is not used by groupand so,
|
||||||
//each time a text is removed from the group, the alignement is not updated
|
//each time a text is removed from the group, the alignement is not updated
|
||||||
Qt::Alignment al = group->alignment();
|
Qt::Alignment al = group->alignment();
|
||||||
group->setAlignement(Qt::AlignTop);
|
group->setAlignment(Qt::AlignTop);
|
||||||
|
|
||||||
//Remove the texts from group
|
//Remove the texts from group
|
||||||
QList<DynamicElementTextItem *> deti_list = group->texts();
|
QList<DynamicElementTextItem *> deti_list = group->texts();
|
||||||
@@ -743,7 +743,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
group->addToGroup(deti);
|
group->addToGroup(deti);
|
||||||
|
|
||||||
//Restor the alignement
|
//Restor the alignement
|
||||||
group->setAlignement(al);
|
group->setAlignment(al);
|
||||||
|
|
||||||
//Save the group to xml
|
//Save the group to xml
|
||||||
texts_group.appendChild(group->toXml(document));
|
texts_group.appendChild(group->toXml(document));
|
||||||
@@ -759,7 +759,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Element::addDynamiqueTextItem
|
* @brief Element::addDynamiqueTextItem
|
||||||
* Add @deti as a dynamic text item of this element
|
* Add @deti as a dynamic text item of this element, @deti is reparented to this
|
||||||
* If @deti is null, a new DynamicElementTextItem is created and added to this element.
|
* If @deti is null, a new DynamicElementTextItem is created and added to this element.
|
||||||
* @param deti
|
* @param deti
|
||||||
*/
|
*/
|
||||||
@@ -768,6 +768,7 @@ void Element::addDynamicTextItem(DynamicElementTextItem *deti)
|
|||||||
if (deti && !m_dynamic_text_list.contains(deti))
|
if (deti && !m_dynamic_text_list.contains(deti))
|
||||||
{
|
{
|
||||||
m_dynamic_text_list.append(deti);
|
m_dynamic_text_list.append(deti);
|
||||||
|
deti->setParentItem(this);
|
||||||
emit textAdded(deti);
|
emit textAdded(deti);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -780,9 +781,8 @@ void Element::addDynamicTextItem(DynamicElementTextItem *deti)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Element::removeDynamicTextItem
|
* @brief Element::removeDynamicTextItem
|
||||||
* Remove @deti, no matter if is a child of this element or
|
* Remove @deti, no matter if is a child of this element or a child of a group of this element.
|
||||||
* a child of a group of this element.
|
* Set he parent item of @deti to 0, @deti is not deleted.
|
||||||
* The parent item of deti stay this item and deti is not deleted.
|
|
||||||
* @param deti
|
* @param deti
|
||||||
*/
|
*/
|
||||||
void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
||||||
@@ -790,6 +790,7 @@ void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
|||||||
if (m_dynamic_text_list.contains(deti))
|
if (m_dynamic_text_list.contains(deti))
|
||||||
{
|
{
|
||||||
m_dynamic_text_list.removeOne(deti);
|
m_dynamic_text_list.removeOne(deti);
|
||||||
|
deti->setParentItem(nullptr);
|
||||||
emit textRemoved(deti);
|
emit textRemoved(deti);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -800,6 +801,7 @@ void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
|||||||
{
|
{
|
||||||
removeTextFromGroup(deti, group);
|
removeTextFromGroup(deti, group);
|
||||||
m_dynamic_text_list.removeOne(deti);
|
m_dynamic_text_list.removeOne(deti);
|
||||||
|
deti->setParentItem(nullptr);
|
||||||
emit textRemoved(deti);
|
emit textRemoved(deti);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -848,10 +850,26 @@ ElementTextItemGroup *Element::addTextGroup(const QString &name)
|
|||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Element::addTextGroup
|
||||||
|
* @param group add group @group to the group of this element.
|
||||||
|
* the group must not be owned by an element.
|
||||||
|
*/
|
||||||
|
void Element::addTextGroup(ElementTextItemGroup *group)
|
||||||
|
{
|
||||||
|
if(group->parentElement())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_texts_group << group;
|
||||||
|
group->setParentItem(this);
|
||||||
|
emit textsGroupAdded(group);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Element::removeTextGroup
|
* @brief Element::removeTextGroup
|
||||||
* Remove the text group with name @name
|
* Remove the text group @group from this element, and set the parent of group to 0.
|
||||||
* All text owned by the group will be reparented to this element
|
* group is not deleted.
|
||||||
|
* All texts owned by the group will be reparented to this element
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
void Element::removeTextGroup(ElementTextItemGroup *group)
|
void Element::removeTextGroup(ElementTextItemGroup *group)
|
||||||
@@ -870,9 +888,10 @@ void Element::removeTextGroup(ElementTextItemGroup *group)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_texts_group.removeOne(group);
|
|
||||||
emit textsGroupAboutToBeRemoved(group);
|
emit textsGroupAboutToBeRemoved(group);
|
||||||
delete group;
|
m_texts_group.removeOne(group);
|
||||||
|
group->setParentItem(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -912,10 +931,13 @@ bool Element::addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup
|
|||||||
return false;
|
return false;
|
||||||
if(!m_texts_group.contains(group))
|
if(!m_texts_group.contains(group))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
m_dynamic_text_list.removeOne(text);
|
||||||
|
emit textRemoved(text);
|
||||||
|
|
||||||
removeDynamicTextItem(text);
|
|
||||||
group->addToGroup(text);
|
group->addToGroup(text);
|
||||||
emit textAddedToGroup(text, group);
|
emit textAddedToGroup(text, group);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,7 +951,7 @@ bool Element::removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemG
|
|||||||
if(!m_texts_group.contains(group))
|
if(!m_texts_group.contains(group))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(group->childItems().contains(text))
|
if(group->texts().contains(text))
|
||||||
{
|
{
|
||||||
group->removeFromGroup(text);
|
group->removeFromGroup(text);
|
||||||
emit textRemovedFromGroup(text, group);
|
emit textRemovedFromGroup(text, group);
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ class Element : public QetGraphicsItem
|
|||||||
void removeDynamicTextItem(DynamicElementTextItem *deti);
|
void removeDynamicTextItem(DynamicElementTextItem *deti);
|
||||||
QList<DynamicElementTextItem *> dynamicTextItems() const;
|
QList<DynamicElementTextItem *> dynamicTextItems() const;
|
||||||
ElementTextItemGroup *addTextGroup(const QString &name);
|
ElementTextItemGroup *addTextGroup(const QString &name);
|
||||||
|
void addTextGroup(ElementTextItemGroup *group);
|
||||||
void removeTextGroup(ElementTextItemGroup *group);
|
void removeTextGroup(ElementTextItemGroup *group);
|
||||||
ElementTextItemGroup *textGroup(const QString &name) const;
|
ElementTextItemGroup *textGroup(const QString &name) const;
|
||||||
QList<ElementTextItemGroup *> textGroups() const;
|
QList<ElementTextItemGroup *> textGroups() const;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
#include "addelementtextcommand.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
@@ -34,8 +35,7 @@ bool sorting(QGraphicsItem *qgia, QGraphicsItem *qgib)
|
|||||||
*/
|
*/
|
||||||
ElementTextItemGroup::ElementTextItemGroup(const QString &name, Element *parent) :
|
ElementTextItemGroup::ElementTextItemGroup(const QString &name, Element *parent) :
|
||||||
QGraphicsItemGroup(parent),
|
QGraphicsItemGroup(parent),
|
||||||
m_name(name),
|
m_name(name)
|
||||||
m_element(parent)
|
|
||||||
{
|
{
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable);
|
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable);
|
||||||
}
|
}
|
||||||
@@ -53,14 +53,14 @@ void ElementTextItemGroup::addToGroup(QGraphicsItem *item)
|
|||||||
{
|
{
|
||||||
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||||
QGraphicsItemGroup::addToGroup(item);
|
QGraphicsItemGroup::addToGroup(item);
|
||||||
updateAlignement();
|
updateAlignment();
|
||||||
|
|
||||||
DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(item);
|
DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(item);
|
||||||
connect(deti, &DynamicElementTextItem::fontSizeChanged, this, &ElementTextItemGroup::updateAlignement);
|
connect(deti, &DynamicElementTextItem::fontSizeChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
connect(deti, &DynamicElementTextItem::textChanged, this, &ElementTextItemGroup::updateAlignement);
|
connect(deti, &DynamicElementTextItem::textChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
connect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateAlignement);
|
connect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
connect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateAlignement);
|
connect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
connect(deti, &DynamicElementTextItem::compositeTextChanged, this, &ElementTextItemGroup::updateAlignement);
|
connect(deti, &DynamicElementTextItem::compositeTextChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,15 +72,15 @@ void ElementTextItemGroup::removeFromGroup(QGraphicsItem *item)
|
|||||||
{
|
{
|
||||||
QGraphicsItemGroup::removeFromGroup(item);
|
QGraphicsItemGroup::removeFromGroup(item);
|
||||||
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
updateAlignement();
|
updateAlignment();
|
||||||
|
|
||||||
if(DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(item))
|
if(DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(item))
|
||||||
{
|
{
|
||||||
disconnect(deti, &DynamicElementTextItem::fontSizeChanged, this, &ElementTextItemGroup::updateAlignement);
|
disconnect(deti, &DynamicElementTextItem::fontSizeChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
disconnect(deti, &DynamicElementTextItem::textChanged, this, &ElementTextItemGroup::updateAlignement);
|
disconnect(deti, &DynamicElementTextItem::textChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
disconnect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateAlignement);
|
disconnect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
disconnect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateAlignement);
|
disconnect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
disconnect(deti, &DynamicElementTextItem::compositeTextChanged, this, &ElementTextItemGroup::updateAlignement);
|
disconnect(deti, &DynamicElementTextItem::compositeTextChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,25 +89,27 @@ void ElementTextItemGroup::removeFromGroup(QGraphicsItem *item)
|
|||||||
* Set the alignement of this group
|
* Set the alignement of this group
|
||||||
* @param alignement
|
* @param alignement
|
||||||
*/
|
*/
|
||||||
void ElementTextItemGroup::setAlignement(Qt::Alignment alignement)
|
void ElementTextItemGroup::setAlignment(Qt::Alignment alignement)
|
||||||
{
|
{
|
||||||
m_alignement = alignement;
|
m_alignment = alignement;
|
||||||
updateAlignement();
|
updateAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::Alignment ElementTextItemGroup::alignment() const
|
Qt::Alignment ElementTextItemGroup::alignment() const
|
||||||
{
|
{
|
||||||
return m_alignement;
|
return m_alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementTextItemGroup::setAlignement
|
* @brief ElementTextItemGroup::setAlignment
|
||||||
* Update the alignement of the items in this group, according
|
* Update the alignement of the items in this group, according
|
||||||
* to the current alignement.
|
* to the current alignement.
|
||||||
* @param alignement
|
* @param alignement
|
||||||
*/
|
*/
|
||||||
void ElementTextItemGroup::updateAlignement()
|
void ElementTextItemGroup::updateAlignment()
|
||||||
{
|
{
|
||||||
|
prepareGeometryChange();
|
||||||
|
|
||||||
QList <QGraphicsItem *> texts = childItems();
|
QList <QGraphicsItem *> texts = childItems();
|
||||||
if (texts.size() > 1)
|
if (texts.size() > 1)
|
||||||
{
|
{
|
||||||
@@ -116,7 +118,7 @@ void ElementTextItemGroup::updateAlignement()
|
|||||||
|
|
||||||
qreal y_offset =0;
|
qreal y_offset =0;
|
||||||
|
|
||||||
if(m_alignement == Qt::AlignLeft)
|
if(m_alignment == Qt::AlignLeft)
|
||||||
{
|
{
|
||||||
QPointF ref = texts.first()->pos();
|
QPointF ref = texts.first()->pos();
|
||||||
|
|
||||||
@@ -127,7 +129,7 @@ void ElementTextItemGroup::updateAlignement()
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(m_alignement == Qt::AlignVCenter)
|
else if(m_alignment == Qt::AlignVCenter)
|
||||||
{
|
{
|
||||||
QPointF ref(texts.first()->pos().x() + texts.first()->boundingRect().width()/2,
|
QPointF ref(texts.first()->pos().x() + texts.first()->boundingRect().width()/2,
|
||||||
texts.first()->pos().y());
|
texts.first()->pos().y());
|
||||||
@@ -141,7 +143,7 @@ void ElementTextItemGroup::updateAlignement()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (m_alignement == Qt::AlignRight)
|
else if (m_alignment == Qt::AlignRight)
|
||||||
{
|
{
|
||||||
QPointF ref(texts.first()->pos().x() + texts.first()->boundingRect().width(),
|
QPointF ref(texts.first()->pos().x() + texts.first()->boundingRect().width(),
|
||||||
texts.first()->pos().y());
|
texts.first()->pos().y());
|
||||||
@@ -193,6 +195,18 @@ Diagram *ElementTextItemGroup::diagram() const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementTextItemGroup::parentElement
|
||||||
|
* @return The parent element of this group or nullptr
|
||||||
|
*/
|
||||||
|
Element *ElementTextItemGroup::parentElement() const
|
||||||
|
{
|
||||||
|
if(parentItem() && parentItem()->type() == Element::Type)
|
||||||
|
return static_cast<Element *>(parentItem());
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementTextItemGroup::toXml
|
* @brief ElementTextItemGroup::toXml
|
||||||
* Export data of this group to xml
|
* Export data of this group to xml
|
||||||
@@ -205,7 +219,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
|
|||||||
dom_element.setAttribute("name", m_name);
|
dom_element.setAttribute("name", m_name);
|
||||||
|
|
||||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||||
dom_element.setAttribute("alignment", me.valueToKey(m_alignement));
|
dom_element.setAttribute("alignment", me.valueToKey(m_alignment));
|
||||||
|
|
||||||
QDomElement dom_texts = dom_document.createElement("texts");
|
QDomElement dom_texts = dom_document.createElement("texts");
|
||||||
for(DynamicElementTextItem *deti : texts())
|
for(DynamicElementTextItem *deti : texts())
|
||||||
@@ -233,19 +247,22 @@ void ElementTextItemGroup::fromXml(QDomElement &dom_element)
|
|||||||
|
|
||||||
m_name = dom_element.attribute("name", "no name");
|
m_name = dom_element.attribute("name", "no name");
|
||||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||||
m_alignement = Qt::Alignment(me.keyToValue(dom_element.attribute("alignment").toStdString().data()));
|
m_alignment = Qt::Alignment(me.keyToValue(dom_element.attribute("alignment").toStdString().data()));
|
||||||
|
|
||||||
for(QDomElement text : QET::findInDomElement(dom_element, "texts", "text"))
|
if(parentElement())
|
||||||
{
|
{
|
||||||
DynamicElementTextItem *deti = nullptr;
|
for(QDomElement text : QET::findInDomElement(dom_element, "texts", "text"))
|
||||||
QUuid uuid(text.attribute("uuid"));
|
{
|
||||||
|
DynamicElementTextItem *deti = nullptr;
|
||||||
for(DynamicElementTextItem *txt : m_element->dynamicTextItems())
|
QUuid uuid(text.attribute("uuid"));
|
||||||
if(txt->uuid() == uuid)
|
|
||||||
deti = txt;
|
for(DynamicElementTextItem *txt : parentElement()->dynamicTextItems())
|
||||||
|
if(txt->uuid() == uuid)
|
||||||
if (deti)
|
deti = txt;
|
||||||
m_element->addTextToGroup(deti, this);
|
|
||||||
|
if (deti)
|
||||||
|
parentElement()->addTextToGroup(deti, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +338,11 @@ void ElementTextItemGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
QPointF old_pos = pos();
|
QPointF old_pos = pos();
|
||||||
if(m_first_move)
|
if(m_first_move)
|
||||||
|
{
|
||||||
m_mouse_to_origin_movement = old_pos - event->buttonDownScenePos(Qt::LeftButton);
|
m_mouse_to_origin_movement = old_pos - event->buttonDownScenePos(Qt::LeftButton);
|
||||||
|
if(parentElement())
|
||||||
|
parentElement()->setHighlighted(true);
|
||||||
|
}
|
||||||
|
|
||||||
QPointF expected_pos = event->scenePos() + m_mouse_to_origin_movement;
|
QPointF expected_pos = event->scenePos() + m_mouse_to_origin_movement;
|
||||||
setPos(Diagram::snapToGrid(expected_pos));
|
setPos(Diagram::snapToGrid(expected_pos));
|
||||||
@@ -344,7 +365,11 @@ void ElementTextItemGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
void ElementTextItemGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void ElementTextItemGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if(diagram())
|
if(diagram())
|
||||||
|
{
|
||||||
diagram()->endMoveElementTexts();
|
diagram()->endMoveElementTexts();
|
||||||
|
if(parentElement())
|
||||||
|
parentElement()->setHighlighted(false);
|
||||||
|
}
|
||||||
|
|
||||||
if(!(event->modifiers() & Qt::ControlModifier))
|
if(!(event->modifiers() & Qt::ControlModifier))
|
||||||
QGraphicsItemGroup::mouseReleaseEvent(event);
|
QGraphicsItemGroup::mouseReleaseEvent(event);
|
||||||
@@ -355,13 +380,27 @@ void ElementTextItemGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
void ElementTextItemGroup::keyPressEvent(QKeyEvent *event)
|
void ElementTextItemGroup::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
if(event->key() == Qt::Key_A && m_alignment != Qt::AlignLeft)
|
||||||
if(event->key() == Qt::Key_A)
|
{
|
||||||
setAlignement(Qt::AlignLeft);
|
if(diagram())
|
||||||
else if (event->key() == Qt::Key_Z)
|
diagram()->undoStack().push(new AlignmentTextsGroupCommand(this, Qt::AlignLeft));
|
||||||
setAlignement(Qt::AlignVCenter);
|
else
|
||||||
else if (event->key() == Qt::Key_E)
|
setAlignment(Qt::AlignLeft);
|
||||||
setAlignement(Qt::AlignRight);
|
}
|
||||||
|
else if (event->key() == Qt::Key_Z && m_alignment != Qt::AlignVCenter)
|
||||||
|
{
|
||||||
|
if(diagram())
|
||||||
|
diagram()->undoStack().push(new AlignmentTextsGroupCommand(this, Qt::AlignVCenter));
|
||||||
|
else
|
||||||
|
setAlignment(Qt::AlignVCenter);
|
||||||
|
}
|
||||||
|
else if (event->key() == Qt::Key_E && m_alignment != Qt::AlignRight)
|
||||||
|
{
|
||||||
|
if(diagram())
|
||||||
|
diagram()->undoStack().push(new AlignmentTextsGroupCommand(this, Qt::AlignRight));
|
||||||
|
else
|
||||||
|
setAlignment(Qt::AlignRight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,19 +35,22 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElementTextItemGroup(const QString &name, Element *parent);
|
ElementTextItemGroup(const QString &name, Element *parent);
|
||||||
~ElementTextItemGroup() override;
|
~ElementTextItemGroup() override;
|
||||||
void addToGroup(QGraphicsItem *item);
|
void addToGroup(QGraphicsItem *item);
|
||||||
void removeFromGroup(QGraphicsItem *item);
|
void removeFromGroup(QGraphicsItem *item);
|
||||||
|
|
||||||
void setAlignement(Qt::Alignment alignement);
|
void setAlignment(Qt::Alignment alignement);
|
||||||
Qt::Alignment alignment() const;
|
Qt::Alignment alignment() const;
|
||||||
void updateAlignement();
|
void updateAlignment();
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
QString name() const {return m_name;}
|
QString name() const {return m_name;}
|
||||||
QList<DynamicElementTextItem *> texts() const;
|
QList<DynamicElementTextItem *> texts() const;
|
||||||
Diagram *diagram() const;
|
Diagram *diagram() const;
|
||||||
|
Element *parentElement() const;
|
||||||
|
|
||||||
QDomElement toXml(QDomDocument &dom_document) const;
|
QDomElement toXml(QDomDocument &dom_document) const;
|
||||||
void fromXml(QDomElement &dom_element);
|
void fromXml(QDomElement &dom_element);
|
||||||
@@ -63,11 +66,10 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|||||||
void keyPressEvent(QKeyEvent *event) override;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Qt::Alignment m_alignement = Qt::AlignJustify;
|
Qt::Alignment m_alignment = Qt::AlignJustify;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
bool m_first_move = true;
|
bool m_first_move = true;
|
||||||
QPointF m_mouse_to_origin_movement;
|
QPointF m_mouse_to_origin_movement;
|
||||||
Element *m_element = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEMENTTEXTITEMGROUP_H
|
#endif // ELEMENTTEXTITEMGROUP_H
|
||||||
|
|||||||
@@ -18,8 +18,15 @@
|
|||||||
#include "addelementtextcommand.h"
|
#include "addelementtextcommand.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
|
#include "elementtextitemgroup.h"
|
||||||
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
|
|
||||||
|
/************************
|
||||||
|
* AddElementTextCommand*
|
||||||
|
* **********************/
|
||||||
|
|
||||||
AddElementTextCommand::AddElementTextCommand(Element *element, DynamicElementTextItem *deti, QUndoCommand *parent):
|
AddElementTextCommand::AddElementTextCommand(Element *element, DynamicElementTextItem *deti, QUndoCommand *parent):
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
m_element(element),
|
m_element(element),
|
||||||
@@ -40,7 +47,6 @@ AddElementTextCommand::~AddElementTextCommand()
|
|||||||
void AddElementTextCommand::undo()
|
void AddElementTextCommand::undo()
|
||||||
{
|
{
|
||||||
m_element->removeDynamicTextItem(m_text);
|
m_element->removeDynamicTextItem(m_text);
|
||||||
m_text->setParentItem(nullptr);
|
|
||||||
if(m_text->scene())
|
if(m_text->scene())
|
||||||
m_text->scene()->removeItem(m_text);
|
m_text->scene()->removeItem(m_text);
|
||||||
}
|
}
|
||||||
@@ -51,36 +57,253 @@ void AddElementTextCommand::redo()
|
|||||||
m_element->addDynamicTextItem(m_text);
|
m_element->addDynamicTextItem(m_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//RemoveElementTextCommand::RemoveElementTextCommand(DynamicElementTextItem *deti, QUndoCommand *parent) :
|
|
||||||
// QUndoCommand(parent),
|
|
||||||
// m_text(deti)
|
|
||||||
//{
|
|
||||||
// setText(QObject::tr("Supprimer un texte d'élément"));
|
|
||||||
// m_element = deti->ParentElement();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//RemoveElementTextCommand::~RemoveElementTextCommand()
|
/***********************
|
||||||
//{
|
* AddTextsGroupCommand*
|
||||||
// if(m_element && !m_element->dynamicTextItems().contains(m_text))
|
* *********************/
|
||||||
// delete m_text;
|
/**
|
||||||
//}
|
* @brief AddTextsGroupCommand::AddTextsGroupCommand
|
||||||
|
* @param element : the element to add a new group
|
||||||
|
* @param groupe_name : the name of the group
|
||||||
|
* @param parent : parent undo
|
||||||
|
*/
|
||||||
|
AddTextsGroupCommand::AddTextsGroupCommand(Element *element, QString groupe_name, QUndoCommand *parent) :
|
||||||
|
QUndoCommand(parent),
|
||||||
|
m_element(element),
|
||||||
|
m_name(groupe_name)
|
||||||
|
{
|
||||||
|
setText(QObject::tr("Ajouter un groupe de textes d'élément"));
|
||||||
|
}
|
||||||
|
|
||||||
//void RemoveElementTextCommand::undo()
|
/**
|
||||||
//{
|
* @brief AddTextsGroupCommand::~AddTextsGroupCommand
|
||||||
// if(m_element)
|
* Destructor
|
||||||
// {
|
*/
|
||||||
// m_text->setParentItem(m_element);
|
AddTextsGroupCommand::~AddTextsGroupCommand()
|
||||||
// m_element->addDynamicTextItem(m_text);
|
{}
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//void RemoveElementTextCommand::redo()
|
void AddTextsGroupCommand::undo()
|
||||||
//{
|
{
|
||||||
// if(m_element && m_text->scene())
|
if(m_element && m_group)
|
||||||
// {
|
m_element.data()->removeTextGroup(m_group);
|
||||||
|
}
|
||||||
// m_element->removeDynamicTextItem(m_text);
|
|
||||||
// m_text->setParentItem(nullptr);
|
void AddTextsGroupCommand::redo()
|
||||||
// m_text->scene()->removeItem(m_text);
|
{
|
||||||
// }
|
if(m_element)
|
||||||
//}
|
{
|
||||||
|
if(m_first_undo)
|
||||||
|
{
|
||||||
|
m_group = m_element.data()->addTextGroup(m_name);
|
||||||
|
m_first_undo = false;
|
||||||
|
}
|
||||||
|
else if(m_group)
|
||||||
|
m_element.data()->addTextGroup(m_group.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************
|
||||||
|
* RemoveTextsGroupCommand*
|
||||||
|
* ************************/
|
||||||
|
/**
|
||||||
|
* @brief RemoveTextsGroupCommand::RemoveTextsGroupCommand
|
||||||
|
* @param element : The element where we remove a group
|
||||||
|
* @param group : the group to remove
|
||||||
|
* @param parent : the parent undo command
|
||||||
|
*/
|
||||||
|
RemoveTextsGroupCommand::RemoveTextsGroupCommand(Element *element, ElementTextItemGroup *group, QUndoCommand *parent) :
|
||||||
|
QUndoCommand(parent),
|
||||||
|
m_element(element),
|
||||||
|
m_group(group)
|
||||||
|
{
|
||||||
|
setText(QObject::tr("Supprimer un groupe de textes d'élément"));
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoveTextsGroupCommand::~RemoveTextsGroupCommand()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void RemoveTextsGroupCommand::undo()
|
||||||
|
{
|
||||||
|
if(m_element && m_group)
|
||||||
|
m_element.data()->addTextGroup(m_group.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveTextsGroupCommand::redo()
|
||||||
|
{
|
||||||
|
if(m_element && m_group)
|
||||||
|
m_element.data()->removeTextGroup(m_group.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************
|
||||||
|
* AddTextToGroupCommand*
|
||||||
|
* **********************/
|
||||||
|
/**
|
||||||
|
* @brief AddTextToGroupCommand::AddTextToGroupCommand
|
||||||
|
* @param text
|
||||||
|
* @param group
|
||||||
|
* @param parent
|
||||||
|
*/
|
||||||
|
AddTextToGroupCommand::AddTextToGroupCommand(DynamicElementTextItem *text, ElementTextItemGroup *group, QUndoCommand *parent) :
|
||||||
|
QUndoCommand(parent),
|
||||||
|
m_text(text),
|
||||||
|
m_group(group),
|
||||||
|
m_element(group->parentElement())
|
||||||
|
{
|
||||||
|
setText(QObject::tr("Insérer un texte d'élément dans un groupe de textes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief AddTextToGroupCommand::~AddTextToGroupCommand
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
|
AddTextToGroupCommand::~AddTextToGroupCommand()
|
||||||
|
{
|
||||||
|
if(m_group && m_text && m_element)
|
||||||
|
{
|
||||||
|
if(!m_group.data()->texts().contains(m_text.data()) &&
|
||||||
|
!m_element.data()->dynamicTextItems().contains(m_text.data()))
|
||||||
|
delete m_text.data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddTextToGroupCommand::undo()
|
||||||
|
{
|
||||||
|
if(m_element && m_group && m_text)
|
||||||
|
m_element.data()->removeTextFromGroup(m_text, m_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddTextToGroupCommand::redo()
|
||||||
|
{
|
||||||
|
if(m_element && m_group && m_text)
|
||||||
|
m_element.data()->addTextToGroup(m_text, m_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************
|
||||||
|
* RemoveTextFromGroupCommand*
|
||||||
|
* ***************************/
|
||||||
|
/**
|
||||||
|
* @brief RemoveTextFromGroupCommand::RemoveTextFromGroupCommand
|
||||||
|
* @param text : text to add to @group
|
||||||
|
* @param group
|
||||||
|
* @param parent : parent undo command
|
||||||
|
*/
|
||||||
|
RemoveTextFromGroupCommand::RemoveTextFromGroupCommand(DynamicElementTextItem *text, ElementTextItemGroup *group, QUndoCommand *parent):
|
||||||
|
QUndoCommand(parent),
|
||||||
|
m_text(text),
|
||||||
|
m_group(group),
|
||||||
|
m_element(group->parentElement())
|
||||||
|
{
|
||||||
|
setText(QObject::tr("Enlever un texte d'élément d'un groupe de textes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
|
RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand()
|
||||||
|
{
|
||||||
|
if(m_group && m_text && m_element)
|
||||||
|
{
|
||||||
|
if(!m_group.data()->texts().contains(m_text.data()) &&
|
||||||
|
!m_element.data()->dynamicTextItems().contains(m_text.data()))
|
||||||
|
delete m_text.data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveTextFromGroupCommand::undo()
|
||||||
|
{
|
||||||
|
if(m_element && m_group && m_text)
|
||||||
|
m_element.data()->addTextToGroup(m_text, m_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveTextFromGroupCommand::redo()
|
||||||
|
{
|
||||||
|
if(m_element && m_group && m_text)
|
||||||
|
m_element.data()->removeTextFromGroup(m_text, m_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************
|
||||||
|
* AlignmentTextsGroupCommand*
|
||||||
|
* ***************************/
|
||||||
|
/**
|
||||||
|
* @brief AlignmentTextsGroupCommand::AlignmentTextsGroupCommand
|
||||||
|
* @param group : Group to change the alignment
|
||||||
|
* @param new_alignment : the new alignment of the group
|
||||||
|
* @param parent : the parent QUndoCommand of this undo
|
||||||
|
*/
|
||||||
|
AlignmentTextsGroupCommand::AlignmentTextsGroupCommand(ElementTextItemGroup *group, Qt::Alignment new_alignment, QUndoCommand *parent) :
|
||||||
|
QUndoCommand(parent),
|
||||||
|
m_group(group),
|
||||||
|
m_previous_alignment(group->alignment()),
|
||||||
|
m_new_alignment(new_alignment)
|
||||||
|
{
|
||||||
|
setText(QObject::tr("Modifier l'alignement d'un groupe de textes"));
|
||||||
|
|
||||||
|
//Text haven't got alignment
|
||||||
|
if(m_previous_alignment != Qt::AlignLeft ||
|
||||||
|
m_previous_alignment != Qt::AlignVCenter ||
|
||||||
|
m_previous_alignment != Qt::AlignRight)
|
||||||
|
{
|
||||||
|
for(DynamicElementTextItem *deti : group->texts())
|
||||||
|
m_texts_pos.insert(deti, deti->pos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief AlignmentTextsGroupCommand::~AlignmentTextsGroupCommand
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
|
AlignmentTextsGroupCommand::~AlignmentTextsGroupCommand()
|
||||||
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief AlignmentTextsGroupCommand::mergeWith
|
||||||
|
* Try to merge this command with other command
|
||||||
|
* @param other
|
||||||
|
* @return true if was merged, else false
|
||||||
|
*/
|
||||||
|
bool AlignmentTextsGroupCommand::mergeWith(const QUndoCommand *other)
|
||||||
|
{
|
||||||
|
if (id() != other->id() || other->childCount())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AlignmentTextsGroupCommand const *undo = static_cast<const AlignmentTextsGroupCommand *>(other);
|
||||||
|
if (m_group != undo->m_group)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_new_alignment= undo->m_new_alignment;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief AlignmentTextsGroupCommand::undo
|
||||||
|
*/
|
||||||
|
void AlignmentTextsGroupCommand::undo()
|
||||||
|
{
|
||||||
|
if(m_group)
|
||||||
|
{
|
||||||
|
m_group.data()->setAlignment(m_previous_alignment);
|
||||||
|
//The alignment befor this command was free, then we must
|
||||||
|
//to restor the pos of each texts
|
||||||
|
if(!m_texts_pos.isEmpty())
|
||||||
|
{
|
||||||
|
for(DynamicElementTextItem *deti : m_group.data()->texts())
|
||||||
|
{
|
||||||
|
if(m_texts_pos.keys().contains(deti))
|
||||||
|
deti->setPos(m_texts_pos.value(deti));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief AlignmentTextsGroupCommand::redo
|
||||||
|
*/
|
||||||
|
void AlignmentTextsGroupCommand::redo()
|
||||||
|
{
|
||||||
|
if(m_group)
|
||||||
|
m_group.data()->setAlignment(m_new_alignment);
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,10 +19,16 @@
|
|||||||
#define ADDELEMENTTEXTCOMMAND_H
|
#define ADDELEMENTTEXTCOMMAND_H
|
||||||
|
|
||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
class Element;
|
class Element;
|
||||||
class DynamicElementTextItem;
|
class DynamicElementTextItem;
|
||||||
|
class ElementTextItemGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The AddElementTextCommand class
|
||||||
|
* Manage the adding of element text
|
||||||
|
*/
|
||||||
class AddElementTextCommand : public QUndoCommand
|
class AddElementTextCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -37,18 +43,90 @@ class AddElementTextCommand : public QUndoCommand
|
|||||||
DynamicElementTextItem *m_text = nullptr;
|
DynamicElementTextItem *m_text = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
//class RemoveElementTextCommand : public QUndoCommand
|
/**
|
||||||
//{
|
* @brief The AddTextsGroupCommand class
|
||||||
// public:
|
* Manage the adding of a texts group
|
||||||
// RemoveElementTextCommand(DynamicElementTextItem *deti, QUndoCommand *parent = nullptr);
|
*/
|
||||||
// virtual ~RemoveElementTextCommand();
|
class AddTextsGroupCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AddTextsGroupCommand(Element *element, QString groupe_name, QUndoCommand *parent = nullptr);
|
||||||
|
~AddTextsGroupCommand() override;
|
||||||
|
|
||||||
// virtual void undo();
|
void undo() override;
|
||||||
// virtual void redo();
|
void redo() override;
|
||||||
|
|
||||||
// private:
|
private:
|
||||||
// Element *m_element = nullptr;
|
QPointer<Element> m_element;
|
||||||
// DynamicElementTextItem *m_text = nullptr;
|
QPointer<ElementTextItemGroup> m_group;
|
||||||
//};
|
QString m_name;
|
||||||
|
bool m_first_undo = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The RemoveTextsGroupCommand class
|
||||||
|
* Manage the removinf of a texts group
|
||||||
|
*/
|
||||||
|
class RemoveTextsGroupCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RemoveTextsGroupCommand(Element *element, ElementTextItemGroup *group, QUndoCommand *parent = nullptr);
|
||||||
|
~RemoveTextsGroupCommand() override;
|
||||||
|
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer<Element> m_element;
|
||||||
|
QPointer<ElementTextItemGroup> m_group;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AddTextToGroupCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AddTextToGroupCommand(DynamicElementTextItem *text, ElementTextItemGroup *group, QUndoCommand *parent = nullptr);
|
||||||
|
~AddTextToGroupCommand() override;
|
||||||
|
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer<DynamicElementTextItem> m_text;
|
||||||
|
QPointer<ElementTextItemGroup> m_group;
|
||||||
|
QPointer<Element> m_element;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RemoveTextFromGroupCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RemoveTextFromGroupCommand(DynamicElementTextItem *text, ElementTextItemGroup *group, QUndoCommand *parent = nullptr);
|
||||||
|
~RemoveTextFromGroupCommand() override;
|
||||||
|
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer<DynamicElementTextItem> m_text;
|
||||||
|
QPointer<ElementTextItemGroup> m_group;
|
||||||
|
QPointer<Element> m_element;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AlignmentTextsGroupCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AlignmentTextsGroupCommand(ElementTextItemGroup *group, Qt::Alignment new_alignment, QUndoCommand *parent = nullptr);
|
||||||
|
~AlignmentTextsGroupCommand() override;
|
||||||
|
|
||||||
|
int id() const override{return 6;}
|
||||||
|
bool mergeWith(const QUndoCommand *other) override;
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer<ElementTextItemGroup> m_group;
|
||||||
|
Qt::Alignment m_previous_alignment,
|
||||||
|
m_new_alignment;
|
||||||
|
QHash<DynamicElementTextItem *, QPointF> m_texts_pos;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // ADDELEMENTTEXTCOMMAND_H
|
#endif // ADDELEMENTTEXTCOMMAND_H
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "conductortextitem.h"
|
#include "conductortextitem.h"
|
||||||
|
#include "elementtextitemgroup.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
|
* @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
|
||||||
@@ -44,7 +45,12 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const D
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||||
m_elmt_text_hash.insert(deti, deti->parentElement());
|
{
|
||||||
|
if(deti->parentGroup())
|
||||||
|
m_grp_texts_hash.insert(deti, deti->parentGroup());
|
||||||
|
else
|
||||||
|
m_elmt_text_hash.insert(deti, deti->parentElement());
|
||||||
|
}
|
||||||
|
|
||||||
setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All)));
|
setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All)));
|
||||||
m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All));
|
m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All));
|
||||||
@@ -72,8 +78,14 @@ void DeleteQGraphicsItemCommand::undo()
|
|||||||
|
|
||||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||||
{
|
{
|
||||||
deti->setParentItem(m_elmt_text_hash.value(deti));
|
if(m_elmt_text_hash.keys().contains(deti))
|
||||||
m_elmt_text_hash.value(deti)->addDynamicTextItem(deti);
|
m_elmt_text_hash.value(deti)->addDynamicTextItem(deti);
|
||||||
|
else if (m_grp_texts_hash.keys().contains(deti))
|
||||||
|
{
|
||||||
|
Element *elmt = m_grp_texts_hash.value(deti)->parentElement();
|
||||||
|
elmt->addDynamicTextItem(deti);
|
||||||
|
elmt->addTextToGroup(deti, m_grp_texts_hash.value(deti));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +121,9 @@ void DeleteQGraphicsItemCommand::redo()
|
|||||||
|
|
||||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||||
{
|
{
|
||||||
|
if(deti->parentGroup() && deti->parentGroup()->parentElement())
|
||||||
|
deti->parentGroup()->parentElement()->removeTextFromGroup(deti, deti->parentGroup());
|
||||||
|
|
||||||
deti->parentElement()->removeDynamicTextItem(deti);
|
deti->parentElement()->removeDynamicTextItem(deti);
|
||||||
deti->setParentItem(nullptr);
|
deti->setParentItem(nullptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "diagramcontent.h"
|
#include "diagramcontent.h"
|
||||||
|
|
||||||
class Diagram;
|
class Diagram;
|
||||||
|
class ElementTextItemGroup;
|
||||||
|
|
||||||
class DeleteQGraphicsItemCommand : public QUndoCommand
|
class DeleteQGraphicsItemCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
@@ -41,6 +42,7 @@ class DeleteQGraphicsItemCommand : public QUndoCommand
|
|||||||
Diagram *m_diagram;
|
Diagram *m_diagram;
|
||||||
QHash <Element *, QList<Element *> > m_link_hash; /// keep linked element for each removed element linked to other element.
|
QHash <Element *, QList<Element *> > m_link_hash; /// keep linked element for each removed element linked to other element.
|
||||||
QHash <DynamicElementTextItem *, Element *> m_elmt_text_hash; /// Keep the parent element of each deleted dynamic element text item
|
QHash <DynamicElementTextItem *, Element *> m_elmt_text_hash; /// Keep the parent element of each deleted dynamic element text item
|
||||||
|
QHash <DynamicElementTextItem *, ElementTextItemGroup *> m_grp_texts_hash; ///Keep the parent group of each deleted element text item
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DELETEQGRAPHICSITEMCOMMAND_H
|
#endif // DELETEQGRAPHICSITEMCOMMAND_H
|
||||||
|
|||||||
Reference in New Issue
Block a user