[qet] [4092] Use QPropertyUndoCommand instead of ChangeSeveralConductorsPropertiesCommand and ChangeConductorsPropertiesCommand. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4092
Author: blacksun
Date: 2015-08-09 14:06:31 +0200 (Sun, 09 Aug 2015)
Log Message:
-----------
Use QPropertyUndoCommand instead of ChangeSeveralConductorsPropertiesCommand and ChangeConductorsPropertiesCommand.
Remove class ChangeSeveralConductorsPropertiesCommand and ChangeConductorsPropertiesCommand.
Modified Paths:
--------------
trunk/sources/conductorautonumerotation.cpp
trunk/sources/conductorproperties.h
trunk/sources/diagramcommands.cpp
trunk/sources/diagramcommands.h
trunk/sources/diagramview.cpp
trunk/sources/qetgraphicsitem/conductor.cpp
trunk/sources/qetgraphicsitem/conductor.h
trunk/sources/qetproject.h
trunk/sources/ui/conductorpropertiesdialog.cpp
trunk/sources/ui/potentialtextsdialog.cpp
Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/conductorautonumerotation.cpp 2015-08-09 12:06:31 UTC (rev 4092)
@@ -16,13 +16,13 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "conductorautonumerotation.h"
-#include "diagramcommands.h"
#include "numerotationcontextcommands.h"
#include "qetdiagrameditor.h"
#include "conductor.h"
#include "diagram.h"
#include "potentialtextsdialog.h"
#include "qet.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
* @brief ConductorAutoNumerotation::ConductorAutoNumerotation
@@ -80,42 +80,34 @@
* @brief ConductorAutoNumerotation::applyText
* apply the text @t to @conductor_ and all conductors at the same potential
*/
-void ConductorAutoNumerotation::applyText(QString t) {
+void ConductorAutoNumerotation::applyText(QString t)
+{
if (!conductor_) return;
- if (conductor_list.empty())
- {
- //initialize the corresponding UndoCommand object
- ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_, m_parent_undo);
- ccpc -> setOldSettings (conductor_ -> properties());
- ConductorProperties cp = conductor_ -> properties();
- cp.text = t;
- ccpc -> setNewSettings(cp);
- if (!m_parent_undo)
- m_diagram -> undoStack().push(ccpc);
- }
- else
- {
- QList <Conductor *> clist = conductor_list.toList();
- clist << conductor_;
- QList <ConductorProperties> old_properties, new_properties;
- ConductorProperties cp;
+ QVariant old_value, new_value;
+ ConductorProperties cp = conductor_ -> properties();
+ old_value.setValue(cp);
+ cp.text = t;
+ new_value.setValue(cp);
- foreach (Conductor *c, clist)
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor_, "properties", old_value, new_value, m_parent_undo);
+ undo->setText(QObject::tr("Modifier les propriétés d'un conducteur", "undo caption"));
+
+ if (!conductor_list.isEmpty())
+ {
+ undo->setText(QObject::tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
+ foreach (Conductor *cond, conductor_list)
{
- old_properties << c -> properties();
- cp = c -> properties();
- cp.text = t;
- new_properties << cp;
+ ConductorProperties cp2 = cond -> properties();
+ old_value.setValue(cp2);
+ cp2.text = t;
+ new_value.setValue(cp2);
+ new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo);
}
-
- //initialize the corresponding UndoCommand object
- ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(clist, m_parent_undo);
- cscpc -> setOldSettings(old_properties);
- cscpc -> setNewSettings(new_properties);
- if (!m_parent_undo)
- m_diagram -> undoStack().push(cscpc);
}
+
+ if (!m_parent_undo)
+ m_diagram->undoStack().push(undo);
}
/**
Modified: trunk/sources/conductorproperties.h
===================================================================
--- trunk/sources/conductorproperties.h 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/conductorproperties.h 2015-08-09 12:06:31 UTC (rev 4092)
@@ -17,9 +17,12 @@
*/
#ifndef CONDUCTOR_PROPERTIES_H
#define CONDUCTOR_PROPERTIES_H
+
#include "qet.h"
-#include <QtWidgets>
-#include <QtXml>
+#include <QColor>
+
+class QPainter;
+
/**
This class represents the properties of a singleline conductor.
*/
@@ -109,4 +112,7 @@
void readStyle(const QString &);
QString writeStyle() const;
};
+
+Q_DECLARE_METATYPE(ConductorProperties)
+
#endif
Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/diagramcommands.cpp 2015-08-09 12:06:31 UTC (rev 4092)
@@ -26,7 +26,6 @@
#include "diagram.h"
#include "qetgraphicsitem/diagramtextitem.h"
#include "qetgraphicsitem/diagramimageitem.h"
-#include "conductorautonumerotation.h"
#include <QPropertyAnimation>
QString itemText(const QetGraphicsItem *item) {
@@ -810,140 +809,3 @@
diagram -> showMe();
diagram -> border_and_titleblock.importBorder(new_properties);
}
-
-/**
- Constructeur
- @param c Le conducteur dont on modifie les proprietes
- @param parent QUndoCommand parent
-*/
-ChangeConductorPropertiesCommand::ChangeConductorPropertiesCommand(Conductor *c, QUndoCommand *parent) :
- QUndoCommand(QObject::tr("modifier les propriétés d'un conducteur", "undo caption"), parent),
- conductor(c),
- old_settings_set(false),
- new_settings_set(false)
-{
-}
-
-/// Destructeur
-ChangeConductorPropertiesCommand::~ChangeConductorPropertiesCommand() {
-}
-
-/// definit l'ancienne configuration
-void ChangeConductorPropertiesCommand::setOldSettings(const ConductorProperties &properties) {
- old_properties = properties;
- old_settings_set = true;
-}
-
-/// definit la nouvelle configuration
-void ChangeConductorPropertiesCommand::setNewSettings(const ConductorProperties &properties) {
- new_properties = properties;
- new_settings_set = true;
-}
-
-/**
- Annule les changements - Attention : les anciens et nouveaux parametres
- doivent avoir ete definis a l'aide de setNewSettings et setOldSettings
-*/
-void ChangeConductorPropertiesCommand::undo() {
- if (conductor -> diagram()) conductor -> diagram() -> showMe();
- if (old_settings_set && new_settings_set) {
- conductor -> setProperties(old_properties);
- conductor -> update();
- }
-}
-
-/**
- Refait les changements - Attention : les anciens et nouveaux parametres
- doivent avoir ete definis a l'aide de setNewSettings et setOldSettings
-*/
-void ChangeConductorPropertiesCommand::redo() {
- if (conductor -> diagram()) conductor -> diagram() -> showMe();
- if (old_settings_set && new_settings_set) {
- conductor -> setProperties(new_properties);
- conductor -> update();
- }
-}
-
-/**
- Constructeur
- @param c La liste des conducteurs dont on modifie les proprietes
- @param parent QUndoCommand parent
-*/
-ChangeSeveralConductorsPropertiesCommand::ChangeSeveralConductorsPropertiesCommand(QList<Conductor *>c, QUndoCommand *parent) :
- QUndoCommand(QObject::tr("modifier les propriétés de plusieurs conducteurs", "undo caption"), parent),
- conductors(c),
- old_settings_set(false),
- new_settings_set(false)
-{
-}
-
-/// Destructeur
-ChangeSeveralConductorsPropertiesCommand::~ChangeSeveralConductorsPropertiesCommand() {
-}
-
-/// definit l'ancienne configuration
-void ChangeSeveralConductorsPropertiesCommand::setOldSettings(const QList<ConductorProperties> &properties) {
- if (!old_settings_set) {
- old_properties = properties;
- old_settings_set = true;
- }
-}
-
-/// definit la nouvelle configuration
-void ChangeSeveralConductorsPropertiesCommand::setNewSettings(const QList<ConductorProperties> &properties) {
- if (!new_settings_set) {
- new_properties = properties;
- new_settings_set = true;
- }
-}
-
-void ChangeSeveralConductorsPropertiesCommand::setNewSettings(const ConductorProperties &properties) {
- if (!new_settings_set) {
- single_new_properties = properties;
- new_settings_set = true;
- }
-}
-
-/**
- Annule les changements - Attention : les anciens et nouveaux parametres
- doivent avoir ete definis a l'aide de setNewSettings et setOldSettings
-*/
-void ChangeSeveralConductorsPropertiesCommand::undo() {
- if (conductors.first() -> diagram()) conductors.first() -> diagram();
- if (old_settings_set && new_settings_set) {
- int i=0;
- foreach(Conductor *c, conductors) {
- c -> setProperties(old_properties.at(i));
- c -> update();
- i++;
- }
- }
-}
-
-/**
- Refait les changements - Attention : les anciens et nouveaux parametres
- doivent avoir ete definis a l'aide de setNewSettings et setOldSettings
-*/
-void ChangeSeveralConductorsPropertiesCommand::redo() {
- if (conductors.first() -> diagram()) conductors.first() -> diagram();
- if (old_settings_set && new_settings_set) {
-
- //new propertie are the same for each conductor
- if (new_properties.isEmpty()) {
- foreach(Conductor *c, conductors) {
- c -> setProperties(single_new_properties);
- c -> update();
- }
- }
-
- //new propertie are different for each conductor
- else {
- int i=0;
- foreach(Conductor *c, conductors) {
- c -> setProperties(new_properties.at(i));
- c -> update();
- i++;
- }
- }
- }
-}
Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/diagramcommands.h 2015-08-09 12:06:31 UTC (rev 4092)
@@ -17,10 +17,9 @@
*/
#ifndef DIAGRAM_COMMANDS_H
#define DIAGRAM_COMMANDS_H
-#include <QtWidgets>
+
#include "borderproperties.h"
#include "qetgraphicsitem/conductor.h"
-#include "conductorproperties.h"
#include "diagramcontent.h"
#include "titleblockproperties.h"
#include "qet.h"
@@ -416,70 +415,4 @@
BorderProperties new_properties;
};
-/**
- This command changes the properties for a particular conductor.
-*/
-class ChangeConductorPropertiesCommand : public QUndoCommand {
- // constructors, destructor
- public:
- ChangeConductorPropertiesCommand(Conductor *, QUndoCommand * = 0);
- virtual ~ChangeConductorPropertiesCommand();
- private:
- ChangeConductorPropertiesCommand(const ChangeConductorPropertiesCommand &);
-
- // methods
- public:
- virtual void undo();
- virtual void redo();
- virtual void setOldSettings(const ConductorProperties &);
- virtual void setNewSettings(const ConductorProperties &);
-
- // attributes
- private:
- /// modified conductor
- Conductor *conductor;
- /// properties before the change
- ConductorProperties old_properties;
- /// properties after the change
- ConductorProperties new_properties;
- /// track whether pre-change properties were set
- bool old_settings_set;
- /// track whether post-change properties were set
- bool new_settings_set;
-};
-
-/**
- This command changes the properties for several conductors.
-*/
-class ChangeSeveralConductorsPropertiesCommand : public QUndoCommand {
- // constructors, destructor
- public:
- ChangeSeveralConductorsPropertiesCommand(QList<Conductor *>, QUndoCommand * = 0);
- virtual ~ChangeSeveralConductorsPropertiesCommand();
- private:
- ChangeSeveralConductorsPropertiesCommand(const ChangeSeveralConductorsPropertiesCommand &);
-
- // methods
- public:
- virtual void undo();
- virtual void redo();
- virtual void setOldSettings(const QList<ConductorProperties> &);
- virtual void setNewSettings(const QList<ConductorProperties> &);
- virtual void setNewSettings(const ConductorProperties &);
-
- // attributes
- private:
- /// modified conductor
- QList<Conductor *> conductors;
- /// properties before the change
- QList <ConductorProperties> old_properties;
- /// properties after the change
- QList <ConductorProperties> new_properties;
- /// single properties for each conductor
- ConductorProperties single_new_properties;
- /// track whether pre-change properties were set
- bool old_settings_set;
- /// track whether post-change properties were set
- bool new_settings_set;
-};
#endif
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/diagramview.cpp 2015-08-09 12:06:31 UTC (rev 4092)
@@ -43,6 +43,7 @@
#include "diagrampropertiesdialog.h"
#include "dveventinterface.h"
#include "diagrameventaddelement.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
Constructeur
@@ -947,14 +948,14 @@
Edit the color of the given conductor
@param edited_conductor Conductor we want to change the color
*/
-void DiagramView::editConductorColor(Conductor *edited_conductor) {
- if (scene -> isReadOnly()) return;
- if (!edited_conductor) return;
+void DiagramView::editConductorColor(Conductor *edited_conductor)
+{
+ if (scene -> isReadOnly() || !edited_conductor) return;
- // store the initial properties of the provided conductor
+ // store the initial properties of the provided conductor
ConductorProperties initial_properties = edited_conductor -> properties();
- // prepare a color dialog showing the initial conductor color
+ // prepare a color dialog showing the initial conductor color
QColorDialog *color_dialog = new QColorDialog(this);
color_dialog -> setWindowTitle(tr("Choisir la nouvelle couleur de ce conducteur"));
#ifdef Q_OS_MAC
@@ -962,18 +963,21 @@
#endif
color_dialog -> setCurrentColor(initial_properties.color);
- // asks the user what color he wishes to apply
- if (color_dialog -> exec() == QDialog::Accepted) {
+ // asks the user what color he wishes to apply
+ if (color_dialog -> exec() == QDialog::Accepted)
+ {
QColor new_color = color_dialog -> selectedColor();
- if (new_color != initial_properties.color) {
- // the user chose a different color
- ConductorProperties new_properties = initial_properties;
- new_properties.color = new_color;
-
- ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
- ccpc -> setOldSettings(initial_properties);
- ccpc -> setNewSettings(new_properties);
- diagram() -> undoStack().push(ccpc);
+ if (new_color != initial_properties.color)
+ {
+ // the user chose a different color
+ QVariant old_value, new_value;
+ old_value.setValue(initial_properties);
+ initial_properties.color = new_color;
+ new_value.setValue(initial_properties);
+
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(edited_conductor, "properties", old_value, new_value);
+ undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption"));
+ diagram() -> undoStack().push(undo);
}
}
}
Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/qetgraphicsitem/conductor.cpp 2015-08-09 12:06:31 UTC (rev 4092)
@@ -27,6 +27,8 @@
#include "terminal.h"
#include "conductorautonumerotation.h"
#include "conductorpropertiesdialog.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
+
#define PR(x) qDebug() << #x " = " << x;
bool Conductor::pen_and_brush_initialized = false;
@@ -1371,6 +1373,7 @@
text_item -> setVisible(properties_.m_show_text);
}
calculateTextItemPosition();
+ update();
}
/**
@@ -1415,14 +1418,15 @@
if (qmbreturn == 0 || qmbreturn == QMessageBox::No)
{
- // initialise l'objet UndoCommand correspondant
+ QVariant old_value, new_value;
+ old_value.setValue(properties_);
ConductorProperties new_properties(properties_);
new_properties.text = text_item -> toPlainText();
+ new_value.setValue(new_properties);
- ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(this);
- ccpc -> setOldSettings(properties_);
- ccpc -> setNewSettings(new_properties);
- my_diagram -> undoStack().push(ccpc);
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "properties", old_value, new_value);
+ undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption"));
+ my_diagram -> undoStack().push(undo);
}
}
}
Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/qetgraphicsitem/conductor.h 2015-08-09 12:06:31 UTC (rev 4092)
@@ -19,6 +19,7 @@
#define CONDUCTOR_H
#include "conductorproperties.h"
+#include <QGraphicsPathItem>
class ConductorProfile;
class ConductorSegmentProfile;
@@ -34,12 +35,13 @@
This class represents a conductor, i.e. a wire between two element
terminals.
*/
-class Conductor : public QObject, public QGraphicsPathItem {
-
+class Conductor : public QObject, public QGraphicsPathItem
+{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
+ Q_PROPERTY(ConductorProperties properties READ properties WRITE setProperties)
// constructors, destructor
public:
Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/qetproject.h 2015-08-09 12:06:31 UTC (rev 4092)
@@ -38,6 +38,7 @@
class MoveElementsHandler;
class MoveTitleBlockTemplatesHandler;
class NumerotationContext;
+class QUndoStack;
/**
This class represents a QET project. Typically saved as a .qet file, it
Modified: trunk/sources/ui/conductorpropertiesdialog.cpp
===================================================================
--- trunk/sources/ui/conductorpropertiesdialog.cpp 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/ui/conductorpropertiesdialog.cpp 2015-08-09 12:06:31 UTC (rev 4092)
@@ -18,11 +18,10 @@
#include "conductorpropertiesdialog.h"
#include "ui_conductorpropertiesdialog.h"
-
#include "conductor.h"
#include "conductorpropertieswidget.h"
-#include "diagramcommands.h"
#include "diagram.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
* @brief ConductorPropertiesDialog::ConductorPropertiesDialog
@@ -58,36 +57,31 @@
* @param conductor, conductor to edit propertie
* @param parent, parent widget
*/
-void ConductorPropertiesDialog::PropertiesDialog(Conductor *conductor, QWidget *parent) {
+void ConductorPropertiesDialog::PropertiesDialog(Conductor *conductor, QWidget *parent)
+{
ConductorPropertiesDialog cpd (conductor, parent);
- if (cpd.exec() == QDialog::Accepted && cpd.properties() != conductor->properties()) {
+ if (cpd.exec() == QDialog::Accepted && cpd.properties() != conductor->properties())
+ {
+ QVariant old_value, new_value;
+ old_value.setValue(conductor->properties());
+ new_value.setValue(cpd.properties());
- if (cpd.applyAll()) {
- QList <Conductor *> conductorslist = conductor -> relatedPotentialConductors().toList();
- conductorslist << conductor;
- QList <ConductorProperties> old_properties_list;
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value);
+ undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption"));
- foreach (Conductor *c, conductorslist) {
- if (c == conductor) {
- old_properties_list << conductor -> properties();
- } else {
- old_properties_list << c -> properties();
- c -> setProperties( cpd.properties() );
- }
+ //Make undo for all related potiential conductors
+ if (cpd.applyAll() && !conductor->relatedPotentialConductors().isEmpty())
+ {
+ undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
+ foreach (Conductor *cond, conductor->relatedPotentialConductors())
+ {
+ old_value.setValue(cond->properties());
+ new QPropertyUndoCommand (cond, "properties", old_value, new_value, undo);
}
- //initialize the corresponding UndoCommand object
- ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
- cscpc -> setOldSettings(old_properties_list);
- cscpc -> setNewSettings(cpd.properties());
- conductor -> diagram() -> undoStack().push(cscpc);
- } else {
- // initialize the corresponding UndoCommand object
- ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(conductor);
- ccpc -> setOldSettings(conductor -> properties());
- ccpc -> setNewSettings(cpd.properties());
- conductor -> diagram() -> undoStack().push(ccpc);
}
+
+ conductor->diagram()->undoStack().push(undo);
}
}
Modified: trunk/sources/ui/potentialtextsdialog.cpp
===================================================================
--- trunk/sources/ui/potentialtextsdialog.cpp 2015-08-08 13:06:21 UTC (rev 4091)
+++ trunk/sources/ui/potentialtextsdialog.cpp 2015-08-09 12:06:31 UTC (rev 4092)
@@ -19,6 +19,7 @@
#include "potentialtextsdialog.h"
#include "ui_potentialtextsdialog.h"
#include <QSignalMapper>
+#include <QRadioButton>
/**
* @brief PotentialTextsDialog::PotentialTextsDialog