[qet] [2096] add dialog when user change a conductor text on a multi conductor potential and revamp class

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


Revision: 2096
Author:   blacksun
Date:     2013-04-10 11:31:51 +0200 (Wed, 10 Apr 2013)
Log Message:
-----------
add dialog when user change a conductor text on a multi conductor potential and revamp class  

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

Modified: trunk/sources/conductor.cpp
===================================================================
--- trunk/sources/conductor.cpp	2013-04-09 11:26:53 UTC (rev 2095)
+++ trunk/sources/conductor.cpp	2013-04-10 09:31:51 UTC (rev 2096)
@@ -1264,15 +1264,30 @@
 	// verifie que le texte a reellement change
 	if (text_item -> toPlainText() == properties_.text) return;
 	
-	// initialise l'objet UndoCommand correspondant
 	if (Diagram *my_diagram = diagram()) {
-		ConductorProperties new_properties(properties_);
-		new_properties.text = text_item -> toPlainText();
-		
-		ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(this);
-		ccpc -> setOldSettings(properties_);
-		ccpc -> setNewSettings(new_properties);
-		my_diagram -> undoStack().push(ccpc);
+		int qmbreturn=0;
+		//if conductor isn't alone at this potential
+		//ask user to apply text on every conductors of this potential
+		if (relatedPotentialConductors().size() >= 1){
+			qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"),
+											  tr("Voulez-vous appliquer le nouveau texte \n"
+												 "\340 l'ensemble des conducteurs de ce potentiel ?"),
+											  QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
+			if (qmbreturn == QMessageBox::Yes){
+				ConductorAutoNumerotation can(this);
+				can.setText(text_item -> toPlainText());
+			}
+		}
+		if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
+			// initialise l'objet UndoCommand correspondant
+			ConductorProperties new_properties(properties_);
+			new_properties.text = text_item -> toPlainText();
+
+			ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(this);
+			ccpc -> setOldSettings(properties_);
+			ccpc -> setNewSettings(new_properties);
+			my_diagram -> undoStack().push(ccpc);
+		}
 	}
 }
 

Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp	2013-04-09 11:26:53 UTC (rev 2095)
+++ trunk/sources/conductorautonumerotation.cpp	2013-04-10 09:31:51 UTC (rev 2096)
@@ -1,9 +1,9 @@
 #include <QStringList>
 #include "conductorautonumerotation.h"
 #include "conductorautonumerotationwidget.h"
-#include "diagram.h"
 #include "qetdiagrameditor.h"
 #include "QGraphicsView"
+#include "diagramcommands.h"
 
 /**
  * Constructor
@@ -11,19 +11,23 @@
 ConductorAutoNumerotation::ConductorAutoNumerotation() :
 conductor_ (0),
 diagram_ (0),
-strategy_(0)
+strategy_ (0),
+strategy_is_set (false)
 {}
 
 /**
  *Constructor
- * @param c le conducteur a appliquer une numerotation
+ * @param c the conductor to apply automatic numerotation
  */
 ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) :
 	conductor_ (c),
 	diagram_ (c -> diagram()),
 	conductor_list(c -> relatedPotentialConductors()),
-	strategy_(0)
-{}
+	strategy_ (0),
+	strategy_is_set (false)
+{
+	setNumStrategy();
+}
 
 /**
  *destructor
@@ -33,69 +37,136 @@
 }
 
 /**
- * @param c le conducteur a appliquer une numerotation
+ * @param c the conductor to apply automatic numerotation
  */
 void ConductorAutoNumerotation::setConductor(Conductor *c) {
 	conductor_ = c;
 	diagram_ = c -> diagram();
-	strategy_ = 0;
 	conductor_list = c -> relatedPotentialConductors();
+	setNumStrategy();
 }
 
 /**
  * @brief ConductorAutoNumerotation::numerate
- *execute la numerotation automatique du conducteur
+ * execute the automatic numerotation
  */
 void ConductorAutoNumerotation::numerate() {
-	if (conductor_ == 0) return;
-	//ce conducteur est sur un potentiel existant
-	if (conductor_list.size() >= 1) {
-		setNumStrategy(new SamePotential);
-		strategy_ -> createNumerotation(conductor_, diagram_);
-	}
-	//ce conducteur est le premier d'un nouveau potentiel
-	else if (conductor_list.size() == 0) {
-	}
+	if (strategy_is_set)
+		strategy_ -> createNumerotation();
 }
 
 /**
+ * @brief ConductorAutoNumerotation::setText
+ * apply the text @t by the strategy
+ */
+void ConductorAutoNumerotation::setText(QString t) {
+	if (strategy_is_set)
+		strategy_ -> applyText(t);
+}
+
+/**
  * @brief ConductorAutoNumerotation::setNumStrategy
- *applique la strategy adéquate à la situation
- * @param strategy la class de la strategy à appliquer
+ * apply the good strategy relative to the conductor
  */
-void ConductorAutoNumerotation::setNumStrategy(NumStrategy *strategy) {
+void ConductorAutoNumerotation::setNumStrategy() {
 	if (strategy_ != 0)
 		delete strategy_;
-	strategy_ = strategy;
+
+	if (conductor_list.size() >= 1) {
+		strategy_ = new SamePotential (conductor_);
+		strategy_is_set = true;
+	}
+	else if (conductor_list.size() == 0) {
+		strategy_is_set = false;
+	}
 }
 
-NumStrategy::NumStrategy () {}
+
+/**
+ * Constructor
+ */
+NumStrategy::NumStrategy (Conductor *c):
+	conductor_ (c),
+	c_list (c -> relatedPotentialConductors()),
+	diagram_ (c -> diagram())
+{}
+
 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
- *crée la numerotation pour le conducteur @c connecté sur un potentiel deja existant
+ *create the numerotation for the conductor @c connected on an existing potential
  */
-void SamePotential::createNumerotation(Conductor *c, Diagram *d) {
-	QSet <Conductor *> cl;
+void SamePotential::createNumerotation() {
 	QStringList strl;
 
-	cl = c -> relatedPotentialConductors();
-	foreach (const Conductor *cc, cl) strl<<(cc->text());
-	//tout les textes sont identique
+	foreach (const Conductor *cc, c_list) strl<<(cc->text());
+	//the texts is identicals
 	if (eachIsEqual(strl)) {
 		ConductorProperties cp;
 		cp.text = strl.at(0);
-		c -> setProperties(cp);
-		c -> setText(strl.at(0));
+		conductor_ -> setProperties(cp);
+		conductor_ -> setText(strl.at(0));
 	}
-	//les textes ne sont pas identique
+	//the texts isn't identicals
 	else {
-		ConductorAutoNumerotationWidget canw (c, cl, c -> diagramEditor());
-		canw.exec();
+		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) {
 	foreach (const QString t, qsl) {
 		if (qsl.at(0) != t) return false;

Modified: trunk/sources/conductorautonumerotation.h
===================================================================
--- trunk/sources/conductorautonumerotation.h	2013-04-09 11:26:53 UTC (rev 2095)
+++ trunk/sources/conductorautonumerotation.h	2013-04-10 09:31:51 UTC (rev 2096)
@@ -1,7 +1,9 @@
 #ifndef CONDUCTORAUTONUMEROTATION_H
 #define CONDUCTORAUTONUMEROTATION_H
 
-#include <conductor.h>
+#include <QObject>
+#include "conductor.h"
+#include "diagram.h"
 
 class NumStrategy;
 
@@ -16,32 +18,48 @@
 	//methods
 	void setConductor(Conductor *);
 	void numerate();
+	void setText(QString);
 
 	protected:
 	//methods
-	void setNumStrategy (NumStrategy *);
+	void setNumStrategy ();
 
 	//attributes
 	Conductor *conductor_;
 	Diagram *diagram_;
 	QSet <Conductor *> conductor_list;
 	NumStrategy *strategy_;
+
+	private:
+	bool strategy_is_set;
 };
 
 
-class NumStrategy
+class NumStrategy: public QObject
 {
+	Q_OBJECT
+
 	public:
-	NumStrategy ();
+	NumStrategy (Conductor *);
 	virtual ~NumStrategy ();
-	virtual void createNumerotation(Conductor *, Diagram *) = 0; //cree la numerotation en fonction de la strategie utilisé
+	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;
+	Diagram *diagram_;
+
 };
 
 
 class SamePotential: public NumStrategy
 {
-	virtual void createNumerotation(Conductor *, Diagram *);
+	public:
+	SamePotential (Conductor *);
+	virtual void createNumerotation();
 };
 
 bool eachIsEqual (const QStringList &);

Modified: trunk/sources/conductorautonumerotationwidget.cpp
===================================================================
--- trunk/sources/conductorautonumerotationwidget.cpp	2013-04-09 11:26:53 UTC (rev 2095)
+++ trunk/sources/conductorautonumerotationwidget.cpp	2013-04-10 09:31:51 UTC (rev 2096)
@@ -1,8 +1,8 @@
 #include "conductorautonumerotationwidget.h"
-#include "conductorproperties.h"
-#include "diagramcommands.h"
-#include "diagram.h"
 
+/**
+ * constructor
+ */
 ConductorAutoNumerotationWidget::ConductorAutoNumerotationWidget(Conductor *c, QSet<Conductor *> cl, QWidget *parent) :
 	QDialog (parent),
 	conductor_(c),
@@ -15,6 +15,9 @@
 	buildInterface();
 }
 
+/**
+ * @brief ConductorAutoNumerotationWidget::buildInterface
+ */
 void ConductorAutoNumerotationWidget::buildInterface() {
 	QVBoxLayout *mainlayout = new QVBoxLayout;
 	QGroupBox *potential_groupbox = new QGroupBox(tr("Textes de potentiel"), this);
@@ -96,31 +99,6 @@
 }
 
 /**
- * @brief ConductorAutoNumerotationWidget::applyText
- *applique le texte selectionne @text_ a tout les conducteur de @c_list et a @conducteur_
- */
-void ConductorAutoNumerotationWidget::applyText() {
-	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 = text_;
-		c -> setProperties(cp);
-		new_properties << c -> properties();
-		c -> setText(text_);
-	}
-	// initialise l'objet UndoCommand correspondant
-	ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
-	cscpc -> setOldSettings(old_properties);
-	cscpc -> setNewSettings(new_properties);
-	diagram_ -> undoStack().push(cscpc);
-}
-
-/**
  * @brief ConductorAutoNumerotationWidget::setText
  * enregistre le texte @t passé en parametre
  */
@@ -134,10 +112,9 @@
  */
 void ConductorAutoNumerotationWidget::accept() {
 	if (text_field -> isEnabled()) {
-		text_ = text_field -> text();
-		applyText();
+		emit textIsSelected(text_field -> text());
 		}
 	else
-		applyText();
+		emit textIsSelected(text_);
 	close();
 }

Modified: trunk/sources/conductorautonumerotationwidget.h
===================================================================
--- trunk/sources/conductorautonumerotationwidget.h	2013-04-09 11:26:53 UTC (rev 2095)
+++ trunk/sources/conductorautonumerotationwidget.h	2013-04-10 09:31:51 UTC (rev 2096)
@@ -20,11 +20,13 @@
 	void setText (QString);
 	void accept();
 
+	signals:
+	void textIsSelected (QString);
+
 	private:
 	//methods
 	void buildInterface();
 	QVBoxLayout* buildRadioList();
-	void applyText();
 
 	//attributes
 	Conductor *conductor_;

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2013-04-09 11:26:53 UTC (rev 2095)
+++ trunk/sources/diagramview.cpp	2013-04-10 09:31:51 UTC (rev 2096)
@@ -37,8 +37,9 @@
 #include "qeticons.h"
 #include "qetmessagebox.h"
 #include "qtextorientationspinboxwidget.h"
+#include "htmleditor/htmleditor.h"
+#include "conductorautonumerotation.h"
 
-
 /**
 	Constructeur
 	@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
@@ -409,8 +410,9 @@
 }
 
 /**
-	Manage the events click mouse :
-	 *  click to add an independent text field
+	Gere les clics et plus particulierement :
+	 *  le clic du milieu (= coller pour X11)
+	 *  le clic pour ajouter un champ de texte independant
 */
 void DiagramView::mousePressEvent(QMouseEvent *e) {
 	if (fresh_focus_in_) {
@@ -418,40 +420,33 @@
 		fresh_focus_in_ = false;
 	}
 	if (isInteractive() && !scene -> isReadOnly()) {
-		if (is_adding_text && e -> buttons() == Qt::LeftButton) {
-			addDiagramTextAtPos(mapToScene(e -> pos()));
-			is_adding_text = false;
+		if (e -> buttons() == Qt::MidButton) {
+			paste(mapToScene(e -> pos()), QClipboard::Selection);
+		} else {
+			if (is_adding_text && e -> buttons() == Qt::LeftButton) {
+				addDiagramTextAtPos(mapToScene(e -> pos()));
+				is_adding_text = false;
+			}
 		}
 	}
 	QGraphicsView::mousePressEvent(e);
 }
 
 /**
-	Manage wheel event of mouse
-	@param e QWheelEvent
+	Gere les actions liees a la rollette de la souris
+	@param e QWheelEvent decrivant l'evenement rollette
 */
 void DiagramView::wheelEvent(QWheelEvent *e) {
-	//Zoom and scrolling
-	if (e->buttons() != Qt::MidButton) {
-		if (!(e -> modifiers() & Qt::ControlModifier)) {
-			if (e -> delta() > 0)	zoomIn();
-			else					zoomOut();
+	// si la touche Ctrl est enfoncee, on zoome / dezoome
+	if (e -> modifiers() & Qt::ControlModifier) {
+		if (e -> delta() > 0) {
+			zoomIn();
+		} else {
+			zoomOut();
 		}
-		else {
-			QAbstractScrollArea::wheelEvent(e);
-		}
+	} else {
+		QAbstractScrollArea::wheelEvent(e);
 	}
-	// Or select visualisation or selection mode
-	else{
-		if (!is_moving_view_) {
-			setVisualisationMode();
-			is_moving_view_ = true;
-		}
-		else{
-			setSelectionMode();
-			is_moving_view_ = false;
-		}
-	}
 }
 
 /**
@@ -716,7 +711,7 @@
 }
 
 /**
-	Enables or disables the drawing grid according to the amount of pixels display
+	Active ou desactive le dessin de grille selon la quantite de pixels affichee
 */
 void DiagramView::adjustGridToZoom() {
 	QRectF viewed_scene = viewedSceneRect();
@@ -982,13 +977,27 @@
 	if (conductor_dialog.exec() == QDialog::Accepted) {
 		// recupere les nouvelles proprietes
 		ConductorProperties new_properties = cpw -> conductorProperties();
-		
 		if (new_properties != old_properties) {
-			// initialise l'objet UndoCommand correspondant
-			ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
-			ccpc -> setOldSettings(old_properties);
-			ccpc -> setNewSettings(new_properties);
-			diagram() -> undoStack().push(ccpc);
+			int qmbreturn=0;
+			//if conductor isn't alone at this potential
+			//ask user to apply text on every conductors of this potential
+			if (edited_conductor -> relatedPotentialConductors().size() >= 1){
+				qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"),
+												  tr("Voulez-vous appliquer le nouveau texte \n"
+													 "\340 l'ensemble des conducteurs de ce potentiel ?"),
+												  QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
+				if (qmbreturn == QMessageBox::Yes){
+					ConductorAutoNumerotation can(edited_conductor);
+					can.setText(new_properties.text);
+				}
+			}
+			if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
+				// initialise l'objet UndoCommand correspondant
+				ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
+				ccpc -> setOldSettings(old_properties);
+				ccpc -> setNewSettings(new_properties);
+				diagram() -> undoStack().push(ccpc);
+			}
 		}
 	}
 }


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