[qet] qet/qet: [4746] Bug fix : Conductor text with formula that contain %id isn 't good when open project (variable %id is replaced by 0 in each folio)

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


Revision: 4746
Author:   blacksun
Date:     2016-10-17 16:26:13 +0200 (Mon, 17 Oct 2016)
Log Message:
-----------
Bug fix : Conductor text with formula that contain %id isn't good when open project (variable %id is replaced by 0 in each folio)

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/diagramevent/diagrameventaddelement.cpp
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/conductor.h
    trunk/sources/qetproject.cpp

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-10-17 12:44:56 UTC (rev 4745)
+++ trunk/sources/diagram.cpp	2016-10-17 14:26:13 UTC (rev 4746)
@@ -983,9 +983,19 @@
 	return(new_node.toElement());
 }
 
-void Diagram::initElementsLinks() {
+/**
+ * @brief Diagram::refreshContents
+ * refresh all content of diagram.
+ * - refresh conductor text.
+ * - linking the elements waiting to be linked
+ */
+void Diagram::refreshContents() {
+
 	foreach (Element *elmt, elements())
 		elmt->initLink(project());
+
+	foreach (Conductor *conductor, conductors())
+		conductor->refreshText();
 }
 
 /**
@@ -1506,7 +1516,7 @@
  */
 void Diagram::freezeConductors() {
 	foreach (Conductor *cnd, conductors()) {
-		cnd->freezeLabel();
+		cnd->setFreezeLabel(true);
 	}
 }
 
@@ -1516,7 +1526,7 @@
  */
 void Diagram::unfreezeConductors() {
 	foreach (Conductor *cnd, conductors()) {
-		cnd->unfreezeLabel();
+		cnd->setFreezeLabel(false);
 	}
 }
 

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2016-10-17 12:44:56 UTC (rev 4745)
+++ trunk/sources/diagram.h	2016-10-17 14:26:13 UTC (rev 4746)
@@ -166,8 +166,9 @@
 	void folioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString, QString, QDomDocument *);
 	void folioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString, QString, QString);
 
-	// methods related to graphics items addition/removal on the diagram
-	void initElementsLinks();
+	void refreshContents();
+
+		// methods related to graphics items addition/removal on the diagram
 	virtual void addItem    (QGraphicsItem *item);
 	virtual void removeItem (QGraphicsItem *item);
 	

Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-10-17 12:44:56 UTC (rev 4745)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-10-17 14:26:13 UTC (rev 4746)
@@ -217,7 +217,8 @@
 	element -> setRotation(m_element -> rotation());
 	m_diagram -> addItem(element);
 
-	QUndoCommand *undo_object = new AddItemCommand<Element *>(element, m_diagram, m_element -> pos());
+	QUndoCommand *undo_object = new QUndoCommand(tr("Ajouter %1").arg(element->name()));
+	new AddItemCommand<Element *>(element, m_diagram, m_element -> pos(), undo_object);
 
 	while (!element -> AlignedFreeTerminals().isEmpty() && m_diagram -> project() -> autoConductor())
 	{
@@ -232,8 +233,9 @@
 		ConductorAutoNumerotation can  (conductor, m_diagram, undo_object);
 		can.numerate();
 		conductor->setSeq = true;
-		if (m_diagram->freezeNewConductors() || m_diagram->project()->freezeNewConductors() )
-			conductor->freeze_label = true;
+		if (m_diagram->freezeNewConductors() || m_diagram->project()->freezeNewConductors()) {
+			conductor->setFreezeLabel(true);
+		}
 	};
 	m_diagram -> undoStack().push(undo_object);
 	element->setSequential();

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2016-10-17 12:44:56 UTC (rev 4745)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2016-10-17 14:26:13 UTC (rev 4746)
@@ -48,7 +48,6 @@
 	terminal1(p1),
 	terminal2(p2),
 	setSeq(true),
-	freeze_label(false),
 	bMouseOver(false),
 	m_handler(10),
 	text_item(0),
@@ -1447,6 +1446,15 @@
 }
 
 /**
+ * @brief Conductor::refreshText
+ * Refresh the text of this conductor.
+ * recalcule and set the text according to the formula.
+ */
+void Conductor::refreshText() {
+	setText(m_freeze_label? text_item->toPlainText() : properties().text);
+}
+
+/**
  * @brief Conductor::setProperties
  * Set new properties for this conductor
  * Also change the common properties for every conductors at the same potential.
@@ -1478,8 +1486,8 @@
 		else
 			m_frozen_label = properties_.text;
 	}
-	if (freeze_label)
-		freezeLabel();
+
+	setFreezeLabel(m_freeze_label);
 	if (properties_.type != ConductorProperties::Multi)
 		text_item -> setVisible(false);
 	else
@@ -1883,22 +1891,23 @@
 }
 
 /**
- * @brief Conductor::freezeLabel
- * Freeze this conductor label
+ * @brief Conductor::setFreezeLabel
+ * Freeze this conductor label if true
+ * Unfreeze this conductor label if false
+ * @param freeze
  */
-void Conductor::freezeLabel() {
-	QString freezelabel = this->text_item->toPlainText();
-	m_frozen_label = properties_.text;
-	this->setText(freezelabel);
-	this->properties_.text = freezelabel;
-}
+void Conductor::setFreezeLabel(bool freeze) {
+	m_freeze_label = freeze;
 
-/**
- * @brief Conductor::unfreezeLabel
- * Unfreeze this conductor label
- */
-void Conductor::unfreezeLabel() {
-	this->setText(m_frozen_label);
-	if (m_frozen_label == "") return;
-	properties_.text = m_frozen_label;
+	if (m_freeze_label) {
+		QString freezelabel = this->text_item->toPlainText();
+		m_frozen_label = properties_.text;
+		this->setText(freezelabel);
+		this->properties_.text = freezelabel;
+	}
+	else {
+		this->setText(m_frozen_label);
+		if (m_frozen_label == "") return;
+		properties_.text = m_frozen_label;
+	}
 }

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2016-10-17 12:44:56 UTC (rev 4745)
+++ trunk/sources/qetgraphicsitem/conductor.h	2016-10-17 14:26:13 UTC (rev 4746)
@@ -95,6 +95,7 @@
 	QString text() const;
 	QString assignVariables(QString) ;
 	void setText(const QString &);
+	void refreshText();
 	QString assignSeq (QString, Conductor*);
 	void setSequential ();
 	void setOthersSequential (Conductor *);
@@ -131,9 +132,7 @@
 		QStringList seq_hundred;
 		QStringList seq_hundredfolio;
 		bool setSeq;
-		bool freeze_label;
-		void freezeLabel();
-		void unfreezeLabel();
+		void setFreezeLabel(bool freeze);
 		QString m_frozen_label;
 	
 	public slots:
@@ -153,32 +152,33 @@
 
 	private:
 		QetGraphicsHandlerUtility m_handler;
-	/// Functional properties
+		/// Functional properties
 	ConductorProperties properties_;
-	/// Text input for non simple, non-singleline conductors
+		/// Text input for non simple, non-singleline conductors
 	ConductorTextItem *text_item;
-	/// Segments composing the conductor
+		/// Segments composing the conductor
 	ConductorSegment *segments;
-	/// Attributs related to mouse interaction
+		/// Attributs related to mouse interaction
 	bool moving_segment;
 	int moved_point;
 	qreal previous_z_value;
 	ConductorSegment *moved_segment;
 	QPointF before_mov_text_pos_;
-	/// Whether the conductor was manually modified by users
+		/// Whether the conductor was manually modified by users
 	bool modified_path;
-	/// Whether the current profile should be saved as soon as possible
+		/// Whether the current profile should be saved as soon as possible
 	bool has_to_save_profile;
-	/// conductor profile: "photography" of what the conductor is supposed to look
-	/// like - there is one profile per kind of traject
+		/// conductor profile: "photography" of what the conductor is supposed to look
+		/// like - there is one profile per kind of traject
 	ConductorProfilesGroup conductor_profiles;
-	/// QPen et QBrush objects used to draw conductors
+		/// QPen et QBrush objects used to draw conductors
 	static QPen conductor_pen;
 	static QBrush conductor_brush;
 	static bool pen_and_brush_initialized;
-	/// Define whether and how the conductor should be highlighted
+		/// Define whether and how the conductor should be highlighted
 	Highlight must_highlight_;
 	bool m_valid;
+	bool m_freeze_label = false;
 	
 	private:
 	void segmentsToPath();

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2016-10-17 12:44:56 UTC (rev 4745)
+++ trunk/sources/qetproject.cpp	2016-10-17 14:26:13 UTC (rev 4746)
@@ -1367,8 +1367,9 @@
 		addDiagram(diagram);
 
 		//Initialise links between elements in this project
+		//and refresh the text of conductor
 	foreach (Diagram *d, diagrams())
-		d->initElementsLinks();
+		d->refreshContents();
 
 	delete dlgWaiting;
 }


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