mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Arc editor : use QPropertyUndoCommand instead of ChangePartCommand
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4066 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
#include "arceditor.h"
|
#include "arceditor.h"
|
||||||
#include "styleeditor.h"
|
#include "styleeditor.h"
|
||||||
#include "partarc.h"
|
#include "partarc.h"
|
||||||
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
#include "elementscene.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -27,7 +29,8 @@
|
|||||||
*/
|
*/
|
||||||
ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
|
ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
|
||||||
ElementItemEditor(editor, parent),
|
ElementItemEditor(editor, parent),
|
||||||
part(arc)
|
part(arc),
|
||||||
|
m_locked(false)
|
||||||
{
|
{
|
||||||
style_ = new StyleEditor(editor);
|
style_ = new StyleEditor(editor);
|
||||||
x = new QDoubleSpinBox();
|
x = new QDoubleSpinBox();
|
||||||
@@ -71,98 +74,147 @@ ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
ArcEditor::~ArcEditor() {
|
ArcEditor::~ArcEditor() {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Permet de specifier a cet editeur quelle primitive il doit editer. A noter
|
* @brief ArcEditor::setPart
|
||||||
qu'un editeur peut accepter ou refuser d'editer une primitive.
|
* Specifie to this editor the part to edit.
|
||||||
L'editeur d'arc acceptera d'editer la primitive new_part s'il s'agit d'un
|
* Note that an editor can accept or refuse to edit a part. This editor accept only partArc.
|
||||||
objet de la classe PartArc.
|
* @param new_part
|
||||||
@param new_part Nouvelle primitive a editer
|
* @return
|
||||||
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
*/
|
||||||
*/
|
bool ArcEditor::setPart(CustomElementPart *new_part)
|
||||||
bool ArcEditor::setPart(CustomElementPart *new_part) {
|
{
|
||||||
if (!new_part) {
|
if (!new_part)
|
||||||
|
{
|
||||||
|
if (part)
|
||||||
|
{
|
||||||
|
disconnect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
||||||
|
disconnect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
||||||
|
disconnect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
||||||
|
}
|
||||||
part = 0;
|
part = 0;
|
||||||
style_ -> setPart(0);
|
style_ -> setPart(0);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
if (PartArc *part_arc = dynamic_cast<PartArc *>(new_part)) {
|
|
||||||
|
if (PartArc *part_arc = dynamic_cast<PartArc *>(new_part))
|
||||||
|
{
|
||||||
|
if (part == part_arc) return true;
|
||||||
|
if (part)
|
||||||
|
{
|
||||||
|
disconnect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
||||||
|
disconnect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
||||||
|
disconnect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
||||||
|
}
|
||||||
part = part_arc;
|
part = part_arc;
|
||||||
style_ -> setPart(part);
|
style_ -> setPart(part);
|
||||||
updateForm();
|
updateForm();
|
||||||
|
connect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
||||||
|
connect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
||||||
|
connect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
||||||
return(true);
|
return(true);
|
||||||
} else {
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
* @brief ArcEditor::currentPart
|
||||||
*/
|
* @return the curent edited part, or 0 if there is no edited part
|
||||||
|
*/
|
||||||
CustomElementPart *ArcEditor::currentPart() const {
|
CustomElementPart *ArcEditor::currentPart() const {
|
||||||
return(part);
|
return(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met a jour l'arc a partir a partir des donnees du formulaire
|
* @brief ArcEditor::updateArcS
|
||||||
*/
|
* Update the start angle of the arc according to the edited value.
|
||||||
void ArcEditor::updateArc() {
|
*/
|
||||||
if (!part) return;
|
void ArcEditor::updateArcS()
|
||||||
part -> setProperty("centerX", x -> value());
|
{
|
||||||
part -> setProperty("centerY", y -> value());
|
if (m_locked) return;
|
||||||
part -> setProperty("diameter_h", h -> value());
|
m_locked = true;
|
||||||
part -> setProperty("diameter_v", v -> value());
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "startAngle", part->property("startAngle"), ((start_angle -> value() * -1) + 90) * 16);
|
||||||
part -> setProperty("startAngle", ((start_angle -> value() * -1) + 90) * 16);
|
undo->setText("Modifier l'angle de depart d'un arc");
|
||||||
part -> setProperty("spanAngle", angle -> value() * -16);
|
undo->enableAnimation();
|
||||||
|
elementScene()->undoStack().push(undo);
|
||||||
|
m_locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met a jour l'abscisse du centre de l'arc et cree un objet d'annulation
|
/**
|
||||||
void ArcEditor::updateArcX() { addChangePartCommand(tr("abscisse"), part, "centerX", x -> value()); }
|
* @brief ArcEditor::updateArcA
|
||||||
/// Met a jour l'ordonnee du centre de l'arc et cree un objet d'annulation
|
* Update the span angle of the arc according to the edited value.
|
||||||
void ArcEditor::updateArcY() { addChangePartCommand(tr("ordonnée"), part, "centerY", y -> value()); }
|
*/
|
||||||
/// Met a jour le diametre horizontal de l'arc et cree un objet d'annulation
|
void ArcEditor::updateArcA()
|
||||||
void ArcEditor::updateArcH() { addChangePartCommand(tr("diamètre horizontal"), part, "diameter_h", h -> value()); }
|
{
|
||||||
/// Met a jour le diametre vertical de l'arc et cree un objet d'annulation
|
if (m_locked) return;
|
||||||
void ArcEditor::updateArcV() { addChangePartCommand(tr("diamètre vertical"), part, "diameter_v", v -> value()); }
|
m_locked = true;
|
||||||
/// Met a jour l'angle de depart de l'arc et cree un objet d'annulation
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "spanAngle", part->property("spanAngle"), angle -> value() * -16);
|
||||||
void ArcEditor::updateArcS() { addChangePartCommand(tr("angle de départ"), part, "startAngle", ((start_angle -> value() * -1) + 90) * 16); }
|
undo->setText("Modifier l'angle d'un arc");
|
||||||
/// Met a jour l'etendue de l'arc et cree un objet d'annulation
|
undo->enableAnimation();
|
||||||
void ArcEditor::updateArcA() { addChangePartCommand(tr("angle"), part, "spanAngle", angle -> value() * -16); }
|
elementScene()->undoStack().push(undo);
|
||||||
|
m_locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met a jour le formulaire d'edition
|
* @brief ArcEditor::updateArcRect
|
||||||
*/
|
* Update the geometrie of the rect that define this arc according the the edited values
|
||||||
void ArcEditor::updateForm() {
|
*/
|
||||||
|
void ArcEditor::updateArcRect()
|
||||||
|
{
|
||||||
|
if (m_locked) return;
|
||||||
|
m_locked = true;
|
||||||
|
QPointF point = part->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2);
|
||||||
|
QRectF rect(point, QSizeF(h->value(), v->value()));
|
||||||
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "rect", part->property("rect"), rect);
|
||||||
|
undo->setText("Modifier un arc");
|
||||||
|
undo->enableAnimation();
|
||||||
|
elementScene()->undoStack().push(undo);
|
||||||
|
m_locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ArcEditor::updateForm
|
||||||
|
* Update the value of the widgets
|
||||||
|
*/
|
||||||
|
void ArcEditor::updateForm()
|
||||||
|
{
|
||||||
if (!part) return;
|
if (!part) return;
|
||||||
activeConnections(false);
|
activeConnections(false);
|
||||||
x->setValue(part->property("x").toReal());
|
QRectF rect = part->property("rect").toRectF();
|
||||||
y->setValue(part->property("y").toReal());
|
x->setValue(part->mapToScene(rect.topLeft()).x() + (rect.width()/2));
|
||||||
h->setValue(part->property("diameter_h").toReal());
|
y->setValue(part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
|
||||||
v->setValue(part->property("diameter_v").toReal());
|
h->setValue(rect.width());
|
||||||
|
v->setValue(rect.height());
|
||||||
start_angle -> setValue(((part->property("startAngle").toInt() / 16) - 90) * -1);
|
start_angle -> setValue(((part->property("startAngle").toInt() / 16) - 90) * -1);
|
||||||
angle -> setValue(part->property("spanAngle").toInt() / -16);
|
angle -> setValue(part->property("spanAngle").toInt() / -16);
|
||||||
activeConnections(true);
|
activeConnections(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Active ou desactive les connexionx signaux/slots entre les widgets internes.
|
* @brief ArcEditor::activeConnections
|
||||||
@param active true pour activer les connexions, false pour les desactiver
|
* Enable/disable connection between editor widget and slot editingFinished
|
||||||
*/
|
* True == enable | false == disable
|
||||||
void ArcEditor::activeConnections(bool active) {
|
* @param active
|
||||||
if (active) {
|
*/
|
||||||
connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcX()));
|
void ArcEditor::activeConnections(bool active)
|
||||||
connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcY()));
|
{
|
||||||
connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcH()));
|
if (active)
|
||||||
connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcV()));
|
{
|
||||||
|
connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
|
connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
|
connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
|
connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
||||||
connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
||||||
} else {
|
}
|
||||||
disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcX()));
|
else
|
||||||
disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcY()));
|
{
|
||||||
disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcH()));
|
disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcV()));
|
disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
|
disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
|
disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
||||||
disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
||||||
disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,45 +17,48 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef ARC_EDITOR_H
|
#ifndef ARC_EDITOR_H
|
||||||
#define ARC_EDITOR_H
|
#define ARC_EDITOR_H
|
||||||
#include <QtWidgets>
|
|
||||||
#include "elementitemeditor.h"
|
#include "elementitemeditor.h"
|
||||||
|
|
||||||
class PartArc;
|
class PartArc;
|
||||||
class StyleEditor;
|
class StyleEditor;
|
||||||
|
class QDoubleSpinBox;
|
||||||
|
class QSpinBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a widget to edit elliptical arcs within the element editor.
|
This class provides a widget to edit elliptical arcs within the element editor.
|
||||||
*/
|
*/
|
||||||
class ArcEditor : public ElementItemEditor {
|
class ArcEditor : public ElementItemEditor
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// constructors, destructor
|
|
||||||
public:
|
|
||||||
ArcEditor(QETElementEditor *, PartArc * = 0, QWidget * = 0);
|
|
||||||
virtual ~ArcEditor();
|
|
||||||
private:
|
|
||||||
ArcEditor(const ArcEditor &);
|
|
||||||
|
|
||||||
// attributes
|
// constructors, destructor
|
||||||
private:
|
|
||||||
PartArc *part;
|
|
||||||
StyleEditor *style_;
|
|
||||||
QDoubleSpinBox *x, *y, *h, *v;
|
|
||||||
QSpinBox *angle, *start_angle;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
public:
|
||||||
virtual bool setPart(CustomElementPart *);
|
ArcEditor(QETElementEditor *, PartArc * = 0, QWidget * = 0);
|
||||||
virtual CustomElementPart *currentPart() const;
|
virtual ~ArcEditor();
|
||||||
|
private:
|
||||||
|
ArcEditor(const ArcEditor &);
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
private:
|
||||||
|
PartArc *part;
|
||||||
|
StyleEditor *style_;
|
||||||
|
QDoubleSpinBox *x, *y, *h, *v;
|
||||||
|
QSpinBox *angle, *start_angle;
|
||||||
|
bool m_locked;
|
||||||
|
|
||||||
|
// methods
|
||||||
|
public:
|
||||||
|
virtual bool setPart(CustomElementPart *);
|
||||||
|
virtual CustomElementPart *currentPart() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateArc();
|
void updateArcS();
|
||||||
void updateArcX();
|
void updateArcA();
|
||||||
void updateArcY();
|
void updateArcRect();
|
||||||
void updateArcH();
|
void updateForm();
|
||||||
void updateArcV();
|
|
||||||
void updateArcS();
|
|
||||||
void updateArcA();
|
|
||||||
void updateForm();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void activeConnections(bool);
|
void activeConnections(bool);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,10 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef ELEMENT_ITEM_EDITOR_H
|
#ifndef ELEMENT_ITEM_EDITOR_H
|
||||||
#define ELEMENT_ITEM_EDITOR_H
|
#define ELEMENT_ITEM_EDITOR_H
|
||||||
#include <QtWidgets>
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
class QETElementEditor;
|
class QETElementEditor;
|
||||||
class ElementScene;
|
class ElementScene;
|
||||||
class CustomElementPart;
|
class CustomElementPart;
|
||||||
|
class QUndoStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This is the base class for primitives editors within the element editor. It
|
This is the base class for primitives editors within the element editor. It
|
||||||
provides methods to access the editor itself, the undo stack, the edition
|
provides methods to access the editor itself, the undo stack, the edition
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ void AbstractPartEllipse::setRect(const QRectF &rect)
|
|||||||
if (rect == m_rect) return;
|
if (rect == m_rect) return;
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_rect = rect;
|
m_rect = rect;
|
||||||
|
emit rectChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,8 +140,9 @@ bool AbstractPartEllipse::isUseless() const {
|
|||||||
void AbstractPartEllipse::setStartAngle(const int &start_angle)
|
void AbstractPartEllipse::setStartAngle(const int &start_angle)
|
||||||
{
|
{
|
||||||
if (m_start_angle == start_angle) return;
|
if (m_start_angle == start_angle) return;
|
||||||
|
prepareGeometryChange();
|
||||||
m_start_angle = start_angle;
|
m_start_angle = start_angle;
|
||||||
update();
|
emit startAngleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,8 +155,9 @@ void AbstractPartEllipse::setStartAngle(const int &start_angle)
|
|||||||
void AbstractPartEllipse::setSpanAngle(const int &span_angle)
|
void AbstractPartEllipse::setSpanAngle(const int &span_angle)
|
||||||
{
|
{
|
||||||
if (m_span_angle == span_angle) return;
|
if (m_span_angle == span_angle) return;
|
||||||
|
prepareGeometryChange();
|
||||||
m_span_angle = span_angle;
|
m_span_angle = span_angle;
|
||||||
update();
|
emit spanAngleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ class AbstractPartEllipse : public CustomElementGraphicPart
|
|||||||
private:
|
private:
|
||||||
AbstractPartEllipse(const AbstractPartEllipse &);
|
AbstractPartEllipse(const AbstractPartEllipse &);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void rectChanged();
|
||||||
|
void startAngleChanged();
|
||||||
|
void spanAngleChanged();
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
virtual void startUserTransformation (const QRectF &);
|
virtual void startUserTransformation (const QRectF &);
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class PartArc : public AbstractPartEllipse
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PartArc(const PartArc &);
|
PartArc(const PartArc &);
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1101 };
|
enum { Type = UserType + 1101 };
|
||||||
|
|||||||
@@ -17,9 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef POLYGON_EDITOR_H
|
#ifndef POLYGON_EDITOR_H
|
||||||
#define POLYGON_EDITOR_H
|
#define POLYGON_EDITOR_H
|
||||||
|
|
||||||
#include "elementitemeditor.h"
|
#include "elementitemeditor.h"
|
||||||
|
#include <QTreeWidget>
|
||||||
|
#include <QCheckBox>
|
||||||
|
|
||||||
class PartPolygon;
|
class PartPolygon;
|
||||||
class StyleEditor;
|
class StyleEditor;
|
||||||
|
class QTreeWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a widget to edit polygons within the element editor.
|
This class provides a widget to edit polygons within the element editor.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,10 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef RECTANGLE_EDITOR_H
|
#ifndef RECTANGLE_EDITOR_H
|
||||||
#define RECTANGLE_EDITOR_H
|
#define RECTANGLE_EDITOR_H
|
||||||
#include <QtWidgets>
|
|
||||||
#include "elementitemeditor.h"
|
#include "elementitemeditor.h"
|
||||||
|
|
||||||
class PartRectangle;
|
class PartRectangle;
|
||||||
class StyleEditor;
|
class StyleEditor;
|
||||||
|
class QDoubleSpinBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a widget to edit rectangles within the element editor.
|
This class provides a widget to edit rectangles within the element editor.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user