diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 250ded6d0..4accb6e91 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -1284,11 +1284,10 @@ QString TitleBlockTemplate::finalTextForCell(const TitleBlockCell &cell, const D QString cell_text = cell.value.name(); QString cell_label = cell.label.name(); - foreach (QString key, diagram_context.keys()) { - cell_text.replace("%{" + key + "}", diagram_context[key].toString()); - cell_text.replace("%" + key, diagram_context[key].toString()); - } + cell_text = interpreteVariables(cell_text, diagram_context); + if (cell.display_label && !cell.label.isEmpty()) { + cell_label = interpreteVariables(cell_label, diagram_context); cell_text = QString(tr(" %1 : %2", "titleblock content - please let the blank space at the beginning")).arg(cell_label).arg(cell_text); } else { cell_text = QString(tr(" %1")).arg(cell_text); @@ -1296,6 +1295,20 @@ QString TitleBlockTemplate::finalTextForCell(const TitleBlockCell &cell, const D return(cell_text); } +/** + @param string A text containing 0 to n variables, e.g. "%var" or "%{var}" + @param diagram_context Diagram context to use to interprete variables + @return the provided string with variables replaced by the values from the diagram context +*/ +QString TitleBlockTemplate::interpreteVariables(const QString &string, const DiagramContext &diagram_context) const { + QString interpreted_string = string; + foreach (QString key, diagram_context.keys()) { + interpreted_string.replace("%{" + key + "}", diagram_context[key].toString()); + interpreted_string.replace("%" + key, diagram_context[key].toString()); + } + return(interpreted_string); +} + /** This method uses a \a painter to render the \a text of a \a cell into the \a cell_rect rectangle. diff --git a/sources/titleblocktemplate.h b/sources/titleblocktemplate.h index 0f215c3a7..c6859bbda 100644 --- a/sources/titleblocktemplate.h +++ b/sources/titleblocktemplate.h @@ -129,6 +129,7 @@ class TitleBlockTemplate : public QObject { void initCells(); int lengthRange(int, int, const QList &) const; QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const; + QString interpreteVariables(const QString &, const DiagramContext &) const; void renderTextCell(QPainter &, const QString &, const TitleBlockCell &, const QRectF &) const; // attributes