Speed up opening big projects with lazy folios

This commit is contained in:
Laurent Trinques
2026-10-13 11:01:21 +02:00
parent a78e95be2c
commit 77e2a9bfc5
45 changed files with 3956 additions and 388 deletions
+5 -2
View File
@@ -105,7 +105,9 @@ QList<Diagram *> AutoNumSchemeCommand::usersOf(const QETProject *project, Kind k
if (!project || title.isEmpty()) {
return users;
}
for (Diagram *diagram : project->diagrams()) {
//The schemes a folio uses are its own data, read on opening:
//folios() builds nothing
for (Diagram *diagram : project->folios()) {
if (kind == Kind::Conductor) {
if (diagram->conductorsAutonumName() == title) {
users << diagram;
@@ -234,7 +236,8 @@ void AutoNumSchemeCommand::rename(const QString &from, const QString &to)
if (m_project->conductorCurrentAutoNum() == from) {
m_project->setCurrentConductorAutoNum(to);
}
for (Diagram *d : m_project->diagrams()) {
//Folios' own data, read on opening: folios() builds nothing
for (Diagram *d : m_project->folios()) {
//The highest folio number given, kept by scheme title
for (auto *hash : {&d->m_cnd_unitfolio_max, &d->m_cnd_tenfolio_max, &d->m_cnd_hundredfolio_max}) {
if (hash->contains(from)) {
+37 -30
View File
@@ -369,10 +369,19 @@ ElementAutoNumSchemeCommand::NumberSupport ElementAutoNumSchemeCommand::numberSu
std::optional<int> ElementAutoNumSchemeCommand::numberOf(const NumberSupport &support,
const Element *element)
{
if (!support.supported || !element) {
if (!element) {
return std::nullopt;
}
return numberOf(support, element->sequenceStruct());
}
/// @return the number the sequential numbers @p seq give, if the scheme knows it
std::optional<int> ElementAutoNumSchemeCommand::numberOf(const NumberSupport &support,
const autonum::sequentialNumbers &seq)
{
if (!support.supported) {
return std::nullopt;
}
const autonum::sequentialNumbers seq = element->sequenceStruct();
const QStringList &list = support.type == QLatin1String("unit") ? seq.unit
: support.type == QLatin1String("ten") ? seq.ten
: seq.hundred;
@@ -385,14 +394,18 @@ std::optional<int> ElementAutoNumSchemeCommand::numberOf(const NumberSupport &su
}
namespace {
/// The elements of @p project which follow the scheme @p title and are not slaves or reports
QVector<Element *> numberedFollowers(const QETProject *project, const QString &title)
/// The symbols of @p project which follow the scheme @p title and are not
/// slaves or reports, built or not (QETProject::symbolNumbering())
QList<QETProject::SymbolNumbering> numberedFollowers(const QETProject *project, const QString &title)
{
QVector<Element *> list;
const auto followers = project->elementsUsingElementAutoNum(title);
for (Element *el : followers) {
if (el->linkType() != Element::Slave && !(el->linkType() & Element::AllReport)) {
list << el;
QList<QETProject::SymbolNumbering> list;
const QUuid id = project->elementAutoNumId(title);
if (id.isNull()) {
return list;
}
for (const auto &symbol : project->symbolNumbering()) {
if (symbol.numbered && !symbol.formula.isEmpty() && symbol.scheme == id) {
list << symbol;
}
}
return list;
@@ -411,13 +424,10 @@ QSet<QString> ElementAutoNumSchemeCommand::labelsHeldBesides(const QETProject *p
if (!project) {
return labels;
}
for (Diagram *d : project->diagrams()) {
for (QGraphicsItem *item : d->items()) {
if (auto *el = qgraphicsitem_cast<Element *>(item)) {
if (el != element) {
labels << el->elementInformations().value(QETInformation::ELMT_LABEL).toString();
}
}
//Folios not built yet answer from what building them would give
for (const auto &symbol : project->symbolNumbering()) {
if (symbol.element != element) {
labels << symbol.label;
}
}
labels.remove(QString());
@@ -453,8 +463,8 @@ std::optional<ElementAutoNumSchemeCommand::CounterConflict> ElementAutoNumScheme
CounterConflict conflict;
conflict.counter = counter;
for (const Element *el : numberedFollowers(project, title)) {
if (const auto number = numberOf(support, el)) {
for (const auto &symbol : numberedFollowers(project, title)) {
if (const auto number = numberOf(support, symbol.sequence)) {
if (*number >= counter) {
++conflict.count;
conflict.highest = std::max(conflict.highest, *number);
@@ -486,8 +496,8 @@ QList<ElementAutoNumSchemeCommand::GapRange> ElementAutoNumSchemeCommand::gapRan
return ranges;
}
QSet<int> used;
for (const Element *el : numberedFollowers(project, title)) {
if (const auto number = numberOf(support, el)) {
for (const auto &symbol : numberedFollowers(project, title)) {
if (const auto number = numberOf(support, symbol.sequence)) {
used << *number;
}
}
@@ -559,22 +569,19 @@ QList<int> ElementAutoNumSchemeCommand::freeNumbers(const QETProject *project,
QSet<int> used;
int highest = context.itemAt(support.partIndex).value(1).toInt();
for (const Element *el : numberedFollowers(project, title)) {
if (el == element) continue;
if (const auto number = numberOf(support, el)) {
for (const auto &symbol : numberedFollowers(project, title)) {
if (symbol.element == element) continue;
if (const auto number = numberOf(support, symbol.sequence)) {
used << *number;
highest = std::max(highest, *number);
}
}
QSet<QString> labels;
for (Diagram *d : project->diagrams()) {
for (QGraphicsItem *item : d->items()) {
if (auto *el = qgraphicsitem_cast<Element *>(item)) {
if (el != element) {
labels << el->elementInformations().value(QETInformation::ELMT_LABEL).toString();
}
}
//Folios not built yet answer from what building them would give
for (const auto &symbol : project->symbolNumbering()) {
if (symbol.element != element) {
labels << symbol.label;
}
}
labels.remove(QString());
@@ -18,6 +18,7 @@
#ifndef ELEMENTAUTONUMSCHEMECOMMAND_H
#define ELEMENTAUTONUMSCHEMECOMMAND_H
#include "assignvariables.h"
#include "numerotationcontext.h"
#include "renumberelementscommand.h"
@@ -201,6 +202,8 @@ class ElementAutoNumSchemeCommand : public QUndoCommand
static QSet<QString> labelsHeldBesides(const QETProject *project, const Element *element);
static NumberSupport numberSupport(const NumerotationContext &context);
static std::optional<int> numberOf(const NumberSupport &support, const Element *element);
static std::optional<int> numberOf(const NumberSupport &support,
const autonum::sequentialNumbers &seq);
static QList<GapRange> gapRanges(const QETProject *project, const QString &title);
static QList<int> freeNumbers(const QETProject *project, const QString &title,
const Element *element, int limit = 500);
@@ -175,7 +175,8 @@ void AutoNumberingManagementW::on_m_apply_folios_rb_clicked()
if (ui->m_from_folios_cb->count()<=0) {
ui->m_from_folios_cb->clear();
ui->m_from_folios_cb->addItem("");
foreach (Diagram *diagram, project_->diagrams()){
//Titles and positions only: folios() builds nothing
foreach (Diagram *diagram, project_->folios()){
if (diagram->title() != "")
ui->m_from_folios_cb->addItem(
diagram->title(),
@@ -206,16 +207,17 @@ void AutoNumberingManagementW::on_m_from_folios_cb_currentIndexChanged(
if (index > 0) {
ui->m_to_folios_cb->setEnabled(true);
ui->m_to_folios_cb->addItem("");
for (int i=index;i<project_->diagrams().size();i++) {
if (project_->diagrams().at(i)->title() != "") {
const QList<Diagram *> folios = project_->folios();
for (int i=index;i<folios.size();i++) {
if (folios.at(i)->title() != "") {
ui->m_to_folios_cb->addItem(
project_->diagrams().at(i)->title(),
project_->diagrams().at(i)->folioIndex());
folios.at(i)->title(),
folios.at(i)->folioIndex());
}
else ui->m_to_folios_cb->addItem(
QString::number(
project_->diagrams().at(i)->folioIndex()),
project_->diagrams().at(i)->folioIndex());
folios.at(i)->folioIndex()),
folios.at(i)->folioIndex());
}
applyEnable(true);
ui->m_selected_folios_le->clear();
+5 -4
View File
@@ -136,7 +136,8 @@ void FolioAutonumberingW::on_m_autonumber_tabs_rb_clicked()
if (ui->m_from_cb->count()<=0){
ui->m_from_cb->clear();
ui->m_from_cb->addItem("");
foreach (Diagram *diagram, project_->diagrams()){
//Titles only: folios() builds nothing
foreach (Diagram *diagram, project_->folios()){
ui->m_from_cb->addItem(diagram->title());
}
}
@@ -164,9 +165,9 @@ void FolioAutonumberingW::on_m_from_cb_currentIndexChanged(int)
ui->m_to_cb->clear();
if (index > 0){
ui->m_to_cb->setEnabled(true);
for (int i=index;i<project_->diagrams().size();i++)
ui->m_to_cb->addItem(project_
->diagrams().at(i)->title());
const QList<Diagram *> folios = project_->folios();
for (int i=index;i<folios.size();i++)
ui->m_to_cb->addItem(folios.at(i)->title());
applyEnable(true);
}
else{