mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Title block templates: variables are now interpreted within labels too.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1781 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
a161ce0bd4
commit
28fca988b9
@ -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.
|
||||
|
@ -129,6 +129,7 @@ class TitleBlockTemplate : public QObject {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user