diff --git a/sources/diagramcontext.cpp b/sources/diagramcontext.cpp index d091b6d5c..fba80cb58 100644 --- a/sources/diagramcontext.cpp +++ b/sources/diagramcontext.cpp @@ -21,8 +21,18 @@ /** @return a list containing all the keys in the context object. */ -QList DiagramContext::keys() const { - return(content_.keys()); +QList DiagramContext::keys(DiagramContext::KeyOrder order) const { + if (order == None) { + return content_.keys(); + } else { + QList keys_list = content_.keys(); + if (order == Alphabetical) { + qSort(keys_list); + } else { + qSort(keys_list.begin(), keys_list.end(), DiagramContext::stringLongerThan); + } + return(keys_list); + } } /** @@ -71,6 +81,13 @@ QString DiagramContext::validKeyRegExp() { return("^[a-z0-9-]+$"); } +/** + @return True if \a a is longer than \a b, false otherwise. +*/ +bool DiagramContext::stringLongerThan(const QString &a, const QString &b) { + return (a.length() > b.length()); +} + /** @param key a key string @return true if that key is acceptable, false otherwise diff --git a/sources/diagramcontext.h b/sources/diagramcontext.h index d1c4cecd5..20cc4453c 100644 --- a/sources/diagramcontext.h +++ b/sources/diagramcontext.h @@ -27,7 +27,12 @@ */ class DiagramContext { public: - QList keys() const; + enum KeyOrder { + None, + Alphabetical, + DecreasingLength + }; + QList keys(KeyOrder = None) const; bool contains(const QString &) const; const QVariant operator[](const QString &) const; bool addValue(const QString &, const QVariant &); @@ -38,6 +43,7 @@ class DiagramContext { static QString validKeyRegExp(); private: + static bool stringLongerThan(const QString &, const QString &); bool keyIsAcceptable(const QString &) const; /// Diagram context data (key/value pairs) QHash content_; diff --git a/sources/titleblockpropertieswidget.cpp b/sources/titleblockpropertieswidget.cpp index 3bb58295c..8f355978d 100644 --- a/sources/titleblockpropertieswidget.cpp +++ b/sources/titleblockpropertieswidget.cpp @@ -145,7 +145,7 @@ void TitleBlockPropertiesWidget::clearDiagramContext() { void TitleBlockPropertiesWidget::setDiagramContext(const DiagramContext &context) { clearDiagramContext(); int i = 0; - foreach (QString key, context.keys()) { + foreach (QString key, context.keys(DiagramContext::Alphabetical)) { additional_fields_table -> setItem(i, 0, new QTableWidgetItem(key)); additional_fields_table -> setItem(i, 1, new QTableWidgetItem(context[key].toString())); ++ i; diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index d3a0b2c86..66352b459 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -1316,13 +1316,13 @@ QString TitleBlockTemplate::finalTextForCell(const TitleBlockCell &cell, const D } /** - @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 + @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()) { + foreach (QString key, diagram_context.keys(DiagramContext::DecreasingLength)) { interpreted_string.replace("%{" + key + "}", diagram_context[key].toString()); interpreted_string.replace("%" + key, diagram_context[key].toString()); }