[qet] [2120] revamp class conductorautonumerotation

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2120
Author:   blacksun
Date:     2013-04-19 15:22:30 +0200 (Fri, 19 Apr 2013)
Log Message:
-----------
revamp class conductorautonumerotation

Modified Paths:
--------------
    trunk/sources/conductor.cpp
    trunk/sources/conductorautonumerotation.cpp
    trunk/sources/conductorautonumerotation.h

Modified: trunk/sources/conductor.cpp
===================================================================
--- trunk/sources/conductor.cpp	2013-04-19 12:28:08 UTC (rev 2119)
+++ trunk/sources/conductor.cpp	2013-04-19 13:22:30 UTC (rev 2120)
@@ -1275,7 +1275,7 @@
 											  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) {

Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp	2013-04-19 12:28:08 UTC (rev 2119)
+++ trunk/sources/conductorautonumerotation.cpp	2013-04-19 13:22:30 UTC (rev 2120)
@@ -12,8 +12,7 @@
 ConductorAutoNumerotation::ConductorAutoNumerotation() :
 conductor_ (0),
 diagram_ (0),
-strategy_ (0),
-strategy_is_set (false)
+strategy_ (0)
 {}
 
 /**
@@ -24,11 +23,8 @@
 	conductor_ (c),
 	diagram_ (c -> diagram()),
 	conductor_list(c -> relatedPotentialConductors()),
-	strategy_ (0),
-	strategy_is_set (false)
-{
-	setNumStrategy();
-}
+	strategy_ (0)
+{}
 
 /**
  *destructor
@@ -44,7 +40,6 @@
 	conductor_ = c;
 	diagram_ = c -> diagram();
 	conductor_list = c -> relatedPotentialConductors();
-	setNumStrategy();
 }
 
 /**
@@ -52,37 +47,78 @@
  * 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 <Conductor *> clist = conductor_list;
+		clist << conductor_;
+		QList <ConductorProperties> 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_;
+void ConductorAutoNumerotation::setNumStrategy() {}
 
-	if (conductor_list.size() >= 1) {
-		strategy_ = new SamePotential (conductor_);
-		strategy_is_set = true;
-	}
-	else if (conductor_list.size() == 0) {
-		strategy_is_set = false;
-	}
-}
 
-
 /**
  * @brief Set the default text to all conductors of the diagram
  * @param dg the diagram
@@ -108,78 +144,8 @@
 
 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 <Conductor *> conductorslist = c_list;
-		conductorslist << conductor_;
-		QList <ConductorProperties> 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.
  */
 bool eachIsEqual (const QStringList &qsl) {

Modified: trunk/sources/conductorautonumerotation.h
===================================================================
--- trunk/sources/conductorautonumerotation.h	2013-04-19 12:28:08 UTC (rev 2119)
+++ trunk/sources/conductorautonumerotation.h	2013-04-19 13:22:30 UTC (rev 2120)
@@ -7,8 +7,10 @@
 
 class NumStrategy;
 
-class ConductorAutoNumerotation
+class ConductorAutoNumerotation: public QObject
 {
+	Q_OBJECT
+
 	public:
 	//constructors & destructor
 	ConductorAutoNumerotation ();
@@ -18,8 +20,11 @@
 	//methods
 	void setConductor(Conductor *);
 	void numerate();
-	void setText(QString);
 	void removeNum_ofDiagram(Diagram *);
+
+	public slots:
+	void applyText(QString);
+
 	
 	protected:
 	//methods
@@ -30,9 +35,6 @@
 	Diagram *diagram_;
 	QSet <Conductor *> conductor_list;
 	NumStrategy *strategy_;
-
-	private:
-	bool strategy_is_set;
 };
 
 
@@ -45,9 +47,6 @@
 	virtual ~NumStrategy ();
 	virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé
 
-	public slots:
-	void applyText(QString);
-
 	protected:
 	Conductor *conductor_;
 	QSet <Conductor *> c_list;
@@ -55,14 +54,6 @@
 
 };
 
-
-class SamePotential: public NumStrategy
-{
-	public:
-	SamePotential (Conductor *);
-	virtual void createNumerotation();
-};
-
 bool eachIsEqual (const QStringList &);
 
 #endif // CONDUCTORAUTONUMEROTATION_H


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/