2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2023-01-01 17:05:57 +01:00
|
|
|
Copyright 2006-2023 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-08-23 15:33:55 +00:00
|
|
|
#ifndef EDITOR_COMMANDS_H
|
|
|
|
#define EDITOR_COMMANDS_H
|
2020-12-10 18:44:03 +01:00
|
|
|
#include "../editor/graphicspart/customelementpart.h"
|
2020-12-09 15:28:43 +01:00
|
|
|
#include "../qgimanager.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "elementcontent.h"
|
2020-12-09 15:28:43 +01:00
|
|
|
#include "elementscene.h"
|
|
|
|
#include "elementview.h"
|
2021-09-13 20:38:39 +02:00
|
|
|
#include "graphicspart/abstractpartellipse.h"
|
|
|
|
#include "graphicspart/customelementgraphicpart.h"
|
|
|
|
#include "graphicspart/customelementpart.h"
|
|
|
|
#include "graphicspart/partarc.h"
|
|
|
|
#include "graphicspart/partdynamictextfield.h"
|
|
|
|
#include "graphicspart/partellipse.h"
|
|
|
|
#include "graphicspart/partline.h"
|
|
|
|
#include "graphicspart/partpolygon.h"
|
|
|
|
#include "graphicspart/partrectangle.h"
|
|
|
|
#include "graphicspart/partterminal.h"
|
|
|
|
#include "graphicspart/parttext.h"
|
|
|
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
2022-07-26 17:03:18 +02:00
|
|
|
#include "UndoCommand/deletepartscommand.h"
|
2021-09-13 20:38:39 +02:00
|
|
|
|
2013-02-08 22:05:08 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief The ElementEditionCommand class
|
|
|
|
ElementEditionCommand is the base class for all commands classes involved in
|
2013-02-08 22:05:08 +00:00
|
|
|
the edition of an electrical element. It provides commonly required methods
|
|
|
|
and attributes, such as accessors to the modified scene and view.
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2015-02-15 10:21:32 +00:00
|
|
|
class ElementEditionCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
// constructors, destructor
|
2013-02-08 22:05:08 +00:00
|
|
|
public:
|
2020-08-20 21:58:23 +02:00
|
|
|
ElementEditionCommand(ElementScene * = nullptr,
|
|
|
|
ElementView * = nullptr,
|
|
|
|
QUndoCommand * = nullptr);
|
|
|
|
ElementEditionCommand(const QString &,
|
|
|
|
ElementScene * = nullptr,
|
|
|
|
ElementView * = nullptr,
|
|
|
|
QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ElementEditionCommand() override;
|
2013-02-08 22:05:08 +00:00
|
|
|
private:
|
2015-02-15 10:21:32 +00:00
|
|
|
ElementEditionCommand(const ElementEditionCommand &);
|
2013-02-08 22:05:08 +00:00
|
|
|
|
2015-02-15 10:21:32 +00:00
|
|
|
// methods
|
2013-02-08 22:05:08 +00:00
|
|
|
public:
|
2015-02-15 10:21:32 +00:00
|
|
|
ElementScene *elementScene() const;
|
|
|
|
void setElementScene(ElementScene *);
|
|
|
|
ElementView *elementView() const;
|
|
|
|
void setElementView(ElementView *);
|
2013-02-08 22:05:08 +00:00
|
|
|
|
2015-02-15 10:21:32 +00:00
|
|
|
// attributes
|
2013-02-08 22:05:08 +00:00
|
|
|
protected:
|
2015-02-15 10:21:32 +00:00
|
|
|
/// Element editor/view/scene the command should take place on
|
2017-10-01 15:25:34 +00:00
|
|
|
ElementScene *m_scene;
|
|
|
|
ElementView *m_view;
|
2013-02-08 22:05:08 +00:00
|
|
|
};
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command cut primitives when editing an electrical element.
|
2009-04-03 19:30:25 +00:00
|
|
|
*/
|
|
|
|
class CutPartsCommand : public DeletePartsCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2009-04-03 19:30:25 +00:00
|
|
|
public:
|
2018-07-19 14:14:31 +00:00
|
|
|
CutPartsCommand(ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~CutPartsCommand() override;
|
2009-04-03 19:30:25 +00:00
|
|
|
private:
|
|
|
|
CutPartsCommand(const CutPartsCommand &);
|
|
|
|
};
|
|
|
|
|
2007-08-23 15:33:55 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command moves primitives when editing an electrical element.
|
2007-08-23 15:33:55 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class MovePartsCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-08-23 15:33:55 +00:00
|
|
|
public:
|
2018-07-19 14:14:31 +00:00
|
|
|
MovePartsCommand(const QPointF &, ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~MovePartsCommand() override;
|
2007-08-23 15:33:55 +00:00
|
|
|
private:
|
|
|
|
MovePartsCommand(const MovePartsCommand &);
|
|
|
|
|
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-08-23 15:33:55 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-08-23 15:33:55 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// List of moved primitives
|
2007-08-23 15:33:55 +00:00
|
|
|
QList<QGraphicsItem *> moved_parts;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// applied movement
|
2007-08-23 15:33:55 +00:00
|
|
|
QPointF movement;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Prevent the first call to redo()
|
2007-08-23 15:33:55 +00:00
|
|
|
bool first_redo;
|
|
|
|
};
|
|
|
|
|
2007-09-10 21:50:17 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes the translated names of an electrical element.
|
2007-09-10 21:50:17 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class ChangeNamesCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-09-10 21:50:17 +00:00
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ChangeNamesCommand() override;
|
2007-09-10 21:50:17 +00:00
|
|
|
private:
|
|
|
|
ChangeNamesCommand(const ChangeNamesCommand &);
|
|
|
|
|
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-10 21:50:17 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-09-10 21:50:17 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// List of former names
|
2007-09-10 21:50:17 +00:00
|
|
|
NamesList names_before;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// List of new names
|
2007-09-10 21:50:17 +00:00
|
|
|
NamesList names_after;
|
2007-09-10 22:11:47 +00:00
|
|
|
};
|
|
|
|
|
2007-10-07 18:52:01 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes the zValue of a set of primitives when editing an
|
|
|
|
electrical element.
|
2007-10-07 18:52:01 +00:00
|
|
|
*/
|
2018-06-20 18:35:06 +00:00
|
|
|
class ChangeZValueCommand : public ElementEditionCommand
|
|
|
|
{
|
|
|
|
// constructors, destructor
|
2007-10-07 18:52:01 +00:00
|
|
|
public:
|
2018-06-20 18:35:06 +00:00
|
|
|
ChangeZValueCommand(ElementScene *, QET::DepthOption , QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ChangeZValueCommand() override;
|
2007-10-07 18:52:01 +00:00
|
|
|
private:
|
|
|
|
ChangeZValueCommand(const ChangeZValueCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-10-07 18:52:01 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2007-10-07 18:52:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void applyBringForward(const QList<QGraphicsItem *> &);
|
|
|
|
void applyRaise(const QList<QGraphicsItem *> &);
|
|
|
|
void applyLower(const QList<QGraphicsItem *> &);
|
|
|
|
void applySendBackward(const QList<QGraphicsItem *> &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-10-07 18:52:01 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// associates impacted primitives with their former zValues
|
2007-10-07 18:52:01 +00:00
|
|
|
QHash<QGraphicsItem *, qreal> undo_hash;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// associates impacted primitives with their new zValues
|
2007-10-07 18:52:01 +00:00
|
|
|
QHash<QGraphicsItem *, qreal> redo_hash;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// kind of treatment to apply
|
2018-06-20 18:35:06 +00:00
|
|
|
QET::DepthOption m_option;
|
2007-10-07 18:52:01 +00:00
|
|
|
};
|
2007-12-09 10:54:59 +00:00
|
|
|
|
2010-02-14 16:28:45 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes extra information carried by an electrical element.
|
2010-02-14 16:28:45 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class ChangeInformationsCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2010-02-14 16:28:45 +00:00
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
ChangeInformationsCommand(ElementScene *, const QString &, const QString &, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ChangeInformationsCommand() override;
|
2010-02-14 16:28:45 +00:00
|
|
|
private:
|
|
|
|
ChangeInformationsCommand(const ChangeInformationsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2010-02-14 16:28:45 +00:00
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2010-02-14 16:28:45 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2010-02-14 16:28:45 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Former information
|
2010-02-14 16:28:45 +00:00
|
|
|
QString old_informations_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// New information
|
2010-02-14 16:28:45 +00:00
|
|
|
QString new_informations_;
|
|
|
|
};
|
2013-02-08 22:05:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
This command scales primitives when editing an electrical element.
|
|
|
|
*/
|
|
|
|
class ScalePartsCommand : public ElementEditionCommand {
|
|
|
|
// constructors, destructor
|
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
ScalePartsCommand(ElementScene * = nullptr, QUndoCommand * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ScalePartsCommand() override;
|
2013-02-08 22:05:15 +00:00
|
|
|
private:
|
|
|
|
ScalePartsCommand(const ScalePartsCommand &);
|
|
|
|
|
|
|
|
// methods
|
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2013-02-08 22:05:15 +00:00
|
|
|
ElementScene *elementScene() const;
|
|
|
|
void setScaledPrimitives(const QList<CustomElementPart *> &);
|
|
|
|
QList<CustomElementPart *> scaledPrimitives() const;
|
|
|
|
void setTransformation(const QRectF &, const QRectF &);
|
|
|
|
QPair<QRectF, QRectF> transformation();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void scale(const QRectF &before, const QRectF &after);
|
|
|
|
void adjustText();
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
private:
|
|
|
|
/// List of moved primitives
|
|
|
|
QList<CustomElementPart *> scaled_primitives_;
|
|
|
|
/// original rect items fit in
|
|
|
|
QRectF original_rect_;
|
|
|
|
/// new rect items should fit in
|
|
|
|
QRectF new_rect_;
|
|
|
|
/// Prevent the first call to redo()
|
|
|
|
bool first_redo;
|
|
|
|
};
|
|
|
|
|
2021-02-13 21:38:36 +01:00
|
|
|
class changeElementDataCommand : public ElementEditionCommand
|
|
|
|
{
|
2014-06-20 20:10:09 +00:00
|
|
|
public:
|
2021-02-13 21:38:36 +01:00
|
|
|
changeElementDataCommand(ElementScene *scene,
|
|
|
|
ElementData old_data,
|
|
|
|
ElementData new_data,
|
|
|
|
QUndoCommand *parent = nullptr);
|
|
|
|
~changeElementDataCommand() override {}
|
2014-06-20 20:10:09 +00:00
|
|
|
|
2021-02-13 21:38:36 +01:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2014-06-20 20:10:09 +00:00
|
|
|
|
|
|
|
private:
|
2021-02-13 21:38:36 +01:00
|
|
|
ElementData m_old,
|
|
|
|
m_new;
|
2014-06-20 20:10:09 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:38:39 +02:00
|
|
|
/**
|
|
|
|
@brief The RotateSelectionInESCommand class
|
|
|
|
Rotate the selected items in the element editor
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RotateElementsCommand : public ElementEditionCommand
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
RotateElementsCommand(ElementScene *scene, QUndoCommand *parent=nullptr);
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ElementScene *m_scene =nullptr;
|
|
|
|
QList<QGraphicsItem*> m_items;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-08-23 15:33:55 +00:00
|
|
|
#endif
|