QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
projectdbmodel.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef PROJECTDBMODEL_H
19#define PROJECTDBMODEL_H
20
21#include <QAbstractTableModel>
22#include <QPointer>
23#include <QDomElement>
24
25class QETProject;
26
43class ProjectDBModel : public QAbstractTableModel
44{
45 Q_OBJECT
46
47 public:
48 explicit ProjectDBModel(QETProject *project, QObject *parent = nullptr);
49 explicit ProjectDBModel (const ProjectDBModel &other_model);
50
51 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
52 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
53 bool setHeaderData(int section,
54 Qt::Orientation orientation,
55 const QVariant &value,
56 int role = Qt::EditRole) override;
57 QVariant headerData(int section,
58 Qt::Orientation orientation,
59 int role = Qt::DisplayRole) const override;
60 bool setData(const QModelIndex &index,
61 const QVariant &value,
62 int role = Qt::EditRole) override;
63 QVariant data(const QModelIndex &index,
64 int role = Qt::DisplayRole) const override;
65 void setQuery(const QString &setQuery);
66 QString queryString() const;
67 QETProject *project() const;
68
69 QDomElement toXml(QDomDocument &document) const;
70 void fromXml(const QDomElement &element);
71 void setIdentifier(const QString &identifier);
72 QString identifier() const {return m_identifier;}
73 static QString xmlTagName() {return QString("project_data_base_model");}
74
75 private:
76 void dataBaseUpdated();
77 void setHeaderString();
78 void fillValue();
79
80 private:
81 QPointer<QETProject> m_project;
82 QString m_query;
83 QVector<QStringList> m_record;
84 //First int = section, second int = Qt::role, QVariant = value
85 QHash<int, QHash<int, QVariant>> m_header_data;
86 QHash<int, QVariant> m_index_0_0_data;
87 QString m_identifier = "unknow";
88};
89
90#endif // PROJECTDBMODEL_H
The ProjectDBModel class This model is intended to be use with the class projectDataBase and is desig...
Definition projectdbmodel.h:44
static QString xmlTagName()
Definition projectdbmodel.h:73
QVector< QStringList > m_record
Definition projectdbmodel.h:83
int rowCount(const QModelIndex &parent=QModelIndex()) const override
ProjectDBModel::rowCount Reimplemented for QAbstractTableModel.
Definition projectdbmodel.cpp:61
QString m_query
Definition projectdbmodel.h:82
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
ProjectDBModel::setData Only store the data for the index 0.0.
Definition projectdbmodel.cpp:142
QString identifier() const
Definition projectdbmodel.h:72
void fromXml(const QDomElement &element)
ProjectDBModel::fromXml Restore the model from xml.
Definition projectdbmodel.cpp:282
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
ProjectDBModel::headerData Reimplemented from QAbstractTableModel.
Definition projectdbmodel.cpp:117
QHash< int, QVariant > m_index_0_0_data
Definition projectdbmodel.h:86
void setHeaderString()
Definition projectdbmodel.cpp:338
void setIdentifier(const QString &identifier)
ProjectDBModel::setIdentifier Set the identifier of this model to identifier.
Definition projectdbmodel.cpp:307
void setQuery(const QString &setQuery)
ProjectDBModel::setQuery Query the internal bd with query.
Definition projectdbmodel.cpp:183
QETProject * project() const
Definition projectdbmodel.cpp:225
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
ProjectDBModel::setHeaderData Reimplemented from QAbstractTableModel. Only horizontal orientation is ...
Definition projectdbmodel.cpp:97
void fillValue()
Definition projectdbmodel.cpp:362
void dataBaseUpdated()
ProjectDBModel::dataBaseUpdated slot called when the project database is updated.
Definition projectdbmodel.cpp:315
QDomElement toXml(QDomDocument &document) const
ProjectDBModel::toXml Save the model to xml,since model can have unlimited data we only save few data...
Definition projectdbmodel.cpp:237
QHash< int, QHash< int, QVariant > > m_header_data
Definition projectdbmodel.h:85
QString m_identifier
Definition projectdbmodel.h:87
QPointer< QETProject > m_project
Definition projectdbmodel.h:81
int columnCount(const QModelIndex &parent=QModelIndex()) const override
ProjectDBModel::columnCount Reimplemented for QAbstractTableModel.
Definition projectdbmodel.cpp:75
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
ProjectDBModel::data Reimplemented for QAbstractTableModel.
Definition projectdbmodel.cpp:159
QString queryString() const
ProjectDBModel::queryString.
Definition projectdbmodel.cpp:220
Definition qetproject.h:62