-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.h
53 lines (38 loc) · 1.25 KB
/
table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef TABLE_H
#define TABLE_H
#include <QObject>
#include <qqml.h>
#include <QAbstractTableModel>
#include <QSqlQuery>
class TableModel : public QAbstractTableModel
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(int columnCount READ columnCount NOTIFY columnCountChanged)
public:
explicit TableModel(QObject *parent = nullptr);
int rowCount(const QModelIndex & = QModelIndex()) const override;
int columnCount(const QModelIndex & = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
Q_INVOKABLE void executeQuery(const QString &sqlQuery);
QHash<int, QByteArray> roleNames() const override;
/*public:
static TableModel *instance();
private:
TableModel(QObject *parent = nullptr) : QAbstractTableModel(parent)
{
}
TableModel(const TableModel &) = delete;
TableModel &operator=(const TableModel &) = delete;
private:
static TableModel *m_instance;
*/
signals:
void columnCountChanged();
private:
QSqlQuery m_query{};
QVector<QVector<QVariant>> m_data{};
QVector<QString> m_headers{};
};
#endif