mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
e19d60ae55
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 <noreply@anthropic.com>
108 lines
4.0 KiB
C++
108 lines
4.0 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "wiringlistdialog.h"
|
|
|
|
#include "../dataBase/projectdatabase.h"
|
|
#include "../qetproject.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QHeaderView>
|
|
#include <QLabel>
|
|
#include <QSqlQueryModel>
|
|
#include <QTableView>
|
|
#include <QVBoxLayout>
|
|
|
|
/**
|
|
@brief WiringListDialog::WiringListDialog
|
|
@param project : project whose wiring list is shown
|
|
@param parent : parent widget
|
|
*/
|
|
WiringListDialog::WiringListDialog(QETProject *project, QWidget *parent) :
|
|
QDialog(parent),
|
|
m_project(project)
|
|
{
|
|
setWindowTitle(tr("Liste de câblage", "window title"));
|
|
resize(900, 500);
|
|
|
|
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,"
|
|
" to_element_label, to_terminal, diagram_position"
|
|
" FROM wiring_list_view"
|
|
" ORDER BY diagram_position, wire_number"),
|
|
m_project->dataBase()->database());
|
|
|
|
model->setHeaderData(0, Qt::Horizontal, tr("Fil", "column title"));
|
|
model->setHeaderData(1, Qt::Horizontal, tr("Composant 1", "column title"));
|
|
model->setHeaderData(2, Qt::Horizontal, tr("Borne 1", "column title"));
|
|
model->setHeaderData(3, Qt::Horizontal, tr("Composant 2", "column title"));
|
|
model->setHeaderData(4, Qt::Horizontal, tr("Borne 2", "column title"));
|
|
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);
|
|
summary->setWordWrap(true);
|
|
if (excluded > 0)
|
|
{
|
|
//The count matters more than it looks: a project whose elements
|
|
//all predate terminal uuids yields an entirely empty list, and
|
|
//without this line that is indistinguishable from a project with
|
|
//no wires in it.
|
|
summary->setText(tr("%n conducteur(s) listé(s).", "wiring list summary", listed)
|
|
% QStringLiteral(" ")
|
|
% tr("%n conducteur(s) exclu(s) : leurs éléments ne définissent pas"
|
|
" d'identifiant de borne (définition d'élément trop ancienne).",
|
|
"wiring list exclusion warning", excluded));
|
|
}
|
|
else {
|
|
summary->setText(tr("%n conducteur(s) listé(s).", "wiring list summary", listed));
|
|
}
|
|
layout->addWidget(summary);
|
|
|
|
auto *view = new QTableView(this);
|
|
view->setModel(model);
|
|
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
view->setAlternatingRowColors(true);
|
|
view->verticalHeader()->setVisible(false);
|
|
view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
layout->addWidget(view);
|
|
|
|
auto *buttons = new QDialogButtonBox(QDialogButtonBox::Close, this);
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
layout->addWidget(buttons);
|
|
}
|