[qet] [1781] Title block templates: variables are now interpreted within labels too.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1781
Author:   xavier
Date:     2012-05-09 23:17:09 +0200 (Wed, 09 May 2012)
Log Message:
-----------
Title block templates: variables are now interpreted within labels too.

Modified Paths:
--------------
    trunk/sources/titleblocktemplate.cpp
    trunk/sources/titleblocktemplate.h

Modified: trunk/sources/titleblocktemplate.cpp
===================================================================
--- trunk/sources/titleblocktemplate.cpp	2012-05-09 17:21:46 UTC (rev 1780)
+++ trunk/sources/titleblocktemplate.cpp	2012-05-09 21:17:09 UTC (rev 1781)
@@ -1284,11 +1284,10 @@
 	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);
@@ -1297,6 +1296,20 @@
 }
 
 /**
+ @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.
 	The alignment, font_size and other cell parameters are taken into account

Modified: trunk/sources/titleblocktemplate.h
===================================================================
--- trunk/sources/titleblocktemplate.h	2012-05-09 17:21:46 UTC (rev 1780)
+++ trunk/sources/titleblocktemplate.h	2012-05-09 21:17:09 UTC (rev 1781)
@@ -129,6 +129,7 @@
 	void initCells();
 	int lengthRange(int, int, const QList<int> &) 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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/