mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-27 20:44:13 +02:00
956836458a
ProjectDBModel::setQuery() calls projectDataBase::updateDB(), which drops and repopulates every table in the database. The rebuild does not depend on the query, so each table model that queries the database while a project is being read triggers another complete repopulate of the same content. Opening a 100 folio project ran updateDB() 26 times, 9.9 s of a 15.7 s load. Two changes, because the first alone is not enough: setUpdateBlocked() lets a bulk operation suppress the rebuild and do it once when it is done. readProjectXml() already wrapped the load in blockSignals(true) "to avoid hundreds of unnecessary emitted signal", but that suppresses only the signal, not the work it announces; this extends the same intent to the work. Both early returns in readProjectXml() sit before the block, so no path leaves the database permanently blocked. Further rebuilds are triggered after readProjectXml() returns, where the load phase timers cannot see them -- with only the block in place updateDB() still ran 5 times on examples/industrial.qet. So the database now also tracks whether anything has changed since the last rebuild, and skips repopulating when nothing has. dataBaseUpdated() is still emitted in that case: callers and models rely on it to refresh, and what they read back is the same either way. Every method of the class that writes rows marks the flag; from outside, the database is reachable only through newQuery(), and all five call sites read. Repeating the rebuild was wasteful rather than wrong -- each populate*Table() begins with a DELETE -- so this changes no output. Verified byte identical --info on all 23 example projects, and identical --export-bom, --export-wires, --export-cables, --export-nets and --export-wiring on industrial.qet. Its load drops from 5.51 s to 5.31 s (median of 6). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6MRq2Ach1ogvnGcbuqNLr
148 lines
4.7 KiB
C++
148 lines
4.7 KiB
C++
/*
|
|
Copyright 2006-2026 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/>.
|
|
*/
|
|
#ifndef PROJECTDATABASE_H
|
|
#define PROJECTDATABASE_H
|
|
|
|
#include <QObject>
|
|
#include <QSqlDatabase>
|
|
#include <QSqlQuery>
|
|
#include <QPointer>
|
|
#include <QFileDialog>
|
|
|
|
class Element;
|
|
class QETProject;
|
|
class Diagram;
|
|
class Conductor;
|
|
class Terminal;
|
|
class sqlite3;
|
|
|
|
/**
|
|
@brief The projectDataBase class
|
|
This class wraps a sqlite data base where you can find several things
|
|
about the content of a project.
|
|
*
|
|
@note this class is still in development.
|
|
*/
|
|
class projectDataBase : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
projectDataBase(QETProject *project, QObject *parent = nullptr);
|
|
virtual ~projectDataBase() override;
|
|
|
|
void updateDB();
|
|
/**
|
|
Suppress the full rebuild performed by updateDB().
|
|
|
|
While blocked, updateDB() returns immediately instead of
|
|
repopulating every table. Meant for bulk operations -- notably
|
|
loading a project, where each table model re-queries the
|
|
database as it is built and would otherwise trigger one
|
|
complete rebuild of it. The caller unblocks and calls
|
|
updateDB() once when done; @see QETProject::readProjectXml().
|
|
*/
|
|
void setUpdateBlocked(bool blocked);
|
|
QETProject *project() const;
|
|
QSqlQuery newQuery(const QString &query = QString());
|
|
QSqlDatabase database() const {return m_data_base;}
|
|
int excludedConductorCount() const;
|
|
|
|
void addElement (Element *element);
|
|
void removeElement (Element *element);
|
|
void elementInfoChanged (Element *element);
|
|
void elementInfoChanged (QList<Element *> elements);
|
|
|
|
void addDiagram (Diagram *diagram);
|
|
void removeDiagram (Diagram *diagram);
|
|
void diagramInfoChanged (Diagram *diagram);
|
|
void diagramOrderChanged();
|
|
|
|
void addConductor (Conductor *conductor);
|
|
void removeConductor (Conductor *conductor);
|
|
void updateConductor (Conductor *conductor);
|
|
|
|
private slots:
|
|
//Refresh the sender()'s row after Conductor::setProperties().
|
|
void conductorPropertiesChanged();
|
|
|
|
public:
|
|
|
|
signals:
|
|
void dataBaseUpdated();
|
|
|
|
private:
|
|
bool createDataBase();
|
|
void createElementNomenclatureView();
|
|
void createSummaryView();
|
|
void createWiringListView();
|
|
void populateDiagramTable();
|
|
void populateElementTable();
|
|
void populateElementInfoTable();
|
|
void populateDiagramInfoTable();
|
|
void populateConductorTable();
|
|
void bindConductorValues(QSqlQuery &query, Conductor *conductor, Diagram *diagram);
|
|
void watchConductor(Conductor *conductor);
|
|
void insertTerminal(Terminal *terminal);
|
|
void prepareQuery();
|
|
static QHash<QString, QString> elementInfoToString(
|
|
Element *elmt);
|
|
void bindDiagramInfoValues(QSqlQuery &query, Diagram *diagram);
|
|
static void bindElementValues(QSqlQuery &query, Element *element, Diagram *diagram);
|
|
static void bindElementInfoValues(QSqlQuery &query, Element *element);
|
|
|
|
private:
|
|
QPointer<QETProject> m_project;
|
|
bool m_update_blocked = false;
|
|
//Starts true : the database is empty until the first rebuild.
|
|
//Set by every method of this class that writes rows, cleared by
|
|
//updateDB(). Callers reach the database from outside only through
|
|
//newQuery(), and every such call site reads.
|
|
bool m_content_changed = true;
|
|
QSqlDatabase m_data_base;
|
|
QSqlQuery m_insert_elements_query,
|
|
m_insert_element_info_query,
|
|
m_remove_element_query,
|
|
m_update_element_query,
|
|
m_insert_diagram_query,
|
|
m_remove_diagram_query,
|
|
m_insert_diagram_info_query,
|
|
m_update_diagram_info_query,
|
|
m_diagram_order_changed,
|
|
m_diagram_info_order_changed,
|
|
m_insert_terminal_query,
|
|
m_insert_conductor_query,
|
|
m_update_conductor_query,
|
|
m_remove_conductor_query,
|
|
m_cascade_remove_element_info_query,
|
|
m_cascade_remove_terminal_query,
|
|
m_cascade_remove_conductor_query,
|
|
m_cascade_remove_element_query;
|
|
|
|
#ifdef QET_EXPORT_PROJECT_DB
|
|
public:
|
|
static sqlite3 *sqliteHandle(QSqlDatabase *db);
|
|
static void exportDb(projectDataBase *db,
|
|
QWidget *parent = nullptr,
|
|
const QString &caption = QString(),
|
|
const QString &dir = QString());
|
|
#endif
|
|
};
|
|
|
|
#endif // PROJECTDATABASE_H
|