2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2014-01-29 18:37:45 +00:00
|
|
|
Copyright 2006-2014 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
|
|
|
|
#include "customelementpart.h"
|
2007-08-25 15:04:45 +00:00
|
|
|
#include "partpolygon.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "elementview.h"
|
2007-08-25 03:43:05 +00:00
|
|
|
#include "elementscene.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "elementcontent.h"
|
2007-08-23 15:33:55 +00:00
|
|
|
#include "qgimanager.h"
|
|
|
|
#include <QtGui>
|
2013-02-08 22:05:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
ElementEditionCommand is the base class for all commands classes involved in
|
|
|
|
the edition of an electrical element. It provides commonly required methods
|
|
|
|
and attributes, such as accessors to the modified scene and view.
|
|
|
|
*/
|
|
|
|
class ElementEditionCommand : public QUndoCommand {
|
|
|
|
// constructors, destructor
|
|
|
|
public:
|
|
|
|
ElementEditionCommand(ElementScene * = 0, ElementView * = 0, QUndoCommand * = 0);
|
|
|
|
ElementEditionCommand(const QString &, ElementScene * = 0, ElementView * = 0, QUndoCommand * = 0);
|
|
|
|
virtual ~ElementEditionCommand();
|
|
|
|
private:
|
|
|
|
ElementEditionCommand(const ElementEditionCommand &);
|
|
|
|
|
|
|
|
// methods
|
|
|
|
public:
|
|
|
|
ElementScene *elementScene() const;
|
|
|
|
void setElementScene(ElementScene *);
|
|
|
|
ElementView *elementView() const;
|
|
|
|
void setElementView(ElementView *);
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
protected:
|
|
|
|
/// Element editor/view/scene the command should take place on
|
|
|
|
ElementScene *editor_scene_;
|
|
|
|
ElementView *editor_view_;
|
|
|
|
};
|
|
|
|
|
2007-08-23 15:33:55 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command deletes one or several primitives/parts when editing an
|
|
|
|
electrical element.
|
2007-08-23 15:33:55 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class DeletePartsCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-08-23 15:33:55 +00:00
|
|
|
public:
|
2007-08-25 03:43:05 +00:00
|
|
|
DeletePartsCommand(ElementScene *, const QList<QGraphicsItem *>, QUndoCommand * = 0);
|
2007-08-23 15:33:55 +00:00
|
|
|
virtual ~DeletePartsCommand();
|
|
|
|
private:
|
|
|
|
DeletePartsCommand(const DeletePartsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2007-08-23 15:33:55 +00:00
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
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
|
|
|
/// Deleted primitives
|
2007-08-23 15:33:55 +00:00
|
|
|
QList<QGraphicsItem *> deleted_parts;
|
|
|
|
};
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command pastes primitives when editing an electrical element.
|
2009-04-03 19:30:25 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class PastePartsCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2009-04-03 19:30:25 +00:00
|
|
|
public:
|
|
|
|
PastePartsCommand(ElementView *, const ElementContent &, QUndoCommand * = 0);
|
|
|
|
virtual ~PastePartsCommand();
|
|
|
|
private:
|
|
|
|
PastePartsCommand(const PastePartsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2009-04-03 19:30:25 +00:00
|
|
|
public:
|
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
virtual void setOffset(int, const QPointF &, int, const QPointF &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2009-04-03 19:30:25 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Pasted content
|
2009-04-03 19:30:25 +00:00
|
|
|
ElementContent content_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Data required to undo a copy/paste with offset
|
2009-04-03 19:30:25 +00:00
|
|
|
int old_offset_paste_count_;
|
|
|
|
QPointF old_start_top_left_corner_;
|
|
|
|
int new_offset_paste_count_;
|
|
|
|
QPointF new_start_top_left_corner_;
|
|
|
|
bool uses_offset;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Prevent the first call to redo()
|
2009-04-03 19:30:25 +00:00
|
|
|
bool first_redo;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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:
|
|
|
|
CutPartsCommand(ElementScene *, const QList<QGraphicsItem *>, QUndoCommand * = 0);
|
|
|
|
virtual ~CutPartsCommand();
|
|
|
|
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:
|
2007-08-25 03:43:05 +00:00
|
|
|
MovePartsCommand(const QPointF &, ElementScene *, const QList<QGraphicsItem *>, QUndoCommand * = 0);
|
2007-08-23 15:33:55 +00:00
|
|
|
virtual ~MovePartsCommand();
|
|
|
|
private:
|
|
|
|
MovePartsCommand(const MovePartsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2007-08-23 15:33:55 +00:00
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command adds a primitive when editing an electrical element.
|
2007-08-23 15:33:55 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class AddPartCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-08-23 15:33:55 +00:00
|
|
|
public:
|
2007-08-25 03:43:05 +00:00
|
|
|
AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand * = 0);
|
2007-08-23 15:33:55 +00:00
|
|
|
virtual ~AddPartCommand();
|
|
|
|
private:
|
|
|
|
AddPartCommand(const AddPartCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2007-08-23 15:33:55 +00:00
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
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
|
|
|
/// Added primitive
|
2007-08-23 15:33:55 +00:00
|
|
|
QGraphicsItem *part;
|
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-08-25 03:43:05 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes a property of a primitive when editing an electrical
|
|
|
|
element.
|
2007-08-25 03:43:05 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class ChangePartCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-08-25 03:43:05 +00:00
|
|
|
public:
|
2014-05-29 13:46:04 +00:00
|
|
|
ChangePartCommand(const QString &, CustomElementPart *, const char *, const QVariant &, const QVariant &, QUndoCommand * = 0);
|
2007-08-25 03:43:05 +00:00
|
|
|
virtual ~ChangePartCommand();
|
|
|
|
private:
|
|
|
|
ChangePartCommand(const ChangePartCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2007-08-25 03:43:05 +00:00
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-08-25 03:43:05 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Changed primitive
|
2007-08-25 03:43:05 +00:00
|
|
|
CustomElementPart *cep;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Changed property
|
2014-05-29 13:46:04 +00:00
|
|
|
const char *property;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Former value
|
2007-08-25 03:43:05 +00:00
|
|
|
QVariant old_value;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// New value
|
2007-08-25 03:43:05 +00:00
|
|
|
QVariant new_value;
|
|
|
|
};
|
2007-08-25 15:04:45 +00:00
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This command changes the points of a polygon when editing an electrical
|
|
|
|
element.
|
2007-08-25 15:04:45 +00:00
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class ChangePolygonPointsCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-08-25 15:04:45 +00:00
|
|
|
public:
|
|
|
|
ChangePolygonPointsCommand(PartPolygon *, const QVector<QPointF> &, const QVector<QPointF> &, QUndoCommand * = 0);
|
|
|
|
virtual ~ChangePolygonPointsCommand();
|
|
|
|
private:
|
|
|
|
ChangePolygonPointsCommand(const ChangePolygonPointsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2007-08-25 15:04:45 +00:00
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
|
|
|
/// Changed polygon
|
2007-08-25 15:04:45 +00:00
|
|
|
PartPolygon *polygon;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Former points
|
2007-08-25 15:04:45 +00:00
|
|
|
QVector<QPointF> old_points;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// New points
|
2007-08-25 15:04:45 +00:00
|
|
|
QVector<QPointF> new_points;
|
|
|
|
};
|
2007-09-10 21:12:49 +00:00
|
|
|
|
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:
|
|
|
|
ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand * = 0);
|
|
|
|
virtual ~ChangeNamesCommand();
|
|
|
|
private:
|
|
|
|
ChangeNamesCommand(const ChangeNamesCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-09-26 17:14:09 +00:00
|
|
|
public:
|
2007-09-10 21:50:17 +00:00
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
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
|
|
|
*/
|
2013-02-08 22:05:08 +00:00
|
|
|
class ChangeZValueCommand : public ElementEditionCommand {
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-10-07 18:52:01 +00:00
|
|
|
public:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// List the various kind of changes for the zValue
|
2007-12-16 14:05:39 +00:00
|
|
|
enum Option {
|
2012-11-09 21:09:24 +00:00
|
|
|
BringForward, ///< Bring primitives to the foreground so they have the highest zValue
|
|
|
|
Raise, ///< Raise primitives one layer above their current one; zValues are incremented
|
|
|
|
Lower, ///< Send primitives one layer below their current one; zValues are decremented
|
|
|
|
SendBackward ///< Send primitives to the background so they have the lowest zValue
|
2007-12-16 14:05:39 +00:00
|
|
|
};
|
2007-10-07 18:52:01 +00:00
|
|
|
ChangeZValueCommand(ElementScene *, Option, QUndoCommand * = 0);
|
|
|
|
virtual ~ChangeZValueCommand();
|
|
|
|
private:
|
|
|
|
ChangeZValueCommand(const ChangeZValueCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-10-07 18:52:01 +00:00
|
|
|
public:
|
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
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
|
2007-10-07 18:52:01 +00:00
|
|
|
Option option;
|
|
|
|
};
|
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:
|
|
|
|
ChangeInformationsCommand(ElementScene *, const QString &, const QString &, QUndoCommand * = 0);
|
|
|
|
virtual ~ChangeInformationsCommand();
|
|
|
|
private:
|
|
|
|
ChangeInformationsCommand(const ChangeInformationsCommand &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2010-02-14 16:28:45 +00:00
|
|
|
public:
|
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
|
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:
|
|
|
|
ScalePartsCommand(ElementScene * = 0, QUndoCommand * = 0);
|
|
|
|
virtual ~ScalePartsCommand();
|
|
|
|
private:
|
|
|
|
ScalePartsCommand(const ScalePartsCommand &);
|
|
|
|
|
|
|
|
// methods
|
|
|
|
public:
|
|
|
|
virtual void undo();
|
|
|
|
virtual void redo();
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2007-08-23 15:33:55 +00:00
|
|
|
#endif
|