2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
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
|
|
|
#ifndef DIAGRAM_COMMANDS_H
|
|
|
|
#define DIAGRAM_COMMANDS_H
|
2015-08-09 12:06:31 +00:00
|
|
|
|
2008-08-15 12:46:22 +00:00
|
|
|
#include "borderproperties.h"
|
2013-11-14 10:11:22 +00:00
|
|
|
#include "qetgraphicsitem/conductor.h"
|
2010-04-18 17:59:54 +00:00
|
|
|
#include "diagramcontent.h"
|
|
|
|
#include "qet.h"
|
2014-02-28 14:30:59 +00:00
|
|
|
#include "qetgraphicsitem/qetshapeitem.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "conductorprofile.h"
|
2014-10-10 08:58:44 +00:00
|
|
|
#include "diagram.h"
|
2017-08-03 17:36:08 +00:00
|
|
|
#include "undocommand/deleteqgraphicsitemcommand.h"
|
2014-10-10 08:58:44 +00:00
|
|
|
|
2010-04-18 17:59:54 +00:00
|
|
|
class DiagramTextItem;
|
|
|
|
class Element;
|
|
|
|
class IndependentTextItem;
|
2013-08-24 15:18:45 +00:00
|
|
|
class DiagramImageItem;
|
2014-10-11 17:45:11 +00:00
|
|
|
class QetGraphicsItem;
|
2010-04-18 17:59:54 +00:00
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
/**
|
2020-07-15 18:17:39 +02:00
|
|
|
@brief The AddItemCommand class
|
|
|
|
This command add an item in a diagram
|
|
|
|
The item to add is template, but must be QGraphicsItem or derived.
|
|
|
|
*/
|
2014-10-10 08:58:44 +00:00
|
|
|
template <typename QGI>
|
|
|
|
class AddItemCommand : public QUndoCommand {
|
2013-08-24 15:18:45 +00:00
|
|
|
public:
|
2020-07-14 22:05:24 +02:00
|
|
|
AddItemCommand(QGI item, Diagram *diagram,
|
|
|
|
const QPointF &pos = QPointF(),
|
|
|
|
QUndoCommand *parent = nullptr) :
|
2014-10-10 08:58:44 +00:00
|
|
|
QUndoCommand (parent),
|
|
|
|
m_item (item),
|
|
|
|
m_diagram (diagram),
|
|
|
|
m_pos(pos)
|
|
|
|
{
|
|
|
|
setText(QObject::tr("Ajouter ") + itemText(item));
|
|
|
|
m_diagram -> qgiManager().manage(m_item);
|
|
|
|
}
|
2013-08-24 15:18:45 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
~AddItemCommand() override {
|
2014-10-10 08:58:44 +00:00
|
|
|
m_diagram -> qgiManager().release(m_item);
|
|
|
|
}
|
2013-08-24 15:18:45 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override {
|
2014-10-10 08:58:44 +00:00
|
|
|
m_diagram -> showMe();
|
|
|
|
m_diagram -> removeItem(m_item);
|
2015-01-09 17:18:16 +00:00
|
|
|
QUndoCommand::undo();
|
2014-10-10 08:58:44 +00:00
|
|
|
}
|
2013-08-24 15:18:45 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void redo() override {
|
2014-10-10 08:58:44 +00:00
|
|
|
m_diagram -> showMe();
|
|
|
|
m_diagram -> addItem(m_item);
|
|
|
|
m_item -> setPos(m_pos);
|
2015-01-09 17:18:16 +00:00
|
|
|
QUndoCommand::redo();
|
2014-10-10 08:58:44 +00:00
|
|
|
}
|
2014-02-28 14:30:59 +00:00
|
|
|
|
|
|
|
private:
|
2014-10-10 08:58:44 +00:00
|
|
|
QGI m_item;
|
|
|
|
Diagram *m_diagram;
|
|
|
|
QPointF m_pos;
|
2014-02-28 14:30:59 +00:00
|
|
|
};
|
|
|
|
|
2014-10-11 17:45:11 +00:00
|
|
|
//Return a string to describe a QGraphicsItem
|
|
|
|
QString itemText(const QetGraphicsItem *item);
|
|
|
|
QString itemText(const IndependentTextItem *item);
|
|
|
|
QString itemText(const Conductor *item);
|
2007-09-25 23:24:36 +00:00
|
|
|
|
2007-09-26 12:36:31 +00:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief The PasteDiagramCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This command pastes some content onto a particular diagram.
|
2007-09-26 12:36:31 +00:00
|
|
|
*/
|
|
|
|
class PasteDiagramCommand : public QUndoCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-09-26 12:36:31 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
PasteDiagramCommand(Diagram *, const DiagramContent &,
|
|
|
|
QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~PasteDiagramCommand() override;
|
2007-09-26 12:36:31 +00:00
|
|
|
private:
|
|
|
|
PasteDiagramCommand(const PasteDiagramCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2007-09-26 12:36:31 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-09-26 12:36:31 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// pasted content
|
2007-11-09 13:06:51 +00:00
|
|
|
DiagramContent content;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// diagram content is pasted onto
|
2007-09-26 12:36:31 +00:00
|
|
|
Diagram *diagram;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// filter stating what kinds of items should be pasted
|
2007-11-11 16:12:45 +00:00
|
|
|
int filter;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// prevent the first call to redo()
|
2007-09-26 12:36:31 +00:00
|
|
|
bool first_redo;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief The CutDiagramCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This command cuts content from a particular diagram.
|
2007-09-26 12:36:31 +00:00
|
|
|
*/
|
2017-08-03 17:36:08 +00:00
|
|
|
class CutDiagramCommand : public DeleteQGraphicsItemCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-09-26 12:36:31 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
CutDiagramCommand(Diagram *, const DiagramContent &,
|
|
|
|
QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~CutDiagramCommand() override;
|
2007-09-26 12:36:31 +00:00
|
|
|
private:
|
|
|
|
CutDiagramCommand(const CutDiagramCommand &);
|
|
|
|
};
|
|
|
|
|
2007-09-26 17:14:09 +00:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief The MoveElementsCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This command moves some content on a particular diagram.
|
2007-09-26 17:14:09 +00:00
|
|
|
*/
|
|
|
|
class MoveElementsCommand : public QUndoCommand {
|
2015-01-09 17:18:16 +00:00
|
|
|
// constructors, destructor
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
MoveElementsCommand(Diagram *, const DiagramContent &,
|
|
|
|
const QPointF &m, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~MoveElementsCommand() override;
|
2007-09-26 17:14:09 +00:00
|
|
|
private:
|
2015-01-09 17:18:16 +00:00
|
|
|
MoveElementsCommand(const MoveElementsCommand &);
|
2007-09-26 17:14:09 +00:00
|
|
|
|
2015-01-09 17:18:16 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2015-01-09 17:18:16 +00:00
|
|
|
virtual void move(const QPointF &);
|
2014-07-09 16:50:30 +00:00
|
|
|
|
|
|
|
private:
|
2020-07-15 18:20:08 +02:00
|
|
|
void setupAnimation (QObject * target,
|
|
|
|
const QByteArray &propertyName,
|
|
|
|
const QVariant& start,
|
|
|
|
const QVariant& end);
|
2007-09-26 17:14:09 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-09-26 17:14:09 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// diagram the movement takes place on.
|
2007-09-26 17:14:09 +00:00
|
|
|
Diagram *diagram;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// moved content
|
2007-11-09 13:06:51 +00:00
|
|
|
DiagramContent content_to_move;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// applied movement
|
2007-09-26 17:14:09 +00:00
|
|
|
QPointF movement;
|
2014-07-09 16:50:30 +00:00
|
|
|
///animation group
|
|
|
|
QParallelAnimationGroup *m_anim_group;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// prevent the first call to redo()
|
2010-04-24 20:42:20 +00:00
|
|
|
bool first_redo;
|
|
|
|
};
|
|
|
|
|
2010-05-08 21:24:43 +00:00
|
|
|
/**
|
2020-07-15 18:02:11 +02:00
|
|
|
@brief The MoveConductorsTextsCommand class
|
|
|
|
This command moves text items related to conductors
|
|
|
|
on a particular diagram.
|
2010-05-08 21:24:43 +00:00
|
|
|
*/
|
|
|
|
class MoveConductorsTextsCommand : public QUndoCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2010-05-08 21:24:43 +00:00
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
MoveConductorsTextsCommand(Diagram *, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~MoveConductorsTextsCommand() override;
|
2010-05-08 21:24:43 +00:00
|
|
|
private:
|
|
|
|
MoveConductorsTextsCommand(const MoveConductorsTextsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2010-05-08 21:24:43 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2020-08-20 21:58:23 +02:00
|
|
|
virtual void addTextMovement(ConductorTextItem *,
|
|
|
|
const QPointF &,
|
|
|
|
const QPointF &,
|
|
|
|
bool = false);
|
2010-05-08 21:24:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void regenerateTextLabel();
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2010-05-08 21:24:43 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// diagram the movement takes place on.
|
2010-05-08 21:24:43 +00:00
|
|
|
Diagram *diagram;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// text items to be moved
|
2010-05-08 21:24:43 +00:00
|
|
|
QHash<ConductorTextItem *, QPair<QPointF, bool> > texts_to_move_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// prevent the first call to redo()
|
2010-05-08 21:24:43 +00:00
|
|
|
bool first_redo;
|
|
|
|
};
|
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
/**
|
2020-07-15 18:20:08 +02:00
|
|
|
@brief The ChangeDiagramTextCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This commad modifies a text item.
|
2007-09-26 22:57:53 +00:00
|
|
|
*/
|
|
|
|
class ChangeDiagramTextCommand : public QUndoCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-09-26 22:57:53 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
ChangeDiagramTextCommand(DiagramTextItem *,
|
|
|
|
const QString &before,
|
|
|
|
const QString &after,
|
|
|
|
QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ChangeDiagramTextCommand() override;
|
2007-09-26 22:57:53 +00:00
|
|
|
private:
|
|
|
|
ChangeDiagramTextCommand(const ChangeDiagramTextCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 22:57:53 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2007-09-26 22:57:53 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-09-26 22:57:53 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// modified text item
|
2007-09-26 22:57:53 +00:00
|
|
|
DiagramTextItem *text_item;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// former text
|
2007-09-26 22:57:53 +00:00
|
|
|
QString text_before;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// new text
|
2007-09-26 22:57:53 +00:00
|
|
|
QString text_after;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// prevent the first call to redo()
|
2007-09-26 22:57:53 +00:00
|
|
|
bool first_redo;
|
2014-01-06 18:21:58 +00:00
|
|
|
Diagram *diagram;
|
2007-09-26 22:57:53 +00:00
|
|
|
};
|
2007-09-27 15:36:15 +00:00
|
|
|
|
2007-09-27 17:42:02 +00:00
|
|
|
/**
|
2020-07-15 18:20:08 +02:00
|
|
|
@brief The ChangeConductorCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes a particular conductor.
|
2007-09-27 17:42:02 +00:00
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
class ChangeConductorCommand : public QUndoCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-09-27 17:42:02 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
ChangeConductorCommand(Conductor *, const ConductorProfile &,
|
|
|
|
const ConductorProfile &, Qt::Corner,
|
|
|
|
QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ChangeConductorCommand() override;
|
2007-09-27 17:42:02 +00:00
|
|
|
private:
|
2007-10-03 17:02:39 +00:00
|
|
|
ChangeConductorCommand(const ChangeConductorCommand &);
|
2007-09-27 17:42:02 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-27 17:42:02 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2010-05-08 21:24:43 +00:00
|
|
|
virtual void setConductorTextItemMove(const QPointF &, const QPointF &);
|
2007-09-27 17:42:02 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-09-27 17:42:02 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// changed conductor
|
2007-10-03 17:02:39 +00:00
|
|
|
Conductor *conductor;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// profile before the change
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorProfile old_profile;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// profile after the change
|
2007-10-03 17:02:39 +00:00
|
|
|
ConductorProfile new_profile;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Path type of the modified conductor
|
2007-10-22 20:27:39 +00:00
|
|
|
Qt::Corner path_type;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// position of the text item before the change
|
2010-05-08 21:24:43 +00:00
|
|
|
QPointF text_pos_before_mov_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// position of the text item after the change
|
2010-05-08 21:24:43 +00:00
|
|
|
QPointF text_pos_after_mov_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// prevent the first call to redo()
|
2007-09-27 17:42:02 +00:00
|
|
|
bool first_redo;
|
2014-01-06 18:21:58 +00:00
|
|
|
Diagram *diagram;
|
2007-09-27 17:42:02 +00:00
|
|
|
};
|
2007-09-28 17:39:30 +00:00
|
|
|
|
2007-10-06 18:37:21 +00:00
|
|
|
/**
|
2020-07-15 18:20:08 +02:00
|
|
|
@brief The ResetConductorCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This command resets conductor paths.
|
2007-10-06 18:37:21 +00:00
|
|
|
*/
|
|
|
|
class ResetConductorCommand : public QUndoCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-10-06 18:37:21 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
ResetConductorCommand(const QHash<Conductor *,
|
|
|
|
ConductorProfilesGroup> &,
|
|
|
|
QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ResetConductorCommand() override;
|
2007-10-06 18:37:21 +00:00
|
|
|
private:
|
|
|
|
ResetConductorCommand(const ResetConductorCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-10-06 18:37:21 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2007-10-06 18:37:21 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-10-06 18:37:21 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// impacted conductors along with their former profiles
|
2007-10-22 20:27:39 +00:00
|
|
|
QHash<Conductor *, ConductorProfilesGroup> conductors_profiles;
|
2014-01-06 18:21:58 +00:00
|
|
|
Diagram *diagram;
|
2007-10-06 18:37:21 +00:00
|
|
|
};
|
|
|
|
|
2018-10-21 09:54:59 +00:00
|
|
|
|
2007-09-28 21:48:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-15 18:20:08 +02:00
|
|
|
@brief The ChangeBorderCommand class
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes the border properties of a particular diagram.
|
2007-09-28 21:48:59 +00:00
|
|
|
*/
|
|
|
|
class ChangeBorderCommand : public QUndoCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-09-28 21:48:59 +00:00
|
|
|
public:
|
2020-07-15 18:20:08 +02:00
|
|
|
ChangeBorderCommand(Diagram *, const BorderProperties &,
|
|
|
|
const BorderProperties &, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ChangeBorderCommand() override;
|
2007-09-28 21:48:59 +00:00
|
|
|
private:
|
|
|
|
ChangeBorderCommand(const ChangeBorderCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-28 21:48:59 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2007-09-28 21:48:59 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-09-28 21:48:59 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// modified diagram
|
2007-09-28 21:48:59 +00:00
|
|
|
Diagram *diagram;
|
|
|
|
public:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// properties before the change
|
2008-08-15 12:46:22 +00:00
|
|
|
BorderProperties old_properties;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// properties after the change
|
2008-08-15 12:46:22 +00:00
|
|
|
BorderProperties new_properties;
|
2007-09-28 21:48:59 +00:00
|
|
|
};
|
2007-10-03 15:51:04 +00:00
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
#endif
|