2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2012-01-01 22:51:51 +00:00
|
|
|
Copyright 2006-2012 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-08-23 15:33:55 +00:00
|
|
|
#include "editorcommands.h"
|
|
|
|
|
|
|
|
/*** DeletePartsCommand ***/
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-08-25 03:43:05 +00:00
|
|
|
@param scene ElementScene concernee
|
2007-08-23 15:33:55 +00:00
|
|
|
@param parts Liste des parties supprimees
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
DeletePartsCommand::DeletePartsCommand(
|
2007-08-25 03:43:05 +00:00
|
|
|
ElementScene *scene,
|
2007-08-23 15:33:55 +00:00
|
|
|
const QList<QGraphicsItem *> parts,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("suppression", "undo caption"), parent),
|
2007-08-23 15:33:55 +00:00
|
|
|
deleted_parts(parts),
|
|
|
|
editor_scene(scene)
|
|
|
|
{
|
|
|
|
foreach(QGraphicsItem *qgi, deleted_parts) {
|
|
|
|
editor_scene -> qgiManager().manage(qgi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur : detruit egalement les parties supprimees
|
|
|
|
DeletePartsCommand::~DeletePartsCommand() {
|
|
|
|
foreach(QGraphicsItem *qgi, deleted_parts) {
|
|
|
|
editor_scene -> qgiManager().release(qgi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Restaure les parties supprimees
|
|
|
|
void DeletePartsCommand::undo() {
|
2010-02-28 16:13:45 +00:00
|
|
|
editor_scene -> blockSignals(true);
|
2007-08-23 15:33:55 +00:00
|
|
|
foreach(QGraphicsItem *qgi, deleted_parts) {
|
|
|
|
editor_scene -> addItem(qgi);
|
|
|
|
}
|
2010-02-28 16:13:45 +00:00
|
|
|
editor_scene -> blockSignals(false);
|
2007-08-23 15:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Supprime les parties
|
|
|
|
void DeletePartsCommand::redo() {
|
2010-02-28 16:13:45 +00:00
|
|
|
editor_scene -> blockSignals(true);
|
2007-08-23 15:33:55 +00:00
|
|
|
foreach(QGraphicsItem *qgi, deleted_parts) {
|
|
|
|
editor_scene -> removeItem(qgi);
|
|
|
|
}
|
2010-02-28 16:13:45 +00:00
|
|
|
editor_scene -> blockSignals(false);
|
2007-08-23 15:33:55 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/*** CutPartsCommand ***/
|
|
|
|
/**
|
|
|
|
Constructeur
|
2009-11-22 16:12:22 +00:00
|
|
|
@param view ElementView concernee
|
|
|
|
@param c Liste des parties collees
|
2009-04-03 19:30:25 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
PastePartsCommand::PastePartsCommand(
|
|
|
|
ElementView *view,
|
|
|
|
const ElementContent &c,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
|
|
|
QUndoCommand(parent),
|
|
|
|
content_(c),
|
|
|
|
editor_view_(view),
|
|
|
|
editor_scene_(view -> scene()),
|
|
|
|
uses_offset(false),
|
|
|
|
first_redo(true)
|
|
|
|
{
|
|
|
|
setText(QObject::tr("coller"));
|
|
|
|
editor_scene_ -> qgiManager().manage(content_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
PastePartsCommand::~PastePartsCommand() {
|
|
|
|
editor_scene_ -> qgiManager().release(content_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// annule le coller
|
|
|
|
void PastePartsCommand::undo() {
|
|
|
|
// enleve les parties
|
2010-02-28 16:13:45 +00:00
|
|
|
editor_scene_ -> blockSignals(true);
|
|
|
|
foreach(QGraphicsItem *part, content_) {
|
|
|
|
editor_scene_ -> removeItem(part);
|
|
|
|
}
|
|
|
|
editor_scene_ -> blockSignals(false);
|
2009-04-03 19:30:25 +00:00
|
|
|
if (uses_offset) {
|
|
|
|
editor_view_ -> offset_paste_count_ = old_offset_paste_count_;
|
|
|
|
editor_view_ -> start_top_left_corner_ = old_start_top_left_corner_;
|
|
|
|
}
|
|
|
|
editor_view_ -> adjustSceneRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// refait le coller
|
|
|
|
void PastePartsCommand::redo() {
|
|
|
|
if (first_redo) first_redo = false;
|
|
|
|
else {
|
|
|
|
// pose les parties
|
2010-02-28 16:13:45 +00:00
|
|
|
editor_scene_ -> blockSignals(true);
|
|
|
|
foreach(QGraphicsItem *part, content_) {
|
|
|
|
editor_scene_ -> addItem(part);
|
|
|
|
}
|
|
|
|
editor_scene_ -> blockSignals(false);
|
2009-04-03 19:30:25 +00:00
|
|
|
if (uses_offset) {
|
|
|
|
editor_view_ -> offset_paste_count_ = new_offset_paste_count_;
|
|
|
|
editor_view_ -> start_top_left_corner_ = new_start_top_left_corner_;
|
|
|
|
}
|
|
|
|
}
|
2009-04-18 18:08:54 +00:00
|
|
|
editor_scene_ -> slot_select(content_);
|
2009-04-03 19:30:25 +00:00
|
|
|
editor_view_ -> adjustSceneRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Indique a cet objet d'annulation que le c/c a annuler ou refaire etait un
|
|
|
|
c/c avec decalage ; il faut plus d'informations pour annuler ce type de
|
|
|
|
collage.
|
|
|
|
*/
|
|
|
|
void PastePartsCommand::setOffset(int old_offset_pc, const QPointF &old_start_tlc, int new_offset_pc, const QPointF &new_start_tlc) {
|
|
|
|
old_offset_paste_count_ = old_offset_pc;
|
|
|
|
old_start_top_left_corner_ = old_start_tlc;
|
|
|
|
new_offset_paste_count_ = new_offset_pc;
|
|
|
|
new_start_top_left_corner_ = new_start_tlc;
|
|
|
|
uses_offset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** CutPartsCommand ***/
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param scene ElementScene concernee
|
|
|
|
@param parts Liste des parties coupees
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
CutPartsCommand::CutPartsCommand(
|
|
|
|
ElementScene *scene,
|
|
|
|
const QList<QGraphicsItem *> parts,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
|
|
|
DeletePartsCommand(scene, parts, parent)
|
|
|
|
{
|
|
|
|
setText(QString(QObject::tr("couper des parties", "undo caption")));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
CutPartsCommand::~CutPartsCommand() {
|
|
|
|
}
|
|
|
|
|
2007-08-23 15:33:55 +00:00
|
|
|
/*** MovePartsCommand ***/
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param m Mouvement sous forme de QPointF
|
2007-08-25 03:43:05 +00:00
|
|
|
@param scene ElementScene concernee
|
2007-08-23 15:33:55 +00:00
|
|
|
@param parts Liste des parties deplacees
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
MovePartsCommand::MovePartsCommand(
|
|
|
|
const QPointF &m,
|
2007-08-25 03:43:05 +00:00
|
|
|
ElementScene *scene,
|
2007-08-23 15:33:55 +00:00
|
|
|
const QList<QGraphicsItem *> parts,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("d\351placement", "undo caption"), parent),
|
2007-08-23 15:33:55 +00:00
|
|
|
movement(m),
|
|
|
|
first_redo(true)
|
|
|
|
{
|
|
|
|
moved_parts = parts;
|
|
|
|
editor_scene = scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
MovePartsCommand::~MovePartsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le deplacement
|
|
|
|
void MovePartsCommand::undo() {
|
|
|
|
foreach(QGraphicsItem *qgi, moved_parts) qgi -> moveBy(-movement.x(), -movement.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le deplacement
|
|
|
|
void MovePartsCommand::redo() {
|
|
|
|
// le premier appel a redo, lors de la construction de l'objet, ne doit pas se faire
|
|
|
|
if (first_redo) {
|
|
|
|
first_redo = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach(QGraphicsItem *qgi, moved_parts) qgi -> moveBy(movement.x(), movement.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** AddPartCommand ***/
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param name Nom de la partie ajoutee
|
2007-09-25 23:24:36 +00:00
|
|
|
@param scene ElementScene concernee
|
|
|
|
@param p partie ajoutee
|
2007-08-23 15:33:55 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
AddPartCommand::AddPartCommand(
|
|
|
|
const QString &name,
|
2007-08-25 03:43:05 +00:00
|
|
|
ElementScene *scene,
|
2007-08-23 15:33:55 +00:00
|
|
|
QGraphicsItem *p,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QString(QObject::tr("ajout %1", "undo caption")).arg(name), parent),
|
2007-08-23 15:33:55 +00:00
|
|
|
part(p),
|
|
|
|
editor_scene(scene),
|
|
|
|
first_redo(true)
|
|
|
|
{
|
|
|
|
editor_scene -> qgiManager().manage(part);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
AddPartCommand::~AddPartCommand() {
|
|
|
|
editor_scene -> qgiManager().release(part);
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
/// Annule l'ajout
|
2007-08-23 15:33:55 +00:00
|
|
|
void AddPartCommand::undo() {
|
|
|
|
editor_scene -> removeItem(part);
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
/// Refait l'ajout
|
2007-08-23 15:33:55 +00:00
|
|
|
void AddPartCommand::redo() {
|
|
|
|
// le premier appel a redo, lors de la construction de l'objet, ne doit pas se faire
|
|
|
|
if (first_redo) {
|
2012-05-12 22:03:07 +00:00
|
|
|
if (!part -> zValue()) {
|
|
|
|
// the added part has no specific zValue already defined, we put it
|
|
|
|
// above existing items (but still under terminals)
|
|
|
|
QList<QGraphicsItem *> existing_items = editor_scene -> zItems();
|
|
|
|
qreal z = existing_items.count() ? existing_items.last() -> zValue() + 1 : 1;
|
|
|
|
part -> setZValue(z);
|
|
|
|
}
|
2007-10-06 19:46:44 +00:00
|
|
|
editor_scene -> clearSelection();
|
|
|
|
part -> setSelected(true);
|
2007-08-23 15:33:55 +00:00
|
|
|
first_redo = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
editor_scene -> addItem(part);
|
|
|
|
}
|
2007-08-25 03:43:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param name nom de la propriete modifiee
|
|
|
|
@param part partie modifiee
|
|
|
|
@param prop propriete modifiee
|
|
|
|
@param old_v ancienne valeur
|
|
|
|
@param new_v nouvelle valeur
|
|
|
|
@param parent qUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangePartCommand::ChangePartCommand(
|
|
|
|
const QString &name,
|
|
|
|
CustomElementPart *part,
|
|
|
|
const QString &prop,
|
|
|
|
const QVariant &old_v,
|
|
|
|
const QVariant &new_v,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QString(QObject::tr("modification %1", "undo caption")).arg(name), parent),
|
2007-08-25 03:43:05 +00:00
|
|
|
cep(part),
|
|
|
|
property(prop),
|
|
|
|
old_value(old_v),
|
|
|
|
new_value(new_v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangePartCommand::~ChangePartCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le changement
|
|
|
|
void ChangePartCommand::undo() {
|
|
|
|
cep -> setProperty(property, old_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le changement
|
|
|
|
void ChangePartCommand::redo() {
|
|
|
|
cep -> setProperty(property, new_value);
|
|
|
|
}
|
2007-08-25 15:04:45 +00:00
|
|
|
|
2007-09-10 21:12:49 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param p Polygone edite
|
|
|
|
@param o_points points avant le changement
|
|
|
|
@param n_points points apres le changement
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
2007-08-25 15:04:45 +00:00
|
|
|
ChangePolygonPointsCommand::ChangePolygonPointsCommand(
|
|
|
|
PartPolygon *p,
|
|
|
|
const QVector<QPointF> &o_points,
|
|
|
|
const QVector<QPointF> &n_points,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modification points polygone", "undo caption"), parent),
|
2007-08-25 15:04:45 +00:00
|
|
|
polygon(p),
|
|
|
|
old_points(o_points),
|
|
|
|
new_points(n_points)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-10 21:12:49 +00:00
|
|
|
/// Destructeur
|
2007-08-25 15:04:45 +00:00
|
|
|
ChangePolygonPointsCommand::~ChangePolygonPointsCommand() {
|
|
|
|
}
|
|
|
|
|
2007-09-10 21:12:49 +00:00
|
|
|
/// Annule le changement
|
2007-08-25 15:04:45 +00:00
|
|
|
void ChangePolygonPointsCommand::undo() {
|
|
|
|
polygon -> setPolygon(old_points);
|
|
|
|
}
|
|
|
|
|
2007-09-10 21:12:49 +00:00
|
|
|
/// Refait le changement
|
2007-08-25 15:04:45 +00:00
|
|
|
void ChangePolygonPointsCommand::redo() {
|
|
|
|
polygon -> setPolygon(new_points);
|
|
|
|
}
|
2007-09-10 21:12:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param element_scene Element edite
|
|
|
|
@param size_1 Dimensions de l'element avant le changement
|
|
|
|
@param size_2 Dimensions de l'element apres le changement
|
|
|
|
@param hotspot_1 Point de saisie de l'element avant le changement
|
|
|
|
@param hotspot_2 Point de saisie de l'element apres le changement
|
|
|
|
@param o Eventuel decalage a appliquer aux parties de l'element edite
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeHotspotCommand::ChangeHotspotCommand(
|
|
|
|
ElementScene *element_scene,
|
|
|
|
const QSize &size_1,
|
|
|
|
const QSize &size_2,
|
|
|
|
const QPoint &hotspot_1,
|
|
|
|
const QPoint &hotspot_2,
|
|
|
|
const QPoint &o,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modification dimensions/hotspot", "undo caption"), parent),
|
2007-09-10 21:12:49 +00:00
|
|
|
element(element_scene),
|
|
|
|
size_before(size_1),
|
|
|
|
size_after(size_2),
|
|
|
|
hotspot_before(hotspot_1),
|
|
|
|
hotspot_after(hotspot_2),
|
|
|
|
offset(o)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeHotspotCommand::~ChangeHotspotCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le changement
|
|
|
|
void ChangeHotspotCommand::undo() {
|
|
|
|
QRectF sc(element -> sceneContent());
|
|
|
|
|
|
|
|
element -> setWidth(size_before.width());
|
|
|
|
element -> setHeight(size_before.height());
|
|
|
|
element -> setHotspot(hotspot_before);
|
|
|
|
if (!offset.isNull()) applyOffset(-offset);
|
|
|
|
|
|
|
|
element -> update(element -> sceneContent().unite(sc));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le changement
|
|
|
|
void ChangeHotspotCommand::redo() {
|
|
|
|
QRectF sc(element -> sceneContent());
|
|
|
|
|
|
|
|
element -> setWidth(size_after.width());
|
|
|
|
element -> setHeight(size_after.height());
|
|
|
|
element -> setHotspot(hotspot_after);
|
|
|
|
if (!offset.isNull()) applyOffset(offset);
|
|
|
|
|
|
|
|
element -> update(element -> sceneContent().unite(sc));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Applique une translation aux parties de l'element edite
|
|
|
|
@param o Translation a appliquer
|
|
|
|
*/
|
|
|
|
void ChangeHotspotCommand::applyOffset(const QPointF &o) {
|
|
|
|
foreach(QGraphicsItem *qgi, element -> items()) {
|
|
|
|
qgi -> translate(o.x(), o.y());
|
|
|
|
}
|
|
|
|
}
|
2007-09-10 21:50:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param element_scene Element edite
|
|
|
|
@param before Listes des noms avant changement
|
|
|
|
@param after Listes des noms apres changement
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeNamesCommand::ChangeNamesCommand(
|
|
|
|
ElementScene *element_scene,
|
|
|
|
const NamesList &before,
|
|
|
|
const NamesList &after,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modification noms", "undo caption"), parent),
|
2007-09-10 21:50:17 +00:00
|
|
|
names_before(before),
|
|
|
|
names_after(after),
|
|
|
|
element(element_scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeNamesCommand::~ChangeNamesCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le changement
|
|
|
|
void ChangeNamesCommand::undo() {
|
|
|
|
element -> setNames(names_before);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le changement
|
|
|
|
void ChangeNamesCommand::redo() {
|
|
|
|
element -> setNames(names_after);
|
|
|
|
}
|
2007-09-10 22:11:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param element_scene Element edite
|
|
|
|
@param before Orientations avant changement
|
2007-12-05 21:16:01 +00:00
|
|
|
@param after Orientations apres changement
|
2007-09-10 22:11:47 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeOrientationsCommand::ChangeOrientationsCommand(
|
|
|
|
ElementScene *element_scene,
|
|
|
|
const OrientationSet &before,
|
|
|
|
const OrientationSet &after,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modification orientations", "undo caption"), parent),
|
2007-09-10 22:11:47 +00:00
|
|
|
ori_before(before),
|
|
|
|
ori_after(after),
|
|
|
|
element(element_scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeOrientationsCommand::~ChangeOrientationsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le changement
|
|
|
|
void ChangeOrientationsCommand::undo() {
|
|
|
|
element -> setOrientations(ori_before);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le changement
|
|
|
|
void ChangeOrientationsCommand::redo() {
|
|
|
|
element -> setOrientations(ori_after);
|
|
|
|
}
|
|
|
|
|
2007-10-07 18:52:01 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
2007-10-21 16:10:21 +00:00
|
|
|
@param elmt ElementScene concernee
|
2007-10-07 18:52:01 +00:00
|
|
|
@param o Option decrivant le type de traitement applique aux zValues des parties de l'element
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeZValueCommand::ChangeZValueCommand(
|
|
|
|
ElementScene *elmt,
|
|
|
|
ChangeZValueCommand::Option o,
|
|
|
|
QUndoCommand *parent
|
|
|
|
) :
|
|
|
|
QUndoCommand(parent),
|
|
|
|
element(elmt),
|
|
|
|
option(o)
|
|
|
|
{
|
|
|
|
// recupere les parties de l'elements, sauf les bornes
|
|
|
|
QList<QGraphicsItem *> items_list = element -> zItems();
|
|
|
|
|
|
|
|
// prend un snapshot des zValues
|
|
|
|
foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue());
|
|
|
|
|
|
|
|
// choisit le nom en fonction du traitement
|
|
|
|
if (option == BringForward) {
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(QObject::tr("amener au premier plan", "undo caption"));
|
2007-10-07 18:52:01 +00:00
|
|
|
applyBringForward(items_list);
|
|
|
|
} else if (option == Raise) {
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(QObject::tr("rapprocher", "undo caption"));
|
2007-10-07 18:52:01 +00:00
|
|
|
applyRaise(items_list);
|
|
|
|
} else if (option == Lower) {
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(QObject::tr("\351loigner", "undo caption"));
|
2007-10-07 18:52:01 +00:00
|
|
|
applyLower(items_list);
|
|
|
|
} else if (option == SendBackward) {
|
2009-04-03 19:30:25 +00:00
|
|
|
setText(QObject::tr("envoyer au fond", "undo caption"));
|
2007-10-07 18:52:01 +00:00
|
|
|
applySendBackward(items_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeZValueCommand::~ChangeZValueCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule les changements de zValue
|
|
|
|
void ChangeZValueCommand::undo() {
|
|
|
|
foreach(QGraphicsItem *qgi, undo_hash.keys()) qgi -> setZValue(undo_hash[qgi]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait les changements de zValue
|
|
|
|
void ChangeZValueCommand::redo() {
|
|
|
|
foreach(QGraphicsItem *qgi, redo_hash.keys()) qgi -> setZValue(redo_hash[qgi]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Amene les elements selectionnes au premier plan
|
|
|
|
@param items_list Liste des elements (selectionnes et non selectionnes)
|
|
|
|
*/
|
|
|
|
void ChangeZValueCommand::applyBringForward(const QList<QGraphicsItem *> &items_list) {
|
|
|
|
QList<QGraphicsItem *> non_selected_items = items_list;
|
|
|
|
QList<QGraphicsItem *> selected_items;
|
|
|
|
foreach(QGraphicsItem *qgi, non_selected_items) {
|
|
|
|
if (qgi -> isSelected()) {
|
|
|
|
selected_items << qgi;
|
|
|
|
non_selected_items.removeAt(non_selected_items.indexOf(qgi));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int z = 1;
|
|
|
|
foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++);
|
|
|
|
foreach(QGraphicsItem *qgi, selected_items) redo_hash.insert(qgi, z ++);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Remonte les elements selectionnes d'un plan
|
|
|
|
@param items_list Liste des elements (selectionnes et non selectionnes)
|
|
|
|
*/
|
|
|
|
void ChangeZValueCommand::applyRaise(const QList<QGraphicsItem *> &items_list) {
|
|
|
|
QList<QGraphicsItem *> my_items_list = items_list;
|
|
|
|
|
|
|
|
for (int i = my_items_list.count() - 2 ; i >= 0 ; -- i) {
|
|
|
|
if (my_items_list[i] -> isSelected()) {
|
|
|
|
if (!my_items_list[i +1] -> isSelected()) {
|
|
|
|
my_items_list.swap(i, i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int z = 1;
|
|
|
|
foreach(QGraphicsItem *qgi, my_items_list) redo_hash.insert(qgi, z ++);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Descend les elements selectionnes d'un plan
|
|
|
|
@param items_list Liste des elements (selectionnes et non selectionnes)
|
|
|
|
*/
|
|
|
|
void ChangeZValueCommand::applyLower(const QList<QGraphicsItem *> &items_list) {
|
|
|
|
QList<QGraphicsItem *> my_items_list = items_list;
|
|
|
|
|
|
|
|
for (int i = 1 ; i < my_items_list.count() ; ++ i) {
|
|
|
|
if (my_items_list[i] -> isSelected()) {
|
|
|
|
if (!my_items_list[i - 1] -> isSelected()) {
|
|
|
|
my_items_list.swap(i, i - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int z = 1;
|
|
|
|
foreach(QGraphicsItem *qgi, my_items_list) redo_hash.insert(qgi, z ++);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Envoie les elements selectionnes au fond
|
|
|
|
@param items_list Liste des elements (selectionnes et non selectionnes)
|
|
|
|
*/
|
|
|
|
void ChangeZValueCommand::applySendBackward(const QList<QGraphicsItem *> &items_list) {
|
|
|
|
QList<QGraphicsItem *> non_selected_items = items_list;
|
|
|
|
QList<QGraphicsItem *> selected_items;
|
|
|
|
foreach(QGraphicsItem *qgi, non_selected_items) {
|
|
|
|
if (qgi -> isSelected()) {
|
|
|
|
selected_items << qgi;
|
|
|
|
non_selected_items.removeAt(non_selected_items.indexOf(qgi));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int z = 1;
|
|
|
|
foreach(QGraphicsItem *qgi, selected_items) redo_hash.insert(qgi, z ++);
|
|
|
|
foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++);
|
|
|
|
}
|
2007-12-09 10:54:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param elmt ElementScene concernee
|
|
|
|
@param allow true pour que les connexions internes soient acceptees, false sinon
|
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
AllowInternalConnectionsCommand::AllowInternalConnectionsCommand(ElementScene *elmt, bool allow, QUndoCommand *parent) :
|
2009-04-03 19:30:25 +00:00
|
|
|
QUndoCommand(QObject::tr("modification connexions internes", "undo caption"), parent),
|
2007-12-09 10:54:59 +00:00
|
|
|
element(elmt),
|
|
|
|
ic(allow)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
AllowInternalConnectionsCommand::~AllowInternalConnectionsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le changement d'autorisation pour les connexions internes
|
|
|
|
void AllowInternalConnectionsCommand::undo() {
|
|
|
|
element -> setInternalConnections(!ic);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le changement d'autorisation pour les connexions internes
|
|
|
|
void AllowInternalConnectionsCommand::redo() {
|
|
|
|
element -> setInternalConnections(ic);
|
|
|
|
}
|
2010-02-14 16:28:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param elmt ElementScene concernee
|
|
|
|
@param old_infos Informations complementaires precedentes
|
2010-03-28 16:27:48 +00:00
|
|
|
@param new_infos Nouvelles informations complementaires
|
2010-02-14 16:28:45 +00:00
|
|
|
@param parent QUndoCommand parent
|
|
|
|
*/
|
|
|
|
ChangeInformationsCommand::ChangeInformationsCommand(ElementScene *elmt, const QString &old_infos, const QString &new_infos, QUndoCommand *parent) :
|
|
|
|
QUndoCommand(QObject::tr("modification informations complementaires", "undo caption"), parent),
|
|
|
|
element(elmt),
|
|
|
|
old_informations_(old_infos),
|
|
|
|
new_informations_(new_infos)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ChangeInformationsCommand::~ChangeInformationsCommand() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Annule le changement d'autorisation pour les connexions internes
|
|
|
|
void ChangeInformationsCommand::undo() {
|
|
|
|
element -> setInformations(old_informations_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Refait le changement d'autorisation pour les connexions internes
|
|
|
|
void ChangeInformationsCommand::redo() {
|
|
|
|
element -> setInformations(new_informations_);
|
|
|
|
}
|