From 230700f845eded5bba72a5395c85b8ec420db1f0 Mon Sep 17 00:00:00 2001 From: dfochi Date: Mon, 29 Aug 2016 15:37:42 +0000 Subject: [PATCH] Conductor Autonum now works with variables. Folio Autonumberings added to conductor autonum git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4674 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/conductorautonumerotation.cpp | 3 +- sources/conductorproperties.cpp | 9 + sources/conductorproperties.h | 1 + sources/configpages.cpp | 2 +- sources/diagram.cpp | 183 ++++++++++++---- sources/diagram.h | 16 +- .../diagramevent/diagrameventaddelement.cpp | 1 + sources/diagramview.cpp | 1 + sources/elementsmover.cpp | 1 + sources/numerotationcontextcommands.cpp | 2 +- sources/projectconfigpages.cpp | 27 ++- sources/projectconfigpages.h | 2 +- sources/projectview.cpp | 1 + sources/qetgraphicsitem/conductor.cpp | 196 +++++++++++++++++- sources/qetgraphicsitem/conductor.h | 15 ++ sources/qetgraphicsitem/customelement.cpp | 8 +- sources/qetgraphicsitem/element.cpp | 2 +- sources/qetgraphicsitem/terminal.cpp | 21 +- sources/qetproject.cpp | 81 +++++++- sources/qetproject.h | 19 +- sources/ui/autonumberingdockwidget.cpp | 9 +- sources/ui/autonumberingmanagementw.cpp | 4 +- sources/ui/folioautonumbering.ui | 12 +- ...mberingw.cpp => formulaautonumberingw.cpp} | 26 +-- ...tonumberingw.h => formulaautonumberingw.h} | 16 +- ...numberingw.ui => formulaautonumberingw.ui} | 12 +- sources/ui/numparteditorw.cpp | 4 +- sources/ui/projectpropertiesdialog.cpp | 2 +- sources/ui/selectautonumw.cpp | 71 ++++--- sources/ui/selectautonumw.h | 8 +- sources/ui/selectautonumw.ui | 6 +- 31 files changed, 604 insertions(+), 157 deletions(-) rename sources/ui/{elementautonumberingw.cpp => formulaautonumberingw.cpp} (66%) rename sources/ui/{elementautonumberingw.h => formulaautonumberingw.h} (81%) rename sources/ui/{elementautonumberingw.ui => formulaautonumberingw.ui} (92%) diff --git a/sources/conductorautonumerotation.cpp b/sources/conductorautonumerotation.cpp index 8538360e8..f3c880d92 100644 --- a/sources/conductorautonumerotation.cpp +++ b/sources/conductorautonumerotation.cpp @@ -121,6 +121,5 @@ void ConductorAutoNumerotation::numerateNewConductor() { if (context.isEmpty()) return; NumerotationContextCommands ncc (context, m_diagram); - applyText(ncc.toRepresentedString()); - m_diagram->project()->addConductorAutoNum(m_diagram -> conductorsAutonumName(), ncc.next()); + applyText(m_diagram->project()->conductorAutoNumCurrentFormula()); } diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 4d2ed0ee0..546140882 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -367,6 +367,15 @@ QString ConductorProperties::typeToString(ConductorType t) { } } +/** + * @brief ConductorProperties::setText + * This method sets the current conductor text + * @param text to be setted + */ +void ConductorProperties::setText(QString text) { + text = text; +} + /** * @brief ConductorProperties::defaultProperties * @return the default properties stored in the setting file diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 99af1fe26..b2d3011ba 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -96,6 +96,7 @@ class ConductorProperties void toSettings(QSettings &, const QString & = QString()) const; void fromSettings(QSettings &, const QString & = QString()); static QString typeToString(ConductorType); + void setText(QString); static ConductorProperties defaultProperties(); diff --git a/sources/configpages.cpp b/sources/configpages.cpp index 2c21d75d3..534fbcc4b 100644 --- a/sources/configpages.cpp +++ b/sources/configpages.cpp @@ -206,7 +206,7 @@ void NewDiagramPage::setFolioAutonum(QString autoNum){ /** * @brief NewDiagramPage::saveCurrentTbp - * Save current TBP to retrieve after auto folio num + * Save current TBP to retrieve after auto folio num */ void NewDiagramPage::saveCurrentTbp(){ savedTbp = ipw->properties(); diff --git a/sources/diagram.cpp b/sources/diagram.cpp index e09ce7336..0c3d1745a 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -82,6 +82,7 @@ Diagram::Diagram(QETProject *project) : connect(&border_and_titleblock, SIGNAL(borderChanged(QRectF,QRectF)), this, SLOT(adjustSceneRect())); connect(&border_and_titleblock, SIGNAL(titleBlockFolioChanged(const QString &)), this, SLOT(updateLabels())); connect(this, SIGNAL (diagramActivated()), this, SLOT(loadElmtFolioSeq())); + connect(this, SIGNAL (diagramActivated()), this, SLOT(loadCndFolioSeq())); adjustSceneRect(); } @@ -477,25 +478,46 @@ QDomDocument Diagram::toXml(bool whole_content) { //Default New Element racine.setAttribute("freezeNewElement", m_freeze_new_elements_ ? "true" : "false"); - //Folio Sequential Variables + //Element Folio Sequential Variables if (!m_elmt_unitfolio_max.isEmpty() || !m_elmt_tenfolio_max.isEmpty() || !m_elmt_hundredfolio_max.isEmpty()) { - QDomElement folioContainedAutonum = document.createElement("elementautonumfoliosequentials"); + QDomElement elmtfoliosequential = document.createElement("elementautonumfoliosequentials"); if (!m_elmt_unitfolio_max.isEmpty()) { QDomElement elmtfolioseq = document.createElement("elementunitfolioseq"); - elementFolioSequentialsToXml(&m_elmt_unitfolio_max, &elmtfolioseq, "sequf_", "unitfolioseq", &document); - folioContainedAutonum.appendChild(elmtfolioseq); + folioSequentialsToXml(&m_elmt_unitfolio_max, &elmtfolioseq, "sequf_", "unitfolioseq", &document); + elmtfoliosequential.appendChild(elmtfolioseq); } if (!m_elmt_tenfolio_max.isEmpty()) { QDomElement elmtfolioseq = document.createElement("elementtenfolioseq"); - elementFolioSequentialsToXml(&m_elmt_tenfolio_max, &elmtfolioseq, "seqtf_", "tenfolioseq", &document); - folioContainedAutonum.appendChild(elmtfolioseq); + folioSequentialsToXml(&m_elmt_tenfolio_max, &elmtfolioseq, "seqtf_", "tenfolioseq", &document); + elmtfoliosequential.appendChild(elmtfolioseq); } if (!m_elmt_hundredfolio_max.isEmpty()) { QDomElement elmtfolioseq = document.createElement("elementhundredfolioseq"); - elementFolioSequentialsToXml(&m_elmt_hundredfolio_max, &elmtfolioseq, "seqhf_", "hundredfolioseq", &document); - folioContainedAutonum.appendChild(elmtfolioseq); + folioSequentialsToXml(&m_elmt_hundredfolio_max, &elmtfolioseq, "seqhf_", "hundredfolioseq", &document); + elmtfoliosequential.appendChild(elmtfolioseq); } - racine.appendChild(folioContainedAutonum); + racine.appendChild(elmtfoliosequential); + } + //Conductor Folio Sequential Variables + if (!m_cnd_unitfolio_max.isEmpty() || !m_cnd_tenfolio_max.isEmpty() || !m_cnd_hundredfolio_max.isEmpty()) { + QDomElement cndfoliosequential = document.createElement("conductorautonumfoliosequentials"); + QHash::iterator i; + if (!m_cnd_unitfolio_max.isEmpty()) { + QDomElement cndfolioseq = document.createElement("conductorunitfolioseq"); + folioSequentialsToXml(&m_cnd_unitfolio_max, &cndfolioseq, "sequf_", "unitfolioseq", &document); + cndfoliosequential.appendChild(cndfolioseq); + } + if (!m_cnd_tenfolio_max.isEmpty()) { + QDomElement cndfolioseq = document.createElement("conductortenfolioseq"); + folioSequentialsToXml(&m_cnd_tenfolio_max, &cndfolioseq, "seqtf_", "tenfolioseq", &document); + cndfoliosequential.appendChild(cndfolioseq); + } + if (!m_cnd_hundredfolio_max.isEmpty()) { + QDomElement cndfolioseq = document.createElement("conductorhundredfolioseq"); + folioSequentialsToXml(&m_cnd_hundredfolio_max, &cndfolioseq, "seqhf_", "hundredfolioseq", &document); + cndfoliosequential.appendChild(cndfolioseq); + } + racine.appendChild(cndfoliosequential); } } else { @@ -594,13 +616,13 @@ QDomDocument Diagram::toXml(bool whole_content) { } /** -+ * @brief Diagram::elementFolioSequentialsToXml -+ * Add element folio sequential to QDomElement ++ * @brief Diagram::folioSequentialsToXml ++ * Add folio sequential to QDomElement + * @param domElement to add attributes + * @param hash to retrieve content with content + * @param sequential type + */ -void Diagram::elementFolioSequentialsToXml(QHash *hash, QDomElement *domElement, QString seq_type, QString type, QDomDocument *doc) { +void Diagram::folioSequentialsToXml(QHash *hash, QDomElement *domElement, QString seq_type, QString type, QDomDocument *doc) { QHash::iterator i; for (i = hash->begin(); i != hash->end(); i++) { QDomElement folioseq = doc->createElement(type); @@ -702,9 +724,15 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf // Load Freeze New Element m_freeze_new_elements_ = root.attribute("freezeNewElement").toInt(); - elementFolioSequentialsFromXml(root, &m_elmt_unitfolio_max, "elementunitfolioseq","sequf_","unitfolioseq"); - elementFolioSequentialsFromXml(root, &m_elmt_tenfolio_max, "elementtenfolioseq","seqtf_", "tenfolioseq"); - elementFolioSequentialsFromXml(root, &m_elmt_hundredfolio_max, "elementhundredfolioseq","seqhf_", "hundredfolioseq"); + //Load Element Folio Sequential + folioSequentialsFromXml(root, &m_elmt_unitfolio_max, "elementunitfolioseq","sequf_","unitfolioseq", "elementautonumfoliosequentials"); + folioSequentialsFromXml(root, &m_elmt_tenfolio_max, "elementtenfolioseq","seqtf_", "tenfolioseq", "elementautonumfoliosequentials"); + folioSequentialsFromXml(root, &m_elmt_hundredfolio_max, "elementhundredfolioseq","seqhf_", "hundredfolioseq", "elementautonumfoliosequentials"); + + //Load Conductor Folio Sequential + folioSequentialsFromXml(root, &m_cnd_unitfolio_max, "conductorunitfolioseq","sequf_","unitfolioseq", "conductorautonumfoliosequentials"); + folioSequentialsFromXml(root, &m_cnd_tenfolio_max, "conductortenfolioseq","seqtf_","tenfolioseq", "conductorautonumfoliosequentials"); + folioSequentialsFromXml(root, &m_cnd_hundredfolio_max, "conductorhundredfolioseq","seqhf_","hundredfolioseq", "conductorautonumfoliosequentials"); } // if child haven't got a child, loading is finish (diagram is empty) @@ -879,16 +907,16 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf } /** - * @brief Diagram::elementFolioSequentialsFromXml - * Load element folio sequential from QDomElement + * @brief Diagram::folioSequentialsFromXml + * Load folio sequential from QDomElement * @param root containing all folio sequentials * @param hash to be loaded with content * @param folioSeq type * @param seq type * @param type of sequential */ -void Diagram::elementFolioSequentialsFromXml(const QDomElement &root, QHash* hash, QString folioSeq, QString seq, QString type) { - foreach (QDomElement folioSeqAutoNum, QET::findInDomElement(root, "elementautonumfoliosequentials", folioSeq)) { +void Diagram::folioSequentialsFromXml(const QDomElement &root, QHash* hash, QString folioSeq, QString seq, QString type, QString autonumFolioSeqType) { + foreach (QDomElement folioSeqAutoNum, QET::findInDomElement(root, autonumFolioSeqType, folioSeq)) { for(QDomElement folioseq = folioSeqAutoNum.firstChildElement(type); !folioseq.isNull(); folioseq = folioseq.nextSiblingElement(type)) { QString title = folioseq.attribute("title"); QStringList list; @@ -1154,22 +1182,19 @@ void Diagram::updateLabels() { * @param type to be treated * @param Numerotation Context to be manipulated */ -void Diagram::insertFolioSeqHash(QHash *hash, QString title, QString seq, QString type, NumerotationContext *nc) { - if (project()->elementAutoNumFormula().contains(seq)) { - QStringList max; - for (int i = 0; i < nc->size(); i++) { - if (nc->itemAt(i).at(0) == type) { - nc->replaceValue(i, QString::number(nc->itemAt(i).at(3).toInt())); - max.append(QString::number(nc->itemAt(i).at(3).toInt() - nc->itemAt(i).at(2).toInt())); - } +void Diagram::insertFolioSeqHash(QHash *hash, QString title, QString type, NumerotationContext *nc) { + QStringList max; + for (int i = 0; i < nc->size(); i++) { + if (nc->itemAt(i).at(0) == type) { + nc->replaceValue(i, QString::number(nc->itemAt(i).at(3).toInt())); + max.append(QString::number(nc->itemAt(i).at(3).toInt() - nc->itemAt(i).at(2).toInt())); } - hash->insert(title,max); - project()->addElementAutoNum(title,*nc); } + hash->insert(title,max); } /** - * @brief Diagram::loadElmtFolioSeqHash + * @brief Diagram::loadFolioSeqHash * This class loads all folio sequential variables * related to the current autonum * @param Hash to be accessed @@ -1178,8 +1203,7 @@ void Diagram::insertFolioSeqHash(QHash *hash, QString titl * @param type to be treated * @param Numerotation Context to be manipulated */ -void Diagram::loadElmtFolioSeqHash(QHash *hash, QString title, QString seq, QString type, NumerotationContext *nc) { - if (project()->elementAutoNumFormula().contains(seq)) { +void Diagram::loadFolioSeqHash(QHash *hash, QString title, QString type, NumerotationContext *nc) { int j = 0; for (int i = 0; i < nc->size(); i++) { if (nc->itemAt(i).at(0) == type) { @@ -1189,8 +1213,6 @@ void Diagram::loadElmtFolioSeqHash(QHash *hash, QString ti j++; } } - project()->addElementAutoNum(title,*nc); - } } /** @@ -1199,35 +1221,114 @@ void Diagram::loadElmtFolioSeqHash(QHash *hash, QString ti * to the current autonum */ void Diagram::loadElmtFolioSeq() { - //Element QString title = project()->elementCurrentAutoNum(); NumerotationContext nc = project()->elementAutoNum(title); + //Unit Folio if (m_elmt_unitfolio_max.isEmpty() || !m_elmt_unitfolio_max.contains(title)) { //Insert Initial Value - insertFolioSeqHash(&m_elmt_unitfolio_max,title,"%sequf_","unitfolio",&nc); + if (project()->elementAutoNumCurrentFormula().contains("%sequf_")) { + insertFolioSeqHash(&m_elmt_unitfolio_max,title,"unitfolio",&nc); + project()->addElementAutoNum(title,nc); + } } else if (m_elmt_unitfolio_max.contains(title)) { //Load Folio Current Value - loadElmtFolioSeqHash(&m_elmt_unitfolio_max,title,"%sequf_","unitfolio",&nc); + if (project()->elementAutoNumCurrentFormula().contains("%sequf_")) { + loadFolioSeqHash(&m_elmt_unitfolio_max,title,"unitfolio",&nc); + project()->addElementAutoNum(title,nc); + } } + //Ten Folio if (m_elmt_tenfolio_max.isEmpty() || !m_elmt_tenfolio_max.contains(title)) { //Insert Initial Value - insertFolioSeqHash(&m_elmt_tenfolio_max,title,"%seqtf_","tenfolio",&nc); + if (project()->elementAutoNumCurrentFormula().contains("%seqtf_")) { + insertFolioSeqHash(&m_elmt_tenfolio_max,title,"tenfolio",&nc); + project()->addElementAutoNum(title,nc); + } } else if (m_elmt_tenfolio_max.contains(title)) { //Load Folio Current Value - loadElmtFolioSeqHash(&m_elmt_tenfolio_max,title,"%seqtf_","tenfolio",&nc); + if (project()->elementAutoNumCurrentFormula().contains("%seqtf_")) { + loadFolioSeqHash(&m_elmt_tenfolio_max,title,"tenfolio",&nc); + project()->addElementAutoNum(title,nc); + } } + //Hundred Folio if (m_elmt_hundredfolio_max.isEmpty() || !m_elmt_hundredfolio_max.contains(title)) { //Insert Initial Value - insertFolioSeqHash(&m_elmt_hundredfolio_max,title,"%seqhf_","hundredfolio",&nc); + if (project()->elementAutoNumCurrentFormula().contains("%seqhf_")) { + insertFolioSeqHash(&m_elmt_hundredfolio_max,title,"hundredfolio",&nc); + project()->addElementAutoNum(title,nc); + } } else if (m_elmt_hundredfolio_max.contains(title)) { //Load Folio Current Value - loadElmtFolioSeqHash(&m_elmt_hundredfolio_max,title,"%seqhf_","hundredfolio",&nc); + if (project()->elementAutoNumCurrentFormula().contains("%seqhf_")) { + loadFolioSeqHash(&m_elmt_hundredfolio_max,title,"hundredfolio",&nc); + project()->addElementAutoNum(title,nc); + } + } +} + +/** + * @brief Diagram::loadCndFolioSeq + * This class loads all conductor folio sequential variables related + * to the current autonum + */ +void Diagram::loadCndFolioSeq() { + //Conductor + QString title = project()->conductorCurrentAutoNum(); + NumerotationContext nc = project()->conductorAutoNum(title); + + //Unit Folio + if (m_cnd_unitfolio_max.isEmpty() || !m_cnd_unitfolio_max.contains(title)) { + //Insert Initial Value + if (project()->conductorAutoNumCurrentFormula().contains("%sequf_")) { + insertFolioSeqHash(&m_cnd_unitfolio_max,title,"unitfolio",&nc); + project()->addConductorAutoNum(title,nc); + } + } + else if (m_cnd_unitfolio_max.contains(title)) { + //Load Folio Current Value + if (project()->conductorAutoNumCurrentFormula().contains("%sequf_")) { + loadFolioSeqHash(&m_cnd_unitfolio_max,title,"unitfolio",&nc); + project()->addConductorAutoNum(title,nc); + } + } + + //Ten Folio + if (m_cnd_tenfolio_max.isEmpty() || !m_cnd_tenfolio_max.contains(title)) { + //Insert Initial Value + if (project()->conductorAutoNumCurrentFormula().contains("%seqtf_")) { + insertFolioSeqHash(&m_cnd_tenfolio_max,title,"tenfolio",&nc); + project()->addConductorAutoNum(title,nc); + } + } + else if (m_cnd_tenfolio_max.contains(title)) { + //Load Folio Current Value + if (project()->conductorAutoNumCurrentFormula().contains("%seqtf_")) { + loadFolioSeqHash(&m_cnd_tenfolio_max,title,"tenfolio",&nc); + project()->addConductorAutoNum(title,nc); + } + } + + //Hundred Folio + if (m_cnd_hundredfolio_max.isEmpty() || !m_cnd_hundredfolio_max.contains(title)) { + //Insert Initial Value + if (project()->conductorAutoNumCurrentFormula().contains("%seqhf_")) { + insertFolioSeqHash(&m_cnd_hundredfolio_max,title,"hundredfolio",&nc); + project()->addConductorAutoNum(title,nc); + } + } + else if (m_cnd_hundredfolio_max.contains(title)) { + //Load Folio Current Value + if (project()->conductorAutoNumCurrentFormula().contains("%seqhf_")) { + loadFolioSeqHash(&m_cnd_hundredfolio_max,title,"hundredfolio",&nc); + project()->addConductorAutoNum(title,nc); + } } } diff --git a/sources/diagram.h b/sources/diagram.h index 628a34668..98d52f6a4 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -87,6 +87,10 @@ class Diagram : public QGraphicsScene QHash m_elmt_unitfolio_max; QHash m_elmt_tenfolio_max; QHash m_elmt_hundredfolio_max; + /// Hash containing max values for folio sequential autonums in this diagram + QHash m_cnd_unitfolio_max; + QHash m_cnd_tenfolio_max; + QHash m_cnd_hundredfolio_max; bool item_paste; private: @@ -158,8 +162,8 @@ class Diagram : public QGraphicsScene void write(const QDomElement &); bool wasWritten() const; QDomElement writeXml(QDomDocument &) const; - void elementFolioSequentialsToXml(QHash*, QDomElement *, QString, QString, QDomDocument *); - void elementFolioSequentialsFromXml(const QDomElement&, QHash*, QString, QString, QString); + void folioSequentialsToXml(QHash*, QDomElement *, QString, QString, QDomDocument *); + void folioSequentialsFromXml(const QDomElement&, QHash*, QString, QString, QString, QString); // methods related to graphics items addition/removal on the diagram void initElementsLinks(); @@ -216,9 +220,10 @@ class Diagram : public QGraphicsScene void unfreezeNew(); bool freezeNewElements(); - //methods related to insertion and loading of element folio sequential - void insertFolioSeqHash (QHash *hash, QString title, QString seq, QString type, NumerotationContext *nc); - void loadElmtFolioSeqHash (QHash *hash, QString title, QString seq, QString type, NumerotationContext *nc); + //methods related to insertion and loading of folio sequential + void insertFolioSeqHash (QHash *hash, QString title, QString seq, NumerotationContext *nc); + void loadFolioSeqHash (QHash *hash, QString title, QString seq, NumerotationContext *nc); + public slots: void adjustSceneRect (); @@ -229,6 +234,7 @@ class Diagram : public QGraphicsScene void setTitleBlockTemplate(const QString &); void updateLabels(); void loadElmtFolioSeq(); + void loadCndFolioSeq(); // methods related to graphics items selection void selectAll(); diff --git a/sources/diagramevent/diagrameventaddelement.cpp b/sources/diagramevent/diagrameventaddelement.cpp index 04acc6b0d..387a9b7dc 100644 --- a/sources/diagramevent/diagrameventaddelement.cpp +++ b/sources/diagramevent/diagrameventaddelement.cpp @@ -231,6 +231,7 @@ void DiagramEventAddElement::addElement() //Autonum the new conductor, the undo command associated for this, have for parent undo_object ConductorAutoNumerotation can (conductor, m_diagram, undo_object); can.numerate(); + conductor->setSeq = true; }; m_diagram -> undoStack().push(undo_object); element->setSequential(); diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 78e992f1d..4020c426b 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -83,6 +83,7 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : adjustSceneRect(); updateWindowTitle(); scene->loadElmtFolioSeq(); + scene->loadCndFolioSeq(); context_menu = new QMenu(this); paste_here = new QAction(QET::Icons::EditPaste, tr("Coller ici", "context menu action"), this); diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index ed94f8659..e4ac9c466 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -178,6 +178,7 @@ void ElementsMover::endMovement() //Autonum the new conductor, the undo command associated for this, have for parent undo_object ConductorAutoNumerotation can (conductor, diagram_, undo_object); can.numerate(); + conductor->setSeq = true; } }; } diff --git a/sources/numerotationcontextcommands.cpp b/sources/numerotationcontextcommands.cpp index 36f3c1635..7d00e4380 100644 --- a/sources/numerotationcontextcommands.cpp +++ b/sources/numerotationcontextcommands.cpp @@ -445,7 +445,7 @@ IdFolioNum::IdFolioNum (Diagram *d): */ QString IdFolioNum::toRepresentedString(const QString str) const { Q_UNUSED(str); - return (QString::number(diagram_ -> folioIndex() + 1)); + return ("%id"); } /** diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index b902d4611..42636e25e 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -28,7 +28,7 @@ #include "selectautonumw.h" #include "numerotationcontext.h" #include "folioautonumbering.h" -#include "elementautonumberingw.h" +#include "formulaautonumberingw.h" #include "autonumberingmanagementw.h" #include "ui_autonumberingmanagementw.h" @@ -483,15 +483,21 @@ void ProjectAutoNumConfigPage::saveContext_conductor() { // With the the name "No name" if (m_context_cb_conductor-> currentText() == tr("Nom de la nouvelle numérotation")) { project_->addConductorAutoNum (tr("Sans nom"), m_saw_conductor -> toNumContext()); + project()->addConductorAutoNumFormula (tr("Sans nom"), m_saw_conductor->formula()); //add hash + project()->setConductorAutoNumCurrentFormula (m_saw_conductor->formula(),tr("Sans nom")); //add last added conductor formula to current formula m_context_cb_conductor-> addItem(tr("Sans nom")); } // If the text isn't yet to the autonum of the project, add this new item to the combo box. else if ( !project_ -> conductorAutoNum().keys().contains( m_context_cb_conductor->currentText())) { project()->addConductorAutoNum(m_context_cb_conductor->currentText(), m_saw_conductor->toNumContext()); + project()->addConductorAutoNumFormula (m_context_cb_conductor->currentText(), m_saw_conductor->formula()); //add hash + project()->setConductorAutoNumCurrentFormula (m_saw_conductor->formula(),m_context_cb_conductor->currentText()); //add last added conductor formula to current formula m_context_cb_conductor-> addItem(m_context_cb_conductor->currentText()); } // Else, the text already exist in the autonum of the project, just update the context else { + project()->addConductorAutoNumFormula (m_context_cb_conductor->currentText(), m_saw_conductor->formula()); //add hash + project()->setConductorAutoNumCurrentFormula (m_saw_conductor->formula(), m_context_cb_conductor->currentText()); //add last added conductor formula to current formula project_->addConductorAutoNum (m_context_cb_conductor-> currentText(), m_saw_conductor -> toNumContext()); } project()->conductorAutoNumAdded(); @@ -530,22 +536,22 @@ void ProjectAutoNumConfigPage::saveContext_element() { // With the the name "No name" if (m_context_cb_element -> currentText() == tr("Nom de la nouvelle numérotation")) { project_->addElementAutoNum (tr("Sans nom"), m_saw_element -> toNumContext()); - project()->addElementAutoNumFormula (tr("Sans nom"), m_saw_element->elementFormula()); //add hash - project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula(),tr("Sans nom")); //add last added element formula to current formula + project()->addElementAutoNumFormula (tr("Sans nom"), m_saw_element->formula()); //add hash + project()->setElementAutoNumCurrentFormula (m_saw_element->formula(),tr("Sans nom")); //add last added element formula to current formula m_context_cb_element -> addItem(tr("Sans nom")); } // If the text isn't yet to the autonum of the project, add this new item to the combo box. else if ( !project_ -> elementAutoNum().keys().contains( m_context_cb_element->currentText())) { project()->addElementAutoNum(m_context_cb_element->currentText(), m_saw_element->toNumContext()); //add hash - project()->addElementAutoNumFormula (m_context_cb_element->currentText(), m_saw_element->elementFormula()); //add hash - project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula(),m_context_cb_element->currentText()); //add last added element formula to current formula + project()->addElementAutoNumFormula (m_context_cb_element->currentText(), m_saw_element->formula()); //add hash + project()->setElementAutoNumCurrentFormula (m_saw_element->formula(),m_context_cb_element->currentText()); //add last added element formula to current formula m_context_cb_element -> addItem(m_context_cb_element->currentText()); } // Else, the text already exist in the autonum of the project, just update the context else { project_->addElementAutoNum (m_context_cb_element -> currentText(), m_saw_element -> toNumContext()); //add hash - project()->addElementAutoNumFormula (m_context_cb_element->currentText(), m_saw_element->elementFormula()); //add hash - project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula(), m_context_cb_element->currentText()); //add last added element formula to current formula + project()->addElementAutoNumFormula (m_context_cb_element->currentText(), m_saw_element->formula()); //add hash + project()->setElementAutoNumCurrentFormula (m_saw_element->formula(), m_context_cb_element->currentText()); //add last added element formula to current formula } project()->elementAutoNumAdded(); } @@ -705,11 +711,12 @@ void ProjectAutoNumConfigPage::changeToTab(int i){ void ProjectAutoNumConfigPage::tabChanged(int i){ if (i>=1){ if (tab_widget->currentIndex() == 4){ - tab_widget->resize(480,tab_widget->height()); + tab_widget->resize(520,tab_widget->height()); } - else { - tab_widget->resize(475,tab_widget->height()); + else if (tab_widget->currentIndex() == 1 || tab_widget->currentIndex() == 2 ){ + tab_widget->resize(495,tab_widget->height()); } + else tab_widget->resize(475,tab_widget->height()); } else { tab_widget->resize(850,tab_widget->height()); diff --git a/sources/projectconfigpages.h b/sources/projectconfigpages.h index a1fbd84a6..38b3405b5 100644 --- a/sources/projectconfigpages.h +++ b/sources/projectconfigpages.h @@ -31,7 +31,7 @@ class SelectAutonumW; class QComboBox; class QPushButton; class FolioAutonumberingW; -class ElementAutonumberingW; +class FormulaAutonumberingW; class AutoNumberingManagementW; class QTabWidget; class QScrollArea; diff --git a/sources/projectview.cpp b/sources/projectview.cpp index f323595cf..234cab3f6 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -898,6 +898,7 @@ void ProjectView::loadDiagrams() { } this->currentDiagram()->diagram()->loadElmtFolioSeq(); + this->currentDiagram()->diagram()->loadCndFolioSeq(); // If project have the folios list, move it at the beginning of the project if (m_project -> getFolioSheetsQuantity()) { diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 8807abfc2..3ca3bfc76 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -28,6 +28,7 @@ #include "conductorautonumerotation.h" #include "conductorpropertiesdialog.h" #include "QPropertyUndoCommand/qpropertyundocommand.h" +#include "numerotationcontextcommands.h" #define PR(x) qDebug() << #x " = " << x; @@ -46,6 +47,7 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) : QGraphicsPathItem(0), terminal1(p1), terminal2(p2), + setSeq(true), bMouseOver(false), m_handler(10), text_item(0), @@ -509,7 +511,7 @@ Diagram *Conductor::diagram() const { return(qobject_cast(scene())); } -/** +/**4 @return le champ de texte associe a ce conducteur */ ConductorTextItem *Conductor::textItem() const { @@ -815,11 +817,36 @@ bool Conductor::fromXml(QDomElement &e) { text_item -> fromXml(e); ConductorProperties pr; pr.fromXml(e); + + //Load Sequential Values + loadSequential(&e,"sequ_",&seq_unit); + loadSequential(&e,"sequf_",&seq_unitfolio); + loadSequential(&e,"seqt_",&seq_ten); + loadSequential(&e,"seqtf_",&seq_tenfolio); + loadSequential(&e,"seqh_",&seq_hundred); + loadSequential(&e,"seqhf_",&seq_hundredfolio); + setProperties(pr); return return_; } +/** + Load Sequentials to display on conductor label + @param QDomElement to set Attributes + @param Qstring seq to be retrieved + @param QStringList list to be inserted values +*/ +void Conductor::loadSequential(QDomElement* e, QString seq, QStringList* list) { + //Load Sequential Values + int i = 0; + while (!e->attribute(seq + QString::number(i+1)).isEmpty()) { + list->append(e->attribute(seq + QString::number(i+1))); + i++; + } + setSeq = false; +} + /** Exporte les caracteristiques du conducteur sous forme d'une element XML. @param d Le document XML a utiliser pour creer l'element XML @@ -847,6 +874,37 @@ QDomElement Conductor::toXml(QDomDocument &d, QHash &table_adr_ e.appendChild(current_segment); } } + + // Save Conductor sequential values to Xml + // Save Unit Sequential Values + for (int i = 0; i < seq_unit.size(); i++) { + e.setAttribute("sequ_" + QString::number(i+1),seq_unit.at(i)); + } + + // Save UnitFolio Sequential Values + for (int i = 0; i < seq_unitfolio.size(); i++) { + e.setAttribute("sequf_" + QString::number(i+1),seq_unitfolio.at(i)); + } + + // Save Ten Sequential Values + for (int i = 0; i < seq_ten.size(); i++) { + e.setAttribute("seqt_" + QString::number(i+1),seq_ten.at(i)); + } + + // Save TenFolio Sequential Values + for (int i = 0; i < seq_tenfolio.size(); i++) { + e.setAttribute("seqtf_" + QString::number(i+1),seq_tenfolio.at(i)); + } + + // Save Hundred Sequential Values + for (int i = 0; i < seq_hundred.size(); i++) { + e.setAttribute("seqh_" + QString::number(i+1),seq_hundred.at(i)); + } + + // Save Hundred Sequential Values + for (int i = 0; i < seq_hundredfolio.size(); i++) { + e.setAttribute("seqhf_" + QString::number(i+1),seq_hundredfolio.at(i)); + } // Export the properties and text properties_. toXml(e); @@ -1205,6 +1263,7 @@ QString Conductor::assignVariables(QString label) { //The check below was introduced to avoid crash caused by the addition of terminal elements //Needs further debbugging. if (diagram() == NULL) return label; + //Titleblock Variables for (int i = 0; i < diagram()->border_and_titleblock.additionalFields().count(); i++) { @@ -1234,9 +1293,138 @@ QString Conductor::assignVariables(QString label) { label.replace("%F", diagram() -> border_and_titleblock.folio()); label.replace("%id", QString::number(diagram()->folioIndex()+1)); label.replace("%total", QString::number(diagram()->border_and_titleblock.folioTotal())); + label = assignSeq(label, this); return label; } +/** + * @brief Conductor::setSequential + * Set sequential values to conductor + */ +void Conductor::setSequential() { + if (diagram()==NULL) return; + QString conductor_currentAutoNum = diagram()->project()->conductorCurrentAutoNum(); + QString formula = diagram()->project()->conductorAutoNumCurrentFormula(); + QString label = this->text(); + NumerotationContext nc = diagram()->project()->conductorAutoNum(conductor_currentAutoNum); + NumerotationContextCommands ncc (nc); + if (!nc.isEmpty()) { + if (label.contains("%sequ_")) + setSequentialToList(&seq_unit,&nc,"unit"); + if (label.contains("%sequf_")) { + setSequentialToList(&seq_unitfolio,&nc,"unitfolio"); + setFolioSequentialToHash(&seq_unitfolio,&diagram()->m_cnd_unitfolio_max,conductor_currentAutoNum); + } + if (label.contains("%seqt_")) + setSequentialToList(&seq_ten,&nc,"ten"); + if (label.contains("%seqtf_")) { + setSequentialToList(&seq_tenfolio,&nc,"tenfolio"); + setFolioSequentialToHash(&seq_tenfolio,&diagram()->m_cnd_tenfolio_max,conductor_currentAutoNum); + } + if (label.contains("%seqh_")) + setSequentialToList(&seq_hundred,&nc,"hundred"); + if (label.contains("%seqhf_")) { + setSequentialToList(&seq_hundredfolio,&nc,"hundredfolio"); + setFolioSequentialToHash(&seq_hundredfolio,&diagram()->m_cnd_hundredfolio_max,conductor_currentAutoNum); + } + this->diagram()->project()->addConductorAutoNum(conductor_currentAutoNum,ncc.next()); + } +} + +/** + * @brief Conductor::setSequentialToList + * This class appends all sequential to selected list + * @param list to have values inserted + * @param nc to retrieve values from + * @param sequential type + */ +void Conductor::setSequentialToList(QStringList* list, NumerotationContext* nc, QString type) { + for (int i = 0; i < nc->size(); i++) { + if (nc->itemAt(i).at(0) == type) { + QString number; + if (type == "ten" || type == "tenfolio") + number = QString("%1").arg(nc->itemAt(i).at(1).toInt(), 2, 10, QChar('0')); + else if (type == "hundred" || type == "hundredfolio") + number = QString("%1").arg(nc->itemAt(i).at(1).toInt(), 3, 10, QChar('0')); + else number = QString::number(nc->itemAt(i).at(1).toInt()); + list->append(number); + } + } +} + +/** + * @brief Conductor::setFolioSequentialToHash + * This class inserts all conductors from list to hash + * @param list to retrieve values from + * @param hash to have values inserted + * @param current element autonum to insert on hash + */ +void Conductor::setFolioSequentialToHash(QStringList* list, QHash *hash, QString conductor_currentAutoNum) { + if (hash->isEmpty() || (!(hash->contains(conductor_currentAutoNum)))) { + QStringList max; + for (int i = 0; i < list->size(); i++) { + max.append(list->at(i)); + } + hash->insert(conductor_currentAutoNum,max); + } + else if (hash->contains(conductor_currentAutoNum)) { + //Load the String List and update it + QStringList max = hash->value(conductor_currentAutoNum); + for (int i = 0; i < list->size(); i++) { + if ((list->at(i).toInt()) > max.at(i).toInt()) { + max.replace(i,list->at(i)); + hash->remove(conductor_currentAutoNum); + hash->insert(conductor_currentAutoNum,max); + } + } + } +} + +/** + * @brief Conductor::assignSeq + * Replace sequential values to conductor label + * @param label to be replaced + * @return replaced label + */ +QString Conductor::assignSeq(QString label, Conductor* cnd) { + for (int i = 1; i <= qMax(qMax(qMax(cnd->seq_unitfolio.size(), cnd->seq_tenfolio.size()),qMax(cnd->seq_hundredfolio.size(),cnd->seq_unit.size())),qMax(cnd->seq_hundred.size(),cnd->seq_ten.size())); i++) { + if (label.contains("%sequ_" + QString::number(i)) && !cnd->seq_unit.isEmpty()) { + label.replace("%sequ_" + QString::number(i),cnd->seq_unit.at(i-1)); + } + if (label.contains("%seqt_" + QString::number(i)) && !cnd->seq_ten.isEmpty()) { + label.replace("%seqt_" + QString::number(i),cnd->seq_ten.at(i-1)); + } + if (label.contains("%seqh_" + QString::number(i)) && !cnd->seq_hundred.isEmpty()) { + label.replace("%seqh_" + QString::number(i),cnd->seq_hundred.at(i-1)); + } + if (label.contains("%sequf_" + QString::number(i)) && !cnd->seq_unitfolio.isEmpty()) { + label.replace("%sequf_" + QString::number(i),cnd->seq_unitfolio.at(i-1)); + } + if (label.contains("%seqtf_" + QString::number(i)) && !cnd->seq_tenfolio.isEmpty()) { + label.replace("%seqtf_" + QString::number(i),cnd->seq_tenfolio.at(i-1)); + } + if (label.contains("%seqhf_" + QString::number(i)) && !cnd->seq_hundredfolio.isEmpty()) { + label.replace("%seqhf_" + QString::number(i),cnd->seq_hundredfolio.at(i-1)); + } + } + return label; +} + +/** + * @brief Conductor::setOthersSequential + * Copy sequentials from conductor in argument to this conductor + * @param conductor to copy sequentials from + */ +void Conductor::setOthersSequential(Conductor *other) { + QString conductor_currentAutoNum = other->diagram()->project()->conductorCurrentAutoNum(); + NumerotationContext nc = other->diagram()->project()->conductorAutoNum(conductor_currentAutoNum); + seq_unit = other->seq_unit; + seq_unitfolio = other->seq_unitfolio; + seq_ten = other->seq_ten; + seq_tenfolio = other->seq_tenfolio; + seq_hundred = other->seq_hundred; + seq_hundredfolio = other->seq_hundredfolio; +} /** * @brief Conductor::setText @@ -1244,6 +1432,11 @@ QString Conductor::assignVariables(QString label) { * @param t */ void Conductor::setText(const QString &t) { + text_item->setPlainText(t); + if (setSeq) { + setSequential(); + setSeq = false; + } QString label = assignVariables(t); text_item -> setPlainText(label); } @@ -1271,7 +1464,6 @@ void Conductor::setProperties(const ConductorProperties &properties) other_properties.m_tension_protocol = properties_.m_tension_protocol; other_conductor->setProperties(other_properties); } - setText(properties_.text); text_item -> setFontSize(properties_.text_size); if (properties_.type != ConductorProperties::Multi) diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index 140b17cc2..1f9f3ce52 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -30,6 +30,7 @@ class ConductorSegment; class ConductorTextItem; class Element; class QETDiagramEditor; +class NumerotationContext; typedef QPair ConductorBend; typedef QHash ConductorProfilesGroup; /** @@ -94,6 +95,11 @@ class Conductor : public QObject, public QGraphicsPathItem QString text() const; QString assignVariables(QString) ; void setText(const QString &); + QString assignSeq (QString, Conductor*); + void setSequential (); + void setOthersSequential (Conductor *); + void setSequentialToList(QStringList*, NumerotationContext*, QString); + void setFolioSequentialToHash(QStringList*, QHash*, QString); public: static bool valideXml (QDomElement &); @@ -117,6 +123,14 @@ class Conductor : public QObject, public QGraphicsPathItem QSet relatedPotentialConductors(const bool all_diagram = true, QList *t_list=0); QETDiagramEditor* diagramEditor() const; void editProperty (); + // Lists containing Sequentials + QStringList seq_unit; + QStringList seq_unitfolio; + QStringList seq_ten; + QStringList seq_tenfolio; + QStringList seq_hundred; + QStringList seq_hundredfolio; + bool setSeq; public slots: void displayedTextChanged(); @@ -180,6 +194,7 @@ class Conductor : public QObject, public QGraphicsPathItem static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0); static Qt::Corner movementType(const QPointF &, const QPointF &); static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &); + void loadSequential(QDomElement* e, QString seq, QStringList* list); }; Conductor * longuestConductorInPotential (Conductor *conductor, bool all_diagram = false); diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 6f1765b9e..70ce84b9a 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -309,9 +309,9 @@ void CustomElement::parseLabels() { prefix = rxml.readElementText(); DiagramContext &dc = this->rElementInformations(); //if there is a formula to assign, assign it - if (!(location().project()->elementAutoNumFormula().isEmpty()) && (location().project()->elementAutoNumFormula() != "") && + if (!(location().project()->elementAutoNumCurrentFormula().isEmpty()) && (location().project()->elementAutoNumCurrentFormula() != "") && (this->linkType()!=Element::Slave) && (this->linkType()!=Element::Terminale)) { - QString formula = location().project()->elementAutoNumFormula(); + QString formula = location().project()->elementAutoNumCurrentFormula(); this->setPrefix(prefix); dc.addValue("label", formula); this->setTaggedText("label",formula); @@ -340,10 +340,10 @@ void CustomElement::parseLabels() { //that are already specified in the element label (inside .elmt file). This method is not called if elements //are being loaded at first time or being pasted else if ((this->taggedText("label")!= NULL) && (location().projectId()!=-1) && - (!location().project()->elementAutoNumFormula().isEmpty()) && + (!location().project()->elementAutoNumCurrentFormula().isEmpty()) && (this->linkType()!=Element::Slave) && (this->linkType()!=Element::Terminale) && !this->diagram()->item_paste) { - QString formula = location().project()->elementAutoNumFormula(); + QString formula = location().project()->elementAutoNumCurrentFormula(); DiagramContext &dc = this->rElementInformations(); QString prefix = this->taggedText("label")->toPlainText(); this->setPrefix(prefix); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index c467fac29..7f5a23b23 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -772,7 +772,7 @@ QString Element::assignVariables(QString label, Element *elmt){ void Element::setSequential() { DiagramContext &dc = this->rElementInformations(); QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum(); - QString formula = diagram()->project()->elementAutoNumFormula(); + QString formula = diagram()->project()->elementAutoNumCurrentFormula(); QString label = dc["label"].toString(); NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum); NumerotationContextCommands ncc (nc); diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index bc209ef8e..f3fb06d59 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -21,6 +21,7 @@ #include "qetgraphicsitem/conductor.h" #include "diagramcommands.h" #include "conductorautonumerotation.h" +#include "conductortextitem.h" QColor Terminal::neutralColor = QColor(Qt::blue); QColor Terminal::allowedColor = QColor(Qt::darkGreen); @@ -594,25 +595,35 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { use_properties = true; others_properties = (*conductors_list.begin())->properties(); - foreach (Conductor *conductor, conductors_list) + foreach (Conductor *conductor, conductors_list) { if (conductor->properties() != others_properties) use_properties = false; + } } QUndoCommand *undo = new AddItemCommand(new_conductor, diagram()); - if (use_properties) + if (use_properties) { + Conductor *other = conductors_list.toList().first(); + new_conductor->setSeq = false; + new_conductor->setOthersSequential(other); new_conductor->setProperties(others_properties); + } else { - //Autonum it + //Autonum it ConductorAutoNumerotation can (new_conductor, diagram(), undo); can.numerate(); + new_conductor->setSeq = true; } - - //Add undo command to the parent diagram + //Add undo command to the parent diagram diagram() -> undoStack().push(undo); + if (use_properties) { + Conductor *other = conductors_list.toList().first(); + new_conductor->setText(""); + new_conductor->setText(other->properties().text); + } } /** diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 718ac6afe..05b83f64c 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -424,6 +424,14 @@ QHash QETProject::elementAutoNumHash() { return m_element_autonum_formula; } +/** + * @brief QETProject::conductorAutoNumHash + * @return Title and Formula Hash + */ +QHash QETProject::conductorAutoNumHash() { + return m_conductor_autonum_formula; +} + /** * @brief QETProject::elementAutoNumFormula * @param element autonum title @@ -436,13 +444,32 @@ QString QETProject::elementAutoNumFormula (QString key) const { } /** - * @brief QETProject::elementAutoNumFormula + * @brief QETProject::conductorAutoNumFormula + * @param conductor autonum title + * @return Formula of element autonum stored in conductor autonum + */ +QString QETProject::conductorAutoNumFormula (QString key) const { + if (m_conductor_autonum.contains(key)) + return m_conductor_autonum_formula[key]; + else return ""; +} + +/** + * @brief QETProject::elementAutoNumCurrentFormula * @return current formula being used by project */ -QString QETProject::elementAutoNumFormula () const { +QString QETProject::elementAutoNumCurrentFormula() const { return m_current_element_formula; } +/** + * @brief QETProject::conductorAutoNumCurrentFormula + * @return current formula being used by project + */ +QString QETProject::conductorAutoNumCurrentFormula() const { + return m_current_conductor_formula; +} + /** * @brief QETProject::elementCurrentAutoNum * @return current element autonum title @@ -451,6 +478,14 @@ QString QETProject::elementCurrentAutoNum () const { return m_current_element_autonum; } +/** + * @brief QETProject::conductorCurrentAutoNum + * @return current element autonum title + */ +QString QETProject::conductorCurrentAutoNum () const { + return m_current_conductor_autonum; +} + /** * @brief QETProject::folioAutoNum * @return All value of folio autonum stored in project @@ -470,6 +505,26 @@ void QETProject::addConductorAutoNum(QString key, NumerotationContext context) { m_conductor_autonum.insert(key, context); } +/** + * @brief QETProject::addConductorAutoNumFormula + * Add the new formula + * @param formula + */ +void QETProject::addConductorAutoNumFormula(QString key, QString formula) { + m_conductor_autonum_formula.insert(key, formula); +} + +/** + * @brief QETProject::setConductorAutoNumCurrentFormula + * Add the formula and title to the current formula and current autonum + * @param formula + * @param title + */ +void QETProject::setConductorAutoNumCurrentFormula(QString formula, QString title) { + m_current_conductor_formula = formula; + m_current_conductor_autonum = title; +} + /** * @brief QETProject::addElementAutoNumFormula * Add the new formula @@ -1049,7 +1104,7 @@ QList QETProject::addNewDiagramFolioList() { diagram_folio_list -> border_and_titleblock.importTitleBlock(defaultTitleBlockProperties()); diagram_folio_list -> defaultConductorProperties = defaultConductorProperties(); - diagram_folio_list -> border_and_titleblock.setTitle(tr("Liste des Folios")); + diagram_folio_list -> border_and_titleblock.setTitle(tr("Liste des Folios")); // no need to display rows and columns diagram_folio_list -> border_and_titleblock.displayRows(false); diagram_folio_list -> border_and_titleblock.displayColumns(false); @@ -1353,11 +1408,14 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project) } if (!conds_autonums.isNull()) { + m_current_conductor_autonum = conds_autonums.attribute("current_autonum"); + m_current_conductor_formula = conds_autonums.attribute("current_formula"); foreach (QDomElement elmt, QET::findInDomElement(conds_autonums, "conductor_autonum")) { NumerotationContext nc; nc.fromXml(elmt); m_conductor_autonum.insert(elmt.attribute("title"), nc); + m_conductor_autonum_formula.insert(elmt.attribute("title"),elmt.attribute("formula")); } } if (!folio_autonums.isNull()) @@ -1434,14 +1492,19 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) { } xml_element.appendChild(xrefs_elmt); - //Export conductors autonums - QDomElement conds_autonums = xml_document.createElement("conductors_autonums"); + //Export Conductor Autonums + 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); foreach (QString key, conductorAutoNum().keys()) { - QDomElement cond_autonum = conductorAutoNum(key).toXml(xml_document, "conductor_autonum"); - cond_autonum.setAttribute("title", key); - conds_autonums.appendChild(cond_autonum); + QDomElement conductor_autonum = conductorAutoNum(key).toXml(xml_document, "conductor_autonum"); + if (key != "" && conductorAutoNumFormula(key) != "") { + conductor_autonum.setAttribute("title", key); + conductor_autonum.setAttribute("formula", conductorAutoNumFormula(key)); + conductor_autonums.appendChild(conductor_autonum); + } } - xml_element.appendChild(conds_autonums); + xml_element.appendChild(conductor_autonums); //Export Folio Autonums QDomElement folio_autonums = xml_document.createElement("folio_autonums"); diff --git a/sources/qetproject.h b/sources/qetproject.h index 202935869..b684218cf 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -109,8 +109,11 @@ class QETProject : public QObject QHash conductorAutoNum() const; QHash elementAutoNum() const; QHash elementAutoNumHash(); + QHash conductorAutoNumHash(); QHash folioAutoNum() const; void addConductorAutoNum (QString key, NumerotationContext context); + void addConductorAutoNumFormula (QString key, QString formula); + void setConductorAutoNumCurrentFormula (QString formula, QString title); void addElementAutoNum (QString key, NumerotationContext context); void addElementAutoNumFormula (QString key, QString formula); void setElementAutoNumCurrentFormula (QString formula, QString title); @@ -121,9 +124,14 @@ class QETProject : public QObject NumerotationContext conductorAutoNum(const QString &key) const; NumerotationContext folioAutoNum(const QString &key) const; NumerotationContext elementAutoNum(const QString &key); + + QString conductorAutoNumFormula(const QString key) const; //returns Formula + QString conductorAutoNumCurrentFormula() const; + QString conductorCurrentAutoNum() const; + QString elementAutoNumFormula(const QString key) const; //returns Formula - QString elementAutoNumFormula() const; - QString elementCurrentAutoNum () const; + QString elementAutoNumCurrentFormula() const; + QString elementCurrentAutoNum() const; void freezeExistentElementLabel(int,int); void freezeNewElementLabel(int,int); @@ -244,12 +252,15 @@ class QETProject : public QObject /// undo stack for this project QUndoStack *undo_stack_; /// Conductor auto numerotation - QHash m_conductor_autonum; + QHash m_conductor_autonum;//Title and NumContext hash + QHash m_conductor_autonum_formula;//Title and Formula hash + QString m_current_conductor_formula; + QString m_current_conductor_autonum; /// Folio auto numbering QHash m_folio_autonum; /// Element Auto Numbering - QHash m_element_autonum_formula; //Title and Formula hash QHash m_element_autonum; //Title and NumContext hash + QHash m_element_autonum_formula; //Title and Formula hash QString m_current_element_formula; QString m_current_element_autonum; /// Folio List Sheets quantity for this project. diff --git a/sources/ui/autonumberingdockwidget.cpp b/sources/ui/autonumberingdockwidget.cpp index 815437ae8..088f9a90d 100644 --- a/sources/ui/autonumberingdockwidget.cpp +++ b/sources/ui/autonumberingdockwidget.cpp @@ -153,7 +153,7 @@ void AutoNumberingDockWidget::setActive() { } //Element - QString element_formula = project_->elementAutoNumFormula(); + QString element_formula = project_->elementAutoNumCurrentFormula(); QString active_element_autonum = project_->elementCurrentAutoNum(); int el_index = ui->m_element_cb->findText(active_element_autonum); ui->m_element_cb->setCurrentIndex(el_index); @@ -191,7 +191,14 @@ void AutoNumberingDockWidget::conductorAutoNumChanged() { */ void AutoNumberingDockWidget::on_m_conductor_cb_activated(int) { QString current_autonum = ui->m_conductor_cb->currentText(); + QString current_formula = project_->conductorAutoNumFormula(current_autonum); + if (current_autonum != "") { + project_->setConductorAutoNumCurrentFormula(current_formula, current_autonum); + } + else + project_->setConductorAutoNumCurrentFormula("",""); projectview_->currentDiagram()->diagram()->setConductorsAutonumName(current_autonum); + projectview_->currentDiagram()->diagram()->loadCndFolioSeq(); } /** diff --git a/sources/ui/autonumberingmanagementw.cpp b/sources/ui/autonumberingmanagementw.cpp index a7aed1ba0..a410ffb2a 100644 --- a/sources/ui/autonumberingmanagementw.cpp +++ b/sources/ui/autonumberingmanagementw.cpp @@ -20,8 +20,8 @@ #include "numparteditorw.h" #include #include "numerotationcontextcommands.h" -#include "elementautonumberingw.h" -#include "ui_elementautonumberingw.h" +#include "formulaautonumberingw.h" +#include "ui_formulaautonumberingw.h" #include "qdebug.h" #include "qetproject.h" #include "diagram.h" diff --git a/sources/ui/folioautonumbering.ui b/sources/ui/folioautonumbering.ui index 2edd0101a..152309d90 100644 --- a/sources/ui/folioautonumbering.ui +++ b/sources/ui/folioautonumbering.ui @@ -6,7 +6,7 @@ 0 0 - 467 + 524 550 @@ -75,8 +75,8 @@ 0 0 - 448 - 498 + 504 + 495 @@ -110,7 +110,7 @@ - + 0 0 @@ -136,7 +136,7 @@ - + 0 0 @@ -149,7 +149,7 @@ - + 0 0 diff --git a/sources/ui/elementautonumberingw.cpp b/sources/ui/formulaautonumberingw.cpp similarity index 66% rename from sources/ui/elementautonumberingw.cpp rename to sources/ui/formulaautonumberingw.cpp index 04b5b06e3..e9c4d6be8 100644 --- a/sources/ui/elementautonumberingw.cpp +++ b/sources/ui/formulaautonumberingw.cpp @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with QElectroTech. If not, see . */ -#include "elementautonumberingw.h" -#include "ui_elementautonumberingw.h" +#include "formulaautonumberingw.h" +#include "ui_formulaautonumberingw.h" #include #include #include @@ -24,9 +24,9 @@ /** * Constructor */ -ElementAutonumberingW::ElementAutonumberingW(QWidget *parent) : +FormulaAutonumberingW::FormulaAutonumberingW(QWidget *parent) : QWidget(parent), - ui(new Ui::ElementAutonumberingW) + ui(new Ui::FormulaAutonumberingW) { ui->setupUi(this); @@ -36,39 +36,39 @@ ElementAutonumberingW::ElementAutonumberingW(QWidget *parent) : /** * Destructor */ -ElementAutonumberingW::~ElementAutonumberingW() +FormulaAutonumberingW::~FormulaAutonumberingW() { delete ui; } /** - * @brief ElementAutonumberingW::setContext + * @brief FormulaAutonumberingW::setContext * @param formula to be inserted into context */ -void ElementAutonumberingW::setContext(QString formula) { +void FormulaAutonumberingW::setContext(QString formula) { ui->m_formula_le->insert(formula); } /** - * @brief ElementAutonumberingW::clearContext + * @brief FormulaAutonumberingW::clearContext * @param clear formula line edit text */ -void ElementAutonumberingW::clearContext() { +void FormulaAutonumberingW::clearContext() { ui->m_formula_le->clear(); } /** - * @brief ElementAutonumberingW::formula + * @brief FormulaAutonumberingW::formula * @return formula to be stored into project */ -QString ElementAutonumberingW::formula() { +QString FormulaAutonumberingW::formula() { return ui->m_formula_le->text(); } /** - * @brief ElementAutonumberingW::on_m_formula_le_textChanged + * @brief FormulaAutonumberingW::on_m_formula_le_textChanged * Update Apply Button */ -void ElementAutonumberingW::on_m_formula_le_textChanged(QString text) { +void FormulaAutonumberingW::on_m_formula_le_textChanged(QString text) { emit (textChanged(text)); } diff --git a/sources/ui/elementautonumberingw.h b/sources/ui/formulaautonumberingw.h similarity index 81% rename from sources/ui/elementautonumberingw.h rename to sources/ui/formulaautonumberingw.h index b01e1d523..dde33545d 100644 --- a/sources/ui/elementautonumberingw.h +++ b/sources/ui/formulaautonumberingw.h @@ -15,15 +15,15 @@ You should have received a copy of the GNU General Public License along with QElectroTech. If not, see . */ -#ifndef ELEMENTAUTONUMBERINGW_H -#define ELEMENTAUTONUMBERINGW_H +#ifndef FORMULAAUTONUMBERINGW_H +#define FORMULAAUTONUMBERINGW_H #include class QAbstractButton; namespace Ui { - class ElementAutonumberingW; + class FormulaAutonumberingW; } /** @@ -32,18 +32,18 @@ namespace Ui { the user to overwrite it with a new formula. Formula is added while parsing label in customelement.cpp */ -class ElementAutonumberingW : public QWidget +class FormulaAutonumberingW : public QWidget { Q_OBJECT //METHODS public: - explicit ElementAutonumberingW(QWidget *parent = 0); - ~ElementAutonumberingW(); + explicit FormulaAutonumberingW(QWidget *parent = 0); + ~FormulaAutonumberingW(); QString formula(); void setContext(QString); void clearContext(); - Ui::ElementAutonumberingW *ui; + Ui::FormulaAutonumberingW *ui; private: @@ -62,4 +62,4 @@ class ElementAutonumberingW : public QWidget }; -#endif // ELEMENTAUTONUMBERINGW_H +#endif // FORMULAAUTONUMBERINGW_H diff --git a/sources/ui/elementautonumberingw.ui b/sources/ui/formulaautonumberingw.ui similarity index 92% rename from sources/ui/elementautonumberingw.ui rename to sources/ui/formulaautonumberingw.ui index 009a6f27c..4204a2325 100644 --- a/sources/ui/elementautonumberingw.ui +++ b/sources/ui/formulaautonumberingw.ui @@ -1,13 +1,13 @@ - ElementAutonumberingW - + FormulaAutonumberingW + 0 0 - 383 - 357 + 370 + 305 @@ -44,7 +44,7 @@ - + 0 0 @@ -88,8 +88,6 @@ -%c: Element Column -%F: Folio Name -%f or %id: Folio ID --%M: Machine --%LM: Location -%total: Total of folios You can also assign any other titleblock variable that you create. Text and number inputs are diff --git a/sources/ui/numparteditorw.cpp b/sources/ui/numparteditorw.cpp index 3bf9532ec..da8a48d9f 100644 --- a/sources/ui/numparteditorw.cpp +++ b/sources/ui/numparteditorw.cpp @@ -84,8 +84,8 @@ void NumPartEditorW::setVisibleItems() { << tr("Texte"); } else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") { - items << tr("Chiffre 1") << tr("Chiffre 01") - << tr("Chiffre 001") + items << tr("Chiffre 1") << tr("Chiffre 1 - Folio") << tr("Chiffre 01") + << tr("Chiffre 01 - Folio") << tr("Chiffre 001") << tr("Chiffre 001 - Folio") << tr("Texte") << tr("N° folio") << tr("Folio"); } else diff --git a/sources/ui/projectpropertiesdialog.cpp b/sources/ui/projectpropertiesdialog.cpp index d9d43259d..e122b5793 100644 --- a/sources/ui/projectpropertiesdialog.cpp +++ b/sources/ui/projectpropertiesdialog.cpp @@ -38,7 +38,7 @@ ProjectPropertiesDialog::ProjectPropertiesDialog(QETProject *project, QWidget *p connect(projectAutoNumConfigPage,SIGNAL(setAutoNum(QString)),newDiagramPage,SLOT(setFolioAutonum(QString))); connect(projectAutoNumConfigPage,SIGNAL(saveCurrentTbp()),newDiagramPage,SLOT(saveCurrentTbp())); connect(projectAutoNumConfigPage,SIGNAL(loadSavedTbp()),newDiagramPage,SLOT(loadSavedTbp())); - m_properties_dialog->setMinimumHeight(690); + m_properties_dialog->setMinimumHeight(690); } diff --git a/sources/ui/selectautonumw.cpp b/sources/ui/selectautonumw.cpp index d8d4fec5f..3b4aa2aef 100644 --- a/sources/ui/selectautonumw.cpp +++ b/sources/ui/selectautonumw.cpp @@ -20,8 +20,8 @@ #include "numparteditorw.h" #include #include "numerotationcontextcommands.h" -#include "elementautonumberingw.h" -#include "ui_elementautonumberingw.h" +#include "formulaautonumberingw.h" +#include "ui_formulaautonumberingw.h" #include "qdebug.h" /** @@ -34,8 +34,13 @@ SelectAutonumW::SelectAutonumW(QWidget *parent) : ui->setupUi(this); if (this->parentWidget() -> objectName()=="ElementTab"){ - m_eaw = new ElementAutonumberingW(); - ui->scrollAreaWidgetContents->layout()->addWidget(m_eaw); + m_feaw = new FormulaAutonumberingW(); + ui->scrollAreaWidgetContents->layout()->addWidget(m_feaw); + } + else if (this->parentWidget() -> objectName()=="ConductorTab"){ + m_fcaw = new FormulaAutonumberingW(); + m_fcaw->ui->label->setHidden(true); + ui->scrollAreaWidgetContents->layout()->addWidget(m_fcaw); } setContext(NumerotationContext()); } @@ -45,8 +50,13 @@ SelectAutonumW::SelectAutonumW(const NumerotationContext &context, QWidget *pare ui(new Ui::SelectAutonumW) { if (this->parentWidget() -> objectName()=="ElementTab"){ - m_eaw = new ElementAutonumberingW(); - ui->scrollAreaWidgetContents->layout()->addWidget(m_eaw); + m_feaw = new FormulaAutonumberingW(); + ui->scrollAreaWidgetContents->layout()->addWidget(m_feaw); + } + else if (this->parentWidget() -> objectName()=="ConductorTab"){ + m_fcaw = new FormulaAutonumberingW(); + m_fcaw->ui->label->setHidden(true); + ui->scrollAreaWidgetContents->layout()->addWidget(m_fcaw); } ui->setupUi(this); setContext(context); @@ -130,11 +140,15 @@ void SelectAutonumW::on_remove_button_clicked() { } /** - * @brief SelectAutonumW::elementFormula - * @return element autonumbering widget formula + * @brief SelectAutonumW::formula + * @return autonumbering widget formula */ -QString SelectAutonumW::elementFormula() { - return m_eaw->formula(); +QString SelectAutonumW::formula() { + if (this->parentWidget() -> objectName()=="ElementTab") + return m_feaw->formula(); + else if (this->parentWidget() ->objectName()=="ConductorTab") + return m_fcaw->formula(); + else return ""; } /** @@ -222,6 +236,8 @@ void SelectAutonumW::applyEnable(bool b) { } if (this->parentWidget() -> objectName()=="ElementTab") contextToFormula(); + if (this->parentWidget()->objectName()=="ConductorTab") + contextToFormula(); } /** @@ -229,7 +245,12 @@ void SelectAutonumW::applyEnable(bool b) { * Apply formula to ElementAutonumbering Widget */ void SelectAutonumW::contextToFormula() { - m_eaw->clearContext(); + FormulaAutonumberingW* m_faw; + if (this->parentWidget() -> objectName()=="ElementTab") + m_faw = m_feaw; + if (this->parentWidget()->objectName()=="ConductorTab") + m_faw = m_fcaw; + m_faw->clearContext(); int count_unit = 0; int count_unitf = 0; int count_ten = 0; @@ -239,54 +260,54 @@ void SelectAutonumW::contextToFormula() { foreach (NumPartEditorW *npe, num_part_list_) { if (npe->isValid()) { if (npe->type_ == NumPartEditorW::idfolio) { - m_eaw->setContext("%id"); + m_faw->setContext("%id"); } else if (npe->type_ == NumPartEditorW::folio) { - m_eaw->setContext("%F"); + m_faw->setContext("%F"); } else if (npe->type_ == NumPartEditorW::machine) { - m_eaw->setContext("%M"); + m_faw->setContext("%M"); } else if (npe->type_ == NumPartEditorW::locmach) { - m_eaw->setContext("%LM"); + m_faw->setContext("%LM"); } else if (npe->type_ == NumPartEditorW::elementcolumn) { - m_eaw->setContext("%c"); + m_faw->setContext("%c"); } else if (npe->type_ == NumPartEditorW::elementline) { - m_eaw->setContext("%l"); + m_faw->setContext("%l"); } else if (npe->type_ == NumPartEditorW::elementprefix) { - m_eaw->setContext("%prefix"); + m_faw->setContext("%prefix"); } else if (npe->type_ == NumPartEditorW::string) { - m_eaw->setContext(npe->toNumContext().itemAt(0).at(1)); + m_faw->setContext(npe->toNumContext().itemAt(0).at(1)); } else if (npe->type_ == NumPartEditorW::unit) { count_unit++; - m_eaw->setContext("%sequ_"+QString::number(count_unit)); + m_faw->setContext("%sequ_"+QString::number(count_unit)); } else if (npe->type_ == NumPartEditorW::unitfolio) { count_unitf++; - m_eaw->setContext("%sequf_"+QString::number(count_unitf)); + m_faw->setContext("%sequf_"+QString::number(count_unitf)); } else if (npe->type_ == NumPartEditorW::ten) { count_ten++; - m_eaw->setContext("%seqt_"+QString::number(count_ten)); + m_faw->setContext("%seqt_"+QString::number(count_ten)); } else if (npe->type_ == NumPartEditorW::tenfolio) { count_tenf++; - m_eaw->setContext("%seqtf_"+QString::number(count_tenf)); + m_faw->setContext("%seqtf_"+QString::number(count_tenf)); } else if (npe->type_ == NumPartEditorW::hundred) { count_hundred++; - m_eaw->setContext("%seqh_"+QString::number(count_hundred)); + m_faw->setContext("%seqh_"+QString::number(count_hundred)); } else if (npe->type_ == NumPartEditorW::hundredfolio) { count_hundredf++; - m_eaw->setContext("%seqhf_"+QString::number(count_hundredf)); + m_faw->setContext("%seqhf_"+QString::number(count_hundredf)); } } } diff --git a/sources/ui/selectautonumw.h b/sources/ui/selectautonumw.h index c81fc1324..37c61536f 100644 --- a/sources/ui/selectautonumw.h +++ b/sources/ui/selectautonumw.h @@ -20,10 +20,11 @@ #include #include "numerotationcontext.h" -#include "elementautonumberingw.h" +#include "formulaautonumberingw.h" class NumPartEditorW; class QAbstractButton; +class FormulaAutonumberingW; namespace Ui { class SelectAutonumW; @@ -42,7 +43,7 @@ class SelectAutonumW : public QWidget void setContext (const NumerotationContext &context); NumerotationContext toNumContext() const; void contextToFormula (); - QString elementFormula(); + QString formula(); signals: void applyPressed(); @@ -65,7 +66,8 @@ class SelectAutonumW : public QWidget Ui::SelectAutonumW *ui; QList num_part_list_; NumerotationContext m_context; - ElementAutonumberingW *m_eaw; + FormulaAutonumberingW *m_feaw; + FormulaAutonumberingW *m_fcaw; }; #endif // SELECTAUTONUMW_H diff --git a/sources/ui/selectautonumw.ui b/sources/ui/selectautonumw.ui index 6c333f0d4..ebff5388c 100644 --- a/sources/ui/selectautonumw.ui +++ b/sources/ui/selectautonumw.ui @@ -224,7 +224,7 @@ Type - Qt::AlignCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -234,7 +234,7 @@ Valeur - Qt::AlignCenter + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -250,7 +250,7 @@ Incrémentation - Qt::AlignCenter + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter