QElectroTech  0.8-dev
projectdbmodel.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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 
25 class QETProject;
26 
43 class 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
QETXML::modelHeaderDataFromXml
void modelHeaderDataFromXml(const QDomElement &element, QAbstractItemModel *model)
QETXML::modelHeaderDataFromXml Restore from xml modele header data.
Definition: qetxml.cpp:501
ProjectDBModel::xmlTagName
static QString xmlTagName()
Definition: projectdbmodel.h:73
QETApp::diagramTranslatedInfoKey
static QString diagramTranslatedInfoKey(const QString &key)
QETApp::diagramTranslatedInfoKey.
Definition: qetapp.cpp:502
ProjectDBModel::fromXml
void fromXml(const QDomElement &element)
ProjectDBModel::fromXml Restore the model from xml.
Definition: projectdbmodel.cpp:278
ProjectDBModel::ProjectDBModel
ProjectDBModel(QETProject *project, QObject *parent=nullptr)
ProjectDBModel::ProjectDBModel.
Definition: projectdbmodel.cpp:32
ProjectDBModel::setQuery
void setQuery(const QString &setQuery)
ProjectDBModel::setQuery Query the internall bd with query.
Definition: projectdbmodel.cpp:181
ProjectDBModel::m_query
QString m_query
Definition: projectdbmodel.h:82
ProjectDBModel::queryString
QString queryString() const
ProjectDBModel::queryString.
Definition: projectdbmodel.cpp:218
ProjectDBModel
The ProjectDBModel class This model is intended to be use with the class projectDataBase and is desig...
Definition: projectdbmodel.h:44
ProjectDBModel::setHeaderData
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:95
ProjectDBModel::m_project
QPointer< QETProject > m_project
Definition: projectdbmodel.h:81
ProjectDBModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
ProjectDBModel::headerData Reimplemented from QAbstractTableModel.
Definition: projectdbmodel.cpp:115
qetapp.h
ProjectDBModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
ProjectDBModel::columnCount Reimplemented for QAbstractTableModel.
Definition: projectdbmodel.cpp:73
QETApp::elementTranslatedInfoKey
static QString elementTranslatedInfoKey(const QString &)
ElementsProperties::translatedInfo Return the translated information key given by info If info don't ...
Definition: qetapp.cpp:400
ProjectDBModel::setIdentifier
void setIdentifier(const QString &identifier)
ProjectDBModel::setIdentifier Set the identifier of this model to identifier.
Definition: projectdbmodel.cpp:303
projectDataBase::dataBaseUpdated
void dataBaseUpdated()
ProjectDBModel::m_record
QVector< QStringList > m_record
Definition: projectdbmodel.h:83
ProjectDBModel::dataBaseUpdated
void dataBaseUpdated()
ProjectDBModel::dataBaseUpdated slot called when the project database is updated.
Definition: projectdbmodel.cpp:311
ProjectDBModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
ProjectDBModel::data Reimplemented for QAbstractTableModel.
Definition: projectdbmodel.cpp:157
ProjectDBModel::setData
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:140
ProjectDBModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
ProjectDBModel::rowCount Reimplemented for QAbstractTableModel.
Definition: projectdbmodel.cpp:59
ProjectDBModel::identifier
QString identifier() const
Definition: projectdbmodel.h:72
qetproject.h
ProjectDBModel::project
QETProject * project() const
Definition: projectdbmodel.cpp:222
QETProject
Definition: qetproject.h:51
QETXML::modelHeaderDataToXml
QDomElement modelHeaderDataToXml(QDomDocument &parent_document, const QAbstractItemModel *model, QHash< int, QList< int >> horizontal_section_role, QHash< int, QList< int >> vertical_section_role)
QETXML::modelHeaderDataToXml Save to xml element all header data specified by horizontal_section_role...
Definition: qetxml.cpp:429
ProjectDBModel::m_identifier
QString m_identifier
Definition: projectdbmodel.h:87
QET::Vertical
@ Vertical
Vertical segment.
Definition: qet.h:90
qetxml.h
ProjectDBModel::m_index_0_0_data
QHash< int, QVariant > m_index_0_0_data
Definition: projectdbmodel.h:86
ProjectDBModel::m_header_data
QHash< int, QHash< int, QVariant > > m_header_data
Definition: projectdbmodel.h:85
QET::Horizontal
@ Horizontal
Horizontal segment.
Definition: qet.h:89
ProjectDBModel::setHeaderString
void setHeaderString()
Definition: projectdbmodel.cpp:334
ProjectDBModel::fillValue
void fillValue()
Definition: projectdbmodel.cpp:361
ProjectDBModel::toXml
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:233
projectdbmodel.h
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
projectdatabase.h