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 pathdbcheckproxy.h
183 lines (144 loc) · 3.9 KB
/
dbcheckproxy.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
/**
* @file dbcheckproxy.h
* @brief Declarations for DbModel class
* @author Nicu Tofan <nicu.tofan@gmail.com>
* @copyright Copyright 2016 piles contributors. All rights reserved.
* This file is released under the
* [MIT License](http://opensource.org/licenses/mit-license.html)
*/
#ifndef GUARD_DBCHECKPROXY_H_INCLUDE
#define GUARD_DBCHECKPROXY_H_INCLUDE
#include <dbmodel/dbmodel-config.h>
#include <dbmodel/dbmodelcol.h>
#include <dbmodel/dbmodeltbl.h>
#include <QMap>
#include <QList>
#include <QSqlRecord>
#include <QSortFilterProxyModel>
#include <QSqlDatabase>
#include <QVector>
#include <QModelIndex>
#include <QIdentityProxyModel>
QT_BEGIN_NAMESPACE
class QSqlQueryModel;
class QSqlTableModel;
class QAbstractItemView;
QT_END_NAMESPACE
//! A Qt model that adds check boxes to a column.
class DBMODEL_EXPORT DbCheckProxy : public QAbstractItemModel {
Q_OBJECT
int check_column_; /**< the index of the column where the check marks will appear */
QMap<int,bool> checks_; /**< the list of rows and associated checked values */
bool has_all_; /**< shows an additional column that checks all / none */
QAbstractItemModel * src_model_;
public:
//! Constructor.
explicit DbCheckProxy (
int check_column = 0,
QObject *parent = 0);
//! The column that shows check marks.
int
checkColumn () const {
return check_column_;
}
//! Change the column that shows check marks.
void
setCheckColumn (
int value) {
check_column_ = value;
}
//! Show or hide the All row.
void
setHasAll (
bool value) {
has_all_ = value;
}
//! Do we show the All row?.
bool
hasAll () const {
return has_all_;
}
//! Tell if a certain row is checked or not.
bool
isChecked (
int row_idx) const;
//! Remove check marks from all rows.
void
clearAllCheckMarks ();
//! Set check marks from all rows.
void
setAllCheckMarks ();
//! Clear the check mark for a row.
void
clearCheckMark (
int row_idx);
//! Set the check mark for a row.
void
setCheckMark (
int row_idx,
bool b_checked = true);
//! Get the index of all rows that have a check mark.
QList<int>
checkedRows () {
return checks_.keys ();
}
QAbstractItemModel *
sourceModel () const {
return src_model_;
}
virtual void
setSourceModel (
QAbstractItemModel *sourceModel);
virtual QVariant
data (
const QModelIndex &proxyIndex,
int role = Qt::DisplayRole) const;
virtual QVariant
headerData (
int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
virtual Qt::ItemFlags
flags (
const QModelIndex &index) const;
virtual bool
setData (
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole);
virtual int
rowCount (
const QModelIndex& parent = QModelIndex()) const;
virtual int
columnCount (
const QModelIndex& parent = QModelIndex()) const;
virtual QModelIndex
index (
int row,
int column,
const QModelIndex& parent = QModelIndex()) const;
virtual QModelIndex
parent (
const QModelIndex& child) const;
virtual QModelIndex
mapFromSource (
const QModelIndex& sourceIndex) const;
virtual QModelIndex
mapToSource (
const QModelIndex& proxyIndex) const;
private:
void
allChanged ();
void
oneChanged (
int row_idx);
void
setCheckMarkInternal (
int row_idx);
signals:
//! Emitted when one or more items change check status.
void
checkChange (
QList<int> rows);
};
#endif // GUARD_DBCHECKPROXY_H_INCLUDE