This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbviewmosql.h
243 lines (192 loc) · 5.26 KB
/
dbviewmosql.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
\file dbviewmosql.h
\date January 2017
\author Nicu Tofan
\brief Contains the definition for DbViewMoSql class.
*//*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please read COPYING and README files in root folder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef DBVIEWMOSQL_H
#define DBVIEWMOSQL_H
//
//
//
//
/* INCLUDES ------------------------------------------------------------ */
#include <dbview/dbviewmo.h>
#include <QSortFilterProxyModel>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQueryModel>
#include <QtSql/QSqlQuery>
/* INCLUDES ============================================================ */
//
//
//
//
/* DEFINITIONS --------------------------------------------------------- */
QT_BEGIN_NAMESPACE
// class QSqlDatabase;
QT_END_NAMESPACE
/* DEFINITIONS ========================================================= */
//
//
//
//
/* CLASS --------------------------------------------------------------- */
//! Allows pagination, sorting and filtering in a sql database.
class DBVIEW_EXPORT DbViewMoSql : public QSqlQueryModel, public DbViewMo
{
//
//
//
//
/* DEFINITIONS ----------------------------------------------------- */
/* DEFINITIONS ===================================================== */
//
//
//
//
/* DATA ------------------------------------------------------------ */
private:
DbViewConfig cfg_;
QSqlDatabase db_;
QString table_;
int total_count_;
/* DATA ============================================================ */
//
//
//
//
/* FUNCTIONS ------------------------------------------------------- */
public:
//! Constructor.
DbViewMoSql (
const QSqlDatabase & db,
const QString & table,
QObject * parent = NULL);
//! destructor
virtual ~DbViewMoSql();
const DbViewConfig &
getCfg() const {
return cfg_;
}
void
setCfg (const DbViewConfig &cfg) {
cfg_ = cfg;
}
const QString &
getTable() const {
return table_;
}
void
setTable (const QString &table) {
table_ = table;
}
/* - - - - - - - - - - - - - - - - */
/** @name DbViewMo Interface
*
*/
///@{
public:
//! The model we're ghosting.
virtual const QAbstractItemModel *
qtModelC () const {
return this;
}
//! The model we're ghosting.
virtual QAbstractItemModel *
qtModel () {
return this;
}
//! Get the data.
virtual QVariant
data (
int display_row,
int true_row,
int column,
int role) const;
//! Get the header data; never display or edit roles.
virtual QVariant
rowHeaderData (
int display_row,
int true_row,
int role) const;
//! The user requested data to be filtered.
virtual void
reloadWithFilters (
DbViewConfig cfg);
//! Get the (cached) number of records in the backend.
virtual int
totalRowCount () const {
return total_count_;
}
//! Bind values to a query.
virtual bool
bindToReloadQuery (
QSqlQuery & q) const {
Q_UNUSED (q);
return true;
}
//! Ask the backend about the total number of records.
virtual int
readTotalCount (
const QString &where_clause = QString ());
//! The condition for sql query.
virtual QString
getReloadWhereClause (
const DbViewConfig &cfg) const;
protected:
virtual void
prepareFilteredQuery (
const QString &s_statement,
QSqlQuery & q);
///@}
/* - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - */
/** @name QSqlQueryModel Interface
*
*/
///@{
public:
//! Change model data.
virtual bool
setData (
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole);
//! Item flags.
Qt::ItemFlags
flags (
const QModelIndex &index) const;
//! Perform model sorting.
void
sort (
int column,
Qt::SortOrder order);
//! Tell if currently installed filter accepts indicated row.
bool
filterAcceptsRow (
int sourceRow,
const QModelIndex &sourceParent) const;
///@}
/* - - - - - - - - - - - - - - - - */
/* FUNCTIONS ======================================================= */
//
//
//
//
}; /* class DbViewMoSql */
/* CLASS =============================================================== */
//
//
//
//
#endif // DBVIEWMOSQL_H
/* ------------------------------------------------------------------------- */
/* ========================================================================= */