diff --git a/borderinset.h b/borderinset.h index 1c9c32178..9287d34a6 100644 --- a/borderinset.h +++ b/borderinset.h @@ -1,5 +1,6 @@ #ifndef BORDERINSET_H #define BORDERINSET_H +#include "insetproperties.h" #include #include #include @@ -63,6 +64,22 @@ class BorderInset : public QObject { void setTitle (const QString &title) { bi_title = title; } void setFolio (const QString &folio) { bi_folio = folio; } void setFileName (const QString &filename) { bi_filename = filename; } + InsetProperties exportInset() { + InsetProperties ip; + ip.author = bi_author; + ip.date = bi_date; + ip.title = bi_title; + ip.folio = bi_folio; + ip.filename = bi_filename; + return(ip); + } + void importInset(const InsetProperties &ip) { + bi_author = ip.author; + bi_date = ip.date; + bi_title = ip.title; + bi_folio = ip.folio; + bi_filename = ip.filename; + } // methodes d'acces en ecriture aux options void displayInset (bool di) { display_inset = di; } @@ -78,8 +95,8 @@ class BorderInset : public QObject { QString bi_author; QDate bi_date; QString bi_title; - QString bi_folio; // vraiment necessaire ce truc ? - QString bi_filename; // meme remarque + QString bi_folio; + QString bi_filename; // dimensions du cadre et du cartouche int nb_columns; diff --git a/diagramcommands.cpp b/diagramcommands.cpp index 1efb3d09d..40bda9651 100644 --- a/diagramcommands.cpp +++ b/diagramcommands.cpp @@ -387,3 +387,37 @@ void ChangeConducerCommand::redo() { if (first_redo) first_redo = false; else conducer -> setProfile(new_profile); } + +/** + Constructeur + @param d Schema dont on modifie le cartouche + @param old_ip Anciennes proprietes du cartouches + @param new_ip Nouvelles proprietes du cartouches + @param parent QUndoCommand parent +*/ +ChangeInsetCommand::ChangeInsetCommand( + Diagram *d, + const InsetProperties &old_ip, + const InsetProperties &new_ip, + QUndoCommand *parent +) : + QUndoCommand(QObject::tr("modifier le cartouche"), parent), + diagram(d), + old_inset(old_ip), + new_inset(new_ip) +{ +} + +/// Destructeur +ChangeInsetCommand::~ChangeInsetCommand() { +} + +/// Annule la modification de cartouche +void ChangeInsetCommand::undo() { + diagram -> border_and_inset.importInset(old_inset); +} + +/// Refait la modification de cartouche +void ChangeInsetCommand::redo() { + diagram -> border_and_inset.importInset(new_inset); +} diff --git a/diagramcommands.h b/diagramcommands.h index 593ba6ba8..bb8a782d8 100644 --- a/diagramcommands.h +++ b/diagramcommands.h @@ -234,4 +234,30 @@ class ChangeConducerCommand : public QUndoCommand { /// booleen pour ne pas executer le premier redo() bool first_redo; }; + +/** + Cette classe represente l'action de modifier les informations du cartouche d'un schema +*/ +class ChangeInsetCommand : public QUndoCommand { + // constructeurs, destructeur + public: + ChangeInsetCommand(Diagram *, const InsetProperties &, const InsetProperties &, QUndoCommand * = 0); + virtual ~ChangeInsetCommand(); + private: + ChangeInsetCommand(const ChangeInsetCommand &); + + // methodes + public: + virtual void undo(); + virtual void redo(); + + // attributs + private: + /// DiagramTextItem modifie + Diagram *diagram; + /// texte avant changement + InsetProperties old_inset; + /// texte apres changement + InsetProperties new_inset; +}; #endif diff --git a/diagramview.cpp b/diagramview.cpp index 1acf48758..fbc100931 100644 --- a/diagramview.cpp +++ b/diagramview.cpp @@ -459,21 +459,21 @@ void DiagramView::dialogPrint() { */ void DiagramView::dialogEditInfos() { // recupere le cartouche du schema - BorderInset *inset = &(scene -> border_and_inset); + InsetProperties inset = scene -> border_and_inset.exportInset(); // construit le dialogue QDialog popup; popup.setMinimumWidth(400); popup.setWindowTitle(tr("Cartouche du sch\351ma")); - QLineEdit *titre = new QLineEdit(inset -> title(), &popup); - QLineEdit *auteur = new QLineEdit(inset -> author(), &popup); - QDate date_diagram = QDate(inset -> date()); + QLineEdit *titre = new QLineEdit(inset.title, &popup); + QLineEdit *auteur = new QLineEdit(inset.author, &popup); + QDate date_diagram = QDate(inset.date); if (date_diagram.isNull() || !date_diagram.isValid()) date_diagram = QDate::currentDate(); QDateEdit *date = new QDateEdit(date_diagram, &popup); date -> setCalendarPopup(true); - QLineEdit *fichier = new QLineEdit(inset -> fileName(), &popup); - QLineEdit *folio = new QLineEdit(inset -> folio(), &popup); + QLineEdit *fichier = new QLineEdit(inset.filename, &popup); + QLineEdit *folio = new QLineEdit(inset.folio, &popup); QWidget bidon(&popup); QGridLayout layout_champs(&bidon); layout_champs.addWidget(new QLabel(tr("Titre : ")), 0, 0); @@ -496,12 +496,19 @@ void DiagramView::dialogEditInfos() { QVBoxLayout layout_v(&popup); layout_v.addWidget(&bidon); layout_v.addWidget(&boutons); + // si le dialogue est accepte if (popup.exec() == QDialog::Accepted) { - inset -> setTitle(titre -> text()); - inset -> setAuthor(auteur -> text()); - inset -> setDate(date -> date()); - inset -> setFileName(fichier -> text()); - inset -> setFolio(folio -> text()); + InsetProperties new_inset; + new_inset.title = titre -> text(); + new_inset.author = auteur -> text(); + new_inset.date = date -> date(); + new_inset.filename = fichier -> text(); + new_inset.folio = folio -> text(); + + // s'il y a des modifications + if (new_inset != inset) { + scene -> undoStack().push(new ChangeInsetCommand(scene, inset, new_inset)); + } } } diff --git a/insetproperties.h b/insetproperties.h new file mode 100644 index 000000000..3483039fd --- /dev/null +++ b/insetproperties.h @@ -0,0 +1,30 @@ +#ifndef INSET_PROPERTIES_H +#define INSET_PROPERTIES_H +#include +#include +class InsetProperties { + public: + InsetProperties() { + } + virtual ~InsetProperties() { + } + bool operator==(const InsetProperties &ip) { + return( + ip.title == title &&\ + ip.author == author &&\ + ip.date == date &&\ + ip.filename == filename &&\ + ip.folio == folio + ); + } + bool operator!=(const InsetProperties &ip) { + return(!(*this == ip)); + } + // attributs + QString title; + QString author; + QDate date; + QString filename; + QString folio; +}; +#endif diff --git a/qelectrotech.pro b/qelectrotech.pro index 4b52675be..ee51f280e 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -66,7 +66,8 @@ HEADERS += aboutqet.h \ editor/textfieldeditor.h \ diagramcommands.h \ diagramitem.h \ - diagramtextitem.h + diagramtextitem.h \ + insetproperties.h SOURCES += aboutqet.cpp \ borderinset.cpp \ conducer.cpp \