[qet] qet/qet: [4791] Start to revamp the code about formula and label of elements and conductors

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


Revision: 4791
Author:   blacksun
Date:     2016-11-24 17:45:55 +0100 (Thu, 24 Nov 2016)
Log Message:
-----------
Start to revamp the code about formula and label of elements and conductors

Modified Paths:
--------------
    trunk/sources/autoNum/assignvariables.cpp
    trunk/sources/autoNum/assignvariables.h
    trunk/sources/autoNum/numerotationcontext.cpp
    trunk/sources/autoNum/ui/selectautonumw.cpp
    trunk/sources/diagramcontext.h
    trunk/sources/qetapp.cpp
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/ui/elementinfopartwidget.cpp
    trunk/sources/ui/elementinfopartwidget.h
    trunk/sources/ui/elementinfowidget.cpp
    trunk/sources/ui/elementinfowidget.h

Modified: trunk/sources/autoNum/assignvariables.cpp
===================================================================
--- trunk/sources/autoNum/assignvariables.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/autoNum/assignvariables.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -20,6 +20,7 @@
 #include "element.h"
 #include "diagramposition.h"
 #include <QVariant>
+#include <QStringList>
 
 namespace autonum
 {
@@ -234,4 +235,81 @@
 		}
 	}
 
+	/**
+	 * @brief NumerotationContextToFormula
+	 * @param nc
+	 * @return the numerotation context, converted to formula
+	 */
+	QString NumerotationContextToFormula(const NumerotationContext &nc)
+	{
+		QString type;
+		QString value;
+		QString formula;
+		int count_unit = 0;
+		int count_unitf = 0;
+		int count_ten = 0;
+		int count_tenf = 0;
+		int count_hundred = 0;
+		int count_hundredf = 0;
+
+		for(int i=0 ; i<nc.size() ; i++)
+		{
+			type = nc.itemAt(i).at(0);
+			value = nc.itemAt(i).at(1);
+
+			if (type == "idfolio") {
+				formula.append("%id");
+			}
+			else if (type == "folio") {
+				formula.append("%F");
+			}
+			else if (type == "machine") {
+				formula.append("%M");
+			}
+			else if (type == "locmach") {
+				formula.append("%LM");
+			}
+
+
+			else if (type == "elementcolumn") {
+				formula.append("%c");
+			}
+			else if (type == "elementline") {
+				formula.append("%l");
+			}
+			else if (type == "elementprefix") {
+				formula.append("%prefix");
+			}
+			else if (type == "string") {
+				formula.append(value);
+			}
+			else if (type == "unit") {
+				count_unit++;
+				formula.append("%sequ_" + QString::number(count_unit));
+			}
+			else if (type == "unitfolio") {
+				count_unitf++;
+				formula.append("%sequf_" + QString::number(count_unitf));
+			}
+			else if (type == "ten") {
+				count_ten++;
+				formula.append("%seqt_" + QString::number(count_ten));
+			}
+			else if (type == "tenfolio") {
+				count_tenf++;
+				formula.append("%seqtf_" + QString::number(count_tenf));
+			}
+			else if (type == "hundred") {
+				count_hundred++;
+				formula.append("%seqh_" + QString::number(count_hundred));
+			}
+			else if (type == "hundredfolio") {
+				count_hundredf++;
+				formula.append("%seqhf_" + QString::number(count_hundredf));
+			}
+		}
+
+		return formula;
+	}
+
 }

Modified: trunk/sources/autoNum/assignvariables.h
===================================================================
--- trunk/sources/autoNum/assignvariables.h	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/autoNum/assignvariables.h	2016-11-24 16:45:55 UTC (rev 4791)
@@ -64,6 +64,7 @@
 	void setSequentialToList(QStringList &list, NumerotationContext &nc, QString type);
 	void setFolioSequentialToHash(QStringList &list, QHash<QString, QStringList> &hash, QString autoNumName);
 	void setSequential(QString label, autonum::sequenceStruct &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey);
+	QString NumerotationContextToFormula(const NumerotationContext &nc);
 }
 
 #endif // ASSIGNVARIABLES_H

Modified: trunk/sources/autoNum/numerotationcontext.cpp
===================================================================
--- trunk/sources/autoNum/numerotationcontext.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/autoNum/numerotationcontext.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -99,7 +99,7 @@
  * @return all type use to numerotation
  */
 QString NumerotationContext::validRegExpNum () const {
-	return ("unit|unitfolio|ten|hundred|string|idfolio|folio|machine|locmach|elementline|elementcolumn|elementprefix");
+	return ("unit|unitfolio|ten|tenfolio|hundred|hundredfolio|string|idfolio|folio|machine|locmach|elementline|elementcolumn|elementprefix");
 }
 
 /**
@@ -107,7 +107,7 @@
  * @return all type represents a number
  */
 QString NumerotationContext::validRegExpNumber() const {
-	return ("unit|unitfolio|ten|hundred");
+	return ("unit|unitfolio|ten|tenfolio|hundred|hundredfolio");
 }
 
 /**

Modified: trunk/sources/autoNum/ui/selectautonumw.cpp
===================================================================
--- trunk/sources/autoNum/ui/selectautonumw.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/autoNum/ui/selectautonumw.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -22,7 +22,7 @@
 #include "numerotationcontextcommands.h"
 #include "formulaautonumberingw.h"
 #include "ui_formulaautonumberingw.h"
-#include "qdebug.h"
+#include "assignvariables.h"
 
 /**
  * Constructor
@@ -244,72 +244,18 @@
  * @brief SelectAutonumW::contextToFormula
  * Apply formula to ElementAutonumbering Widget
  */
-void SelectAutonumW::contextToFormula() {
-	FormulaAutonumberingW* m_faw;
+void SelectAutonumW::contextToFormula()
+{
+	FormulaAutonumberingW* m_faw = nullptr;
 	if (this->parentWidget() -> objectName()=="ElementTab")
 		m_faw = m_feaw;
-	if (this->parentWidget()->objectName()=="ConductorTab")
+	else if (this->parentWidget()->objectName()=="ConductorTab")
 		m_faw = m_fcaw;
-	m_faw->clearContext();
-	int count_unit = 0;
-	int count_unitf = 0;
-	int count_ten = 0;
-	int count_tenf = 0;
-	int count_hundred = 0;
-	int count_hundredf = 0;
-	foreach (NumPartEditorW *npe, num_part_list_) {
-		if (npe->isValid()) {
-			if (npe->type_ == NumPartEditorW::idfolio) {
-				m_faw->setContext("%id");
-			}
-			else if (npe->type_ == NumPartEditorW::folio) {
-				m_faw->setContext("%F");
-			}
-			else if (npe->type_ == NumPartEditorW::machine) {
-				m_faw->setContext("%M");
-			}
-			else if (npe->type_ == NumPartEditorW::locmach) {
-				m_faw->setContext("%LM");
-			}
-			
-			
-			else if (npe->type_ == NumPartEditorW::elementcolumn) {
-				m_faw->setContext("%c");
-			}
-			else if (npe->type_ == NumPartEditorW::elementline) {
-				m_faw->setContext("%l");
-			}
-			else if (npe->type_ == NumPartEditorW::elementprefix) {
-				m_faw->setContext("%prefix");
-			}
-			else if (npe->type_ == NumPartEditorW::string) {
-				m_faw->setContext(npe->toNumContext().itemAt(0).at(1));
-			}
-			else if (npe->type_ == NumPartEditorW::unit) {
-				count_unit++;
-				m_faw->setContext("%sequ_"+QString::number(count_unit));
-			}
-			else if (npe->type_ == NumPartEditorW::unitfolio) {
-				count_unitf++;
-				m_faw->setContext("%sequf_"+QString::number(count_unitf));
-			}
-			else if (npe->type_ == NumPartEditorW::ten) {
-				count_ten++;
-				m_faw->setContext("%seqt_"+QString::number(count_ten));
-			}
-			else if (npe->type_ == NumPartEditorW::tenfolio) {
-				count_tenf++;
-				m_faw->setContext("%seqtf_"+QString::number(count_tenf));
-			}
-			else if (npe->type_ == NumPartEditorW::hundred) {
-				count_hundred++;
-				m_faw->setContext("%seqh_"+QString::number(count_hundred));
-			}
-			else if (npe->type_ == NumPartEditorW::hundredfolio) {
-				count_hundredf++;
-				m_faw->setContext("%seqhf_"+QString::number(count_hundredf));
-			}
-		}
+
+	if (m_faw)
+	{
+		m_faw->clearContext();
+		m_faw->setContext(autonum::NumerotationContextToFormula(toNumContext()));
 	}
 }
 

Modified: trunk/sources/diagramcontext.h
===================================================================
--- trunk/sources/diagramcontext.h	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/diagramcontext.h	2016-11-24 16:45:55 UTC (rev 4791)
@@ -32,6 +32,7 @@
 /**
  * Key for element :
  * label                          -> label or identification of element
+ * formula                        -> formula used to create the label (formula is make with variable)
  * designation                    -> exhaustive comment used to explain what the element does.
  * comment                        -> a little comment wich can be displayed in the folio
  * manufacturer                   -> the manufacturer of the element

Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/qetapp.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -282,9 +282,11 @@
  * @brief QETApp::elementInfoKeys
  * @return all available key for describe an element
  */
-QStringList QETApp::elementInfoKeys() {
+QStringList QETApp::elementInfoKeys()
+{
 	QStringList info_list;
-	info_list << "label"
+	info_list << "formula"
+			  << "label"
 			  << "comment"
 			  << "designation"
 			  << "manufacturer"
@@ -304,8 +306,10 @@
  * @param info the key to be translated
  * @return
  */
-QString QETApp::elementTranslatedInfoKey(QString &info) {
-	if (info == "label") return tr("Label");
+QString QETApp::elementTranslatedInfoKey(QString &info)
+{
+	if (info == "formula") return tr("formule du label");
+	else if (info == "label") return tr("Label");
 	else if (info == "comment") return tr("Commentaire");
 	else if (info == "designation") return tr("Désignation");
 	else if (info == "manufacturer") return tr("Fabricant");

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -437,8 +437,18 @@
 	loadSequential(&e,"seqh_",&m_autoNum_seq.hundred);
 	loadSequential(&e,"seqhf_",&m_autoNum_seq.hundred_folio);
 
-	//load informations
+		//load informations
 	m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
+		/**
+		 * Since the commit 4791, the value used as "label" and "formula" is stored in differents keys (instead of the same key, "label" in previous version),
+		 * so, if "label" contain "%" (Use variable value), and "formula" does not exist,
+		 * this mean the label was made before commit 4791 (0.51 dev). So we swap the value stored in "label" to "formula" as expected.
+		 * @TODO remove this code at version 0.7 or more (probably useless).
+		 */
+	if (m_element_informations["label"].toString().contains("%") && m_element_informations["formula"].toString().isNull())
+	{
+		m_element_informations.addValue("formula", m_element_informations["label"]);
+	}
 
 	//Position and selection.
 	//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid

Modified: trunk/sources/ui/elementinfopartwidget.cpp
===================================================================
--- trunk/sources/ui/elementinfopartwidget.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/ui/elementinfopartwidget.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -99,3 +99,23 @@
 void ElementInfoPartWidget::setFocusTolineEdit() {
 	ui->line_edit->setFocus();
 }
+
+/**
+ * @brief ElementInfoPartWidget::setEnabled
+ * enable the line edit
+ * @param e
+ */
+void ElementInfoPartWidget::setEnabled(bool e)
+{
+	ui->line_edit->setEnabled(e);
+}
+
+/**
+ * @brief ElementInfoPartWidget::setDisabled
+ * disable the line edit
+ * @param d
+ */
+void ElementInfoPartWidget::setDisabled(bool d)
+{
+	ui->line_edit->setDisabled(d);
+}

Modified: trunk/sources/ui/elementinfopartwidget.h
===================================================================
--- trunk/sources/ui/elementinfopartwidget.h	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/ui/elementinfopartwidget.h	2016-11-24 16:45:55 UTC (rev 4791)
@@ -40,6 +40,8 @@
 		void    setShow     (const bool &);
 		void    setHideShow (const bool &);
 		void    setFocusTolineEdit();
+		void    setEnabled(bool e);
+		void    setDisabled(bool d);
 
 	signals:
 		void textEdited  (const QString & text);

Modified: trunk/sources/ui/elementinfowidget.cpp
===================================================================
--- trunk/sources/ui/elementinfowidget.cpp	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/ui/elementinfowidget.cpp	2016-11-24 16:45:55 UTC (rev 4791)
@@ -75,7 +75,20 @@
 void ElementInfoWidget::apply()
 {
 	if (QUndoCommand *undo = associatedUndo())
+	{
 		m_element -> diagram() -> undoStack().push(undo);
+
+		ElementInfoPartWidget *f = infoPartWidgetForKey("formula");
+		ElementInfoPartWidget *l = infoPartWidgetForKey("label");
+
+		if (f && l)
+		{
+			if (f->text().isEmpty())
+				l->setEnabled(true);
+			else
+				l->setDisabled(true);
+		}
+	}
 }
 
 /**
@@ -177,6 +190,22 @@
 }
 
 /**
+ * @brief ElementInfoWidget::infoPartWidgetForKey
+ * @param key
+ * @return the ElementInfoPartWidget with key @key, if not found return nullptr;
+ */
+ElementInfoPartWidget *ElementInfoWidget::infoPartWidgetForKey(const QString &key) const
+{
+	foreach (ElementInfoPartWidget *eipw, m_eipw_list)
+	{
+		if (eipw->key() == key)
+			return eipw;
+	}
+
+	return nullptr;
+}
+
+/**
  * @brief ElementInfoWidget::updateUi
  * fill information fetch in m_element_info to the
  * corresponding line edit
@@ -203,6 +232,17 @@
 			eipw->setHideShow(true);
 	}
 
+	ElementInfoPartWidget *f = infoPartWidgetForKey("formula");
+	ElementInfoPartWidget *l = infoPartWidgetForKey("label");
+
+	if (f && l)
+	{
+		if (f->text().isEmpty())
+			l->setEnabled(true);
+		else
+			l->setDisabled(true);
+	}
+
 	if (m_live_edit) enableLiveEdit();
 }
 

Modified: trunk/sources/ui/elementinfowidget.h
===================================================================
--- trunk/sources/ui/elementinfowidget.h	2016-11-22 17:21:53 UTC (rev 4790)
+++ trunk/sources/ui/elementinfowidget.h	2016-11-24 16:45:55 UTC (rev 4791)
@@ -60,6 +60,7 @@
 
 	private:
 		void buildInterface();
+		ElementInfoPartWidget *infoPartWidgetForKey(const QString &key) const;
 
 	private slots:
 		void firstActivated();


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