mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
polygon editor : use QPropertyUndoCommand instead of ChangePartCommand
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4069 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -360,40 +360,6 @@ void ChangePartCommand::redo()
|
|||||||
ElementEditionCommand::redo();
|
ElementEditionCommand::redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Constructeur
|
|
||||||
@param p Polygone edite
|
|
||||||
@param o_points points avant le changement
|
|
||||||
@param n_points points apres le changement
|
|
||||||
@param parent QUndoCommand parent
|
|
||||||
*/
|
|
||||||
ChangePolygonPointsCommand::ChangePolygonPointsCommand(
|
|
||||||
PartPolygon *p,
|
|
||||||
const QVector<QPointF> &o_points,
|
|
||||||
const QVector<QPointF> &n_points,
|
|
||||||
QUndoCommand *parent
|
|
||||||
) :
|
|
||||||
ElementEditionCommand(QObject::tr("modification points polygone", "undo caption"), 0, 0, parent),
|
|
||||||
polygon(p),
|
|
||||||
old_points(o_points),
|
|
||||||
new_points(n_points)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destructeur
|
|
||||||
ChangePolygonPointsCommand::~ChangePolygonPointsCommand() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Annule le changement
|
|
||||||
void ChangePolygonPointsCommand::undo() {
|
|
||||||
polygon -> setPolygon(old_points);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Refait le changement
|
|
||||||
void ChangePolygonPointsCommand::redo() {
|
|
||||||
polygon -> setPolygon(new_points);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param element_scene Element edite
|
@param element_scene Element edite
|
||||||
|
|||||||
@@ -18,12 +18,10 @@
|
|||||||
#ifndef EDITOR_COMMANDS_H
|
#ifndef EDITOR_COMMANDS_H
|
||||||
#define EDITOR_COMMANDS_H
|
#define EDITOR_COMMANDS_H
|
||||||
#include "customelementpart.h"
|
#include "customelementpart.h"
|
||||||
#include "partpolygon.h"
|
|
||||||
#include "elementview.h"
|
#include "elementview.h"
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
#include "elementcontent.h"
|
#include "elementcontent.h"
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ElementEditionCommand class
|
* @brief The ElementEditionCommand class
|
||||||
@@ -201,32 +199,6 @@ class ChangePartCommand : public ElementEditionCommand
|
|||||||
QVariant m_new_value;
|
QVariant m_new_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
This command changes the points of a polygon when editing an electrical
|
|
||||||
element.
|
|
||||||
*/
|
|
||||||
class ChangePolygonPointsCommand : public ElementEditionCommand {
|
|
||||||
// constructors, destructor
|
|
||||||
public:
|
|
||||||
ChangePolygonPointsCommand(PartPolygon *, const QVector<QPointF> &, const QVector<QPointF> &, QUndoCommand * = 0);
|
|
||||||
virtual ~ChangePolygonPointsCommand();
|
|
||||||
private:
|
|
||||||
ChangePolygonPointsCommand(const ChangePolygonPointsCommand &);
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
virtual void undo();
|
|
||||||
virtual void redo();
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
/// Changed polygon
|
|
||||||
PartPolygon *polygon;
|
|
||||||
/// Former points
|
|
||||||
QVector<QPointF> old_points;
|
|
||||||
/// New points
|
|
||||||
QVector<QPointF> new_points;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This command changes the translated names of an electrical element.
|
This command changes the translated names of an electrical element.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ void PartPolygon::setPolygon(const QPolygonF &polygon)
|
|||||||
if (m_polygon == polygon) return;
|
if (m_polygon == polygon) return;
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_polygon = polygon;
|
m_polygon = polygon;
|
||||||
|
emit polygonChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,6 +240,14 @@ void PartPolygon::removeLastPoint()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartPolygon::setClosed(bool close)
|
||||||
|
{
|
||||||
|
if (m_closed == close) return;
|
||||||
|
prepareGeometryChange();
|
||||||
|
m_closed = close;
|
||||||
|
emit closedChange();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartPolygon::mousePressEvent
|
* @brief PartPolygon::mousePressEvent
|
||||||
* Handle mouse press event
|
* Handle mouse press event
|
||||||
@@ -274,6 +283,7 @@ void PartPolygon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
|
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_polygon.replace(m_handler_index, pos_);
|
m_polygon.replace(m_handler_index, pos_);
|
||||||
|
emit polygonChanged();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CustomElementGraphicPart::mouseMoveEvent(event);
|
CustomElementGraphicPart::mouseMoveEvent(event);
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ class PartPolygon : public CustomElementGraphicPart
|
|||||||
private:
|
private:
|
||||||
PartPolygon(const PartPolygon &);
|
PartPolygon(const PartPolygon &);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void closedChange();
|
||||||
|
void polygonChanged();
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1105 };
|
enum { Type = UserType + 1105 };
|
||||||
@@ -78,7 +82,7 @@ class PartPolygon : public CustomElementGraphicPart
|
|||||||
void removeLastPoint ();
|
void removeLastPoint ();
|
||||||
|
|
||||||
bool isClosed () const {return m_closed;}
|
bool isClosed () const {return m_closed;}
|
||||||
void setClosed (bool c) {m_closed = c;}
|
void setClosed (bool close);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include "polygoneditor.h"
|
#include "polygoneditor.h"
|
||||||
#include "partpolygon.h"
|
#include "partpolygon.h"
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
#include "editorcommands.h"
|
|
||||||
#include "qetmessagebox.h"
|
#include "qetmessagebox.h"
|
||||||
#include "styleeditor.h"
|
#include "styleeditor.h"
|
||||||
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -58,45 +58,40 @@ PolygonEditor::PolygonEditor(QETElementEditor *editor, PartPolygon *p, QWidget *
|
|||||||
PolygonEditor::~PolygonEditor() {
|
PolygonEditor::~PolygonEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Met a jour le polygone a partir des donnees du formulaire : points et etat ferme ou non
|
|
||||||
*/
|
|
||||||
void PolygonEditor::updatePolygon() {
|
|
||||||
updatePolygonPoints();
|
|
||||||
updatePolygonClosedState();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met a jour les points du polygone et cree un objet d'annulation
|
Met a jour les points du polygone et cree un objet d'annulation
|
||||||
*/
|
*/
|
||||||
void PolygonEditor::updatePolygonPoints() {
|
void PolygonEditor::updatePolygonPoints()
|
||||||
|
{
|
||||||
if (!part) return;
|
if (!part) return;
|
||||||
QVector<QPointF> points = getPointsFromTree();
|
QPolygonF points = getPointsFromTree();
|
||||||
if (points.count() < 2) {
|
if (points.count() < 2)
|
||||||
QET::QetMessageBox::warning(
|
{
|
||||||
this,
|
QET::QetMessageBox::warning(this, tr("Erreur", "message box title"), tr("Le polygone doit comporter au moins deux points.", "message box content"));
|
||||||
tr("Erreur", "message box title"),
|
|
||||||
tr("Le polygone doit comporter au moins deux points.", "message box content")
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
undoStack().push(new ChangePolygonPointsCommand(part, part -> polygon(), points));
|
|
||||||
|
if (points != part->polygon())
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "polygon", part->property("polygon"), points);
|
||||||
|
undo->setText(tr("Modifier un polygone"));
|
||||||
|
undoStack().push(undo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met a jour l'etat ferme ou non du polygone
|
Met a jour l'etat ferme ou non du polygone
|
||||||
*/
|
*/
|
||||||
void PolygonEditor::updatePolygonClosedState() {
|
void PolygonEditor::updatePolygonClosedState()
|
||||||
|
{
|
||||||
if (!part) return;
|
if (!part) return;
|
||||||
undoStack().push(
|
bool close = close_polygon.isChecked();
|
||||||
new ChangePartCommand(
|
if (close != part->isClosed())
|
||||||
tr("fermeture du polygone"),
|
{
|
||||||
part,
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "closed", part->property("closed"), close);
|
||||||
"closed",
|
undo->setText(tr("Modifier un polygone"));
|
||||||
QVariant(!close_polygon.isChecked()),
|
undoStack().push(undo);
|
||||||
QVariant(close_polygon.isChecked())
|
}
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,20 +121,35 @@ void PolygonEditor::updateForm() {
|
|||||||
@param new_part Nouvelle primitive a editer
|
@param new_part Nouvelle primitive a editer
|
||||||
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
||||||
*/
|
*/
|
||||||
bool PolygonEditor::setPart(CustomElementPart *new_part) {
|
bool PolygonEditor::setPart(CustomElementPart *new_part)
|
||||||
if (!new_part) {
|
{
|
||||||
|
if (!new_part)
|
||||||
|
{
|
||||||
|
if (part)
|
||||||
|
{
|
||||||
|
disconnect(part, &PartPolygon::polygonChanged, this, &PolygonEditor::updateForm);
|
||||||
|
disconnect(part, &PartPolygon::closedChange, this, &PolygonEditor::updateForm);
|
||||||
|
}
|
||||||
part = 0;
|
part = 0;
|
||||||
style_ -> setPart(0);
|
style_ -> setPart(0);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
if (PartPolygon *part_polygon = dynamic_cast<PartPolygon *>(new_part)) {
|
if (PartPolygon *part_polygon = dynamic_cast<PartPolygon *>(new_part))
|
||||||
|
{
|
||||||
|
if (part == part_polygon) return true;
|
||||||
|
if (part)
|
||||||
|
{
|
||||||
|
disconnect(part, &PartPolygon::polygonChanged, this, &PolygonEditor::updateForm);
|
||||||
|
disconnect(part, &PartPolygon::closedChange, this, &PolygonEditor::updateForm);
|
||||||
|
}
|
||||||
part = part_polygon;
|
part = part_polygon;
|
||||||
style_ -> setPart(part);
|
style_ -> setPart(part);
|
||||||
updateForm();
|
updateForm();
|
||||||
|
connect(part, &PartPolygon::polygonChanged, this, &PolygonEditor::updateForm);
|
||||||
|
connect(part, &PartPolygon::closedChange, this, &PolygonEditor::updateForm);
|
||||||
return(true);
|
return(true);
|
||||||
} else {
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ class PolygonEditor : public ElementItemEditor {
|
|||||||
QVector<QPointF> getPointsFromTree();
|
QVector<QPointF> getPointsFromTree();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updatePolygon();
|
|
||||||
void updatePolygonPoints();
|
void updatePolygonPoints();
|
||||||
void updatePolygonClosedState();
|
void updatePolygonClosedState();
|
||||||
void updateForm();
|
void updateForm();
|
||||||
|
|||||||
Reference in New Issue
Block a user