[qet] [2142] revamp conductorautonumerotation and add autonumerotation class

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


Revision: 2142
Author:   blacksun
Date:     2013-05-03 19:35:22 +0200 (Fri, 03 May 2013)
Log Message:
-----------
revamp conductorautonumerotation and add autonumerotation class

Modified Paths:
--------------
    trunk/sources/conductorautonumerotation.cpp
    trunk/sources/conductorautonumerotation.h
    trunk/sources/ui/dialogconductorautonum.cpp

Added Paths:
-----------
    trunk/sources/autonumerotation.cpp
    trunk/sources/autonumerotation.h

Added: trunk/sources/autonumerotation.cpp
===================================================================
--- trunk/sources/autonumerotation.cpp	                        (rev 0)
+++ trunk/sources/autonumerotation.cpp	2013-05-03 17:35:22 UTC (rev 2142)
@@ -0,0 +1,5 @@
+#include "autonumerotation.h"
+
+AutoNumerotation::AutoNumerotation(Diagram *d):
+	diagram_ (d)
+{}

Added: trunk/sources/autonumerotation.h
===================================================================
--- trunk/sources/autonumerotation.h	                        (rev 0)
+++ trunk/sources/autonumerotation.h	2013-05-03 17:35:22 UTC (rev 2142)
@@ -0,0 +1,22 @@
+#ifndef AUTONUMEROTATION_H
+#define AUTONUMEROTATION_H
+
+#include "diagram.h"
+
+class AutoNumerotation: public QObject
+{
+	Q_OBJECT
+
+	public:
+	AutoNumerotation(Diagram *);
+	virtual void numerate() = 0;
+
+	public slots:
+	virtual void applyText(QString) = 0;
+
+	protected:
+	Diagram *diagram_;
+	NumerotationContext num_context;
+};
+
+#endif // AUTONUMEROTATION_H

Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp	2013-05-03 16:21:25 UTC (rev 2141)
+++ trunk/sources/conductorautonumerotation.cpp	2013-05-03 17:35:22 UTC (rev 2142)
@@ -1,56 +1,54 @@
-#include <QStringList>
+/*
+	Copyright 2006-2013 The QElectroTech team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #include "conductorautonumerotation.h"
 #include "conductorautonumerotationwidget.h"
-#include "qetdiagrameditor.h"
-#include "QGraphicsView"
 #include "diagramcommands.h"
-#include "qetapp.h"
+#include "numerotationcontextcommands.h"
 
 /**
- * Constructor
- */
-ConductorAutoNumerotation::ConductorAutoNumerotation() :
-conductor_ (0),
-diagram_ (0),
-strategy_ (0)
-{}
-
-/**
  *Constructor
  * @param c the conductor to apply automatic numerotation
  */
 ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) :
+	AutoNumerotation (c -> diagram()),
 	conductor_ (c),
-	diagram_ (c -> diagram()),
-	conductor_list(c -> relatedPotentialConductors()),
-	strategy_ (0)
-{}
+	conductor_list(c -> relatedPotentialConductors())
+{
+	num_context = diagram_ -> getNumerotation(Diagram::Conductors);
+}
 
 /**
  * Constructor
  * @param d a diagram to apply automatic numerotation
  */
 ConductorAutoNumerotation::ConductorAutoNumerotation(Diagram *d) :
-	conductor_ (0),
-	diagram_ (d),
-	strategy_ (0)
+	AutoNumerotation (d),
+	conductor_ (NULL)
 {}
 
 /**
- *destructor
- */
-ConductorAutoNumerotation::~ConductorAutoNumerotation() {
-	delete strategy_;
-}
-
-/**
  * @param c the conductor to apply automatic numerotation
  */
 void ConductorAutoNumerotation::setConductor(Conductor *c) {
 	conductor_ = c;
 	diagram_ = c -> diagram();
 	conductor_list = c -> relatedPotentialConductors();
-	if (strategy_) delete strategy_;
+	num_context = diagram_ -> getNumerotation(Diagram::Conductors);
 }
 
 /**
@@ -59,33 +57,30 @@
  */
 void ConductorAutoNumerotation::numerate() {
 	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();
-		}
+	if (conductor_list.size() >= 1 ) numeratePotential();
+	else numerateNewConductor();
+}
+
+/**
+ * @brief ConductorAutoNumerotation::numerateDiagram
+ * Numerate all conductor in diagram
+ */
+void ConductorAutoNumerotation::numerateDiagram() {
+	if (!diagram_) return;
+	//Get all potentials presents in diagram
+	QList <QSet <Conductor *> > potential_list = diagram_ -> potentials();
+	//Browse all potentials and set new numerotation
+	for (int i=0; i < potential_list.size(); ++i) {
+		setConductor (potential_list.at(i).toList().first());
+		NumerotationContextCommands ncc(diagram_, num_context);
+		applyText(ncc.toRepresentedString());
+		diagram_ -> setNumerotation(Diagram::Conductors, ncc.next());
 	}
-	//conductor create a new potential
-	else {
-	}
 }
 
 /**
- * @brief ConductorAutoNumerotation::setText
- * apply the text @t by the strategy
+ * @brief ConductorAutoNumerotation::applyText
+ * apply the text @t to @conductor_ and all conductors at the same potential
  */
 void ConductorAutoNumerotation::applyText(QString t) {
 	if (!conductor_) return;
@@ -119,17 +114,9 @@
 }
 
 /**
- * @brief ConductorAutoNumerotation::setNumStrategy
- * apply the good strategy relative to the conductor
- */
-void ConductorAutoNumerotation::setNumStrategy() {}
-
-
-/**
  * @brief Set the default text to all potentials of the diagram
- * @param dg the diagram
  */
-void ConductorAutoNumerotation::removeNum_ofDiagram() {
+void ConductorAutoNumerotation::removeNumOfDiagram() {
 	if (!diagram_) return;
 	//Get all potentials presents in diagram
 	QList <QSet <Conductor *> > potential_list = diagram_ -> potentials();
@@ -140,19 +127,40 @@
 	}
 }
 
+/**
+ * @brief ConductorAutoNumerotation::numeratePotential
+ * Numerate a conductor on an existing potential
+ */
+void ConductorAutoNumerotation::numeratePotential() {
+	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();
+	}
+}
 
 /**
- * Constructor
+ * @brief ConductorAutoNumerotation::numerateNewConductor
+ * create and apply a new numerotation to @conductor_
  */
-NumStrategy::NumStrategy (Conductor *c):
-	conductor_ (c),
-	c_list (c -> relatedPotentialConductors()),
-	diagram_ (c -> diagram())
-{}
+void ConductorAutoNumerotation::numerateNewConductor() {
+	if (!conductor_) return;
+	NumerotationContextCommands ncc (diagram_, num_context);
+	applyText(ncc.toRepresentedString());
+	diagram_-> setNumerotation(Diagram::Conductors, ncc.next());
+}
 
-NumStrategy::~NumStrategy() {}
-
-
 /**
  * @return true if every text of qsl is identical, else false.
  */

Modified: trunk/sources/conductorautonumerotation.h
===================================================================
--- trunk/sources/conductorautonumerotation.h	2013-05-03 16:21:25 UTC (rev 2141)
+++ trunk/sources/conductorautonumerotation.h	2013-05-03 17:35:22 UTC (rev 2142)
@@ -1,60 +1,53 @@
+/*
+	Copyright 2006-2013 The QElectroTech team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #ifndef CONDUCTORAUTONUMEROTATION_H
 #define CONDUCTORAUTONUMEROTATION_H
 
-#include <QObject>
 #include "conductor.h"
-#include "diagram.h"
+#include "numerotationcontext.h"
+#include "autonumerotation.h"
 
-class NumStrategy;
-
-class ConductorAutoNumerotation: public QObject
+class ConductorAutoNumerotation: public AutoNumerotation
 {
-	Q_OBJECT
-
 	public:
 	//constructors & destructor
-	ConductorAutoNumerotation ();
 	ConductorAutoNumerotation (Conductor *);
 	ConductorAutoNumerotation (Diagram *);
-	~ConductorAutoNumerotation();
 
 	//methods
 	void setConductor(Conductor *);
 	void numerate();
-	void removeNum_ofDiagram();
+	void numerateDiagram();
+	void removeNumOfDiagram();
 
 	public slots:
 	void applyText(QString);
 
-	
-	protected:
+	private:
 	//methods
-	void setNumStrategy ();
+	void numeratePotential ();
+	void numerateNewConductor ();
 
 	//attributes
 	Conductor *conductor_;
-	Diagram *diagram_;
 	QSet <Conductor *> conductor_list;
-	NumStrategy *strategy_;
 };
 
-
-class NumStrategy: public QObject
-{
-	Q_OBJECT
-
-	public:
-	NumStrategy (Conductor *);
-	virtual ~NumStrategy ();
-	virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé
-
-	protected:
-	Conductor *conductor_;
-	QSet <Conductor *> c_list;
-	Diagram *diagram_;
-
-};
-
 bool eachIsEqual (const QStringList &);
 
 #endif // CONDUCTORAUTONUMEROTATION_H

Modified: trunk/sources/ui/dialogconductorautonum.cpp
===================================================================
--- trunk/sources/ui/dialogconductorautonum.cpp	2013-05-03 16:21:25 UTC (rev 2141)
+++ trunk/sources/ui/dialogconductorautonum.cpp	2013-05-03 17:35:22 UTC (rev 2142)
@@ -68,7 +68,7 @@
 	if( answer ==  QMessageBox::Yes) {
 		for(int i=0; i<listDiag.count(); i++){
 			ConductorAutoNumerotation can(listDiag.at(i));
-			can.removeNum_ofDiagram();
+			can.removeNumOfDiagram();
 		}
 	}
 }


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