Merge pull request #1545 from ispyisail/refactor/save-links-from-db

Fix removed folios leaving links to their symbols in the saved file
This commit is contained in:
ispyisail
2026-10-19 15:07:03 +13:00
committed by GitHub
4 changed files with 88 additions and 5 deletions
+33
View File
@@ -4061,6 +4061,39 @@ QStringList projectDataBase::linkRowMismatches()
return mismatches;
}
/**
@brief projectDataBase::savedLinks
The links @p element saves, read from its link rows, in their order
(insertLinkRows()): what Element::toXml() writes (QETZ-DB-FIRST stage
2a). A partner the project no longer has, on a removed folio, has no
row, so it is not saved.
@return false if the database does not hold @p element (not placed in
this project): the caller then takes the links from the symbol itself
*/
bool projectDataBase::savedLinks(const Element *element, QList<std::pair<QUuid, int>> *links)
{
if (!element || !m_placed_elements.contains(element->uuid(), const_cast<Element *>(element))) {
return false;
}
flushLinks();
if (m_saved_links_query.lastQuery().isEmpty()) {
m_saved_links_query = QSqlQuery(m_data_base);
m_saved_links_query.prepare(QStringLiteral("SELECT linked_uuid, group_index FROM link "
"WHERE element_uuid = :uuid ORDER BY ord, rowid"));
}
m_saved_links_query.bindValue(QStringLiteral(":uuid"), element->uuid().toString());
if (!m_saved_links_query.exec()) {
qDebug() << "projectDataBase::savedLinks error : " << m_saved_links_query.lastError();
return false;
}
links->clear();
while (m_saved_links_query.next()) {
links->append({QUuid(m_saved_links_query.value(0).toString()),
m_saved_links_query.value(1).isNull() ? -1 : m_saved_links_query.value(1).toInt()});
}
return true;
}
/**
@brief projectDataBase::waitingSymbols
@return the symbols on folios not built yet (lazy folios): partners a
+2
View File
@@ -155,6 +155,7 @@ class projectDataBase : public QObject
void conductorUuidChanged(Conductor *conductor, const QUuid &old_uuid);
QStringList conductorPropertiesMismatches() const;
QStringList linkRowMismatches();
bool savedLinks(const Element *element, QList<std::pair<QUuid, int>> *links);
//Fill the three stores from a project's document before its
//folios are built, then, once
@@ -332,6 +333,7 @@ class projectDataBase : public QObject
//written: a link is made first and its contact group set after,
//so the rows are written when next read, as drawing items are.
QList<QPointer<Element>> m_dirty_link_elements;
QSqlQuery m_saved_links_query;
//Elements moved since their folio cell was last written: a move
//sends xChanged and yChanged for every step of a drag, so the
//cell is written when next read, as drawing items are.