Use QPropertyUndoCommand instead of ChangeSeveralConductorsPropertiesCommand and ChangeConductorsPropertiesCommand.

Remove class ChangeSeveralConductorsPropertiesCommand and ChangeConductorsPropertiesCommand.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4092 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2015-08-09 12:06:31 +00:00
parent c801c3e0a5
commit ed75c57c1d
10 changed files with 87 additions and 288 deletions

View File

@ -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 @@ void ConductorAutoNumerotation::checkPotential(Conductor *conductor, QUndoComman
* @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);
}
/**

View File

@ -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 @@ class ConductorProperties {
void readStyle(const QString &);
QString writeStyle() const;
};
Q_DECLARE_METATYPE(ConductorProperties)
#endif

View File

@ -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 @@ void ChangeBorderCommand::redo() {
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++;
}
}
}
}

View File

@ -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 @@ class ChangeBorderCommand : public QUndoCommand {
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

View File

@ -43,6 +43,7 @@
#include "diagrampropertiesdialog.h"
#include "dveventinterface.h"
#include "diagrameventaddelement.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
Constructeur
@ -947,14 +948,14 @@ void DiagramView::editSelectedConductorColor() {
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 @@ void DiagramView::editConductorColor(Conductor *edited_conductor) {
#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);
}
}
}

View File

@ -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 @@ void Conductor::readProperties() {
text_item -> setVisible(properties_.m_show_text);
}
calculateTextItemPosition();
update();
}
/**
@ -1415,14 +1418,15 @@ void Conductor::displayedTextChanged() {
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);
}
}
}

View File

@ -19,6 +19,7 @@
#define CONDUCTOR_H
#include "conductorproperties.h"
#include <QGraphicsPathItem>
class ConductorProfile;
class ConductorSegmentProfile;
@ -34,12 +35,13 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
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:

View File

@ -38,6 +38,7 @@ class XmlElementsCollection;
class MoveElementsHandler;
class MoveTitleBlockTemplatesHandler;
class NumerotationContext;
class QUndoStack;
/**
This class represents a QET project. Typically saved as a .qet file, it

View File

@ -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 @@ ConductorPropertiesDialog::~ConductorPropertiesDialog()
* @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);
}
}

View File

@ -19,6 +19,7 @@
#include "potentialtextsdialog.h"
#include "ui_potentialtextsdialog.h"
#include <QSignalMapper>
#include <QRadioButton>
/**
* @brief PotentialTextsDialog::PotentialTextsDialog