mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 13:24:14 +02:00
030e6ebf00
The element and element_info tables had two independent insert paths -- addElement() for an element added to a live diagram, and populateElementTable()/populateElementInfoTable() for a full rebuild -- which bound the same row differently. The incremental path wrote kindInformations()["type"] into element.sub_type; the bulk path wrote elementData().masterTypeToString(). So the table held different values depending on whether the project had been reloaded since the element was placed, and element_nomenclature_view exposes that column as element_sub_type, which ElementQueryWidget filters on for the Coil, Protection, Commutator and PLC nomenclature options. That divergence is the same shape as the type-filter one fixed in the previous commit, and it is the reason this stack kept finding bugs that were invisible while editing and only appeared after a reload. Rather than correct a second instance of it, both paths now go through bindElementValues() and bindElementInfoValues(), following the bindDiagramInfoValues() helper this class already had. Live and reloaded now agree by construction instead of by coincidence. The bulk path's values are the ones kept, because they are what every already saved project contains: nothing a reload produces changes, and the previous commit's 19-project BOM regression stays valid. It is the live path that moves, onto the values a reload would have given it anyway. Measured, placing one element into a new project and then saving and reopening it: live element table: slave/ x1 reloaded element table: slave/ x1 and for the same element, what the two paths would have stored: bulk (now shared): "" incremental (before this commit): "simple" Re-ran the BOM regression over the same 19 projects after this change: content identical to the pre-change baseline on all 19, and identical line-for-line on 18, the exception being the three byte-identical photovoltaique rows already described in the previous commit. Note for anyone reading masterTypeToString(): the const no-argument overload returns an empty string for anything that is not a Master, so the "coil" fallback in the static overload is only reached for real master elements. Non-master elements get an empty sub_type, not a spurious "coil".
127 lines
3.7 KiB
C++
127 lines
3.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();
|
|
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;
|
|
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;
|
|
|
|
#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
|