2020-09-16 21:28:47 +02:00
|
|
|
|
/*
|
2021-02-20 12:13:46 +01:00
|
|
|
|
Copyright 2006-2021 QElectroTech Team
|
2020-04-12 18:51:38 +02:00
|
|
|
|
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;
|
2020-07-06 21:52:14 +02:00
|
|
|
|
class Diagram;
|
2020-09-16 21:28:47 +02:00
|
|
|
|
class sqlite3;
|
2020-04-12 18:51:38 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief The projectDataBase class
|
2024-04-07 10:42:37 +02:00
|
|
|
|
This class wraps a sqlite data base where you can find several things
|
2020-08-20 21:57:35 +02:00
|
|
|
|
about the content of a project.
|
2020-04-12 18:51:38 +02:00
|
|
|
|
*
|
2022-12-04 08:21:12 -05:00
|
|
|
|
@note this class is still in development.
|
2020-08-16 11:19:36 +02:00
|
|
|
|
*/
|
2020-04-12 18:51:38 +02:00
|
|
|
|
class projectDataBase : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
projectDataBase(QETProject *project, QObject *parent = nullptr);
|
|
|
|
|
virtual ~projectDataBase() override;
|
|
|
|
|
|
|
|
|
|
void updateDB();
|
|
|
|
|
QETProject *project() const;
|
2020-06-03 19:15:21 +02:00
|
|
|
|
QSqlQuery newQuery(const QString &query = QString());
|
2020-11-01 21:27:40 +01:00
|
|
|
|
|
|
|
|
|
void addElement (Element *element);
|
|
|
|
|
void removeElement (Element *element);
|
|
|
|
|
void elementInfoChanged (Element *element);
|
2020-11-22 11:31:43 +01:00
|
|
|
|
void elementInfoChanged (QList<Element *> elements);
|
2020-11-01 21:27:40 +01:00
|
|
|
|
|
|
|
|
|
void addDiagram (Diagram *diagram);
|
|
|
|
|
void removeDiagram (Diagram *diagram);
|
|
|
|
|
void diagramInfoChanged (Diagram *diagram);
|
|
|
|
|
void diagramOrderChanged();
|
2020-04-12 18:51:38 +02:00
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void dataBaseUpdated();
|
|
|
|
|
|
|
|
|
|
private:
|
2020-09-16 21:28:47 +02:00
|
|
|
|
bool createDataBase();
|
2020-04-25 15:52:06 +02:00
|
|
|
|
void createElementNomenclatureView();
|
2020-06-18 18:52:29 +02:00
|
|
|
|
void createSummaryView();
|
2020-04-12 18:51:38 +02:00
|
|
|
|
void populateDiagramTable();
|
|
|
|
|
void populateElementTable();
|
|
|
|
|
void populateElementInfoTable();
|
|
|
|
|
void populateDiagramInfoTable();
|
2020-07-01 18:31:19 +02:00
|
|
|
|
void prepareQuery();
|
2020-08-20 21:58:23 +02:00
|
|
|
|
static QHash<QString, QString> elementInfoToString(
|
|
|
|
|
Element *elmt);
|
2020-11-01 21:27:40 +01:00
|
|
|
|
void bindDiagramInfoValues(QSqlQuery &query, Diagram *diagram);
|
2020-04-12 18:51:38 +02:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QPointer<QETProject> m_project;
|
|
|
|
|
QSqlDatabase m_data_base;
|
2020-07-01 18:31:19 +02:00
|
|
|
|
QSqlQuery m_insert_elements_query,
|
|
|
|
|
m_insert_element_info_query,
|
|
|
|
|
m_remove_element_query,
|
2020-07-06 21:52:14 +02:00
|
|
|
|
m_update_element_query,
|
|
|
|
|
m_insert_diagram_query,
|
|
|
|
|
m_remove_diagram_query,
|
2020-11-01 21:27:40 +01:00
|
|
|
|
m_insert_diagram_info_query,
|
|
|
|
|
m_update_diagram_info_query,
|
|
|
|
|
m_diagram_order_changed,
|
|
|
|
|
m_diagram_info_order_changed;
|
2020-04-12 18:51:38 +02:00
|
|
|
|
|
2020-10-02 20:09:03 +02:00
|
|
|
|
#ifdef QET_EXPORT_PROJECT_DB
|
2020-04-12 18:51:38 +02:00
|
|
|
|
public:
|
2020-09-16 21:28:47 +02:00
|
|
|
|
static sqlite3 *sqliteHandle(QSqlDatabase *db);
|
2020-08-20 21:58:23 +02:00
|
|
|
|
static void exportDb(projectDataBase *db,
|
|
|
|
|
QWidget *parent = nullptr,
|
|
|
|
|
const QString &caption = QString(),
|
|
|
|
|
const QString &dir = QString());
|
2020-10-02 20:09:03 +02:00
|
|
|
|
#endif
|
2020-04-12 18:51:38 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // PROJECTDATABASE_H
|