when change a propertie of conductor, ask for apply the change for each conductor of the same potential

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2634 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2013-11-21 21:34:49 +00:00
parent 8496b000d1
commit 73bf32a640
3 changed files with 44 additions and 22 deletions

View File

@@ -988,15 +988,26 @@ ChangeSeveralConductorsPropertiesCommand::~ChangeSeveralConductorsPropertiesComm
/// definit l'ancienne configuration /// definit l'ancienne configuration
void ChangeSeveralConductorsPropertiesCommand::setOldSettings(const QList<ConductorProperties> &properties) { void ChangeSeveralConductorsPropertiesCommand::setOldSettings(const QList<ConductorProperties> &properties) {
if (!old_settings_set) {
old_properties = properties; old_properties = properties;
old_settings_set = true; old_settings_set = true;
} }
}
/// definit la nouvelle configuration /// definit la nouvelle configuration
void ChangeSeveralConductorsPropertiesCommand::setNewSettings(const QList<ConductorProperties> &properties) { void ChangeSeveralConductorsPropertiesCommand::setNewSettings(const QList<ConductorProperties> &properties) {
if (!new_settings_set) {
new_properties = properties; new_properties = properties;
new_settings_set = true; 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 Annule les changements - Attention : les anciens et nouveaux parametres
@@ -1019,6 +1030,17 @@ void ChangeSeveralConductorsPropertiesCommand::undo() {
*/ */
void ChangeSeveralConductorsPropertiesCommand::redo() { void ChangeSeveralConductorsPropertiesCommand::redo() {
if (old_settings_set && new_settings_set) { 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; int i=0;
foreach(Conductor *c, conductors) { foreach(Conductor *c, conductors) {
c -> setProperties(new_properties.at(i)); c -> setProperties(new_properties.at(i));
@@ -1027,6 +1049,7 @@ void ChangeSeveralConductorsPropertiesCommand::redo() {
} }
} }
} }
}
/** /**
* @brief ImageResizerCommand::ImageResizerCommand Constructor * @brief ImageResizerCommand::ImageResizerCommand Constructor

View File

@@ -544,6 +544,7 @@ class ChangeSeveralConductorsPropertiesCommand : public QUndoCommand {
virtual void redo(); virtual void redo();
virtual void setOldSettings(const QList<ConductorProperties> &); virtual void setOldSettings(const QList<ConductorProperties> &);
virtual void setNewSettings(const QList<ConductorProperties> &); virtual void setNewSettings(const QList<ConductorProperties> &);
virtual void setNewSettings(const ConductorProperties &);
// attributes // attributes
private: private:
@@ -553,6 +554,8 @@ class ChangeSeveralConductorsPropertiesCommand : public QUndoCommand {
QList <ConductorProperties> old_properties; QList <ConductorProperties> old_properties;
/// properties after the change /// properties after the change
QList <ConductorProperties> new_properties; QList <ConductorProperties> new_properties;
/// single properties for each conductor
ConductorProperties single_new_properties;
/// track whether pre-change properties were set /// track whether pre-change properties were set
bool old_settings_set; bool old_settings_set;
/// track whether post-change properties were set /// track whether post-change properties were set

View File

@@ -1047,43 +1047,39 @@ void DiagramView::editConductor(Conductor *edited_conductor) {
if (conductor_dialog.exec() == QDialog::Accepted) { if (conductor_dialog.exec() == QDialog::Accepted) {
// recupere les nouvelles proprietes // recupere les nouvelles proprietes
ConductorProperties new_properties = cpw -> conductorProperties(); ConductorProperties new_properties = cpw -> conductorProperties();
if (new_properties != old_properties) { if (new_properties != old_properties) {
int qmbreturn=0; int qmbreturn=0;
//if conductor isn't alone at this potential and text is changed //if conductor isn't alone at this potential and is property is changed
//ask user to apply text on every conductors of this potential //ask user to apply text on every conductors of this potential
if ((edited_conductor -> relatedPotentialConductors().size() >= 1) && (old_properties.text != new_properties.text)){ if (edited_conductor -> relatedPotentialConductors().size() >= 1){
qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"), qmbreturn = QMessageBox::question(diagramEditor(), tr("Propri\351t\351 de conducteurs"),
tr("Voulez-vous appliquer le nouveau texte \n" tr("Voulez-vous appliquer les nouvelles propri\351t\351s \n"
"\340 l'ensemble des conducteurs de ce potentiel ?"), "\340 l'ensemble des conducteurs de ce potentiel ?"),
QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes); QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
if (qmbreturn == QMessageBox::Yes){ if (qmbreturn == QMessageBox::Yes){
QSet <Conductor *> conductorslist = edited_conductor -> relatedPotentialConductors(); QSet <Conductor *> conductorslist = edited_conductor -> relatedPotentialConductors();
conductorslist << edited_conductor; conductorslist << edited_conductor;
QList <ConductorProperties> old_properties_list, new_properties_list; QList <ConductorProperties> old_properties_list;
ConductorProperties cp;
foreach (Conductor *c, conductorslist) { foreach (Conductor *c, conductorslist) {
if (c == edited_conductor) { if (c == edited_conductor) {
old_properties_list << old_properties; old_properties_list << old_properties;
new_properties_list << new_properties;
} }
else { else {
old_properties_list << c -> properties(); old_properties_list << c -> properties();
cp = c -> properties(); c -> setProperties(new_properties);
cp.text = new_properties.text;
c -> setProperties(cp);
new_properties_list << c -> properties();
c -> setText(new_properties.text);
} }
} }
//initialize the corresponding UndoCommand object //initialize the corresponding UndoCommand object
ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist); ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
cscpc -> setOldSettings(old_properties_list); cscpc -> setOldSettings(old_properties_list);
cscpc -> setNewSettings(new_properties_list); cscpc -> setNewSettings(new_properties);
diagram() -> undoStack().push(cscpc); diagram() -> undoStack().push(cscpc);
} }
} }
if (qmbreturn == 0 || qmbreturn == QMessageBox::No) { if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
// initialise l'objet UndoCommand correspondant // initialise l'objet UndoCommand correspondant
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor); ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);