diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 272eb9c47..5a0a689d0 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2016 The QElectroTech Team This file is part of QElectroTech. @@ -37,6 +37,7 @@ #include "qetapp.h" #include "elementcollectionhandler.h" #include "element.h" +#include "diagramview.h" const int Diagram::xGrid = 10; const int Diagram::yGrid = 10; @@ -79,6 +80,7 @@ Diagram::Diagram(QETProject *project) : connect(&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(titleChanged(const QString &))); connect(&border_and_titleblock, SIGNAL(borderChanged(QRectF,QRectF)), this, SLOT(adjustSceneRect())); connect(&border_and_titleblock, SIGNAL(titleBlockFolioChanged()), this, SLOT(updateLabels())); + connect(this, SIGNAL (diagramActivated()), this, SLOT(loadElmtFolioSeq())); adjustSceneRect(); } @@ -473,6 +475,28 @@ QDomDocument Diagram::toXml(bool whole_content) { //Default New Element racine.setAttribute("freezeNewElement", m_freeze_new_elements_ ? "true" : "false"); + + //Folio Sequential Variables + if (!m_elmt_unitfolio_max.isEmpty() || !m_elmt_tenfolio_max.isEmpty() || !m_elmt_hundredfolio_max.isEmpty()) { + QDomElement folioContainedAutonum = document.createElement("elementautonumfoliosequentials"); + QHash::iterator i; + if (!m_elmt_unitfolio_max.isEmpty()) { + QDomElement elmtfolioseq = document.createElement("elementunitfolioseq"); + elementFolioSequentialsToXml(&m_elmt_unitfolio_max, &elmtfolioseq, "sequf_"); + folioContainedAutonum.appendChild(elmtfolioseq); + } + if (!m_elmt_tenfolio_max.isEmpty()) { + QDomElement elmtfolioseq = document.createElement("elementtenfolioseq"); + elementFolioSequentialsToXml(&m_elmt_tenfolio_max, &elmtfolioseq, "seqtf_"); + folioContainedAutonum.appendChild(elmtfolioseq); + } + if (!m_elmt_hundredfolio_max.isEmpty()) { + QDomElement elmtfolioseq = document.createElement("elementhundredfolioseq"); + elementFolioSequentialsToXml(&m_elmt_hundredfolio_max, &elmtfolioseq, "seqhf_"); + folioContainedAutonum.appendChild(elmtfolioseq); + } + racine.appendChild(folioContainedAutonum); + } } else { //this method with whole_content to false, @@ -569,6 +593,23 @@ QDomDocument Diagram::toXml(bool whole_content) { return(document); } +/** ++ * @brief Diagram::elementFolioSequentialsToXml ++ * Add element 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) { + QHash::iterator i; + for (i = hash->begin(); i != hash->end(); i++) { + domElement->setAttribute("title", i.key()); + for (int j = 0; j < i.value().size(); j++) { + domElement->setAttribute(seq_type + QString::number(j+1), i.value().at(j)); + } + } +} + /** Importe le schema decrit dans un document XML. Si une position est precisee, les elements importes sont positionnes de maniere a ce que le @@ -658,8 +699,12 @@ 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_"); + elementFolioSequentialsFromXml(root, &m_elmt_tenfolio_max, "elementtenfolioseq","seqtf_"); + elementFolioSequentialsFromXml(root, &m_elmt_hundredfolio_max, "elementhundredfolioseq","seqhf_"); } - + // if child haven't got a child, loading is finish (diagram is empty) if (root.firstChild().isNull()) { write(document); @@ -831,6 +876,27 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf return(true); } +/** + * @brief Diagram::elementFolioSequentialsFromXml + * Load element folio sequential from QDomElement + * @param root containing all folio sequentials + * @param hash to be loaded with content + * @param folioSeq type + * @param seq type + */ +void Diagram::elementFolioSequentialsFromXml(const QDomElement &root, QHash* hash, QString folioSeq, QString seq) { + foreach (QDomElement folioSeqAutoNum, QET::findInDomElement(root, "elementautonumfoliosequentials", folioSeq)) { + QString title = folioSeqAutoNum.attribute("title"); + QStringList unit; + int i = 1; + while (folioSeqAutoNum.hasAttribute(seq + QString::number(i))) { + unit << folioSeqAutoNum.attribute(seq + QString::number(i)); + i++; + } + hash->insert(title,unit); + } +} + /** Enregistre le schema XML dans son document XML interne et emet le signal written(). @@ -1073,6 +1139,93 @@ void Diagram::updateLabels() { } } +/** + * @brief Diagram::insertFolioSeqHash + * This class inserts a stringlist containing all + * sequential variables related to an autonum in a QHash + * @param Hash to be accessed + * @param autonum title + * @param sequential to be treated + * @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())); + } + } + hash->insert(title,max); + project()->addElementAutoNum(title,*nc); + } +} + +/** + * @brief Diagram::loadElmtFolioSeqHash + * This class loads all folio sequential variables + * related to the current autonum + * @param Hash to be accessed + * @param autonum title + * @param sequential to be treated + * @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)) { + int j = 0; + for (int i = 0; i < nc->size(); i++) { + if (nc->itemAt(i).at(0) == type) { + QString new_value; + new_value = QString::number(hash->value(title).at(j).toInt() + nc->itemAt(i).at(2).toInt()); + nc->replaceValue(i,new_value); + j++; + } + } + project()->addElementAutoNum(title,*nc); + } +} + +/** + * @brief Diagram::loadElmtFolioSeq + * This class loads all folio sequential variables related + * 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); + } + else if (m_elmt_unitfolio_max.contains(title)) { + //Load Folio Current Value + loadElmtFolioSeqHash(&m_elmt_unitfolio_max,title,"%sequf_","unitfolio",&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); + } + else if (m_elmt_tenfolio_max.contains(title)) { + //Load Folio Current Value + loadElmtFolioSeqHash(&m_elmt_tenfolio_max,title,"%seqtf_","tenfolio",&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); + } + else if (m_elmt_hundredfolio_max.contains(title)) { + //Load Folio Current Value + loadElmtFolioSeqHash(&m_elmt_hundredfolio_max,title,"%seqhf_","hundredfolio",&nc); + } +} + /** @return le titre du cartouche */ diff --git a/sources/diagram.h b/sources/diagram.h index 52c7c6679..7af8efc93 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -83,6 +83,10 @@ class Diagram : public QGraphicsScene static const qreal margin; /// background color of diagram static QColor background_color; + /// Hash containing max values for folio sequential autonums in this diagram + QHash m_elmt_unitfolio_max; + QHash m_elmt_tenfolio_max; + QHash m_elmt_hundredfolio_max; private: QGraphicsLineItem *conductor_setter_; @@ -153,8 +157,10 @@ class Diagram : public QGraphicsScene void write(const QDomElement &); bool wasWritten() const; QDomElement writeXml(QDomDocument &) const; - - // methods related to graphics items addition/removal on the diagram + void elementFolioSequentialsToXml(QHash*, QDomElement *, QString); + void elementFolioSequentialsFromXml(const QDomElement&, QHash*, QString, QString); + + // methods related to graphics items addition/removal on the diagram void initElementsLinks(); virtual void addItem (QGraphicsItem *item); virtual void removeItem (QGraphicsItem *item); @@ -202,12 +208,17 @@ class Diagram : public QGraphicsScene QUndoStack &undoStack(); QGIManager &qgiManager(); + //methods related to element label Update Policy void freezeElements(); void unfreezeElements(); void freezeNew(); 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); + public slots: void adjustSceneRect (); void titleChanged(const QString &); @@ -216,6 +227,7 @@ class Diagram : public QGraphicsScene void titleBlockTemplateRemoved(const QString &, const QString & = QString()); void setTitleBlockTemplate(const QString &); void updateLabels(); + void loadElmtFolioSeq(); // methods related to graphics items selection void selectAll(); @@ -231,6 +243,7 @@ class Diagram : public QGraphicsScene void editElementRequired(const ElementsLocation &); /// Signal emitted when users wish to edit an element from the diagram void reportPropertiesChanged(QString); void XRefPropertiesChanged(); + void diagramActivated(); }; Q_DECLARE_METATYPE(Diagram *) diff --git a/sources/diagramevent/diagrameventaddelement.cpp b/sources/diagramevent/diagrameventaddelement.cpp index a3a65e300..04acc6b0d 100644 --- a/sources/diagramevent/diagrameventaddelement.cpp +++ b/sources/diagramevent/diagrameventaddelement.cpp @@ -233,7 +233,7 @@ void DiagramEventAddElement::addElement() can.numerate(); }; m_diagram -> undoStack().push(undo_object); - element->setSeq(); + element->setSequential(); element->freezeNewAddedElement(); element->updateLabel(); } diff --git a/sources/numerotationcontext.cpp b/sources/numerotationcontext.cpp index 4ced5cf49..169360887 100644 --- a/sources/numerotationcontext.cpp +++ b/sources/numerotationcontext.cpp @@ -45,13 +45,13 @@ void NumerotationContext::clear () { * @param increase the increase number of value * @return true if value is append */ -bool NumerotationContext::addValue(const QString &type, const QVariant &value, const int increase) { +bool NumerotationContext::addValue(const QString &type, const QVariant &value, const int increase, const int initialvalue) { if (!keyIsAcceptable(type) && !value.canConvert(QVariant::String)) return false; if (keyIsNumber(type) && !value.canConvert(QVariant::Int)) return false; QString valuestr = value.toString(); valuestr.remove("|"); - content_ << type + "|" + valuestr + "|" + QString::number(increase); + content_ << type + "|" + valuestr + "|" + QString::number(increase) + "|" + QString::number(initialvalue); return true; } @@ -99,7 +99,7 @@ QStringList NumerotationContext::itemAt(const int i) const { * @return all type use to numerotation */ QString NumerotationContext::validRegExpNum () const { - return ("unit|ten|hundred|string|idfolio|folio|elementline|elementcolumn|elementprefix"); + return ("unit|unitfolio|ten|hundred|string|idfolio|folio|elementline|elementcolumn|elementprefix"); } /** @@ -107,7 +107,7 @@ QString NumerotationContext::validRegExpNum () const { * @return all type represents a number */ QString NumerotationContext::validRegExpNumber() const { - return ("unit|ten|hundred"); + return ("unit|unitfolio|ten|hundred"); } /** @@ -138,6 +138,11 @@ QDomElement NumerotationContext::toXml(QDomDocument &d, QString str) { part.setAttribute("type", strl.at(0)); part.setAttribute("value", strl.at(1)); part.setAttribute("increase", strl.at(2)); + if (strl.at(0) == ("unitfolio") || + strl.at(0) == ("tenfolio") || + strl.at(0) == ("hundredfolio")) { + part.setAttribute("initialvalue", strl.at(3)); + } num_auto.appendChild(part); } return num_auto; @@ -149,5 +154,20 @@ QDomElement NumerotationContext::toXml(QDomDocument &d, QString str) { */ void NumerotationContext::fromXml(QDomElement &e) { clear(); - foreach(QDomElement qde, QET::findInDomElement(e, "part")) addValue(qde.attribute("type"), qde.attribute("value"), qde.attribute("increase").toInt()); + foreach(QDomElement qde, QET::findInDomElement(e, "part")) addValue(qde.attribute("type"), qde.attribute("value"), qde.attribute("increase").toInt(), qde.attribute("initialvalue").toInt()); +} + +/** + * @brief NumerotationContext::replaceValue + * This class replaces the current NC field value with content + * @param index of NC Item + * @param QString content to replace current value + */ +void NumerotationContext::replaceValue(int index, QString content) { + QString sep = "|"; + QString type = content_[index].split("|").at(0); + QString value = content; + QString increase = content_[index].split("|").at(2); + QString initvalue = content_[index].split("|").at(3); + content_[index].replace(content_[index], type + "|" + value + "|" + increase + "|" + initvalue); } diff --git a/sources/numerotationcontext.h b/sources/numerotationcontext.h index 011e8af65..152012b5a 100644 --- a/sources/numerotationcontext.h +++ b/sources/numerotationcontext.h @@ -33,7 +33,7 @@ class NumerotationContext NumerotationContext (); NumerotationContext (QDomElement &); void clear(); - bool addValue(const QString &, const QVariant & = QVariant(1), const int = 1); + bool addValue(const QString &, const QVariant & = QVariant(1), const int = 1, const int = 0); QString operator[] (const int &) const; void operator << (const NumerotationContext &); int size() const; @@ -45,6 +45,7 @@ class NumerotationContext bool keyIsNumber(const QString &) const; QDomElement toXml(QDomDocument &, QString); void fromXml(QDomElement &); + void replaceValue(int, QString); private: QStringList content_; diff --git a/sources/numerotationcontextcommands.cpp b/sources/numerotationcontextcommands.cpp index a4914b6ea..42ad962fb 100644 --- a/sources/numerotationcontextcommands.cpp +++ b/sources/numerotationcontextcommands.cpp @@ -92,14 +92,26 @@ void NumerotationContextCommands::setNumStrategy(const QString &str) { strategy_ = new UnitNum(diagram_); return; } + else if (str == "unitfolio") { + strategy_ = new UnitFNum (diagram_); + return; + } else if (str == "ten") { strategy_ = new TenNum (diagram_); return; } + else if (str == "tenfolio") { + strategy_ = new TenFNum (diagram_); + return; + } else if (str == "hundred") { strategy_ = new HundredNum (diagram_); return; } + else if (str == "hundredfolio") { + strategy_ = new HundredFNum (diagram_); + return; + } else if (str == "string") { strategy_ = new StringNum (diagram_); return; @@ -156,7 +168,7 @@ NumerotationContext NumStrategy::nextNumber (const NumerotationContext &nc, cons QStringList strl = nc.itemAt(i); NumerotationContext newnc; QString value = QString::number( (strl.at(1).toInt()) + (strl.at(2).toInt()) ); - newnc.addValue(strl.at(0), value, strl.at(2).toInt()); + newnc.addValue(strl.at(0), value, strl.at(2).toInt(), strl.at(3).toInt()); return (newnc); } @@ -168,7 +180,7 @@ NumerotationContext NumStrategy::previousNumber(const NumerotationContext &nc, c QStringList strl = nc.itemAt(i); NumerotationContext newnc; QString value = QString::number( (strl.at(1).toInt()) - (strl.at(2).toInt()) ); - newnc.addValue(strl.at(0), value, strl.at(2).toInt()); + newnc.addValue(strl.at(0), value, strl.at(2).toInt(), strl.at(3).toInt()); return (newnc); } @@ -203,6 +215,37 @@ NumerotationContext UnitNum::previous(const NumerotationContext &nc, const int i return (previousNumber(nc, i)); } +/** + * Constructor + */ +UnitFNum::UnitFNum(Diagram *d): + NumStrategy(d) +{} + +/** + * @brief UnitFNum::toRepresentedString + * @return the represented string of num + */ +QString UnitFNum::toRepresentedString(const QString num) const { + return (num); +} + +/** + * @brief UnitFNum::next + * @return the next NumerotationContext nc at position i + */ +NumerotationContext UnitFNum::next (const NumerotationContext &nc, const int i) const { + return (nextNumber(nc, i)); +} + +/** + * @brief UnitFNum::previous + * @return the previous NumerotationContext nc at posiiton i + */ +NumerotationContext UnitFNum::previous(const NumerotationContext &nc, const int i) const { + return (previousNumber(nc, i)); +} + /** * Constructor */ @@ -237,6 +280,41 @@ NumerotationContext TenNum::previous(const NumerotationContext &nc, const int i) return (previousNumber(nc, i)); } +/** + * Constructor + */ +TenFNum::TenFNum (Diagram *d): + NumStrategy (d) +{} + +/** + * @brief TenFNum::toRepresentedString + * @return the represented string of num + */ +QString TenFNum::toRepresentedString(const QString num) const { + int numint = num.toInt(); + QString numstr = num; + if (numint<10) numstr.prepend("0"); + return (numstr); +} + +/** + * @brief TenFNum::next + * @return the next NumerotationContext nc at position i + */ +NumerotationContext TenFNum::next (const NumerotationContext &nc, const int i) const { + return (nextNumber(nc, i)); +} + +/** + * @brief TenFNum::previous + * @return the previous NumerotationContext nc at posiiton i + */ +NumerotationContext TenFNum::previous(const NumerotationContext &nc, const int i) const { + return (previousNumber(nc, i)); +} + + /** * Constructor */ @@ -276,6 +354,45 @@ NumerotationContext HundredNum::previous(const NumerotationContext &nc, const in return (previousNumber(nc, i)); } +/** + * Constructor + */ +HundredFNum::HundredFNum (Diagram *d): + NumStrategy (d) +{} + +/** + * @brief HundredFNum::toRepresentedString + * @return the represented string of num + */ +QString HundredFNum::toRepresentedString(const QString num) const { + int numint = num.toInt(); + QString numstr = num; + if (numint<100) { + if (numint<10) { + numstr.prepend("00"); + } + else numstr.prepend("0"); + } + return (numstr); +} + +/** + * @brief HundredFNum::next + * @return the next NumerotationContext nc at position i + */ +NumerotationContext HundredFNum::next (const NumerotationContext &nc, const int i) const { + return (nextNumber(nc, i)); +} + +/** + * @brief HundredFNum::previous + * @return the previous NumerotationContext nc at posiiton i + */ +NumerotationContext HundredFNum::previous(const NumerotationContext &nc, const int i) const { + return (previousNumber(nc, i)); +} + /** * Constructor */ @@ -352,7 +469,7 @@ FolioNum::FolioNum (Diagram *d): */ QString FolioNum::toRepresentedString(const QString str) const { Q_UNUSED(str); - return (diagram_->border_and_titleblock.folio()); + return ("%F"); } /** diff --git a/sources/numerotationcontextcommands.h b/sources/numerotationcontextcommands.h index 3811c03c0..ce0541105 100644 --- a/sources/numerotationcontextcommands.h +++ b/sources/numerotationcontextcommands.h @@ -69,6 +69,15 @@ class UnitNum: public NumStrategy NumerotationContext previous (const NumerotationContext &, const int) const; }; +class UnitFNum: public NumStrategy +{ + public: + UnitFNum (Diagram *); + QString toRepresentedString(const QString) const; + NumerotationContext next (const NumerotationContext &, const int) const; + NumerotationContext previous (const NumerotationContext &, const int) const; +}; + class TenNum: public NumStrategy { public: @@ -78,6 +87,15 @@ class TenNum: public NumStrategy NumerotationContext previous (const NumerotationContext &, const int) const; }; +class TenFNum: public NumStrategy +{ + public: + TenFNum (Diagram *); + QString toRepresentedString(const QString) const; + NumerotationContext next (const NumerotationContext &, const int) const; + NumerotationContext previous (const NumerotationContext &, const int) const; +}; + class HundredNum: public NumStrategy { public: @@ -87,6 +105,15 @@ class HundredNum: public NumStrategy NumerotationContext previous (const NumerotationContext &, const int) const; }; +class HundredFNum: public NumStrategy +{ + public: + HundredFNum (Diagram *); + QString toRepresentedString(const QString) const; + NumerotationContext next (const NumerotationContext &, const int) const; + NumerotationContext previous (const NumerotationContext &, const int) const; +}; + class StringNum: public NumStrategy { public: diff --git a/sources/projectview.cpp b/sources/projectview.cpp index 75da2dca8..b75183431 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -1019,6 +1019,8 @@ void ProjectView::tabChanged(int tab_id) { setDisplayFallbackWidget(false); emit(diagramActivated(diagram_ids_[tab_id])); + if (diagram_ids_[tab_id] != nullptr) + diagram_ids_[tab_id]->diagram()->diagramActivated(); } /** diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 8a9ad09b8..e820ea47b 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -954,6 +954,7 @@ bool QETDiagramEditor::addProject(QETProject *project, bool update_panel) { // met a jour le panel d'elements if (update_panel) { pa -> elementsPanel().projectWasOpened(project); + if (currentDiagram() != NULL) m_autonumbering_dock->setProject(project, project_view); } @@ -1326,7 +1327,7 @@ void QETDiagramEditor::slot_updateActions() void QETDiagramEditor::slot_updateAutoNumDock() { if ( workspace.subWindowList().indexOf(workspace.activeSubWindow()) != activeSubWindowIndex) { activeSubWindowIndex = workspace.subWindowList().indexOf(workspace.activeSubWindow()); - if (currentProject()!=NULL) { + if (currentProject() != NULL && currentDiagram() != NULL) { m_autonumbering_dock->setProject(currentProject()->project(),currentProject()); } } diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 307045c35..170ef4930 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -429,26 +429,13 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //load prefix m_prefix = e.attribute("prefix"); - //Load Unit Sequential Values - int i = 0; - while (!e.attribute("sequ_" + QString::number(i+1)).isEmpty()) { - seq_unit.append(e.attribute("sequ_" + QString::number(i+1))); - i++; - } - - //Load Ten Sequential Values - i = 0; - while (!e.attribute("seqt_" + QString::number(i+1)).isEmpty()) { - seq_ten.append(e.attribute("seqt_" + QString::number(i+1))); - i++; - } - - //Load Hundred Sequential Values - i = 0; - while (!e.attribute("seqh_" + QString::number(i+1)).isEmpty()) { - seq_hundred.append(e.attribute("seqh_" + QString::number(i+1))); - i++; - } + //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); //load informations m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation"); @@ -470,6 +457,21 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool return(true); } +/** + Load Sequentials to display on element label + @param element QDomElement to set Attributes + @param Qstring seq to be retrieved + @param QStringList list to be inserted values +*/ +void Element::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++; + } +} + /** Permet d'exporter l'element en XML @param document Document XML a utiliser @@ -488,20 +490,36 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table // prefix element.setAttribute("prefix", m_prefix); - //Save Unit Sequential Values + // Save Element sequential values to Xml + // Save Unit Sequential Values for (int i = 0; i < seq_unit.size(); i++) { element.setAttribute("sequ_" + QString::number(i+1),seq_unit.at(i)); } - //Save Ten Sequential Values + // Save UnitFolio Sequential Values + for (int i = 0; i < seq_unitfolio.size(); i++) { + element.setAttribute("sequf_" + QString::number(i+1),seq_unitfolio.at(i)); + } + + // Save Ten Sequential Values for (int i = 0; i < seq_ten.size(); i++) { element.setAttribute("seqt_" + QString::number(i+1),seq_ten.at(i)); } - //Save Hundred Sequential Values + // Save TenFolio Sequential Values + for (int i = 0; i < seq_tenfolio.size(); i++) { + element.setAttribute("seqtf_" + QString::number(i+1),seq_tenfolio.at(i)); + } + + // Save Hundred Sequential Values for (int i = 0; i < seq_hundred.size(); i++) { element.setAttribute("seqh_" + QString::number(i+1),seq_hundred.at(i)); } + + // Save Hundred Sequential Values + for (int i = 0; i < seq_hundredfolio.size(); i++) { + element.setAttribute("seqhf_" + QString::number(i+1),seq_hundredfolio.at(i)); + } // position, selection et orientation element.setAttribute("x", QString("%1").arg(pos().x())); @@ -748,10 +766,10 @@ QString Element::assignVariables(QString label, Element *elmt){ } /** - * @brief Element::setSeq() + * @brief Element::setSequential * Set sequential values to element */ -void Element::setSeq() { +void Element::setSequential() { DiagramContext &dc = this->rElementInformations(); QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum(); QString formula = diagram()->project()->elementAutoNumFormula(); @@ -759,34 +777,75 @@ void Element::setSeq() { NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum); NumerotationContextCommands ncc (nc); if (!nc.isEmpty()) { - //Unit Format - if (label.contains("%sequ_")) { - for (int i = 0; i < nc.size(); i++) { - if (nc.itemAt(i).at(0) == "unit") { - seq_unit.append(QString::number(nc.itemAt(i).at(1).toInt())); - } - } + if (label.contains("%sequ_")) + setSequentialToList(&seq_unit,&nc,"unit"); + if (label.contains("%sequf_")) { + setSequentialToList(&seq_unitfolio,&nc,"unitfolio"); + setFolioSequentialToHash(&seq_unitfolio,&diagram()->m_elmt_unitfolio_max,element_currentAutoNum); } - //Ten Format - if (label.contains("%seqt_")) { - for (int i = 0; i < nc.size(); i++) { - if (nc.itemAt(i).at(0) == "ten") { - QString number = QString ("%1").arg(nc.itemAt(i).at(1).toInt(), 2, 10, QChar('0')); - seq_ten.append(number); - } - } + if (label.contains("%seqt_")) + setSequentialToList(&seq_ten,&nc,"ten"); + if (label.contains("%seqtf_")) { + setSequentialToList(&seq_tenfolio,&nc,"tenfolio"); + setFolioSequentialToHash(&seq_tenfolio,&diagram()->m_elmt_tenfolio_max,element_currentAutoNum); } - //Hundred Format - if (label.contains("%seqh_")) { - for (int i = 0; i < nc.size(); i++) { - if (nc.itemAt(i).at(0) == "hundred") { - QString number = QString ("%1").arg(nc.itemAt(i).at(1).toInt(), 3, 10, QChar('0')); - seq_hundred.append(number); - } + if (label.contains("%seqh_")) + setSequentialToList(&seq_hundred,&nc,"hundred"); + if (label.contains("%seqhf_")) { + setSequentialToList(&seq_hundredfolio,&nc,"hundredfolio"); + setFolioSequentialToHash(&seq_hundredfolio,&diagram()->m_elmt_hundredfolio_max,element_currentAutoNum); + } + this->diagram()->project()->addElementAutoNum(element_currentAutoNum,ncc.next()); + } +} + +/** + * @brief Element::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 Element::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 Element::setFolioSequentialToHash + * This class inserts all elements 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 Element::setFolioSequentialToHash(QStringList* list, QHash *hash, QString element_currentAutoNum) { + if (hash->isEmpty() || (!(hash->contains(element_currentAutoNum)))) { + QStringList max; + for (int i = 0; i < list->size(); i++) { + max.append(list->at(i)); + } + hash->insert(element_currentAutoNum,max); + } + else if (hash->contains(element_currentAutoNum)) { + //Load the String List and update it + QStringList max = hash->value(element_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(element_currentAutoNum); + hash->insert(element_currentAutoNum,max); } } } - this->diagram()->project()->addElementAutoNum(element_currentAutoNum,ncc.next()); } /** @@ -796,7 +855,7 @@ void Element::setSeq() { * @return replaced label */ QString Element::assignSeq(QString label) { - for (int i = 1; i <= qMax(seq_unit.size(),qMax(seq_hundred.size(),seq_ten.size())); i++) { + for (int i = 1; i <= qMax(qMax(qMax(seq_unitfolio.size(), seq_tenfolio.size()),qMax(seq_hundredfolio.size(),seq_unit.size())),qMax(seq_hundred.size(),seq_ten.size())); i++) { if (label.contains("%sequ_" + QString::number(i))) { label.replace("%sequ_" + QString::number(i),seq_unit.at(i-1)); } @@ -806,6 +865,15 @@ QString Element::assignSeq(QString label) { if (label.contains("%seqh_" + QString::number(i))) { label.replace("%seqh_" + QString::number(i),seq_hundred.at(i-1)); } + if (label.contains("%sequf_" + QString::number(i))) { + label.replace("%sequf_" + QString::number(i),seq_unitfolio.at(i-1)); + } + if (label.contains("%seqtf_" + QString::number(i))) { + label.replace("%seqtf_" + QString::number(i),seq_tenfolio.at(i-1)); + } + if (label.contains("%seqhf_" + QString::number(i))) { + label.replace("%seqhf_" + QString::number(i),seq_hundredfolio.at(i-1)); + } } return label; } diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index d772d812e..2e152c5fe 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -26,6 +26,7 @@ class ElementTextItem; class QETProject; class Terminal; class Conductor; +class NumerotationContext; /** This is the base class for electrical elements. @@ -135,7 +136,9 @@ class Element : public QetGraphicsItem { // kind of contact (simple tempo) or number of contact show by the element. QString assignVariables (QString, Element *); QString assignSeq (QString); - void setSeq (); + void setSequential (); + void setSequentialToList(QStringList*, NumerotationContext*, QString); + void setFolioSequentialToHash(QStringList*, QHash*, QString); void setPrefix(QString); QString getPrefix(); void freezeLabel(); @@ -194,6 +197,7 @@ class Element : public QetGraphicsItem { void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); void updatePixmap(); void etiToElementLabels(ElementTextItem*); + void loadSequential(QDomElement* e, QString seq, QStringList* list); protected: virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ); @@ -205,8 +209,11 @@ class Element : public QetGraphicsItem { bool m_mouse_over; QString m_prefix; QStringList seq_unit; + QStringList seq_unitfolio; QStringList seq_ten; + QStringList seq_tenfolio; QStringList seq_hundred; + QStringList seq_hundredfolio; }; diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 8ca00afa3..302ae90e2 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -556,7 +556,7 @@ NumerotationContext QETProject::conductorAutoNum (const QString &key) const { * If key is not found, return an empty numerotation context * @param key */ -NumerotationContext QETProject::elementAutoNum (const QString &key) const { +NumerotationContext QETProject::elementAutoNum (const QString &key) { if (m_element_autonum.contains(key)) return m_element_autonum[key]; else return NumerotationContext(); } diff --git a/sources/qetproject.h b/sources/qetproject.h index 23575b321..202935869 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -120,7 +120,7 @@ class QETProject : public QObject void removeFolioAutoNum (QString key); NumerotationContext conductorAutoNum(const QString &key) const; NumerotationContext folioAutoNum(const QString &key) const; - NumerotationContext elementAutoNum(const QString &key) const; + NumerotationContext elementAutoNum(const QString &key); QString elementAutoNumFormula(const QString key) const; //returns Formula QString elementAutoNumFormula() const; QString elementCurrentAutoNum () const; diff --git a/sources/ui/autonumberingdockwidget.cpp b/sources/ui/autonumberingdockwidget.cpp index b4ddb7632..b96b46158 100644 --- a/sources/ui/autonumberingdockwidget.cpp +++ b/sources/ui/autonumberingdockwidget.cpp @@ -223,6 +223,7 @@ void AutoNumberingDockWidget::on_m_element_cb_activated(int) { } else project_->setElementAutoNumCurrentFormula("",""); + projectview_->currentDiagram()->diagram()->loadElmtFolioSeq(); } /** diff --git a/sources/ui/numparteditorw.cpp b/sources/ui/numparteditorw.cpp index 043c23a42..40feceb15 100644 --- a/sources/ui/numparteditorw.cpp +++ b/sources/ui/numparteditorw.cpp @@ -28,8 +28,7 @@ NumPartEditorW::NumPartEditorW(QWidget *parent) : intValidator (new QIntValidator(0,99999,this)) { ui -> setupUi(this); - if (parentWidget()->parentWidget()->objectName()=="FolioTab") ui->type_combo->setMaxCount(4); - else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") ui->type_combo->setMaxCount(6); + setVisibleItems(); setType(NumPartEditorW::unit, true); } @@ -43,16 +42,17 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context, int i, QWidget *pa intValidator (new QIntValidator(0,99999,this)) { ui -> setupUi(this); - if (parentWidget()->parentWidget()->objectName()=="FolioTab") ui->type_combo->setMaxCount(4); - else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") ui->type_combo->setMaxCount(6); - //if @context contains nothing build with default value + setVisibleItems(); if(context.size()==0) setType(NumPartEditorW::unit, true); else { QStringList strl = context.itemAt(i); if (strl.at(0)=="unit") setType(NumPartEditorW::unit, true); + else if (strl.at(0)=="unitfolio") setType(NumPartEditorW::unitfolio, true); else if (strl.at(0)=="ten") setType(NumPartEditorW::ten, true); + else if (strl.at(0)=="tenfolio") setType(NumPartEditorW::tenfolio, true); else if (strl.at(0)=="hundred") setType(NumPartEditorW::hundred, true); + else if (strl.at(0)=="hundredfolio") setType(NumPartEditorW::hundredfolio, true); else if (strl.at(0)=="string") setType(NumPartEditorW::string); else if (strl.at(0)=="idfolio") setType(NumPartEditorW::idfolio); else if (strl.at(0)=="folio") setType(NumPartEditorW::folio); @@ -73,6 +73,27 @@ NumPartEditorW::~NumPartEditorW() delete ui; } +void NumPartEditorW::setVisibleItems() { + ui->type_cb->setInsertPolicy(QComboBox::InsertAtBottom); + QStringList items; + if (parentWidget()->parentWidget()->objectName()=="FolioTab") { + items << tr("Chiffre 1") << tr("Chiffre 01") + << tr("Chiffre 001") + << tr("Texte") << tr("N° folio"); + } + else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") { + items << tr("Chiffre 1") << tr("Chiffre 01") + << tr("Chiffre 001") + << tr("Texte") << tr("N° folio") << tr("Folio"); + } + else + 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") + << tr("Element Line") << tr("Element Column") << tr("Element Prefix"); + ui->type_cb->insertItems(0,items); +} + /** * @brief NumPartEditorW::toNumContext * @return the display to NumerotationContext @@ -84,12 +105,21 @@ NumerotationContext NumPartEditorW::toNumContext() { case unit: type_str = "unit"; break; + case unitfolio: + type_str = "unitfolio"; + break; case ten: type_str = "ten"; break; + case tenfolio: + type_str = "tenfolio"; + break; case hundred: type_str = "hundred"; break; + case hundredfolio: + type_str = "hundredfolio"; + break; case string: type_str = "string"; break; @@ -109,6 +139,9 @@ NumerotationContext NumPartEditorW::toNumContext() { type_str = "elementprefix"; break; } + if (type_str == "unitfolio" || type_str == "tenfolio" || type_str == "hundredfolio") + nc.addValue(type_str, ui -> value_field -> displayText(), ui -> increase_spinBox -> value(), ui->value_field->displayText().toInt()); + else nc.addValue(type_str, ui -> value_field -> displayText(), ui -> increase_spinBox -> value()); return nc; } @@ -125,39 +158,34 @@ bool NumPartEditorW::isValid() { } /** - * @brief NumPartEditorW::on_type_combo_activated + * @brief NumPartEditorW::on_type_cb_activated * Action when user change the type comboBox */ -void NumPartEditorW::on_type_combo_activated(int index) { - switch (index) { - case unit: - setType(unit); - break; - case ten: - setType(ten); - break; - case hundred: - setType(hundred); - break; - case string: - setType(string); - break; - case idfolio: - setType(idfolio); - break; - case folio: - setType(folio); - break; - case elementline: - setType(elementline); - break; - case elementcolumn: - setType(elementcolumn); - break; - case elementprefix: - setType(elementprefix); - break; - }; +void NumPartEditorW::on_type_cb_activated(int) { + if (ui->type_cb->currentText() == tr("Chiffre 1")) + setType(unit); + else if (ui->type_cb->currentText() == tr("Chiffre 1 - Folio")) + setType(unitfolio); + else if (ui->type_cb->currentText() == tr("Chiffre 01")) + setType(ten); + else if (ui->type_cb->currentText() == tr("Chiffre 01 - Folio")) + setType(tenfolio); + else if (ui->type_cb->currentText() == tr("Chiffre 001")) + setType(hundred); + else if (ui->type_cb->currentText() == tr("Chiffre 001 - Folio")) + setType(hundredfolio); + else if (ui->type_cb->currentText() == tr("Texte")) + setType(string); + else if (ui->type_cb->currentText() == tr("N° folio")) + setType(idfolio); + else if (ui->type_cb->currentText() == tr("Folio")) + setType(folio); + else if (ui->type_cb->currentText() == tr("Element Line")) + setType(elementline); + else if (ui->type_cb->currentText() == tr("Element Column")) + setType(elementcolumn); + else if (ui->type_cb->currentText() == tr("Element Prefix")) + setType(elementprefix); emit changed(); } @@ -184,11 +212,11 @@ void NumPartEditorW::on_increase_spinBox_valueChanged(int) { * @param fnum, force the behavior of numeric type */ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) { - ui -> type_combo -> setCurrentIndex(t); +// ui -> type_cb -> setCurrentIndex(t); //if @t is a numeric type and preview type @type_ isn't a numeric type //or @fnum is true, we set numeric behavior - if ( ((t==unit || t==ten || t==hundred) && + if ( ((t==unit || t==unitfolio || t==ten || t==tenfolio || t==hundred || t==hundredfolio) && (type_==string || type_==folio || type_==idfolio || type_==elementcolumn || type_==elementline || type_==elementprefix)) || fnum) { diff --git a/sources/ui/numparteditorw.h b/sources/ui/numparteditorw.h index 211d4648b..411c14b18 100644 --- a/sources/ui/numparteditorw.h +++ b/sources/ui/numparteditorw.h @@ -41,13 +41,20 @@ class NumPartEditorW : public QWidget NumPartEditorW (NumerotationContext &, int, QWidget *parent=0); ~NumPartEditorW(); - enum type {unit,ten,hundred,string,idfolio,folio,elementline,elementcolumn,elementprefix}; + enum type {unit,unitfolio,ten,tenfolio, hundred, hundredfolio, + string,idfolio,folio, + elementline,elementcolumn,elementprefix, + }; NumerotationContext toNumContext(); bool isValid (); type type_; + private: + void setVisibleItems(); + void disableItem(int index); + private slots: - void on_type_combo_activated(int); + void on_type_cb_activated(int); void on_value_field_textEdited(); void on_increase_spinBox_valueChanged(int); void setType (NumPartEditorW::type t, bool=false); diff --git a/sources/ui/numparteditorw.ui b/sources/ui/numparteditorw.ui index a9d17e9e3..17c3b849c 100644 --- a/sources/ui/numparteditorw.ui +++ b/sources/ui/numparteditorw.ui @@ -30,7 +30,7 @@ 2 - + 0 @@ -40,51 +40,6 @@ true - - - Chiffre 1 - - - - - Chiffre 01 - - - - - Chiffre 001 - - - - - Texte - - - - - N° folio - - - - - Folio - - - - - Element Line - - - - - Element Column - - - - - Element Prefix - - diff --git a/sources/ui/selectautonumw.cpp b/sources/ui/selectautonumw.cpp index b1b9ea354..34b01057c 100644 --- a/sources/ui/selectautonumw.cpp +++ b/sources/ui/selectautonumw.cpp @@ -233,8 +233,11 @@ void SelectAutonumW::applyEnable(bool b) { void SelectAutonumW::contextToFormula() { m_eaw->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) { @@ -259,14 +262,26 @@ void SelectAutonumW::contextToFormula() { count_unit++; m_eaw->setContext("%sequ_"+QString::number(count_unit)); } + else if (npe->type_ == NumPartEditorW::unitfolio) { + count_unitf++; + m_eaw->setContext("%sequf_"+QString::number(count_unitf)); + } else if (npe->type_ == NumPartEditorW::ten) { count_ten++; m_eaw->setContext("%seqt_"+QString::number(count_ten)); } + else if (npe->type_ == NumPartEditorW::tenfolio) { + count_tenf++; + m_eaw->setContext("%seqtf_"+QString::number(count_tenf)); + } else if (npe->type_ == NumPartEditorW::hundred) { count_hundred++; m_eaw->setContext("%seqh_"+QString::number(count_hundred)); } + else if (npe->type_ == NumPartEditorW::hundredfolio) { + count_hundredf++; + m_eaw->setContext("%seqhf_"+QString::number(count_hundredf)); + } } } }