diff --git a/sources/bordertitleblock.h b/sources/bordertitleblock.h index 666e2cc1c..128f45c7c 100644 --- a/sources/bordertitleblock.h +++ b/sources/bordertitleblock.h @@ -138,7 +138,10 @@ class BorderTitleBlock : public QObject } } /// @param author the new value of the "Folio" field - void setFolio(const QString &folio) { btb_folio_ = folio; } + void setFolio(const QString &folio) { + btb_folio_ = folio; + emit (titleBlockFolioChanged()); + } void setFolioData(int, int, QString = NULL, const DiagramContext & = DiagramContext()); /// @param author the new value of the "File" field void setFileName(const QString &filename) { btb_filename_ = filename; } @@ -191,6 +194,12 @@ class BorderTitleBlock : public QObject Signal emitted after the title has changed */ void diagramTitleChanged(const QString &); + + /** + @brief titleBlockFolioChanged + Signal emitted after Folio has changed + */ + void titleBlockFolioChanged(); /** Signal emitted when the title block requires its data to be updated in order diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 568efa656..272eb9c47 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -78,6 +78,7 @@ Diagram::Diagram(QETProject *project) : connect(&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)), this, SLOT(setTitleBlockTemplate(const QString &))); 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())); adjustSceneRect(); } @@ -1056,6 +1057,22 @@ void Diagram::invertSelection() { emit(selectionChanged()); } +/** + * @brief Diagram::updateLabels + * Update elements and conductors that reference folio field + * in their labels. + */ +void Diagram::updateLabels() { + foreach (Element *elmt, elements()) { + if (elmt->elementInformations()["label"].toString().contains(("%F"))) + elmt->updateLabel(); + } + foreach (Conductor *cnd, content().conductors()) { + if (cnd->properties().text.contains("%F")) + cnd->setText(cnd->properties().text); + } +} + /** @return le titre du cartouche */ diff --git a/sources/diagram.h b/sources/diagram.h index e48535fc4..52c7c6679 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -215,12 +215,13 @@ class Diagram : public QGraphicsScene void titleBlockTemplateChanged(const QString &); void titleBlockTemplateRemoved(const QString &, const QString & = QString()); void setTitleBlockTemplate(const QString &); + void updateLabels(); // methods related to graphics items selection void selectAll(); void deselectAll(); void invertSelection(); - + signals: void showDiagram (Diagram *); void written(); diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index fc5790687..4fbce12c2 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1191,16 +1191,58 @@ ConductorProfile Conductor::profile(Qt::Corner path_type) const { /// @return le texte du conducteur QString Conductor::text() const { - return(text_item -> toPlainText()); + QString label = text_item->toPlainText(); + return(label); } +/** + * @brief Conductor::assignVariables + * Apply variables to conductor label + * @param label to be processed + * @return label with variables assigned + */ +QString Conductor::assignVariables(QString label) { + //Titleblock Variables + for (int i = 0; i < diagram()->border_and_titleblock.additionalFields().count(); i++) + { + QString folio_variable = diagram()->border_and_titleblock.additionalFields().keys().at(i); + QVariant folio_value = diagram()->border_and_titleblock.additionalFields().operator [](folio_variable); + + if (label.contains(folio_variable)) { + label.replace("%{" + folio_variable + "}", folio_value.toString()); + label.replace("%" + folio_variable , folio_value.toString()); + } + } + + //Project Variables + for (int i = 0; i < diagram()->project()->projectProperties().count(); i++) + { + QString folio_variable = diagram()->project()->projectProperties().keys().at(i); + QVariant folio_value = diagram()->project()->projectProperties().operator [](folio_variable); + + if (label.contains(folio_variable)) { + label.replace("%{" + folio_variable + "}", folio_value.toString()); + label.replace("%" + folio_variable , folio_value.toString()); + } + } + + //Default Variables + label.replace("%f", QString::number(diagram()->folioIndex()+1)); + label.replace("%F", diagram() -> border_and_titleblock.folio()); + label.replace("%id", QString::number(diagram()->folioIndex()+1)); + label.replace("%total", QString::number(diagram()->border_and_titleblock.folioTotal())); + return label; +} + + /** * @brief Conductor::setText * The text of this conductor * @param t */ void Conductor::setText(const QString &t) { - text_item -> setPlainText(t); + QString label = assignVariables(t); + text_item -> setPlainText(label); } /** @@ -1269,7 +1311,7 @@ void Conductor::setHighlighted(Conductor::Highlight hl) { */ void Conductor::displayedTextChanged() { - if ((text_item->toPlainText() == properties_.text) || !diagram()) return; + if ((text_item->toPlainText() == assignVariables(properties_.text)) || !diagram()) return; QVariant old_value, new_value; old_value.setValue(properties_); diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index b46dec254..140b17cc2 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -92,6 +92,7 @@ class Conductor : public QObject, public QGraphicsPathItem ConductorSegment *middleSegment(); QPointF posForText(Qt::Orientations &flag); QString text() const; + QString assignVariables(QString) ; void setText(const QString &); public: