Move a folio's numbering counters into the project database

QETZ-DB-FIRST stage 2b-4: the unit/ten/hundred-folio sequential
counters Diagram tracks per numbering scheme (insertFolioSeqHash())
now write through to a new folio_counter table, keyed by
(folio_uuid, owner, level, title, ord). The hashes stay the source
for now, same write-through pattern as 2b-1's numbering rows.
renameElementAutoNum()/AutoNumSchemeCommand::rename() carry the
rows along on a scheme rename.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-20 14:02:14 +13:00
parent f692d2d35a
commit 8d5c164d09
6 changed files with 138 additions and 8 deletions
+103
View File
@@ -2715,6 +2715,21 @@ bool projectDataBase::createDataBase()
}
}
//2b-4: a folio's own unit/ten/hundred-folio counters, one row per
//(folio, owner, level, scheme title, ord). owner is "element" or
//"conductor"; level keeps Diagram's own "unitfolio"/"tenfolio"/
//"hundredfolio" strings. Not filled from the folio's XML here --
//Diagram writes these rows itself, the same write-through pattern
//as the numbering tables above.
if (!query_.exec(QLatin1String(
"CREATE TABLE folio_counter ("
"folio_uuid VARCHAR(50) NOT NULL, owner VARCHAR(20) NOT NULL, "
"level VARCHAR(20) NOT NULL, title TEXT NOT NULL, ord INTEGER NOT NULL, "
"value TEXT, "
"PRIMARY KEY (folio_uuid, owner, level, title, ord))"))) {
qDebug() << " folio_counter table query : " << query_.lastError();
}
//Create the terminal table.
//Terminal::uuid() is the terminal-position id baked into the catalog
//.elmt definition (e.g. "the top terminal") -- identical across every
@@ -4427,6 +4442,94 @@ void projectDataBase::setNumberingFlag(const QString &name, bool value)
setNumberingSetting(name, value ? QStringLiteral("true") : QStringLiteral("false"));
}
/**
@brief projectDataBase::folioCounterValues
@return the folio counter values for @p folio_uuid / @p owner /
@p level / @p title, in @c ord order (Diagram::insertFolioSeqHash()'s
@c max list); empty if never written
*/
QStringList projectDataBase::folioCounterValues(const QUuid &folio_uuid, const QString &owner,
const QString &level, const QString &title) const
{
QSqlQuery query(m_data_base);
query.prepare(QStringLiteral(
"SELECT value FROM folio_counter WHERE folio_uuid = :folio_uuid "
"AND owner = :owner AND level = :level AND title = :title ORDER BY ord"));
query.bindValue(QStringLiteral(":folio_uuid"), folio_uuid.toString());
query.bindValue(QStringLiteral(":owner"), owner);
query.bindValue(QStringLiteral(":level"), level);
query.bindValue(QStringLiteral(":title"), title);
QStringList values;
if (query.exec()) {
while (query.next()) {
values.append(query.value(0).toString());
}
} else {
qDebug() << "projectDataBase::folioCounterValues error : " << query.lastError();
}
return values;
}
/**
@brief projectDataBase::setFolioCounterValues
The folio counter for @p folio_uuid / @p owner / @p level / @p title
is @p values from now on (one row per entry, in order)
*/
void projectDataBase::setFolioCounterValues(const QUuid &folio_uuid, const QString &owner,
const QString &level, const QString &title,
const QStringList &values)
{
QSqlQuery del(m_data_base);
del.prepare(QStringLiteral(
"DELETE FROM folio_counter WHERE folio_uuid = :folio_uuid "
"AND owner = :owner AND level = :level AND title = :title"));
del.bindValue(QStringLiteral(":folio_uuid"), folio_uuid.toString());
del.bindValue(QStringLiteral(":owner"), owner);
del.bindValue(QStringLiteral(":level"), level);
del.bindValue(QStringLiteral(":title"), title);
if (!del.exec()) {
qDebug() << "projectDataBase::setFolioCounterValues delete error : " << del.lastError();
return;
}
QSqlQuery query(m_data_base);
query.prepare(QStringLiteral(
"INSERT INTO folio_counter (folio_uuid, owner, level, title, ord, value) "
"VALUES (:folio_uuid, :owner, :level, :title, :ord, :value)"));
for (int i = 0; i < values.size(); ++i) {
query.bindValue(QStringLiteral(":folio_uuid"), folio_uuid.toString());
query.bindValue(QStringLiteral(":owner"), owner);
query.bindValue(QStringLiteral(":level"), level);
query.bindValue(QStringLiteral(":title"), title);
query.bindValue(QStringLiteral(":ord"), i);
query.bindValue(QStringLiteral(":value"), values.at(i));
if (!query.exec()) {
qDebug() << "projectDataBase::setFolioCounterValues insert error : " << query.lastError();
}
}
}
/**
@brief projectDataBase::renameFolioCounterScheme
Every folio_counter row for @p owner under @p old_title moves to
@p new_title (renameNumberingScheme()'s counterpart for the rows a
folio keeps on its own)
*/
void projectDataBase::renameFolioCounterScheme(const QString &owner, const QString &old_title,
const QString &new_title)
{
QSqlQuery query(m_data_base);
query.prepare(QStringLiteral(
"UPDATE folio_counter SET title = :new_title "
"WHERE owner = :owner AND title = :old_title"));
query.bindValue(QStringLiteral(":new_title"), new_title);
query.bindValue(QStringLiteral(":owner"), owner);
query.bindValue(QStringLiteral(":old_title"), old_title);
if (!query.exec()) {
qDebug() << "projectDataBase::renameFolioCounterScheme error : " << query.lastError();
}
}
/**
@brief projectDataBase::savedLinks
The links @p element saves, read from its link rows, in their order
+12
View File
@@ -194,6 +194,18 @@ class projectDataBase : public QObject
bool numberingFlag(const QString &name, bool default_value) const;
void setNumberingSetting(const QString &name, const QString &value);
void setNumberingFlag(const QString &name, bool value);
//2b-4: a folio's own numbering counters (unit/ten/hundred-folio
//sequentials), one row per (folio, owner, level, scheme, ord).
//owner is "element" or "conductor"; level is "unitfolio",
//"tenfolio" or "hundredfolio" (kept as Diagram's own strings,
//not renamed, so the two stay comparable in logs/greps).
QStringList folioCounterValues(const QUuid &folio_uuid, const QString &owner,
const QString &level, const QString &title) const;
void setFolioCounterValues(const QUuid &folio_uuid, const QString &owner,
const QString &level, const QString &title,
const QStringList &values);
void renameFolioCounterScheme(const QString &owner, const QString &old_title,
const QString &new_title);
bool savedLinks(const Element *element, QList<std::pair<QUuid, int>> *links);
//The link rows are written (opening filled them): a symbol
//built links from them (Element::initLink())