-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotadatabasemodel.h
39 lines (31 loc) · 1.02 KB
/
notadatabasemodel.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
#ifndef NOTADATABASEMODEL_H
#define NOTADATABASEMODEL_H
#include <QObject>
#include <QtSql/QSqlTableModel>
#include "database.h"
class NotaDatabaseModel : public QSqlTableModel
{
Q_OBJECT
public:
enum Roles {
Id = Qt::UserRole + 1,
Titulo,
Desc,
Cor,
Date
};
Q_ENUM(Roles)
explicit NotaDatabaseModel(QObject *parent = nullptr, Database *database = new Database());
void configureRoles();
void registerRoleColumn(int role, QByteArray columnName);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Q_INVOKABLE void newRow(QString titulo, QString desc, QString cor, QString date);
Q_INVOKABLE void updateRow(QString id, QString titulo, QString desc, QString cor, QString date);
Q_INVOKABLE QVariant getNextId();
Q_INVOKABLE void deleteRow(QString id);
Q_INVOKABLE QHash<int, QByteArray> roleNames() const;
private:
Database m_db;
QHash<int, QByteArray> m_roleColumns;
};
#endif // NOTADATABASEMODEL_H