Folio properties: auto-add a title block's custom variables (#271)

When a title block template uses custom variables (e.g. %{department},
%{owner}), the user previously had to declare each one by hand in the
folio properties 'Custom' tab before a value could be entered. Now the
template's undefined custom variables are added automatically, so the
user only fills in the values.

- listOfVariables() now extracts %{name} placeholders with a regex
  (deduplicated) instead of a crude '%' strip that returned '{name}'.
- The folio properties widget merges the template's custom variables into
  the Custom tab both on open (setProperties) and when the template is
  changed, preserving any values already entered and skipping the
  standard fields (title, author, date, ...) which have their own inputs.

Fixes #271 (variable auto-population; the revision-history request in the
thread is a separate feature).
This commit is contained in:
Shane Ringrose
2026-06-12 05:45:08 +12:00
parent e7787daa2c
commit ba6320bff8
3 changed files with 72 additions and 22 deletions
+11 -6
View File
@@ -1756,6 +1756,10 @@ QString TitleBlockTemplate::interpreteVariables(
QStringList TitleBlockTemplate::listOfVariables()
{
QStringList list;
// Match every "%{name}" placeholder. The bare "%name" form can't be
// extracted reliably without the variable list, and templates use the
// braced form, so only that is collected here.
static const QRegularExpression rx(QStringLiteral("%\\{([^}]+)\\}"));
// run through each individual cell
for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
for (int i = 0 ; i < columns_width_.count() ; ++ i) {
@@ -1763,14 +1767,15 @@ QStringList TitleBlockTemplate::listOfVariables()
|| cells_[i][j] -> cell_type
== TitleBlockCell::EmptyCell)
continue;
#if TODO_LIST
#pragma message("@TODO not works on all cases...")
#endif
// TODO: not works on all cases...
list << cells_[i][j] -> value.name().replace("%","");
const QString cell_value = cells_[i][j] -> value.name();
auto it = rx.globalMatch(cell_value);
while (it.hasNext()) {
const QString name = it.next().captured(1);
if (!name.isEmpty() && !list.contains(name))
list << name;
}
}
}
qDebug() << list;
return list;
}