2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2010-01-03 16:25:37 +00:00
|
|
|
Copyright 2006-2010 Xavier Guerrin
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-09-25 23:24:36 +00:00
|
|
|
#include "diagramcommands.h"
|
|
|
|
#include "element.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
#include "conductor.h"
|
2007-09-25 23:24:36 +00:00
|
|
|
#include "diagram.h"
|
2010-04-18 17:59:54 +00:00
|
|
|
#include "independenttextitem.h"
|
2007-09-25 23:24:36 +00:00
|
|
|
#include "qgimanager.h"
|
2010-04-18 17:59:54 +00:00
|
|
|
#include "diagram.h"
|
|
|
|
#include "diagramtextitem.h"
|
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
2007-10-21 16:10:21 +00:00
|
|
|
@param d Schema auquel on ajoute un element
|
|
|
|
@param elmt Element ajoute
|
|
|
|
@param p Position a laquelle l'element est ajoute
|
2007-09-25 23:24:36 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
AddElementCommand::AddElementCommand(
|
|
|
|
Diagram *d,
|
|
|
|
Element *elmt,
|
|
|
|
const QPointF &p,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QString(QObject::tr("ajouter 1 %1", "undo caption - %1 is an element name")).arg(elmt -> name()), parent),
|
2007-09-25 23:24:36 +00:00
|
|
|
element(elmt),
|
|
|
|
diagram(d),
|
|
|
|
position(p)
|
|
|
|
{
|
|
|
|
diagram -> qgiManager().manage(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
AddElementCommand::~AddElementCommand() {
|
|
|
|
diagram -> qgiManager().release(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule l'ajout
|
|
|
|
void AddElementCommand::undo() {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> removeElement(element);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait l'ajout
|
|
|
|
void AddElementCommand::redo() {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> addElement(element);
|
2007-09-25 23:24:36 +00:00
|
|
|
element -> setPos(position);
|
|
|
|
element -> setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
|
|
|
}
|
|
|
|
|
2007-10-27 13:18:17 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param dia Schema auquel on ajoute du texte
|
2007-12-05 21:16:01 +00:00
|
|
|
@param text Texte ajoute
|
|
|
|
@param pos Position a laquelle le texte est ajoute
|
2007-10-27 13:18:17 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2010-04-18 17:59:54 +00:00
|
|
|
AddTextCommand::AddTextCommand(Diagram *dia, IndependentTextItem *text, const QPointF &pos, QUndoCommand *parent) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("Ajouter un champ de texte", "undo caption"), parent),
|
2007-10-27 13:18:17 +00:00
|
|
|
textitem(text),
|
|
|
|
diagram(dia),
|
|
|
|
position(pos)
|
|
|
|
{
|
|
|
|
diagram -> qgiManager().manage(textitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
AddTextCommand::~AddTextCommand() {
|
|
|
|
diagram -> qgiManager().release(textitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule l'ajout
|
|
|
|
void AddTextCommand::undo() {
|
2010-04-18 17:59:54 +00:00
|
|
|
diagram -> removeIndependentTextItem(textitem);
|
2007-10-27 13:18:17 +00:00
|
|
|
}
|
|
|
|
|
2009-12-06 22:48:08 +00:00
|
|
|
/// Refait l'ajout
|
2007-10-27 13:18:17 +00:00
|
|
|
void AddTextCommand::redo() {
|
2010-04-18 17:59:54 +00:00
|
|
|
diagram -> addIndependentTextItem(textitem);
|
2007-10-27 13:18:17 +00:00
|
|
|
textitem -> setPos(position);
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param d Schema auquel on ajoute un conducteur
|
2007-10-10 17:50:26 +00:00
|
|
|
@param c Conducteur ajoute
|
2007-09-25 23:24:36 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
AddConductorCommand::AddConductorCommand(
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *d,
|
2007-10-03 17:02:39 +00:00
|
|
|
Conductor *c,
|
2007-09-25 23:24:36 +00:00
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("ajouter un conducteur", "undo caption"), parent),
|
2007-10-03 17:02:39 +00:00
|
|
|
conductor(c),
|
2007-09-25 23:24:36 +00:00
|
|
|
diagram(d)
|
|
|
|
{
|
2007-10-03 17:02:39 +00:00
|
|
|
diagram -> qgiManager().manage(conductor);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
2007-10-03 17:02:39 +00:00
|
|
|
AddConductorCommand::~AddConductorCommand() {
|
|
|
|
diagram -> qgiManager().release(conductor);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule l'ajout
|
2007-10-03 17:02:39 +00:00
|
|
|
void AddConductorCommand::undo() {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> removeConductor(conductor);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait l'ajout
|
2007-10-03 17:02:39 +00:00
|
|
|
void AddConductorCommand::redo() {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> addConductor(conductor);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-09-26 12:36:31 +00:00
|
|
|
@param dia Schema dont on supprime des elements et conducteurs
|
2007-11-09 13:06:51 +00:00
|
|
|
@param content Contenu supprime
|
2007-09-26 12:36:31 +00:00
|
|
|
@param parent QUndoCommand parent
|
2007-09-25 23:24:36 +00:00
|
|
|
*/
|
|
|
|
DeleteElementsCommand::DeleteElementsCommand(
|
|
|
|
Diagram *dia,
|
2007-11-09 13:06:51 +00:00
|
|
|
const DiagramContent &content,
|
2007-09-25 23:24:36 +00:00
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
|
|
|
QUndoCommand(parent),
|
2007-11-09 13:06:51 +00:00
|
|
|
removed_content(content),
|
2007-09-25 23:24:36 +00:00
|
|
|
diagram(dia)
|
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(
|
|
|
|
QString(
|
|
|
|
QObject::tr(
|
|
|
|
"supprimer %1",
|
|
|
|
"undo caption - %1 is a sentence listing the removed content"
|
|
|
|
)
|
|
|
|
).arg(removed_content.sentence(DiagramContent::All))
|
|
|
|
);
|
2007-11-11 16:12:45 +00:00
|
|
|
diagram -> qgiManager().manage(removed_content.items(DiagramContent::All));
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
DeleteElementsCommand::~DeleteElementsCommand() {
|
2007-11-11 16:12:45 +00:00
|
|
|
diagram -> qgiManager().release(removed_content.items(DiagramContent::All));
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// annule les suppressions
|
|
|
|
void DeleteElementsCommand::undo() {
|
|
|
|
// remet les elements
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(Element *e, removed_content.elements) {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> addElement(e);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remet les conducteurs
|
2007-11-11 16:12:45 +00:00
|
|
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> addConductor(c);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
2007-10-27 13:18:17 +00:00
|
|
|
|
|
|
|
// remet les textes
|
2010-04-18 17:59:54 +00:00
|
|
|
foreach(IndependentTextItem *t, removed_content.textFields) {
|
|
|
|
diagram -> addIndependentTextItem(t);
|
2007-10-27 13:18:17 +00:00
|
|
|
}
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// refait les suppressions
|
|
|
|
void DeleteElementsCommand::redo() {
|
|
|
|
// enleve les conducteurs
|
2007-11-11 16:12:45 +00:00
|
|
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> removeConductor(c);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// enleve les elements
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(Element *e, removed_content.elements) {
|
2009-04-04 21:47:07 +00:00
|
|
|
diagram -> removeElement(e);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
2007-10-27 13:18:17 +00:00
|
|
|
|
|
|
|
// enleve les textes
|
2010-04-18 17:59:54 +00:00
|
|
|
foreach(IndependentTextItem *t, removed_content.textFields) {
|
|
|
|
diagram -> removeIndependentTextItem(t);
|
2007-10-27 13:18:17 +00:00
|
|
|
}
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
2007-09-26 12:36:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param dia Schema sur lequel on colle les elements et conducteurs
|
2007-12-05 21:16:01 +00:00
|
|
|
@param c Contenu a coller sur le schema
|
2007-09-26 12:36:31 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
PasteDiagramCommand::PasteDiagramCommand(
|
|
|
|
Diagram *dia,
|
2007-11-09 13:06:51 +00:00
|
|
|
const DiagramContent &c,
|
2007-09-26 12:36:31 +00:00
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
|
|
|
QUndoCommand(parent),
|
2007-11-09 13:06:51 +00:00
|
|
|
content(c),
|
2007-09-26 12:36:31 +00:00
|
|
|
diagram(dia),
|
2007-11-11 16:12:45 +00:00
|
|
|
filter(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::ConductorsToMove),
|
2007-09-26 12:36:31 +00:00
|
|
|
first_redo(true)
|
|
|
|
{
|
2007-11-11 16:12:45 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(
|
|
|
|
QString(
|
|
|
|
QObject::tr(
|
|
|
|
"coller %1",
|
|
|
|
"undo caption - %1 is a sentence listing the content to paste"
|
|
|
|
).arg(content.sentence(filter))
|
|
|
|
)
|
|
|
|
);
|
2007-11-11 16:12:45 +00:00
|
|
|
diagram -> qgiManager().manage(content.items(filter));
|
2007-09-26 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
PasteDiagramCommand::~PasteDiagramCommand() {
|
2007-11-11 16:12:45 +00:00
|
|
|
diagram -> qgiManager().release(content.items(filter));
|
2007-09-26 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// annule le coller
|
|
|
|
void PasteDiagramCommand::undo() {
|
|
|
|
// enleve les conducteurs
|
2009-04-04 21:47:07 +00:00
|
|
|
foreach(Conductor *c, content.conductorsToMove) diagram -> removeConductor(c);
|
2007-09-26 12:36:31 +00:00
|
|
|
|
|
|
|
// enleve les elements
|
2009-04-04 21:47:07 +00:00
|
|
|
foreach(Element *e, content.elements) diagram -> removeElement(e);
|
2007-10-27 13:18:17 +00:00
|
|
|
|
|
|
|
// enleve les textes
|
2010-04-18 17:59:54 +00:00
|
|
|
foreach(IndependentTextItem *t, content.textFields) diagram -> removeIndependentTextItem(t);
|
2007-09-26 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// refait le coller
|
|
|
|
void PasteDiagramCommand::redo() {
|
|
|
|
if (first_redo) first_redo = false;
|
|
|
|
else {
|
|
|
|
// pose les elements
|
2009-04-04 21:47:07 +00:00
|
|
|
foreach(Element *e, content.elements) diagram -> addElement(e);
|
2007-09-26 12:36:31 +00:00
|
|
|
|
|
|
|
// pose les conducteurs
|
2009-04-04 21:47:07 +00:00
|
|
|
foreach(Conductor *c, content.conductorsToMove) diagram -> addConductor(c);
|
2007-10-27 13:18:17 +00:00
|
|
|
|
|
|
|
// pose les textes
|
2010-04-18 17:59:54 +00:00
|
|
|
foreach(IndependentTextItem *t, content.textFields) diagram -> addIndependentTextItem(t);
|
2007-09-26 12:36:31 +00:00
|
|
|
}
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(Element *e, content.elements) e -> setSelected(true);
|
|
|
|
foreach(Conductor *c, content.conductorsToMove) c -> setSelected(true);
|
2010-04-18 17:59:54 +00:00
|
|
|
foreach(IndependentTextItem *t, content.textFields) t -> setSelected(true);
|
2007-09-26 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-10-10 17:50:26 +00:00
|
|
|
@param dia Schema dont on coupe des elements et conducteurs
|
2007-11-09 13:06:51 +00:00
|
|
|
@param content Contenu coupe
|
2007-09-26 12:36:31 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
CutDiagramCommand::CutDiagramCommand(
|
|
|
|
Diagram *dia,
|
2007-11-09 13:06:51 +00:00
|
|
|
const DiagramContent &content,
|
2007-09-26 12:36:31 +00:00
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2007-11-09 13:06:51 +00:00
|
|
|
DeleteElementsCommand(dia, content, parent)
|
2007-09-26 12:36:31 +00:00
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(
|
|
|
|
QString(
|
|
|
|
QObject::tr(
|
|
|
|
"couper %1",
|
|
|
|
"undo caption - %1 is a sentence listing the content to cut"
|
|
|
|
).arg(content.sentence(DiagramContent::All))
|
|
|
|
)
|
|
|
|
);
|
2007-09-26 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
CutDiagramCommand::~CutDiagramCommand() {
|
|
|
|
}
|
2007-09-26 17:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-09-26 22:57:53 +00:00
|
|
|
@param dia Schema sur lequel on deplace des elements
|
2007-11-09 13:06:51 +00:00
|
|
|
@param diagram_content Contenu a deplacer
|
2007-09-26 22:57:53 +00:00
|
|
|
@param m translation subie par les elements
|
|
|
|
@param parent QUndoCommand parent
|
2007-09-26 17:14:09 +00:00
|
|
|
*/
|
|
|
|
MoveElementsCommand::MoveElementsCommand(
|
|
|
|
Diagram *dia,
|
2007-11-09 13:06:51 +00:00
|
|
|
const DiagramContent &diagram_content,
|
2007-09-26 17:14:09 +00:00
|
|
|
const QPointF &m,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
|
|
|
QUndoCommand(parent),
|
|
|
|
diagram(dia),
|
2007-11-09 13:06:51 +00:00
|
|
|
content_to_move(diagram_content),
|
2007-10-27 13:18:17 +00:00
|
|
|
movement(m),
|
|
|
|
first_redo(true)
|
2007-09-26 17:14:09 +00:00
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
QString moved_content_sentence = content_to_move.sentence(
|
|
|
|
DiagramContent::Elements |
|
|
|
|
DiagramContent::TextFields |
|
|
|
|
DiagramContent::ConductorsToUpdate |
|
|
|
|
DiagramContent::ConductorsToMove
|
|
|
|
);
|
|
|
|
|
|
|
|
setText(
|
|
|
|
QString(
|
|
|
|
QObject::tr(
|
|
|
|
"d\351placer %1",
|
|
|
|
"undo caption - %1 is a sentence listing the moved content"
|
|
|
|
).arg(moved_content_sentence)
|
|
|
|
)
|
|
|
|
);
|
2007-09-26 17:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
MoveElementsCommand::~MoveElementsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// annule le deplacement
|
|
|
|
void MoveElementsCommand::undo() {
|
|
|
|
move(-movement);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// refait le deplacement
|
|
|
|
void MoveElementsCommand::redo() {
|
|
|
|
if (first_redo) first_redo = false;
|
|
|
|
else move(movement);
|
|
|
|
}
|
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
/**
|
|
|
|
deplace les elements et conducteurs
|
|
|
|
@param actual_movement translation a effectuer sur les elements et conducteurs
|
|
|
|
*/
|
2007-09-26 17:14:09 +00:00
|
|
|
void MoveElementsCommand::move(const QPointF &actual_movement) {
|
|
|
|
// deplace les elements
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(Element *element, content_to_move.elements) {
|
2007-09-26 17:14:09 +00:00
|
|
|
element -> setPos(element -> pos() + actual_movement);
|
|
|
|
}
|
|
|
|
|
|
|
|
// deplace certains conducteurs
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(Conductor *conductor, content_to_move.conductorsToMove) {
|
2007-10-03 17:02:39 +00:00
|
|
|
conductor -> setPos(conductor -> pos() + actual_movement);
|
2007-09-26 17:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// recalcule les autres conducteurs
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(Conductor *conductor, content_to_move.conductorsToUpdate.keys()) {
|
|
|
|
conductor -> updateWithNewPos(
|
|
|
|
QRectF(),
|
|
|
|
content_to_move.conductorsToUpdate[conductor],
|
2010-04-18 20:48:15 +00:00
|
|
|
content_to_move.conductorsToUpdate[conductor] -> dockConductor()
|
2007-11-09 13:06:51 +00:00
|
|
|
);
|
2007-09-26 17:14:09 +00:00
|
|
|
}
|
2007-10-27 13:18:17 +00:00
|
|
|
|
|
|
|
// deplace les textes
|
2007-11-09 13:06:51 +00:00
|
|
|
foreach(DiagramTextItem *text, content_to_move.textFields) {
|
2007-10-27 13:18:17 +00:00
|
|
|
text -> setPos(text -> pos() + actual_movement);
|
|
|
|
}
|
2007-09-26 17:14:09 +00:00
|
|
|
}
|
2007-09-26 22:57:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param dti Champ de texte modifie
|
|
|
|
@param before texte avant
|
|
|
|
@param after texte apres
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeDiagramTextCommand::ChangeDiagramTextCommand(
|
|
|
|
DiagramTextItem *dti,
|
|
|
|
const QString &before,
|
|
|
|
const QString &after,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modifier le texte", "undo caption"), parent),
|
2007-09-26 22:57:53 +00:00
|
|
|
text_item(dti),
|
|
|
|
text_before(before),
|
|
|
|
text_after(after),
|
|
|
|
first_redo(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// destructeur
|
|
|
|
ChangeDiagramTextCommand::~ChangeDiagramTextCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// annule la modification de texte
|
|
|
|
void ChangeDiagramTextCommand::undo() {
|
|
|
|
text_item -> setPlainText(text_before);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// refait la modification de texte
|
|
|
|
void ChangeDiagramTextCommand::redo() {
|
2010-04-23 22:39:59 +00:00
|
|
|
if (first_redo) {
|
|
|
|
first_redo = false;
|
|
|
|
} else {
|
2007-09-26 22:57:53 +00:00
|
|
|
text_item -> setPlainText(text_after);
|
|
|
|
}
|
|
|
|
}
|
2007-09-27 15:36:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param elements Elements a pivoter associes a leur orientation d'origine
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2009-11-29 21:56:48 +00:00
|
|
|
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, QUndoCommand *parent) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(parent),
|
2009-11-29 21:56:48 +00:00
|
|
|
elements_to_rotate(elements),
|
2010-02-11 23:35:04 +00:00
|
|
|
texts_to_rotate(texts),
|
|
|
|
applied_rotation_angle_(-90.0)
|
2007-09-27 15:36:15 +00:00
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(
|
|
|
|
QString(
|
|
|
|
QObject::tr(
|
|
|
|
"pivoter %1",
|
|
|
|
"undo caption - %1 is a sentence listing the rotated content"
|
|
|
|
)
|
2009-11-29 21:56:48 +00:00
|
|
|
).arg(QET::ElementsAndConductorsSentence(elements.count(), 0, texts.count()))
|
2009-04-03 19:30:25 +00:00
|
|
|
);
|
2007-09-27 15:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
RotateElementsCommand::~RotateElementsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// defait le pivotement
|
|
|
|
void RotateElementsCommand::undo() {
|
|
|
|
foreach(Element *e, elements_to_rotate.keys()) {
|
|
|
|
e -> setOrientation(elements_to_rotate[e]);
|
|
|
|
}
|
2009-11-29 21:56:48 +00:00
|
|
|
foreach(DiagramTextItem *dti, texts_to_rotate) {
|
2010-02-11 23:35:04 +00:00
|
|
|
dti -> rotateBy(-applied_rotation_angle_);
|
2009-11-29 21:56:48 +00:00
|
|
|
}
|
2007-09-27 15:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// refait le pivotement
|
|
|
|
void RotateElementsCommand::redo() {
|
|
|
|
foreach(Element *e, elements_to_rotate.keys()) {
|
|
|
|
e -> setOrientation(e -> orientation().next());
|
|
|
|
e -> update();
|
2009-11-29 21:56:48 +00:00
|
|
|
}
|
|
|
|
foreach(DiagramTextItem *dti, texts_to_rotate) {
|
2010-02-11 23:35:04 +00:00
|
|
|
dti -> rotateBy(applied_rotation_angle_);
|
2007-09-27 15:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-27 17:42:02 +00:00
|
|
|
|
2010-02-11 23:35:04 +00:00
|
|
|
/**
|
|
|
|
@return l'angle de rotation applique aux textes
|
|
|
|
*/
|
|
|
|
qreal RotateElementsCommand::appliedRotationAngle() const {
|
|
|
|
return(applied_rotation_angle_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param angle l'angle de rotation a appliquer aux textes
|
|
|
|
*/
|
|
|
|
void RotateElementsCommand::setAppliedRotationAngle(const qreal &angle) {
|
|
|
|
applied_rotation_angle_ = QET::correctAngle(angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action
|
|
|
|
@param applied_rotation Nouvel angle de rotation, a appliquer au textes concernes
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
RotateTextsCommand::RotateTextsCommand(const QHash<DiagramTextItem *, double> &previous_state, double applied_rotation, QUndoCommand *parent) :
|
|
|
|
QUndoCommand(parent),
|
|
|
|
texts_to_rotate(previous_state),
|
|
|
|
applied_rotation_angle_(applied_rotation)
|
|
|
|
{
|
|
|
|
defineCommandName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param texts Liste des textes impactes par l'action. L'objet retiendra leur angle de rotation au moment de sa construction.
|
|
|
|
@param applied_rotation Nouvel angle de rotation, a appliquer au textes concernes
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
RotateTextsCommand::RotateTextsCommand(const QList<DiagramTextItem *> &texts, double applied_rotation, QUndoCommand *parent) :
|
|
|
|
QUndoCommand(parent),
|
|
|
|
applied_rotation_angle_(applied_rotation)
|
|
|
|
{
|
|
|
|
foreach(DiagramTextItem *text, texts) {
|
|
|
|
texts_to_rotate.insert(text, text -> rotationAngle());
|
|
|
|
}
|
|
|
|
defineCommandName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructeur
|
|
|
|
*/
|
|
|
|
RotateTextsCommand::~RotateTextsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Annule la rotation des textes
|
|
|
|
*/
|
|
|
|
void RotateTextsCommand::undo() {
|
|
|
|
foreach(DiagramTextItem *text, texts_to_rotate.keys()) {
|
|
|
|
text -> setRotationAngle(texts_to_rotate[text]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Applique l'angle de rotation aux textes
|
|
|
|
*/
|
|
|
|
void RotateTextsCommand::redo() {
|
|
|
|
foreach(DiagramTextItem *text, texts_to_rotate.keys()) {
|
|
|
|
text -> setRotationAngle(applied_rotation_angle_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Definit le nom de la commande d'annulation
|
|
|
|
*/
|
|
|
|
void RotateTextsCommand::defineCommandName() {
|
|
|
|
setText(
|
|
|
|
QString(
|
|
|
|
QObject::tr(
|
|
|
|
"orienter %1 \340 %2\260",
|
|
|
|
"undo caption - %1 looks like '42 texts', %2 is a rotation angle"
|
|
|
|
)
|
|
|
|
).arg(QET::ElementsAndConductorsSentence(0, 0, texts_to_rotate.count()))
|
|
|
|
.arg(applied_rotation_angle_)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-09-27 17:42:02 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param c Conducteur modifie
|
|
|
|
@param old_p ancien profil du conducteur
|
|
|
|
@param new_p nouveau profil du conducteur
|
2007-12-05 21:16:01 +00:00
|
|
|
@param path_t Trajectoire du trajet modifie
|
2007-09-27 17:42:02 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
ChangeConductorCommand::ChangeConductorCommand(
|
|
|
|
Conductor *c,
|
|
|
|
const ConductorProfile &old_p,
|
|
|
|
const ConductorProfile &new_p,
|
2007-10-22 20:27:39 +00:00
|
|
|
Qt::Corner path_t,
|
2007-09-27 17:42:02 +00:00
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modifier un conducteur", "undo caption"), parent),
|
2007-10-03 17:02:39 +00:00
|
|
|
conductor(c),
|
2007-09-27 17:42:02 +00:00
|
|
|
old_profile(old_p),
|
|
|
|
new_profile(new_p),
|
2007-10-22 20:27:39 +00:00
|
|
|
path_type(path_t),
|
2007-09-27 17:42:02 +00:00
|
|
|
first_redo(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
2007-10-03 17:02:39 +00:00
|
|
|
ChangeConductorCommand::~ChangeConductorCommand() {
|
2007-09-27 17:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule la modification du conducteur
|
2007-10-03 17:02:39 +00:00
|
|
|
void ChangeConductorCommand::undo() {
|
2007-10-22 20:27:39 +00:00
|
|
|
conductor -> setProfile(old_profile, path_type);
|
2007-09-27 17:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait la modification du conducteur
|
2007-10-03 17:02:39 +00:00
|
|
|
void ChangeConductorCommand::redo() {
|
2007-09-27 17:42:02 +00:00
|
|
|
if (first_redo) first_redo = false;
|
2007-10-22 20:27:39 +00:00
|
|
|
else conductor -> setProfile(new_profile, path_type);
|
2007-09-27 17:42:02 +00:00
|
|
|
}
|
2007-09-28 17:39:30 +00:00
|
|
|
|
2007-10-06 18:37:21 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
2007-10-10 17:50:26 +00:00
|
|
|
@param cp Conducteurs reinitialises, associes a leur ancien profil
|
2007-10-06 18:37:21 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ResetConductorCommand::ResetConductorCommand(
|
2007-10-22 20:27:39 +00:00
|
|
|
const QHash<Conductor *, ConductorProfilesGroup> &cp,
|
2007-10-06 18:37:21 +00:00
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(parent),
|
2007-10-06 18:37:21 +00:00
|
|
|
conductors_profiles(cp)
|
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(
|
|
|
|
QObject::tr(
|
|
|
|
"R\351initialiser %1",
|
|
|
|
"undo caption - %1 is a sentence listing the reset content"
|
|
|
|
).arg(QET::ElementsAndConductorsSentence(0, cp.count()))
|
|
|
|
);
|
2007-10-06 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ResetConductorCommand::~ResetConductorCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule la reinitialisation des conducteurs
|
|
|
|
void ResetConductorCommand::undo() {
|
|
|
|
foreach(Conductor *c, conductors_profiles.keys()) {
|
2007-10-22 20:27:39 +00:00
|
|
|
c -> setProfiles(conductors_profiles[c]);
|
2007-10-06 18:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait la reinitialisation des conducteurs
|
|
|
|
void ResetConductorCommand::redo() {
|
|
|
|
foreach(Conductor *c, conductors_profiles.keys()) {
|
2007-10-22 20:27:39 +00:00
|
|
|
c -> setProfiles(ConductorProfilesGroup());
|
2007-10-06 18:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-28 17:39:30 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param d Schema dont on modifie le cartouche
|
2007-10-10 17:50:26 +00:00
|
|
|
@param old_ip Anciennes proprietes du cartouche
|
|
|
|
@param new_ip Nouvelles proprietes du cartouche
|
2007-09-28 17:39:30 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeInsetCommand::ChangeInsetCommand(
|
|
|
|
Diagram *d,
|
|
|
|
const InsetProperties &old_ip,
|
|
|
|
const InsetProperties &new_ip,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modifier le cartouche", "undo caption"), parent),
|
2007-09-28 17:39:30 +00:00
|
|
|
diagram(d),
|
|
|
|
old_inset(old_ip),
|
|
|
|
new_inset(new_ip)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeInsetCommand::~ChangeInsetCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule la modification de cartouche
|
|
|
|
void ChangeInsetCommand::undo() {
|
|
|
|
diagram -> border_and_inset.importInset(old_inset);
|
2007-10-15 19:42:18 +00:00
|
|
|
diagram -> invalidate(diagram -> border());
|
2007-09-28 17:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait la modification de cartouche
|
|
|
|
void ChangeInsetCommand::redo() {
|
|
|
|
diagram -> border_and_inset.importInset(new_inset);
|
2007-10-15 19:42:18 +00:00
|
|
|
diagram -> invalidate(diagram -> border());
|
2007-09-28 17:39:30 +00:00
|
|
|
}
|
2007-09-28 21:48:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param dia Schema modifie
|
2009-11-22 16:12:22 +00:00
|
|
|
@param old_bp Anciennes proprietes du cadre du schema
|
|
|
|
@param new_bp Nouvelles proprietes du cadre du schema
|
2007-09-28 21:48:59 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2008-08-15 12:46:22 +00:00
|
|
|
ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, const BorderProperties &old_bp, const BorderProperties &new_bp, QUndoCommand *parent) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modifier les dimensions du sch\351ma", "undo caption"), parent),
|
2007-09-28 21:48:59 +00:00
|
|
|
diagram(dia),
|
2008-08-15 12:46:22 +00:00
|
|
|
old_properties(old_bp),
|
|
|
|
new_properties(new_bp)
|
2007-09-28 21:48:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeBorderCommand::~ChangeBorderCommand() {
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// Annule les changements apportes au schema
|
2007-09-28 21:48:59 +00:00
|
|
|
void ChangeBorderCommand::undo() {
|
2008-08-15 12:46:22 +00:00
|
|
|
diagram -> border_and_inset.importBorder(old_properties);
|
2007-09-28 21:48:59 +00:00
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// Refait les changements apportes au schema
|
2007-09-28 21:48:59 +00:00
|
|
|
void ChangeBorderCommand::redo() {
|
2008-08-15 12:46:22 +00:00
|
|
|
diagram -> border_and_inset.importBorder(new_properties);
|
2007-09-28 21:48:59 +00:00
|
|
|
}
|
2007-10-03 15:51:04 +00:00
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param c Le conducteur dont on modifie les proprietes
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
ChangeConductorPropertiesCommand::ChangeConductorPropertiesCommand(Conductor *c, QUndoCommand *parent) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modifier les propri\351t\351s d'un conducteur", "undo caption"), parent),
|
2007-10-03 17:02:39 +00:00
|
|
|
conductor(c),
|
2007-10-03 15:51:04 +00:00
|
|
|
old_settings_set(false),
|
|
|
|
new_settings_set(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// Destructeur
|
2007-10-03 17:02:39 +00:00
|
|
|
ChangeConductorPropertiesCommand::~ChangeConductorPropertiesCommand() {
|
2007-10-03 15:51:04 +00:00
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// definit l'ancienne configuration
|
2007-10-14 14:44:33 +00:00
|
|
|
void ChangeConductorPropertiesCommand::setOldSettings(const ConductorProperties &properties) {
|
|
|
|
old_properties = properties;
|
2007-10-03 15:51:04 +00:00
|
|
|
old_settings_set = true;
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// definit la nouvelle configuration
|
2007-10-14 14:44:33 +00:00
|
|
|
void ChangeConductorPropertiesCommand::setNewSettings(const ConductorProperties &properties) {
|
|
|
|
new_properties = properties;
|
2007-10-03 15:51:04 +00:00
|
|
|
new_settings_set = true;
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Annule les changements - Attention : les anciens et nouveaux parametres
|
|
|
|
doivent avoir ete definis a l'aide de setNewSettings et setOldSettings
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
void ChangeConductorPropertiesCommand::undo() {
|
2007-10-03 15:51:04 +00:00
|
|
|
if (old_settings_set && new_settings_set) {
|
2007-10-14 14:44:33 +00:00
|
|
|
conductor -> setProperties(old_properties);
|
2007-10-03 17:02:39 +00:00
|
|
|
conductor -> update();
|
2007-10-03 15:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Refait les changements - Attention : les anciens et nouveaux parametres
|
|
|
|
doivent avoir ete definis a l'aide de setNewSettings et setOldSettings
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
void ChangeConductorPropertiesCommand::redo() {
|
2007-10-03 15:51:04 +00:00
|
|
|
if (old_settings_set && new_settings_set) {
|
2007-10-14 14:44:33 +00:00
|
|
|
conductor -> setProperties(new_properties);
|
2007-10-03 17:02:39 +00:00
|
|
|
conductor -> update();
|
2007-10-03 15:51:04 +00:00
|
|
|
}
|
|
|
|
}
|