diff --git a/sources/conductor.cpp b/sources/conductor.cpp index ad4ef4098..b7b0f83d3 100644 --- a/sources/conductor.cpp +++ b/sources/conductor.cpp @@ -1275,7 +1275,7 @@ void Conductor::displayedTextChanged() { QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes); if (qmbreturn == QMessageBox::Yes){ ConductorAutoNumerotation can(this); - can.setText(text_item -> toPlainText()); + can.applyText(text_item -> toPlainText()); } } if (qmbreturn == 0 || qmbreturn == QMessageBox::No) { diff --git a/sources/conductorautonumerotation.cpp b/sources/conductorautonumerotation.cpp index 3af80a4a9..b11b9431f 100644 --- a/sources/conductorautonumerotation.cpp +++ b/sources/conductorautonumerotation.cpp @@ -12,8 +12,7 @@ ConductorAutoNumerotation::ConductorAutoNumerotation() : conductor_ (0), diagram_ (0), -strategy_ (0), -strategy_is_set (false) +strategy_ (0) {} /** @@ -24,11 +23,8 @@ ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) : conductor_ (c), diagram_ (c -> diagram()), conductor_list(c -> relatedPotentialConductors()), - strategy_ (0), - strategy_is_set (false) -{ - setNumStrategy(); -} + strategy_ (0) +{} /** *destructor @@ -44,7 +40,6 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) { conductor_ = c; diagram_ = c -> diagram(); conductor_list = c -> relatedPotentialConductors(); - setNumStrategy(); } /** @@ -52,35 +47,76 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) { * execute the automatic numerotation */ void ConductorAutoNumerotation::numerate() { - if (strategy_is_set) - strategy_ -> createNumerotation(); + if (!conductor_) return; + //conductor is on an existing potential + if (conductor_list.size() >= 1 ) { + QStringList strl; + foreach (const Conductor *cc, conductor_list) strl<<(cc->text()); + //the texts is identicals + if (eachIsEqual(strl)) { + ConductorProperties cp; + cp.text = strl.at(0); + conductor_ -> setProperties(cp); + conductor_ -> setText(strl.at(0)); + } + //the texts isn't identicals + else { + ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, conductor_list, conductor_ -> diagramEditor()); + connect(canw, SIGNAL(textIsSelected(QString)), + this, SLOT(applyText(QString))); + canw -> exec(); + } + } + //conductor create a new potential + else { + } } /** * @brief ConductorAutoNumerotation::setText * apply the text @t by the strategy */ -void ConductorAutoNumerotation::setText(QString t) { - if (strategy_is_set) - strategy_ -> applyText(t); +void ConductorAutoNumerotation::applyText(QString t) { + if (!conductor_) return; + if (conductor_list.empty()) { + //initialize the corresponding UndoCommand object + ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_); + ConductorProperties cp; + cp = conductor_ ->properties(); + ccpc -> setOldSettings(cp); + cp.text = t; + ccpc -> setNewSettings(cp); + diagram_ -> undoStack().push(ccpc); + conductor_ -> setProperties(cp); + conductor_ -> setText(t); + } + else { + QSet clist = conductor_list; + clist << conductor_; + QList old_properties, new_properties; + ConductorProperties cp; + + foreach (Conductor *c, clist) { + old_properties << c -> properties(); + cp = c -> properties(); + cp.text = t; + c -> setProperties(cp); + new_properties << c -> properties(); + c -> setText(t); + } + //initialize the corresponding UndoCommand object + ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(clist); + cscpc -> setOldSettings(old_properties); + cscpc -> setNewSettings(new_properties); + diagram_ -> undoStack().push(cscpc); + } } /** * @brief ConductorAutoNumerotation::setNumStrategy * apply the good strategy relative to the conductor */ -void ConductorAutoNumerotation::setNumStrategy() { - if (strategy_ != 0) - delete strategy_; - - if (conductor_list.size() >= 1) { - strategy_ = new SamePotential (conductor_); - strategy_is_set = true; - } - else if (conductor_list.size() == 0) { - strategy_is_set = false; - } -} +void ConductorAutoNumerotation::setNumStrategy() {} /** @@ -108,76 +144,6 @@ NumStrategy::NumStrategy (Conductor *c): NumStrategy::~NumStrategy() {} -/** - * @brief ConductorAutoNumerotationWidget::applyText - *apply the text @t on every conductors of @c_list and @conductor_ - */ -void NumStrategy::applyText(QString t) { - if (!c_list.empty()) { - QSet conductorslist = c_list; - conductorslist << conductor_; - QList old_properties, new_properties; - ConductorProperties cp; - - foreach (Conductor *c, conductorslist) { - old_properties << c -> properties(); - cp = c -> properties(); - cp.text = t; - c -> setProperties(cp); - new_properties << c -> properties(); - c -> setText(t); - } - //initialize the corresponding UndoCommand object - ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist); - cscpc -> setOldSettings(old_properties); - cscpc -> setNewSettings(new_properties); - diagram_ -> undoStack().push(cscpc); - } - else { - //initialize the corresponding UndoCommand object - ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_); - ConductorProperties cp; - cp = conductor_ ->properties(); - ccpc -> setOldSettings(cp); - cp.text = t; - ccpc -> setNewSettings(cp); - diagram_ -> undoStack().push(ccpc); - conductor_ -> setProperties(cp); - conductor_ -> setText(t); - } -} - - -/** - * Constructor - */ -SamePotential::SamePotential(Conductor *c): - NumStrategy(c) -{} - -/** - * @brief SamePotential::createNumerotation - *create the numerotation for the conductor @c connected on an existing potential - */ -void SamePotential::createNumerotation() { - QStringList strl; - - foreach (const Conductor *cc, c_list) strl<<(cc->text()); - //the texts is identicals - if (eachIsEqual(strl)) { - ConductorProperties cp; - cp.text = strl.at(0); - conductor_ -> setProperties(cp); - conductor_ -> setText(strl.at(0)); - } - //the texts isn't identicals - else { - ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, c_list, conductor_ -> diagramEditor()); - connect(canw, SIGNAL(textIsSelected(QString)), - this, SLOT(applyText(QString))); - canw -> exec(); - } -} /** * @return true if every text of qsl is identical, else false. diff --git a/sources/conductorautonumerotation.h b/sources/conductorautonumerotation.h index 15b0eb2b8..33136a9ba 100644 --- a/sources/conductorautonumerotation.h +++ b/sources/conductorautonumerotation.h @@ -7,8 +7,10 @@ class NumStrategy; -class ConductorAutoNumerotation +class ConductorAutoNumerotation: public QObject { + Q_OBJECT + public: //constructors & destructor ConductorAutoNumerotation (); @@ -18,8 +20,11 @@ class ConductorAutoNumerotation //methods void setConductor(Conductor *); void numerate(); - void setText(QString); void removeNum_ofDiagram(Diagram *); + + public slots: + void applyText(QString); + protected: //methods @@ -30,9 +35,6 @@ class ConductorAutoNumerotation Diagram *diagram_; QSet conductor_list; NumStrategy *strategy_; - - private: - bool strategy_is_set; }; @@ -45,9 +47,6 @@ class NumStrategy: public QObject virtual ~NumStrategy (); virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé - public slots: - void applyText(QString); - protected: Conductor *conductor_; QSet c_list; @@ -55,14 +54,6 @@ class NumStrategy: public QObject }; - -class SamePotential: public NumStrategy -{ - public: - SamePotential (Conductor *); - virtual void createNumerotation(); -}; - bool eachIsEqual (const QStringList &); #endif // CONDUCTORAUTONUMEROTATION_H