From e19d60ae55f59d987d2ae028a5d680fecfad3a0a Mon Sep 17 00:00:00 2001 From: ispyisail Date: Fri, 21 Aug 2026 19:18:42 +1200 Subject: [PATCH] Report the real wire count, and show current data The summary line exists so that an empty wiring list is distinguishable from one where every conductor was excluded, and it was reporting the wrong number to do it. QSqlQueryModel fetches lazily, so rowCount() straight after setQuery() returns the rows fetched so far -- 256 -- not the size of the query. Measured with Qt's own QSQLITE driver: a 1000-row view reports 256 until the model is drained, then 1000. The test project quoted in slice 2 has 280 conductors, so this was already displaying 256 on our own data, plausibly enough that nobody looked twice. Drain the model before reading the count. Also refresh the database before building the model. The dialog queries the database rather than the diagrams, so anything not yet written through was invisible here; with conductor text now updated on change that gap is smaller, but a project loaded before this dialog was ever opened still relies on the repopulate. Co-Authored-By: Claude Opus 5 --- sources/ui/wiringlistdialog.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sources/ui/wiringlistdialog.cpp b/sources/ui/wiringlistdialog.cpp index 791c5e5cf..581b7426b 100644 --- a/sources/ui/wiringlistdialog.cpp +++ b/sources/ui/wiringlistdialog.cpp @@ -41,6 +41,12 @@ WiringListDialog::WiringListDialog(QETProject *project, QWidget *parent) : auto *layout = new QVBoxLayout(this); + //The wiring list reads the database rather than the diagrams, and a + //conductor's row is only as fresh as the last thing that touched it. + //Refresh before querying so the dialog cannot show a wire number that + //was edited earlier in the session. + m_project->dataBase()->updateDB(); + auto *model = new QSqlQueryModel(this); model->setQuery(QStringLiteral( "SELECT wire_number, from_element_label, from_terminal," @@ -57,6 +63,14 @@ WiringListDialog::WiringListDialog(QETProject *project, QWidget *parent) : model->setHeaderData(5, Qt::Horizontal, tr("Folio", "column title")); const int excluded = m_project->dataBase()->excludedConductorCount(); + + //QSqlQueryModel fetches lazily, so rowCount() straight after + //setQuery() reports the first batch (256) rather than the query's + //size. Draining it first is what makes the count below true for a + //project with more wires than that. + while (model->canFetchMore()) { + model->fetchMore(); + } const int listed = model->rowCount(); auto *summary = new QLabel(this);