[qet] [4680] Update Policy now works with conductor autonumberings

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


Revision: 4680
Author:   dfochi
Date:     2016-09-01 21:41:49 +0200 (Thu, 01 Sep 2016)
Log Message:
-----------
Update Policy now works with conductor autonumberings

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

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/diagram.cpp	2016-09-01 19:41:49 UTC (rev 4680)
@@ -60,7 +60,8 @@
 	draw_terminals_          (true),
 	draw_colored_conductors_ (true),
 	m_event_interface (nullptr),
-	m_freeze_new_elements_   (false)
+	m_freeze_new_elements_   (false),
+	m_freeze_new_conductors_ (false)
 {
 	setProject(project);
 	qgi_manager_ = new QGIManager(this);
@@ -478,6 +479,9 @@
 		//Default New Element
 		racine.setAttribute("freezeNewElement", m_freeze_new_elements_ ? "true" : "false");
 
+		//Default New Conductor
+		racine.setAttribute("freezeNewConductor", m_freeze_new_conductors_ ? "true" : "false");
+
 		//Element Folio Sequential Variables
 		if (!m_elmt_unitfolio_max.isEmpty() || !m_elmt_tenfolio_max.isEmpty() || !m_elmt_hundredfolio_max.isEmpty()) {
 			QDomElement elmtfoliosequential = document.createElement("elementautonumfoliosequentials");
@@ -724,6 +728,9 @@
 		// Load Freeze New Element
 		m_freeze_new_elements_ = root.attribute("freezeNewElement").toInt();
 
+		// Load Freeze New Conductor
+		m_freeze_new_conductors_ = root.attribute("freezeNewConductor").toInt();
+
 		//Load Element Folio Sequential
 		folioSequentialsFromXml(root, &m_elmt_unitfolio_max, "elementunitfolioseq","sequf_","unitfolioseq", "elementautonumfoliosequentials");
 		folioSequentialsFromXml(root, &m_elmt_tenfolio_max, "elementtenfolioseq","seqtf_", "tenfolioseq", "elementautonumfoliosequentials");
@@ -861,6 +868,10 @@
 					addItem(c);
 					c -> fromXml(f);
 					added_conductors << c;
+					if (item_paste) {
+						c->m_frozen_label = f.attribute("frozenlabel");
+						qDebug() << "Frozen Label" << f.attribute("frozenlabel");
+					}
 				}
 				else
 					delete c;
@@ -1362,6 +1373,19 @@
 }
 
 /**
+ * @brief Diagram::conductors
+ * Return the list containing all conductors
+ */
+QList <Conductor *> Diagram::conductors() const {
+	QList<Conductor *> cnd_list;
+	foreach (QGraphicsItem *qgi, items()) {
+		if (Conductor *cnd = qgraphicsitem_cast<Conductor *>(qgi))
+			cnd_list <<cnd;
+	}
+	return (cnd_list);
+}
+
+/**
 	Initialise un deplacement d'elements, conducteurs et champs de texte sur le
 	schema.
 	@param driver_item Item deplace par la souris et ne necessitant donc pas
@@ -1461,22 +1485,14 @@
 }
 
 /**
- * @brief Diagram::freezeNew
+ * @brief Diagram::freezeNewElements
  * Set new element label to be frozen.
  */
-void Diagram::freezeNew() {
-	m_freeze_new_elements_ = true;
+void Diagram::setFreezeNewElements(bool b) {
+	m_freeze_new_elements_ = b;
 }
 
 /**
- * @brief Diagram::unfreezeNew
- * Set new element label to not be frozen.
- */
-void Diagram::unfreezeNew() {
-	m_freeze_new_elements_ = false;
-}
-
-/**
  * @brief Diagram::freezeNewElements
  * @return current freeze new element status .
  */
@@ -1485,6 +1501,42 @@
 }
 
 /**
+ * @brief Diagram::freezeConductors
+ * Freeze every existent conductor label.
+ */
+void Diagram::freezeConductors() {
+	foreach (Conductor *cnd, conductors()) {
+		cnd->freezeLabel();
+	}
+}
+
+/**
+ * @brief Diagram::unfreezeConductors
+ * Unfreeze every existent conductor label.
+ */
+void Diagram::unfreezeConductors() {
+	foreach (Conductor *cnd, conductors()) {
+		cnd->unfreezeLabel();
+	}
+}
+
+/**
+ * @brief Diagram::setfreezeNewConductors
+ * Set new conductor label to be frozen.
+ */
+void Diagram::setFreezeNewConductors(bool b) {
+	m_freeze_new_conductors_ = b;
+}
+
+/**
+ * @brief Diagram::freezeNewConductors
+ * @return current freeze new conductor status .
+ */
+bool Diagram::freezeNewConductors() {
+	return m_freeze_new_conductors_;
+}
+
+/**
  * @brief Diagram::adjustSceneRect
  * Recalcul and adjust the size of the scene
  */

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/diagram.h	2016-09-01 19:41:49 UTC (rev 4680)
@@ -113,6 +113,7 @@
 		DiagramEventInterface *m_event_interface;
 
 		bool m_freeze_new_elements_;
+		bool m_freeze_new_conductors_;
 	
 	// METHODS
 	protected:
@@ -194,6 +195,7 @@
 	
 	QList<CustomElement *> customElements() const;
 	QList<Element *> elements() const;
+	QList<Conductor *> conductors() const;
 	QSet<DiagramTextItem *> selectedTexts() const;
 	QSet<ConductorTextItem *> selectedConductorTexts() const;
 	QSet<ElementTextItem*> selectedElementTexts() const;
@@ -216,10 +218,15 @@
 	//methods related to element label Update Policy
 	void freezeElements();
 	void unfreezeElements();
-	void freezeNew();
-	void unfreezeNew();
+	void setFreezeNewElements(bool);
 	bool freezeNewElements();
 
+	//methods related to conductor label Update Policy
+	void freezeConductors();
+	void unfreezeConductors();
+	void setFreezeNewConductors(bool);
+	bool freezeNewConductors();
+
 	//methods related to insertion and loading of folio sequential
 	void insertFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc);
 	void loadFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc);

Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-09-01 19:41:49 UTC (rev 4680)
@@ -232,6 +232,8 @@
 		ConductorAutoNumerotation can  (conductor, m_diagram, undo_object);
 		can.numerate();
 		conductor->setSeq = true;
+		if (m_diagram->freezeNewConductors() || m_diagram->project()->freezeNewConductors() )
+			conductor->freeze_label = true;
 	};
 	m_diagram -> undoStack().push(undo_object);
 	element->setSequential();

Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/projectconfigpages.cpp	2016-09-01 19:41:49 UTC (rev 4680)
@@ -598,18 +598,34 @@
 		to = m_amw->ui->m_to_folios_cb->itemData(m_amw->ui->m_to_folios_cb->currentIndex()).toInt();
 	}
 
-	//Conductor Autonumbering Status
+	//Conductor Autonumbering Update Policy
+	//Allow Both Existent and New Conductors
 	if (m_amw->ui->m_both_conductor_rb->isChecked()) {
-
+		//Unfreeze Existent and New Conductors
+		project()->unfreezeExistentConductorLabel(from,to);
+		project()->unfreezeNewConductorLabel(from,to);
+		project()->setFreezeNewConductors(false);
 	}
+	//Allow Only New
 	else if (m_amw->ui->m_new_conductor_rb->isChecked()) {
-
+		//Freeze Existent and Unfreeze New Conductors
+		project()->freezeExistentConductorLabel(from,to);
+		project()->unfreezeNewConductorLabel(from,to);
+		project()->setFreezeNewConductors(false);
 	}
+	//Allow Only Existent
 	else if (m_amw->ui->m_existent_conductor_rb->isChecked()) {
-
+		//Freeze Existent and Unfreeze New Conductors
+		project()->unfreezeExistentConductorLabel(from,to);
+		project()->freezeNewConductorLabel(from,to);
+		project()->setFreezeNewConductors(true);
 	}
+	//Disable
 	else if (m_amw->ui->m_disable_conductor_rb->isChecked()) {
-
+		//Freeze Existent and New Elements, Set Freeze Element Project Wide
+		project()->freezeExistentConductorLabel(from,to);
+		project()->freezeNewConductorLabel(from,to);
+		project()->setFreezeNewConductors(true);
 	}
 
 	//Element Autonumbering Update Policy

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2016-09-01 19:41:49 UTC (rev 4680)
@@ -48,6 +48,7 @@
 	terminal1(p1),
 	terminal2(p2),
 	setSeq(true),
+	freeze_label(false),
 	bMouseOver(false),
 	m_handler(10),
 	text_item(0),
@@ -826,6 +827,8 @@
 	loadSequential(&e,"seqh_",&seq_hundred);
 	loadSequential(&e,"seqhf_",&seq_hundredfolio);
 
+	m_frozen_label = e.attribute("frozenlabel");
+
 	setProperties(pr);
 
 	return return_;
@@ -905,6 +908,8 @@
 	for (int i = 0; i < seq_hundredfolio.size(); i++) {
 			e.setAttribute("seqhf_" + QString::number(i+1),seq_hundredfolio.at(i));
 	}
+
+	if (m_frozen_label != "") e.setAttribute("frozenlabel", m_frozen_label);
 	
 	// Export the properties and text
 	properties_. toXml(e);
@@ -1466,6 +1471,12 @@
 	}
 	setText(properties_.text);
 	text_item -> setFontSize(properties_.text_size);
+	if (terminal1->diagram()->item_paste)
+		m_frozen_label = "";
+	else
+	m_frozen_label = properties_.text;
+	if (freeze_label)
+		freezeLabel();
 	if (properties_.type != ConductorProperties::Multi)
 		text_item -> setVisible(false);
 	else
@@ -1867,3 +1878,23 @@
 	other_conductors_list.removeAll(const_cast<Conductor *> (conductor));
 	return(other_conductors_list);
 }
+
+/**
+ * @brief Conductor::freezeLabel
+ * Freeze this conductor label
+ */
+void Conductor::freezeLabel() {
+	QString freezelabel = this->text_item->toPlainText();
+	m_frozen_label = properties_.text;
+	this->setText(freezelabel);
+	this->properties_.text = freezelabel;
+}
+
+/**
+ * @brief Conductor::unfreezeLabel
+ * Unfreeze this conductor label
+ */
+void Conductor::unfreezeLabel() {
+	this->setText(m_frozen_label);
+	properties_.text = m_frozen_label;
+}

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/qetgraphicsitem/conductor.h	2016-09-01 19:41:49 UTC (rev 4680)
@@ -131,6 +131,10 @@
 		QStringList seq_hundred;
 		QStringList seq_hundredfolio;
 		bool setSeq;
+		bool freeze_label;
+		void freezeLabel();
+		void unfreezeLabel();
+		QString m_frozen_label;
 	
 	public slots:
 	void displayedTextChanged();

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/qetproject.cpp	2016-09-01 19:41:49 UTC (rev 4680)
@@ -49,7 +49,8 @@
 	folioSheetsQuantity  (0     ),
 	m_auto_conductor     (true  ),
 	m_elements_collection (nullptr),
-	m_freeze_new_elements (false)
+	m_freeze_new_elements (false),
+	m_freeze_new_conductors (false)
 {
 	// 0 a n schema(s) vide(s)
 	int diagrams_count = qMax(0, diagrams);
@@ -628,6 +629,70 @@
 }
 
 /**
+ * @brief QETProject::freezeExistentConductorLabel
+ * Freeze Existent Conductors in the selected folios
+ * @param from - first folio index to apply freeze
+ * @param to - last folio index to apply freeze
+ */
+void QETProject::freezeExistentConductorLabel(int from, int to) {
+	for (int i = from; i <= to; i++) {
+		diagrams_.at(i)->freezeConductors();
+	}
+}
+
+/**
+ * @brief QETProject::unfreezeExistentConductorLabel
+ * Unfreeze Existent Conductors in the selected folios
+ * @param from - first folio index to apply unfreeze
+ * @param to - last folio index to apply unfreeze
+ */
+void QETProject::unfreezeExistentConductorLabel(int from, int to) {
+	for (int i = from; i <= to; i++) {
+		diagrams_.at(i)->unfreezeConductors();
+	}
+}
+
+/**
+ * @brief QETProject::freezeNewConductorLabel
+ * Freeze New Conductors in the selected folios
+ * @param from - first folio index to apply freeze
+ * @param to - last folio index to apply freeze
+ */
+void QETProject::freezeNewConductorLabel(int from, int to) {
+	for (int i = from; i <= to; i++) {
+		diagrams_.at(i)->setFreezeNewConductors(true);
+	}
+}
+
+/**
+ * @brief QETProject::unfreezeNewElementLabel
+ * Unfreeze New Conductors in the selected folios
+ * @param from - first folio index to apply unfreeze
+ * @param to - last folio index to apply unfreeze
+ */
+void QETProject::unfreezeNewConductorLabel(int from, int to) {
+	for (int i = from; i <= to; i++) {
+		diagrams_.at(i)->setFreezeNewConductors(false);
+	}
+}
+
+/**
+ * @brief QETProject::freezeNewConductors
+ * @return freeze new conductors Project Wide status
+ */
+bool QETProject::freezeNewConductors() {
+	return m_freeze_new_conductors;
+}
+
+/**
+ * @brief QETProject::setfreezeNewConductors
+ * Set Project Wide freeze new conductors
+ */
+void QETProject::setFreezeNewConductors(bool set) {
+	m_freeze_new_conductors = set;
+}
+
+/**
  * @brief QETProject::freezeExistentElementLabel
  * Freeze Existent Elements in the selected folios
  * @param from - first folio index to apply freeze
@@ -659,7 +724,7 @@
  */
 void QETProject::freezeNewElementLabel(int from, int to) {
 	for (int i = from; i <= to; i++) {
-		diagrams_.at(i)->freezeNew();
+		diagrams_.at(i)->setFreezeNewElements(true);
 	}
 }
 
@@ -671,7 +736,7 @@
  */
 void QETProject::unfreezeNewElementLabel(int from, int to) {
 	for (int i = from; i <= to; i++) {
-		diagrams_.at(i)->unfreezeNew();
+		diagrams_.at(i)->setFreezeNewElements(false);
 	}
 }
 
@@ -1410,6 +1475,7 @@
 	{
 		m_current_conductor_autonum = conds_autonums.attribute("current_autonum");
 		m_current_conductor_formula = conds_autonums.attribute("current_formula");
+		m_freeze_new_conductors = conds_autonums.attribute("freeze_new_conductors") == "true";
 		foreach (QDomElement elmt, QET::findInDomElement(conds_autonums, "conductor_autonum"))
 		{
 			NumerotationContext nc;
@@ -1431,7 +1497,7 @@
 	{
 		m_current_element_autonum = element_autonums.attribute("current_autonum");
 		m_current_element_formula = element_autonums.attribute("current_formula");
-		m_freeze_new_elements = element_autonums.attribute("freeze_new_elements").toInt();
+		m_freeze_new_elements = element_autonums.attribute("freeze_new_elements") == "true";
 		foreach (QDomElement elmt, QET::findInDomElement(element_autonums, "element_autonum"))
 		{
 			NumerotationContext nc;
@@ -1496,6 +1562,7 @@
 	QDomElement conductor_autonums = xml_document.createElement("conductors_autonums");
 	conductor_autonums.setAttribute("current_autonum", m_current_conductor_autonum);
 	conductor_autonums.setAttribute("current_formula", m_current_conductor_formula);
+	conductor_autonums.setAttribute("freeze_new_conductors", m_freeze_new_conductors ? "true" : "false");
 	foreach (QString key, conductorAutoNum().keys()) {
 	QDomElement conductor_autonum = conductorAutoNum(key).toXml(xml_document, "conductor_autonum");
 		if (key != "" && conductorAutoNumFormula(key) != "") {

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/qetproject.h	2016-09-01 19:41:49 UTC (rev 4680)
@@ -133,6 +133,7 @@
 		QString elementAutoNumCurrentFormula() const;
 		QString elementCurrentAutoNum() const;
 
+		//Element
 		void freezeExistentElementLabel(int,int);
 		void freezeNewElementLabel(int,int);
 		void unfreezeExistentElementLabel(int,int);
@@ -140,6 +141,14 @@
 		bool freezeNewElements();
 		void setFreezeNewElements(bool);
 
+		//Conductor
+		void freezeExistentConductorLabel(int,int);
+		void unfreezeExistentConductorLabel(int,int);
+		void freezeNewConductorLabel(int,int);
+		void unfreezeNewConductorLabel(int,int);
+		bool freezeNewConductors();
+		void setFreezeNewConductors(bool);
+
 		bool autoConductor () const;
 		bool autoElement () const;
 		bool autoFolio () const;
@@ -268,6 +277,7 @@
 	bool m_auto_conductor;
 	XmlElementCollection *m_elements_collection;
 	bool m_freeze_new_elements;
+	bool m_freeze_new_conductors;
 };
 Q_DECLARE_METATYPE(QETProject *)
 #endif

Modified: trunk/sources/ui/autonumberingmanagementw.cpp
===================================================================
--- trunk/sources/ui/autonumberingmanagementw.cpp	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/ui/autonumberingmanagementw.cpp	2016-09-01 19:41:49 UTC (rev 4680)
@@ -37,7 +37,6 @@
 	ui->setupUi(this);
 	ui->m_apply_locations_rb->setHidden(true);
 	ui->m_selected_locations_le->setHidden(true);
-	ui->conductorWidget->setHidden(true);
 	ui->folioWidget->setHidden(true);
 	ui->m_selected_folios_widget->setDisabled(true);
 	ui->m_selected_folios_le->setDisabled(true);

Modified: trunk/sources/ui/autonumberingmanagementw.ui
===================================================================
--- trunk/sources/ui/autonumberingmanagementw.ui	2016-08-31 19:58:58 UTC (rev 4679)
+++ trunk/sources/ui/autonumberingmanagementw.ui	2016-09-01 19:41:49 UTC (rev 4680)
@@ -76,7 +76,7 @@
         <x>0</x>
         <y>0</y>
         <width>630</width>
-        <height>498</height>
+        <height>495</height>
        </rect>
       </property>
       <property name="sizePolicy">
@@ -255,9 +255,9 @@
               </widget>
              </item>
              <item>
-              <widget class="QRadioButton" name="m_new_conductor_rb">
+              <widget class="QRadioButton" name="m_both_conductor_rb">
                <property name="text">
-                <string>Only New</string>
+                <string>Both</string>
                </property>
                <property name="autoExclusive">
                 <bool>true</bool>
@@ -265,9 +265,9 @@
               </widget>
              </item>
              <item>
-              <widget class="QRadioButton" name="m_existent_conductor_rb">
+              <widget class="QRadioButton" name="m_new_conductor_rb">
                <property name="text">
-                <string>Existent and New</string>
+                <string>Only New</string>
                </property>
                <property name="autoExclusive">
                 <bool>true</bool>
@@ -275,9 +275,9 @@
               </widget>
              </item>
              <item>
-              <widget class="QRadioButton" name="m_both_conductor_rb">
+              <widget class="QRadioButton" name="m_existent_conductor_rb">
                <property name="text">
-                <string>Both</string>
+                <string>Only Existent</string>
                </property>
                <property name="autoExclusive">
                 <bool>true</bool>


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