-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfbasesqltablemodel.h
59 lines (45 loc) · 1.64 KB
/
fbasesqltablemodel.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
54
55
56
57
58
59
#ifndef FBASESQLTABLEMODEL_H
#define FBASESQLTABLEMODEL_H
#include "fsqlrelation.h"
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QDebug>
class QTimer;
class FBaseSqlTableModel : public QSqlTableModel
{
Q_OBJECT
public:
enum FetchMode {
ImmediateFetch,
LazyFetch,
ParallelFetch,
ManualFetch
};
explicit FBaseSqlTableModel(QObject *parent = 0, QSqlDatabase db = QSqlDatabase());
QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole);
virtual bool select(FetchMode fetchMode = ImmediateFetch);
virtual bool selectRow(int row);
virtual void setTable(const QString &tableName);
virtual bool canFetchMore(const QModelIndex &parent = QModelIndex()) const;
virtual void fetchMore(const QModelIndex &parent = QModelIndex());
void setRelation(const QString &relationColumn,
const QString &tableName,
const QString &indexColumn,
const QString &displayColumn);
QSqlQueryModel *relationModel(int column) const;
FSqlRelation relation(int column) const;
int getRelationalId(const QModelIndex &item) const;
private slots:
void doFetchMore();
protected:
virtual QString selectStatement() const;
virtual bool updateRowInTable(int row, const QSqlRecord &values);
private:
mutable QVector<FSqlRelation> m_relations;
mutable QHash<int, QHash<int, QVariant>> m_displayCache;
QSqlRecord m_baseRec;
QTimer *m_timerFetch;
mutable QMutex m_mutex;
};
#endif // FBASESQLTABLEMODEL_H