From f8a829d32862e6968f6fc967841a587f4d202f6d Mon Sep 17 00:00:00 2001 From: dfochi Date: Sun, 10 Jul 2016 01:33:49 +0000 Subject: [PATCH] Element Autonumbering now has sequential variables and selectautonum widget. Renamed autonumbering variables. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4569 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagram.cpp | 1 - .../diagramevent/diagrameventaddelement.cpp | 2 + sources/numerotationcontext.cpp | 2 +- sources/numerotationcontextcommands.cpp | 108 ++++++++ sources/numerotationcontextcommands.h | 29 ++ sources/projectconfigpages.cpp | 260 +++++++++++------- sources/projectconfigpages.h | 36 ++- sources/qetgraphicsitem/customelement.cpp | 8 +- sources/qetgraphicsitem/element.cpp | 67 +++++ sources/qetgraphicsitem/element.h | 2 + sources/qetgraphicsitem/masterelement.cpp | 2 +- sources/qetgraphicsitem/simpleelement.cpp | 2 +- sources/qetproject.cpp | 107 ++++++- sources/qetproject.h | 25 +- sources/ui/elementautonumberingw.cpp | 40 +-- sources/ui/elementautonumberingw.h | 11 +- sources/ui/elementautonumberingw.ui | 190 +++++-------- sources/ui/numparteditorw.cpp | 48 +++- sources/ui/numparteditorw.h | 6 +- sources/ui/numparteditorw.ui | 28 +- sources/ui/selectautonumw.cpp | 72 ++++- sources/ui/selectautonumw.h | 7 +- sources/ui/selectautonumw.ui | 4 +- 23 files changed, 746 insertions(+), 311 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index cc4aab1de..8c19d9ea2 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -866,7 +866,6 @@ void Diagram::addItem(QGraphicsItem *item) CustomElement *celmt = static_cast(item); celmt->parseLabels(); } - elmt->updateLabel(); } break; diff --git a/sources/diagramevent/diagrameventaddelement.cpp b/sources/diagramevent/diagrameventaddelement.cpp index c1cd14a2e..b9bdbce90 100644 --- a/sources/diagramevent/diagrameventaddelement.cpp +++ b/sources/diagramevent/diagrameventaddelement.cpp @@ -233,4 +233,6 @@ void DiagramEventAddElement::addElement() can.numerate(); }; m_diagram -> undoStack().push(undo_object); + element->assignSeq(); + element->updateLabel(); } diff --git a/sources/numerotationcontext.cpp b/sources/numerotationcontext.cpp index 710b41258..4ced5cf49 100644 --- a/sources/numerotationcontext.cpp +++ b/sources/numerotationcontext.cpp @@ -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"); + return ("unit|ten|hundred|string|idfolio|folio|elementline|elementcolumn|elementprefix"); } /** diff --git a/sources/numerotationcontextcommands.cpp b/sources/numerotationcontextcommands.cpp index cb3c414d9..a4914b6ea 100644 --- a/sources/numerotationcontextcommands.cpp +++ b/sources/numerotationcontextcommands.cpp @@ -112,6 +112,18 @@ void NumerotationContextCommands::setNumStrategy(const QString &str) { strategy_ = new FolioNum (diagram_); return; } + else if (str=="elementline"){ + strategy_ = new ElementLineNum (diagram_); + return; + } + else if (str=="elementcolumn"){ + strategy_ = new ElementColumnNum (diagram_); + return; + } + else if (str=="elementprefix"){ + strategy_ = new ElementPrefixNum (diagram_); + return; + } } @@ -359,3 +371,99 @@ NumerotationContext FolioNum::previous(const NumerotationContext &nc, const int return (nextString(nc, i)); } +/** + * Constructor + */ +ElementLineNum::ElementLineNum (Diagram *d): + NumStrategy (d) +{} + +/** + * @brief ElementLineNum::toRepresentedString + * @return the represented string of folio + */ +QString ElementLineNum::toRepresentedString(const QString str) const { + Q_UNUSED(str); + return "%l"; +} + +/** + * @brief ElementLineNum::next + * @return the next NumerotationContext nc at position i + */ +NumerotationContext ElementLineNum::next (const NumerotationContext &nc, const int i) const { + return (nextString(nc, i)); +} + +/** + * @brief ElementLineNum::previous + * @return the previous NumerotationContext nc at posiiton i + */ +NumerotationContext ElementLineNum::previous(const NumerotationContext &nc, const int i) const { + return (nextString(nc, i)); +} + +/** + * Constructor + */ +ElementColumnNum::ElementColumnNum (Diagram *d): + NumStrategy (d) +{} + +/** + * @brief ElementColumnNum::toRepresentedString + * @return the represented string of folio + */ +QString ElementColumnNum::toRepresentedString(const QString str) const { + Q_UNUSED(str); + return "%c"; +} + +/** + * @brief ElementColumnNum::next + * @return the next NumerotationContext nc at position i + */ +NumerotationContext ElementColumnNum::next (const NumerotationContext &nc, const int i) const { + return (nextString(nc, i)); +} + +/** + * @brief ElementColumnNum::previous + * @return the previous NumerotationContext nc at posiiton i + */ +NumerotationContext ElementColumnNum::previous(const NumerotationContext &nc, const int i) const { + return (nextString(nc, i)); +} + +/** + * Constructor + */ +ElementPrefixNum::ElementPrefixNum (Diagram *d): + NumStrategy (d) +{} + +/** + * @brief ElementPrefixNum::toRepresentedString + * @return the represented string of folio + */ +QString ElementPrefixNum::toRepresentedString(const QString str) const { + Q_UNUSED(str); + return "%prefix"; +} + +/** + * @brief ElementPrefixNum::next + * @return the next NumerotationContext nc at position i + */ +NumerotationContext ElementPrefixNum::next (const NumerotationContext &nc, const int i) const { + return (nextString(nc, i)); +} + +/** + * @brief ElementPrefixNum::previous + * @return the previous NumerotationContext nc at posiiton i + */ +NumerotationContext ElementPrefixNum::previous(const NumerotationContext &nc, const int i) const { + return (nextString(nc, i)); +} + diff --git a/sources/numerotationcontextcommands.h b/sources/numerotationcontextcommands.h index 18a6a5e71..3811c03c0 100644 --- a/sources/numerotationcontextcommands.h +++ b/sources/numerotationcontextcommands.h @@ -113,4 +113,33 @@ class FolioNum: public NumStrategy NumerotationContext next (const NumerotationContext &, const int) const; NumerotationContext previous (const NumerotationContext &, const int) const; }; + +class ElementLineNum: public NumStrategy +{ + public: + ElementLineNum (Diagram *); + QString toRepresentedString(const QString) const; + NumerotationContext next (const NumerotationContext &, const int) const; + NumerotationContext previous (const NumerotationContext &, const int) const; +}; + +class ElementColumnNum: public NumStrategy +{ + public: + ElementColumnNum (Diagram *); + QString toRepresentedString(const QString) const; + NumerotationContext next (const NumerotationContext &, const int) const; + NumerotationContext previous (const NumerotationContext &, const int) const; +}; + +class ElementPrefixNum: public NumStrategy +{ + public: + ElementPrefixNum (Diagram *); + QString toRepresentedString(const QString) const; + NumerotationContext next (const NumerotationContext &, const int) const; + NumerotationContext previous (const NumerotationContext &, const int) const; +}; + + #endif // NUMEROTATIONCONTEXTCOMMANDS_H diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index 73a384da9..8ba62fe7c 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -257,38 +257,51 @@ void ProjectAutoNumConfigPage::initWidgets() { //Conductor Tab conductor_tab_widget = new QWidget(this); + conductor_tab_widget->setObjectName("ConductorTab"); - m_label = new QLabel(tr("Numérotations disponibles :", "availables numerotations"), conductor_tab_widget); + m_label_conductor = new QLabel(tr("Numérotations disponibles :", "availables numerotations"), conductor_tab_widget); - m_context_cb = new QComboBox(conductor_tab_widget); - m_context_cb->setEditable(true); - m_context_cb->lineEdit()->setClearButtonEnabled(true); - m_context_cb->addItem(tr("Nom de la nouvelle numérotation")); + m_context_cb_conductor= new QComboBox(conductor_tab_widget); + m_context_cb_conductor->setEditable(true); + m_context_cb_conductor->lineEdit()->setClearButtonEnabled(true); + m_context_cb_conductor->addItem(tr("Nom de la nouvelle numérotation")); - m_remove_pb = new QPushButton(QET::Icons::EditDelete, QString(), conductor_tab_widget); - m_remove_pb -> setToolTip(tr("Supprimer la numérotation")); + m_remove_pb_conductor= new QPushButton(QET::Icons::EditDelete, QString(), conductor_tab_widget); + m_remove_pb_conductor-> setToolTip(tr("Supprimer la numérotation")); - m_saw = new SelectAutonumW(conductor_tab_widget); + m_saw_conductor = new SelectAutonumW(conductor_tab_widget); //Element Tab element_tab_widget = new QWidget(this); - m_eaw = new ElementAutonumberingW(element_tab_widget); + element_tab_widget->setObjectName("ElementTab"); + + m_label_element = new QLabel(tr("Numérotations disponibles :", "availables numerotations"), element_tab_widget); + + m_context_cb_element = new QComboBox(element_tab_widget); + m_context_cb_element->setEditable(true); + m_context_cb_element->lineEdit()->setClearButtonEnabled(true); + m_context_cb_element->addItem(tr("Nom de la nouvelle numérotation")); + + m_remove_pb_element = new QPushButton(QET::Icons::EditDelete, QString(), element_tab_widget); + m_remove_pb_element -> setToolTip(tr("Supprimer la numérotation")); + + m_saw_element = new SelectAutonumW(element_tab_widget); //Folio Tab folio_tab_widget = new QWidget(this); folio_tab_widget->setObjectName("FolioTab"); - m_label_2 = new QLabel(tr("Numérotations disponibles :", "availables numerotations"), folio_tab_widget); + m_label_folio = new QLabel(tr("Numérotations disponibles :", "availables numerotations"), folio_tab_widget); - m_context_cb_2 = new QComboBox(folio_tab_widget); - m_context_cb_2->setEditable(true); - m_context_cb_2->lineEdit()->setClearButtonEnabled(true); - m_context_cb_2->addItem(tr("Nom de la nouvelle numérotation")); + m_context_cb_folio = new QComboBox(folio_tab_widget); + m_context_cb_folio->setEditable(true); + m_context_cb_folio->lineEdit()->setClearButtonEnabled(true); + m_context_cb_folio->addItem(tr("Nom de la nouvelle numérotation")); - m_remove_pb_2 = new QPushButton(QET::Icons::EditDelete, QString(), folio_tab_widget); - m_remove_pb_2 -> setToolTip(tr("Supprimer la numérotation")); + m_remove_pb_folio = new QPushButton(QET::Icons::EditDelete, QString(), folio_tab_widget); + m_remove_pb_folio -> setToolTip(tr("Supprimer la numérotation")); - m_saw_2 = new SelectAutonumW(folio_tab_widget); + m_saw_folio = new SelectAutonumW(folio_tab_widget); //AutoNumbering Tab autoNumbering_tab_widget = new QWidget(this); @@ -304,42 +317,55 @@ void ProjectAutoNumConfigPage::initLayout() { //Conductor Tab tab_widget->addTab(conductor_tab_widget, tr("Conductor")); - QHBoxLayout *context_layout = new QHBoxLayout(); - context_layout -> addWidget (m_label); - context_layout -> addWidget (m_context_cb); - context_layout -> addWidget (m_remove_pb); + QHBoxLayout *context_layout_conductor = new QHBoxLayout(); + context_layout_conductor -> addWidget (m_label_conductor); + context_layout_conductor -> addWidget (m_context_cb_conductor); + context_layout_conductor -> addWidget (m_remove_pb_conductor); - QVBoxLayout *main_layout = new QVBoxLayout(); - QVBoxLayout *aux_layout = new QVBoxLayout(); - aux_layout->addLayout(context_layout); - aux_layout->addWidget(m_saw); + QVBoxLayout *main_layout_conductor = new QVBoxLayout(); + QVBoxLayout *aux_layout_conductor = new QVBoxLayout(); + aux_layout_conductor->addLayout(context_layout_conductor); + aux_layout_conductor->addWidget(m_saw_conductor); - main_layout->addLayout(aux_layout); - conductor_tab_widget -> setLayout (main_layout); + main_layout_conductor->addLayout(aux_layout_conductor); + conductor_tab_widget -> setLayout (main_layout_conductor); //Element Tab tab_widget->addTab(element_tab_widget,tr ("Element")); + QHBoxLayout *element_context_layout = new QHBoxLayout(); + element_context_layout -> addWidget (m_label_element); + element_context_layout -> addWidget (m_context_cb_element); + element_context_layout -> addWidget (m_remove_pb_element); + + QVBoxLayout *main_layout_element = new QVBoxLayout(); + QVBoxLayout *aux_layout_element = new QVBoxLayout(); + aux_layout_element->addLayout(element_context_layout); + aux_layout_element->addWidget(m_saw_element); + + main_layout_element->addLayout(aux_layout_element); + element_tab_widget->setLayout(main_layout_element); + // Folio Tab tab_widget->addTab(folio_tab_widget, tr("Folio")); - QHBoxLayout *context_layout_2 = new QHBoxLayout(); - context_layout_2 -> addWidget (m_label_2); - context_layout_2 -> addWidget (m_context_cb_2); - context_layout_2 -> addWidget (m_remove_pb_2); + QHBoxLayout *context_layout_folio = new QHBoxLayout(); + context_layout_folio -> addWidget (m_label_folio); + context_layout_folio -> addWidget (m_context_cb_folio); + context_layout_folio -> addWidget (m_remove_pb_folio); - QVBoxLayout *main_layout_2 = new QVBoxLayout(); - QVBoxLayout *aux_layout_2 = new QVBoxLayout(); - aux_layout_2->addLayout(context_layout_2); - aux_layout_2->addWidget(m_saw_2); + QVBoxLayout *main_layout_folio = new QVBoxLayout(); + QVBoxLayout *aux_layout_folio = new QVBoxLayout(); + aux_layout_folio->addLayout(context_layout_folio); + aux_layout_folio->addWidget(m_saw_folio); - main_layout_2->addLayout(aux_layout_2); - folio_tab_widget -> setLayout (main_layout_2); + main_layout_folio->addLayout(aux_layout_folio); + folio_tab_widget->setLayout(main_layout_folio); //Auto Numbering Tab tab_widget->addTab(autoNumbering_tab_widget,tr ("Folio Auto Numbering")); - tab_widget->resize(455,590); + tab_widget->resize(465,590); } /** @@ -348,23 +374,25 @@ void ProjectAutoNumConfigPage::initLayout() { */ void ProjectAutoNumConfigPage::readValuesFromProject() { //Conductor Tab - QList keys = project_->conductorAutoNum().keys(); - if (!keys.isEmpty()){ - foreach (QString str, keys) { m_context_cb -> addItem(str); } + QList keys_conductor = project_->conductorAutoNum().keys(); + if (!keys_conductor.isEmpty()){ + foreach (QString str, keys_conductor) { m_context_cb_conductor-> addItem(str); } } //Element Tab - if (!project_->elementAutoNum().isEmpty()) - m_eaw->setContext(project_->elementAutoNum()); + QList keys_element = project_->elementAutoNum().keys(); + if (!keys_element.isEmpty()){ + foreach (QString str, keys_element) { m_context_cb_element -> addItem(str);} + } //Folio Tab - QList keys_2 = project_->folioAutoNum().keys(); - if (!keys_2.isEmpty()){ - foreach (QString str, keys_2) { m_context_cb_2 -> addItem(str);} + QList keys_folio = project_->folioAutoNum().keys(); + if (!keys_folio.isEmpty()){ + foreach (QString str, keys_folio) { m_context_cb_folio -> addItem(str);} } //Folio AutoNumbering Tab - m_faw->setContext(keys_2); + m_faw->setContext(keys_folio); } /** @@ -383,92 +411,125 @@ void ProjectAutoNumConfigPage::buildConnections() { connect(tab_widget,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int))); //Conductor Tab - connect (m_context_cb, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext(QString))); - connect (m_saw, SIGNAL (applyPressed()), this, SLOT (saveContext())); - connect (m_remove_pb, SIGNAL (clicked()), this, SLOT(removeContext())); + connect (m_context_cb_conductor, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_conductor(QString))); + connect (m_saw_conductor, SIGNAL (applyPressed()), this, SLOT (saveContext_conductor())); + connect (m_remove_pb_conductor, SIGNAL (clicked()), this, SLOT (removeContext_conductor())); //Element Tab - connect (m_eaw, SIGNAL (applyPressed()), this, SLOT (saveContext_3())); + connect (m_context_cb_element, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_element(QString))); + connect (m_saw_element, SIGNAL (applyPressed()), this, SLOT (saveContext_element())); + connect (m_remove_pb_element, SIGNAL (clicked()), this, SLOT (removeContext_element())); //Folio Tab - connect (m_context_cb_2, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_2(QString))); - connect (m_saw_2, SIGNAL (applyPressed()), this, SLOT (saveContext_2())); - connect (m_remove_pb_2, SIGNAL (clicked()), this, SLOT (removeContext_2())); + connect (m_context_cb_folio, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_folio(QString))); + connect (m_saw_folio, SIGNAL (applyPressed()), this, SLOT (saveContext_folio())); + connect (m_remove_pb_folio, SIGNAL (clicked()), this, SLOT (removeContext_folio())); // Auto Folio Numbering connect (m_faw, SIGNAL (applyPressed()), this, SLOT (applyAutoNum())); } /** - * @brief ProjectAutoNumConfigPage::updateContext + * @brief ProjectAutoNumConfigPage::updateContext_conductor * Display the current selected context for conductor * @param str, key of context stored in project */ -void ProjectAutoNumConfigPage::updateContext(QString str) { - if (str == tr("Nom de la nouvelle numérotation")) m_saw -> setContext(NumerotationContext()); - else m_saw ->setContext(project_->conductorAutoNum(str)); +void ProjectAutoNumConfigPage::updateContext_conductor(QString str) { + if (str == tr("Nom de la nouvelle numérotation")) m_saw_conductor -> setContext(NumerotationContext()); + else m_saw_conductor ->setContext(project_->conductorAutoNum(str)); } /** - * @brief ProjectAutoNumConfigPage::updateContext_2 + * @brief ProjectAutoNumConfigPage::updateContext_folio * Display the current selected context for folio * @param str, key of context stored in project */ -void ProjectAutoNumConfigPage::updateContext_2(QString str) { - if (str == tr("Nom de la nouvelle numérotation")) m_saw_2 -> setContext(NumerotationContext()); - else m_saw_2 ->setContext(project_->folioAutoNum(str)); +void ProjectAutoNumConfigPage::updateContext_folio(QString str) { + if (str == tr("Nom de la nouvelle numérotation")) m_saw_folio -> setContext(NumerotationContext()); + else m_saw_folio ->setContext(project_->folioAutoNum(str)); } /** - * @brief ProjectAutoNumConfigPage::saveContext + * @brief ProjectAutoNumConfigPage::updateContext_element + * Display the current selected context for element + * @param str, key of context stored in project + */ +void ProjectAutoNumConfigPage::updateContext_element(QString str) { + if (str == tr("Nom de la nouvelle numérotation")) m_saw_element -> setContext(NumerotationContext()); + else m_saw_element ->setContext(project_->elementAutoNum(str)); +} + +/** + * @brief ProjectAutoNumConfigPage::saveContext_conductor * Save the current displayed conductor context in project */ -void ProjectAutoNumConfigPage::saveContext() { +void ProjectAutoNumConfigPage::saveContext_conductor() { // If the text is the default text "Name of new numerotation" save the edited context // With the the name "No name" - if (m_context_cb -> currentText() == tr("Nom de la nouvelle numérotation")) { - project_->addConductorAutoNum (tr("Sans nom"), m_saw -> toNumContext()); - m_context_cb -> addItem(tr("Sans nom")); + if (m_context_cb_conductor-> currentText() == tr("Nom de la nouvelle numérotation")) { + project_->addConductorAutoNum (tr("Sans nom"), m_saw_conductor -> toNumContext()); + 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->currentText())) { - project()->addConductorAutoNum(m_context_cb->currentText(), m_saw->toNumContext()); - m_context_cb -> addItem(m_context_cb->currentText()); + else if ( !project_ -> conductorAutoNum().keys().contains( m_context_cb_conductor->currentText())) { + project()->addConductorAutoNum(m_context_cb_conductor->currentText(), m_saw_conductor->toNumContext()); + 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_->addConductorAutoNum (m_context_cb -> currentText(), m_saw -> toNumContext()); + project_->addConductorAutoNum (m_context_cb_conductor-> currentText(), m_saw_conductor -> toNumContext()); } } /** - * @brief ProjectAutoNumConfigPage::saveContext_2 + * @brief ProjectAutoNumConfigPage::saveContext_folio * Save the current displayed folio context in project */ -void ProjectAutoNumConfigPage::saveContext_2() { +void ProjectAutoNumConfigPage::saveContext_folio() { // If the text is the default text "Name of new numerotation" save the edited context // With the the name "No name" - if (m_context_cb_2 -> currentText() == tr("Nom de la nouvelle numérotation")) { - project_->addFolioAutoNum (tr("Sans nom"), m_saw_2 -> toNumContext()); - m_context_cb_2 -> addItem(tr("Sans nom")); + if (m_context_cb_folio -> currentText() == tr("Nom de la nouvelle numérotation")) { + project_->addFolioAutoNum (tr("Sans nom"), m_saw_folio -> toNumContext()); + m_context_cb_folio -> 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_ -> folioAutoNum().keys().contains( m_context_cb_2->currentText())) { - project()->addFolioAutoNum(m_context_cb_2->currentText(), m_saw_2->toNumContext()); - m_context_cb_2 -> addItem(m_context_cb_2->currentText()); + else if ( !project_ -> folioAutoNum().keys().contains( m_context_cb_folio->currentText())) { + project()->addFolioAutoNum(m_context_cb_folio->currentText(), m_saw_folio->toNumContext()); + m_context_cb_folio -> addItem(m_context_cb_folio->currentText()); } // Else, the text already exist in the autonum of the project, just update the context else { - project_->addFolioAutoNum (m_context_cb_2 -> currentText(), m_saw_2 -> toNumContext()); + project_->addFolioAutoNum (m_context_cb_folio -> currentText(), m_saw_folio -> toNumContext()); } } /** - * @brief ProjectAutoNumConfigPage::saveContext_3 + * @brief ProjectAutoNumConfigPage::saveContext_element * Save the current displayed Element formula in project */ -void ProjectAutoNumConfigPage::saveContext_3() { - project()->addElementAutoNum (m_eaw->formula()); +void ProjectAutoNumConfigPage::saveContext_element() { + + // If the text is the default text "Name of new numerotation" save the edited context + // 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 (m_context_cb_element->currentText(), m_saw_element->elementFormula()); //add hash + project()->addElementAutoNumCurrentFormula (m_saw_element->elementFormula()); //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()->addElementAutoNumCurrentFormula (m_saw_element->elementFormula()); //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()->addElementAutoNumCurrentFormula (m_saw_element->elementFormula()); //add last added element formula to current formula + } } /** @@ -499,22 +560,35 @@ void ProjectAutoNumConfigPage::applyAutoNum() { * @brief ProjectAutoNumConfigPage::removeContext * Remove from project the current conductor numerotation context */ -void ProjectAutoNumConfigPage::removeContext() { +void ProjectAutoNumConfigPage::removeContext_conductor() { //if default text, return - if ( m_context_cb -> currentText() == tr("Nom de la nouvelle numérotation") ) return; - project_ -> removeConductorAutonum (m_context_cb -> currentText() ); - m_context_cb -> removeItem (m_context_cb -> currentIndex() ); + if ( m_context_cb_conductor-> currentText() == tr("Nom de la nouvelle numérotation") ) return; + project_ -> removeConductorAutoNum (m_context_cb_conductor-> currentText() ); + m_context_cb_conductor-> removeItem (m_context_cb_conductor-> currentIndex() ); } + /** - * @brief ProjectAutoNumConfigPage::removeContext_2 + * @brief ProjectAutoNumConfigPage::removeContext_folio * Remove from project the current folio numerotation context */ -void ProjectAutoNumConfigPage::removeContext_2() { +void ProjectAutoNumConfigPage::removeContext_folio() { //if default text, return - if ( m_context_cb_2 -> currentText() == tr("Nom de la nouvelle numérotation") ) return; - project_ -> removeFolioAutoNum (m_context_cb_2 -> currentText() ); - m_context_cb_2 -> removeItem (m_context_cb_2 -> currentIndex() ); + if ( m_context_cb_folio -> currentText() == tr("Nom de la nouvelle numérotation") ) return; + project_ -> removeFolioAutoNum (m_context_cb_folio -> currentText() ); + m_context_cb_folio -> removeItem (m_context_cb_folio -> currentIndex() ); } + +/** + * @brief ProjectAutoNumConfigPage::removeContext_element + * Remove from project the current element numerotation context + */ +void ProjectAutoNumConfigPage::removeContext_element() { + //if default text, return + if ( m_context_cb_element -> currentText() == tr("Nom de la nouvelle numérotation") ) return; + project_ -> removeElementAutoNum (m_context_cb_element -> currentText() ); + m_context_cb_element -> removeItem (m_context_cb_element -> currentIndex() ); +} + /** * @brief ProjectAutoNumConfigPage::changeToTab * @param tab index @@ -535,7 +609,7 @@ void ProjectAutoNumConfigPage::tabChanged(int i){ tab_widget->resize(470,tab_widget->height()); } else { - tab_widget->resize(455,tab_widget->height()); + tab_widget->resize(465,tab_widget->height()); } } } diff --git a/sources/projectconfigpages.h b/sources/projectconfigpages.h index 6b167cea1..bfcc58a15 100644 --- a/sources/projectconfigpages.h +++ b/sources/projectconfigpages.h @@ -141,13 +141,15 @@ class ProjectAutoNumConfigPage : public ProjectConfigPage { private: void buildConnections(); private slots: - void updateContext(QString); - void saveContext(); - void removeContext(); //conductor - void updateContext_2(QString); - void saveContext_2(); //folio - void removeContext_2(); - void saveContext_3(); //element + void updateContext_conductor(QString);//conductor + void saveContext_conductor(); + void removeContext_conductor(); + void updateContext_folio(QString);//folio + void saveContext_folio(); + void removeContext_folio(); + void updateContext_element(QString);//element + void saveContext_element(); + void removeContext_element(); void applyAutoNum(); @@ -167,14 +169,18 @@ class ProjectAutoNumConfigPage : public ProjectConfigPage { QWidget *folio_tab_widget; QWidget *autoNumbering_tab_widget; QScrollArea *scrollArea; - QLabel *m_label; - QLabel *m_label_2; - QComboBox *m_context_cb; - QComboBox *m_context_cb_2; - QPushButton *m_remove_pb; - QPushButton *m_remove_pb_2; - SelectAutonumW *m_saw; - SelectAutonumW *m_saw_2; + QLabel *m_label_conductor; + QLabel *m_label_folio; + QLabel *m_label_element; + QComboBox *m_context_cb_conductor; + QComboBox *m_context_cb_folio; + QComboBox *m_context_cb_element; + QPushButton *m_remove_pb_conductor; + QPushButton *m_remove_pb_folio; + QPushButton *m_remove_pb_element; + SelectAutonumW *m_saw_conductor; + SelectAutonumW *m_saw_folio; + SelectAutonumW *m_saw_element; FolioAutonumberingW *m_faw; ElementAutonumberingW *m_eaw; diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 4bc1e4ce9..e0c608264 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -309,8 +309,8 @@ void CustomElement::parseLabels() { prefix = rxml.readElementText(); DiagramContext &dc = this->rElementInformations(); //if there is a formula to assign, assign it - if (!location().project()->elementAutoNum().isEmpty() && this->linkType()!=Element::Slave) { - QString formula = location().project()->elementAutoNum(); + if (!location().project()->elementAutoNumFormula().isEmpty() && this->linkType()!=Element::Slave) { + QString formula = location().project()->elementAutoNumFormula(); formula.replace("%prefix", prefix); dc.addValue("label", formula); this->setTaggedText("label",formula); @@ -336,8 +336,8 @@ void CustomElement::parseLabels() { } //apply formula to specific label else if ((this->taggedText("label")!= NULL) && (location().projectId()!=-1) && - (!location().project()->elementAutoNum().isEmpty()) && (this->linkType()!=Element::Slave)) { - QString formula = location().project()->elementAutoNum(); + (!location().project()->elementAutoNumFormula().isEmpty()) && (this->linkType()!=Element::Slave)) { + QString formula = location().project()->elementAutoNumFormula(); DiagramContext &dc = this->rElementInformations(); QString prefix = this->taggedText("label")->toPlainText(); formula.replace("%prefix", prefix); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 74e46c44f..4da4881dd 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -26,6 +26,7 @@ #include "terminal.h" #include "PropertiesEditor/propertieseditordialog.h" #include "elementpropertieswidget.h" +#include "numerotationcontextcommands.h" /** Constructeur pour un element sans scene ni parent @@ -677,3 +678,69 @@ QString Element::assignVariables(QString label, Element *elmt){ label.replace("%total", QString::number(elmt->diagram()->border_and_titleblock.folioTotal())); return label; } + +/** + * @brief Element::assignSeq() + * Assign sequential values to element label + */ +void Element::assignSeq() { + DiagramContext &dc = this->rElementInformations(); + QString formula = diagram()->project()->elementAutoNumFormula(); + QHash hash = diagram()->project()->elementAutoNum_2(); + QString formula_name = hash.key(formula); + QString label = dc["label"].toString(); + qDebug() << "Label" << label; + NumerotationContext nc = diagram()->project()->elementAutoNum(formula_name); + NumerotationContextCommands ncc (nc); + if (!nc.isEmpty()) { + if (label.contains("%sequ_")) { + int count = 1; + for (int i = 0; i < nc.size(); i++) { + if (nc.itemAt(i).at(0) == "unit") { + label.replace("%sequ_" + QString::number(count), QString::number(nc.itemAt(i).at(1).toInt())); + count++; + } + } + } + if (label.contains("%seqt_")) { + int count = 1; + for (int i = 0; i < nc.size(); i++) { + if (nc.itemAt(i).at(0) == "ten") { + label.replace("%seqt_" + QString::number(count), QString::number(nc.itemAt(i).at(1).toInt())); + count++; + } + } + } + if (label.contains("%seqh_")) { + int count = 1; + for (int i = 0; i < nc.size(); i++) { + if (nc.itemAt(i).at(0) == "hundred") { + label.replace("%seqh_" + QString::number(count), QString::number(nc.itemAt(i).at(1).toInt())); + count++; + } + } + } + } + dc.addValue("label",label); + this->diagram()->project()->addElementAutoNum(formula_name,ncc.next()); + this->setElementInformations(dc); + this->setTaggedText("label", label); +} + +/** + * @brief ElementTextItem::setTaggedText + * Set text @newstr to the text tagged with @tagg. + * If tagg is found return the text item, else return NULL. + * @param tagg required tagg + * @param newstr new label + * @param noeditable set editable or not (by default, set editable) + */ +ElementTextItem* Element::setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable) { + ElementTextItem *eti = taggedText(tagg); + if (eti) { + eti -> setPlainText(newstr); + eti -> setNoEditable(noeditable); + } + return eti; +} + diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 7e60abf1e..7335d2d4a 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -118,6 +118,7 @@ class Element : public QetGraphicsItem { QList tmp_uuids_link; QUuid uuid_; kind link_type_; + ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false); signals: void linkedElementChanged(); //This signal is emited when the linked elements with this element change @@ -133,6 +134,7 @@ class Element : public QetGraphicsItem { //about the herited class like contactelement for know // kind of contact (simple tempo) or number of contact show by the element. QString assignVariables (QString, Element *); + void assignSeq (); //ATTRIBUTES protected: diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index 8431ea400..290e8ff5f 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -128,7 +128,7 @@ void MasterElement::initLink(QETProject *project) { */ void MasterElement::changeElementInfo(){ QString temp_label = this->elementInformations()["label"].toString(); - if (temp_label.contains("\%l")||temp_label.contains("\%c")||temp_label.contains("\%f")||temp_label.contains("\%F")) { + if (temp_label.contains("\%")) { if (this->diagram()!=NULL) this->updateLabel(this->elementInformations(),this->elementInformations()); } diff --git a/sources/qetgraphicsitem/simpleelement.cpp b/sources/qetgraphicsitem/simpleelement.cpp index c80cf8539..66468fc04 100644 --- a/sources/qetgraphicsitem/simpleelement.cpp +++ b/sources/qetgraphicsitem/simpleelement.cpp @@ -62,7 +62,7 @@ void SimpleElement::initLink(QETProject *project) { */ void SimpleElement::changeElementInfo(){ QString temp_label = this->elementInformations()["label"].toString(); - if (temp_label.contains("\%l")||temp_label.contains("\%c")||temp_label.contains("\%f")||temp_label.contains("\%F")) { + if (temp_label.contains("\%")) { if (this->diagram()!=NULL) this->updateLabel(this->elementInformations(),this->elementInformations()); } diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index e5e77cfb2..afe522921 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -410,15 +410,42 @@ QHash QETProject::conductorAutoNum() const { /** * @brief QETProject::elementAutoNum - * @return Formula of element autonum stored in project + * @return All value of element autonum stored in project */ -QString QETProject::elementAutoNum() const { +QHash QETProject::elementAutoNum() const { return m_element_autonum; } +/** + * @brief QETProject::elementAutoNum_2 + * @return Title and Formula Hash + */ +QHash QETProject::elementAutoNum_2() { + return m_element_autonum_formula; +} + +/** + * @brief QETProject::elementAutoNumFormula + * @param element autonum title + * @return Formula of element autonum stored in element autonum + */ +QString QETProject::elementAutoNumFormula (QString key) const { + if (m_element_autonum.contains(key)) + return m_element_autonum_formula[key]; + else return ""; +} + +/** + * @brief QETProject::elementAutoNumFormula + * @return current formula being used by project + */ +QString QETProject::elementAutoNumFormula () const { + return m_current_element_formula; +} + /** * @brief QETProject::folioAutoNum - * @return All value of conductor autonum stored in project + * @return All value of folio autonum stored in project */ QHash QETProject::folioAutoNum() const { return m_folio_autonum; @@ -436,12 +463,33 @@ void QETProject::addConductorAutoNum(QString key, NumerotationContext context) { } /** - * @brief QETProject::addElementAutoNum + * @brief QETProject::addElementAutoNumFormula * Add the new formula * @param formula */ -void QETProject::addElementAutoNum(QString formula) { - m_element_autonum = formula; +void QETProject::addElementAutoNumFormula(QString key, QString formula) { + m_element_autonum_formula.insert(key, formula); +} + +/** + * @brief QETProject::addElementAutoNumCurrentFormula + * Add the formula to the current formula + * @param formula + */ +void QETProject::addElementAutoNumCurrentFormula(QString formula) { + m_current_element_formula = formula; +} + + +/** + * @brief QETProject::addElementAutoNum + * Add a new element numerotation context. If key already exist, + * replace old context by the new context + * @param key + * @param context + */ +void QETProject::addElementAutoNum(QString key, NumerotationContext context) { + m_element_autonum.insert(key, context); } /** @@ -456,14 +504,23 @@ void QETProject::addFolioAutoNum(QString key, NumerotationContext context) { } /** - * @brief QETProject::removeConductorAutonum + * @brief QETProject::removeConductorAutoNum * Remove Conductor Numerotation Context stored with key * @param key */ -void QETProject::removeConductorAutonum(QString key) { +void QETProject::removeConductorAutoNum(QString key) { m_conductor_autonum.remove(key); } +/** + * @brief QETProject::removeElementAutonum + * Remove Element Numerotation Context stored with key + * @param key + */ +void QETProject::removeElementAutoNum(QString key) { + m_element_autonum.remove(key); +} + /** * @brief QETProject::removeFolioAutonum * Remove Folio Numerotation Context stored with key @@ -484,6 +541,17 @@ NumerotationContext QETProject::conductorAutoNum (const QString &key) const { else return NumerotationContext(); } +/** + * @brief QETProject::elementAutoNum + * Return element numerotation context stored with @key. + * If key is not found, return an empty numerotation context + * @param key + */ +NumerotationContext QETProject::elementAutoNum (const QString &key) const { + if (m_element_autonum.contains(key)) return m_element_autonum[key]; + else return NumerotationContext(); +} + /** * @brief QETProject::folioAutoNum * Return folio numerotation context stored with @key. @@ -508,7 +576,7 @@ bool QETProject::autoConductor() const /** * @brief QETProject::autoFolio * @return true if use of auto folio is authorized. - * See also Q_PROPERTY autoFolio + * See also Q_PROPERTY autoConductor */ bool QETProject::autoFolio() const { @@ -531,7 +599,7 @@ void QETProject::setAutoConductor(bool ac) * @brief QETProject::setAutoFolio * @param ac * Enable the use of auto folio if true - * See also Q_PROPERTY autoConductor + * See also Q_PROPERTY autoFolio */ void QETProject::setAutoFolio(bool af) { @@ -1244,7 +1312,7 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project) if (!folio_autonums.isNull()) { foreach (QDomElement elmt, QET::findInDomElement(folio_autonums, "folio_autonum")) - { + { NumerotationContext nc; nc.fromXml(elmt); m_folio_autonum.insert(elmt.attribute("title"), nc); @@ -1252,7 +1320,14 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project) } if (!element_autonums.isNull()) { - m_element_autonum = element_autonums.attribute("formula"); + m_current_element_formula = element_autonums.attribute("current_formula"); + foreach (QDomElement elmt, QET::findInDomElement(element_autonums, "element_autonum")) + { + NumerotationContext nc; + nc.fromXml(elmt); + m_element_autonum.insert(elmt.attribute("title"), nc); + m_element_autonum_formula.insert(elmt.attribute("title"),elmt.attribute("formula")); + } } } @@ -1326,7 +1401,13 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) { //Export Element Autonums QDomElement element_autonums = xml_document.createElement("element_autonums"); - element_autonums.setAttribute("formula", m_element_autonum); + element_autonums.setAttribute("current_formula", m_current_element_formula); + foreach (QString key, elementAutoNum().keys()) { + QDomElement element_autonum = elementAutoNum(key).toXml(xml_document, "element_autonum"); + element_autonum.setAttribute("title", key); + element_autonum.setAttribute("formula", elementAutoNumFormula(key)); + element_autonums.appendChild(element_autonum); + } xml_element.appendChild(element_autonums); } diff --git a/sources/qetproject.h b/sources/qetproject.h index dc394b863..8642425f9 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -107,19 +107,28 @@ class QETProject : public QObject void setDefaultXRefProperties(QHash hash); QHash conductorAutoNum() const; + QHash elementAutoNum() const; + QHash elementAutoNum_2(); QHash folioAutoNum() const; void addConductorAutoNum (QString key, NumerotationContext context); - void addElementAutoNum (QString formula); + void addElementAutoNum (QString key, NumerotationContext context); + void addElementAutoNumFormula (QString key, QString formula); + void addElementAutoNumCurrentFormula (QString formula); void addFolioAutoNum (QString key, NumerotationContext context); - void removeConductorAutonum (QString key); + void removeConductorAutoNum (QString key); + void removeElementAutoNum (QString key); void removeFolioAutoNum (QString key); NumerotationContext conductorAutoNum(const QString &key) const; - NumerotationContext folioAutoNum(const QString &key) const; - QString elementAutoNum() const; + NumerotationContext folioAutoNum(const QString &key) const; + NumerotationContext elementAutoNum(const QString &key) const; + QString elementAutoNumFormula(const QString key) const; //returns Formula + QString elementAutoNumFormula() const; - bool autoConductor () const; - bool autoFolio () const; + bool autoConductor () const; + bool autoElement () const; + bool autoFolio () const; void setAutoConductor (bool ac); + void setAutoElement (bool ae); void setAutoFolio (bool af); void autoFolioNumberingNewFolios (); void autoFolioNumberingSelectedFolios(int, int, QString); @@ -223,7 +232,9 @@ class QETProject : public QObject /// Folio auto numbering QHash m_folio_autonum; /// Element Auto Numbering - QString m_element_autonum; + QHash m_element_autonum_formula; //Title and Formula hash + QHash m_element_autonum; //Title and NumContext hash + QString m_current_element_formula; /// Folio List Sheets quantity for this project. int folioSheetsQuantity; bool m_auto_conductor; diff --git a/sources/ui/elementautonumberingw.cpp b/sources/ui/elementautonumberingw.cpp index 4a9200e47..04b5b06e3 100644 --- a/sources/ui/elementautonumberingw.cpp +++ b/sources/ui/elementautonumberingw.cpp @@ -30,7 +30,7 @@ ElementAutonumberingW::ElementAutonumberingW(QWidget *parent) : { ui->setupUi(this); - applyEnable(false); + setContext(formula_); } /** @@ -49,6 +49,14 @@ void ElementAutonumberingW::setContext(QString formula) { ui->m_formula_le->insert(formula); } +/** + * @brief ElementAutonumberingW::clearContext + * @param clear formula line edit text + */ +void ElementAutonumberingW::clearContext() { + ui->m_formula_le->clear(); +} + /** * @brief ElementAutonumberingW::formula * @return formula to be stored into project @@ -61,32 +69,6 @@ QString ElementAutonumberingW::formula() { * @brief ElementAutonumberingW::on_m_formula_le_textChanged * Update Apply Button */ -void ElementAutonumberingW::on_m_formula_le_textChanged() { - if (!ui->m_formula_le->text().isEmpty()) - applyEnable(true); - else applyEnable(false); -} - -/** - * @brief ElementAutonumberingW::on_buttonBox_clicked - * Action on @buttonBox clicked - */ -void ElementAutonumberingW::on_buttonBox_clicked(QAbstractButton *button) { - //transform button to int - int answer = ui -> buttonBox -> buttonRole(button); - - switch (answer) { - case QDialogButtonBox::ApplyRole: - applyEnable(true); - emit applyPressed(); - break; - } -} - -/** - * @brief ElementAutonumberingW::applyEnable - * enable/disable the apply button - */ -void ElementAutonumberingW::applyEnable(bool b) { - ui -> buttonBox -> button(QDialogButtonBox::Apply) -> setEnabled(b); +void ElementAutonumberingW::on_m_formula_le_textChanged(QString text) { + emit (textChanged(text)); } diff --git a/sources/ui/elementautonumberingw.h b/sources/ui/elementautonumberingw.h index 163e044d9..b01e1d523 100644 --- a/sources/ui/elementautonumberingw.h +++ b/sources/ui/elementautonumberingw.h @@ -42,23 +42,24 @@ class ElementAutonumberingW : public QWidget ~ElementAutonumberingW(); QString formula(); void setContext(QString); - + void clearContext(); + Ui::ElementAutonumberingW *ui; private: // SIGNALS signals: void applyPressed(); + void textChanged(QString); //SLOTS private slots: - void on_m_formula_le_textChanged(); - void on_buttonBox_clicked(QAbstractButton *); - void applyEnable (bool = true); + void on_m_formula_le_textChanged(QString); //ATTRIBUTES private: - Ui::ElementAutonumberingW *ui; + QString formula_; + }; #endif // ELEMENTAUTONUMBERINGW_H diff --git a/sources/ui/elementautonumberingw.ui b/sources/ui/elementautonumberingw.ui index 187822c83..e94cde21c 100644 --- a/sources/ui/elementautonumberingw.ui +++ b/sources/ui/elementautonumberingw.ui @@ -6,19 +6,19 @@ 0 0 - 460 - 550 + 383 + 305 - + 0 0 - 460 + 0 0 @@ -30,117 +30,59 @@ QLayout::SetDefaultConstraint - + - + 0 - 50 + 0 - - - 0 - 0 - + + Auto Naming Pattern: - - - 0 - 50 - + + + + + + 0 + 0 + + + + + + + + + + Insert Formula Here e.g.: %prefix%l%c + + + + + + + + 0 + 0 + + + + Formula: + + + + + + + + + + - - false - - - Qt::LeftToRight - - - Qt::ScrollBarAsNeeded - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - Qt::AlignHCenter|Qt::AlignTop - - - - - 0 - 0 - 440 - 498 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - QLayout::SetFixedSize - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Auto Naming Pattern: - - - - - - - - - - - - Insert Formula Here e.g.: %prefix%l%c - - - - - - - Formula: - - - - - - - - - - You can use the following variables to your formula: + + You can use the following variables to your formula: -%prefix: Default Element Prefix -%l: Element Line -%c: Element Column @@ -148,29 +90,23 @@ -%f or %id: Folio ID -%total: Total of folios You can also assign any other titleblock variable -that you create. Text and number inputs are also available - - - - - - - - +that you create. Text and number inputs are + also available. + - - - - 0 - 0 - + + + Qt::Vertical - - QDialogButtonBox::Apply + + + 20 + 40 + - + diff --git a/sources/ui/numparteditorw.cpp b/sources/ui/numparteditorw.cpp index b1ad10a8e..043c23a42 100644 --- a/sources/ui/numparteditorw.cpp +++ b/sources/ui/numparteditorw.cpp @@ -29,6 +29,7 @@ NumPartEditorW::NumPartEditorW(QWidget *parent) : { ui -> setupUi(this); if (parentWidget()->parentWidget()->objectName()=="FolioTab") ui->type_combo->setMaxCount(4); + else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") ui->type_combo->setMaxCount(6); setType(NumPartEditorW::unit, true); } @@ -42,7 +43,8 @@ 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(5); + 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 if(context.size()==0) setType(NumPartEditorW::unit, true); @@ -54,6 +56,9 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context, int i, QWidget *pa 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); + else if (strl.at(0)=="elementline") setType(NumPartEditorW::elementline); + else if (strl.at(0)=="elementcolumn") setType(NumPartEditorW::elementcolumn); + else if (strl.at(0)=="elementprefix") setType(NumPartEditorW::elementprefix); ui -> value_field -> setText(strl.at(1)); ui -> increase_spinBox -> setValue(strl.at(2).toInt()); } @@ -94,6 +99,15 @@ NumerotationContext NumPartEditorW::toNumContext() { case folio: type_str = "folio"; break; + case elementline: + type_str = "elementline"; + break; + case elementcolumn: + type_str = "elementcolumn"; + break; + case elementprefix: + type_str = "elementprefix"; + break; } nc.addValue(type_str, ui -> value_field -> displayText(), ui -> increase_spinBox -> value()); return nc; @@ -104,7 +118,8 @@ NumerotationContext NumPartEditorW::toNumContext() { * @return true if value field isn't empty or if type is folio */ bool NumPartEditorW::isValid() { - if (type_ == folio||type_ == idfolio) {return true;} + if (type_ == folio || type_ == idfolio || type_ == elementline || + type_ == elementcolumn || type_ == elementprefix) {return true;} else if(ui -> value_field -> text().isEmpty()) {return false;} else return true; } @@ -133,6 +148,15 @@ void NumPartEditorW::on_type_combo_activated(int index) { case folio: setType(folio); break; + case elementline: + setType(elementline); + break; + case elementcolumn: + setType(elementcolumn); + break; + case elementprefix: + setType(elementprefix); + break; }; emit changed(); } @@ -164,7 +188,10 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) { //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) && (type_==string || type_==folio || type_==idfolio)) || fnum) { + if ( ((t==unit || t==ten || t==hundred) && + (type_==string || type_==folio || type_==idfolio || + type_==elementcolumn || type_==elementline || type_==elementprefix)) + || fnum) { ui -> value_field -> clear(); ui -> value_field -> setEnabled(true); ui -> value_field -> setValidator(intValidator); @@ -172,7 +199,8 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) { ui -> increase_spinBox -> setValue(1); } //@t isn't a numeric type - else if (t==string || t==folio || t==idfolio) { + else if (t == string || t == folio || t == idfolio || t == elementline || + t == elementcolumn || t == elementprefix) { ui -> value_field -> clear(); ui -> increase_spinBox -> setDisabled(true); if (t==string) { @@ -187,6 +215,18 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) { ui -> value_field -> setDisabled(true); ui -> increase_spinBox -> setDisabled(true); } + else if (t==elementcolumn) { + ui -> value_field -> setDisabled(true); + ui -> increase_spinBox -> setDisabled(true); + } + else if (t==elementline) { + ui -> value_field -> setDisabled(true); + ui -> increase_spinBox -> setDisabled(true); + } + else if (t==elementprefix) { + ui -> value_field -> setDisabled(true); + ui -> increase_spinBox -> setDisabled(true); + } } type_= t; } diff --git a/sources/ui/numparteditorw.h b/sources/ui/numparteditorw.h index 90fdf9060..211d4648b 100644 --- a/sources/ui/numparteditorw.h +++ b/sources/ui/numparteditorw.h @@ -41,10 +41,10 @@ class NumPartEditorW : public QWidget NumPartEditorW (NumerotationContext &, int, QWidget *parent=0); ~NumPartEditorW(); - enum type {unit,ten,hundred,string,idfolio,folio}; + enum type {unit,ten,hundred,string,idfolio,folio,elementline,elementcolumn,elementprefix}; NumerotationContext toNumContext(); bool isValid (); - + type type_; private slots: void on_type_combo_activated(int); @@ -58,7 +58,7 @@ class NumPartEditorW : public QWidget private: Ui::NumPartEditorW *ui; QValidator *intValidator; - type type_; + }; diff --git a/sources/ui/numparteditorw.ui b/sources/ui/numparteditorw.ui index 15e9a5f59..a9d17e9e3 100644 --- a/sources/ui/numparteditorw.ui +++ b/sources/ui/numparteditorw.ui @@ -6,20 +6,29 @@ 0 0 - 308 - 45 + 368 + 33 Form + + 3 + 0 + + 2 + 0 + + 2 + @@ -61,6 +70,21 @@ Folio + + + Element Line + + + + + Element Column + + + + + Element Prefix + + diff --git a/sources/ui/selectautonumw.cpp b/sources/ui/selectautonumw.cpp index 3b790b1db..086e2caaa 100644 --- a/sources/ui/selectautonumw.cpp +++ b/sources/ui/selectautonumw.cpp @@ -20,6 +20,9 @@ #include "numparteditorw.h" #include #include "numerotationcontextcommands.h" +#include "elementautonumberingw.h" +#include "ui_elementautonumberingw.h" +#include "qdebug.h" /** * Constructor @@ -28,7 +31,13 @@ SelectAutonumW::SelectAutonumW(QWidget *parent) : QWidget(parent), ui(new Ui::SelectAutonumW) { + ui->setupUi(this); + if (this->parentWidget() -> objectName()=="ElementTab"){ + m_eaw = new ElementAutonumberingW(); + connect(m_eaw,SIGNAL(textChanged(QString)),this,SLOT(formula_textChanged(QString))); + ui->scrollAreaWidgetContents->layout()->addWidget(m_eaw); + } setContext(NumerotationContext()); } @@ -36,6 +45,11 @@ SelectAutonumW::SelectAutonumW(const NumerotationContext &context, QWidget *pare QWidget(parent), ui(new Ui::SelectAutonumW) { + if (this->parentWidget() -> objectName()=="ElementTab"){ + m_eaw = new ElementAutonumberingW(); + connect(m_eaw,SIGNAL(textChanged(QString)),this,SLOT(formula_textChanged(QString))); + ui->scrollAreaWidgetContents->layout()->addWidget(m_eaw); + } ui->setupUi(this); setContext(context); } @@ -117,6 +131,14 @@ void SelectAutonumW::on_remove_button_clicked() { applyEnable(); } +/** + * @brief SelectAutonumW::elementFormula + * @return element autonumbering widget formula + */ +QString SelectAutonumW::elementFormula() { + return m_eaw->formula(); +} + /** * @brief SelectAutonumW::on_buttonBox_clicked * Action on @buttonBox clicked @@ -189,8 +211,56 @@ void SelectAutonumW::applyEnable(bool b) { foreach (NumPartEditorW *npe, num_part_list_) if (!npe -> isValid()) valid= false; ui -> buttonBox -> button(QDialogButtonBox::Apply) -> setEnabled(valid); } - else + else { ui -> buttonBox -> button(QDialogButtonBox::Apply) -> setEnabled(b); + } + if (this->parentWidget() -> objectName()=="ElementTab") + contextToFormula(); +} + +/** + * @brief SelectAutonumW::contextToFormula + * Apply formula to ElementAutonumbering Widget + */ +void SelectAutonumW::contextToFormula() { + m_eaw->clearContext(); + int count_unit = 0; + int count_ten = 0; + int count_hundred = 0; + foreach (NumPartEditorW *npe, num_part_list_) { + if (npe->isValid()) { + if (npe->type_ == NumPartEditorW::idfolio) { + m_eaw->setContext("%id"); + } + else if (npe->type_ == NumPartEditorW::folio) { + m_eaw->setContext("%F"); + } + else if (npe->type_ == NumPartEditorW::elementcolumn) { + m_eaw->setContext("%c"); + } + else if (npe->type_ == NumPartEditorW::elementline) { + m_eaw->setContext("%l"); + } + else if (npe->type_ == NumPartEditorW::elementprefix) { + m_eaw->setContext("%prefix"); + } + else if (npe->type_ == NumPartEditorW::string) { + m_eaw->setContext(npe->toNumContext().itemAt(0).at(1)); + } + else if (npe->type_ == NumPartEditorW::unit) { + count_unit++; + m_eaw->setContext("%sequ_"+QString::number(count_unit)); + } + else if (npe->type_ == NumPartEditorW::ten) { + count_ten++; + m_eaw->setContext("%seqt_"+QString::number(count_ten)); + } + else if (npe->type_ == NumPartEditorW::hundred) { + count_hundred++; + m_eaw->setContext("%seqh_"+QString::number(count_hundred)); + } + } + } } /** diff --git a/sources/ui/selectautonumw.h b/sources/ui/selectautonumw.h index 4deaf7aa6..0f5b9e0f4 100644 --- a/sources/ui/selectautonumw.h +++ b/sources/ui/selectautonumw.h @@ -20,6 +20,7 @@ #include #include "numerotationcontext.h" +#include "elementautonumberingw.h" class NumPartEditorW; class QAbstractButton; @@ -40,6 +41,8 @@ class SelectAutonumW : public QWidget void setContext (const NumerotationContext &context); NumerotationContext toNumContext() const; + void contextToFormula (); + QString elementFormula(); signals: void applyPressed(); @@ -51,15 +54,15 @@ class SelectAutonumW : public QWidget void on_buttonBox_clicked(QAbstractButton *); void applyEnable (bool = true); - //ATTRIBUTS + //ATTRIBUTES void on_m_next_pb_clicked(); - void on_m_previous_pb_clicked(); private: Ui::SelectAutonumW *ui; QList num_part_list_; NumerotationContext m_context; + ElementAutonumberingW *m_eaw; }; #endif // SELECTAUTONUMW_H diff --git a/sources/ui/selectautonumw.ui b/sources/ui/selectautonumw.ui index c644bd9c2..6c333f0d4 100644 --- a/sources/ui/selectautonumw.ui +++ b/sources/ui/selectautonumw.ui @@ -7,7 +7,7 @@ 0 0 418 - 506 + 508 @@ -269,7 +269,7 @@ 20 - 30 + 0