This repository was 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
Expand file tree
/
Copy pathdbdelegate.h
More file actions
232 lines (187 loc) · 5.48 KB
/
dbdelegate.h
File metadata and controls
232 lines (187 loc) · 5.48 KB
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
/**
* @file dbdelegate.h
* @brief Declarations for DbDelegate class
* @author Nicu Tofan <nicu.tofan@gmail.com>
* @copyright Copyright 2014 piles contributors. All rights reserved.
* This file is released under the
* [MIT License](http://opensource.org/licenses/mit-license.html)
*/
#ifndef GUARD_DBDELEGATE_H_INCLUDE
#define GUARD_DBDELEGATE_H_INCLUDE
#include <dbdelegate/dbdelegate-config.h>
#include <dbstruct/dbcolumn.h>
#include <QStyledItemDelegate>
QT_BEGIN_NAMESPACE
class QTableView;
class QAbstractItemModel;
class QCheckBox;
class QComboBox;
class QDateEdit;
class QDateTimeEdit;
class QDoubleSpinBox;
class QLineEdit;
class QSpinBox;
class QTimeEdit;
class QTextEdit;
QT_END_NAMESPACE
class DbTaew;
class DbModel;
class DbModelCol;
class Resolve99Bug;
//! Provides display and editing facilities for data items from a model.
class DBDELEGATE_EXPORT DbDelegate : public QStyledItemDelegate {
Q_OBJECT
DbColumn column_;
public:
//! Sets all delegates for a table.
static bool
setAllDelegates (
QTableView * view);
//! Sets all delegates for a table.
static bool
setAllDelegates (
DbTaew * table,
QTableView * view);
//! Resets all delegates for a table.
static bool
resetAllDelegates (
QTableView * view);
virtual const DbModel *
dbModelConst (
const QModelIndex &index) const;
virtual DbModel *
dbModel (
const QModelIndex &index) const;
virtual QVariant
getData (
const QModelIndex &index,
int role) const;
virtual QModelIndex
mapIndex (
const QModelIndex & idx) const {
return idx;
}
public:
//! Default constructor.
explicit DbDelegate (
QObject *parent = NULL);
//! Destructor.
virtual ~DbDelegate();
//! Painting an item.
virtual void
paint(
QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
//! The size needed by the delegate to display the item.
virtual QSize
sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
//! Create a widget for editing a gived value.
virtual QWidget *
createEditor (
QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
//! Sets the data to be displayed and edited from the model.
virtual void
setEditorData (
QWidget *editor,
const QModelIndex &index) const;
//! Gets data from the editor and stores it in the model.
virtual void
setModelData (
QWidget *editor,
QAbstractItemModel *model,
const QModelIndex &index) const;
//! Updates the editor for the item according to the style.
virtual void
updateEditorGeometry (
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
//! Last chance to change displayed text before actual paint.
virtual QString
displayText (
const QVariant & value,
const QLocale &locale) const;
public:
/* - - - - - - - - - - - - - - - - */
/** @name Control SetUp
* Prepare controls to be used according to their type.
*/
///@{
static bool
setupControl (
const DbModelCol & col_data,
QCheckBox *control,
const QVariant & value);
static bool
setupControl (const DbModelCol & col_data,
QComboBox *control,
const QVariant & value,
bool b_delegate_enh = true);
static bool
setupControl (
const DbModelCol & col_data,
QDateEdit *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol & col_data,
QDateTimeEdit *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol & col_data,
QDoubleSpinBox *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol & col_data,
QLineEdit *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol & col_data,
QSpinBox *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol & col_data,
QTimeEdit *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol & col_data,
QTextEdit *control,
const QVariant & value);
static bool
setupControl (
const DbModelCol &col_data,
Resolve99Bug *control,
const QVariant &value);
///@}
/* - - - - - - - - - - - - - - - - */
protected:
//! Initialize style options for an item.
virtual void
initStyleOption (
QStyleOptionViewItem *option,
const QModelIndex &index) const;
//! Filter out some events.
virtual bool
eventFilter (
QObject *object,
QEvent *event);
//! Start of editing and mouse events.
virtual bool
editorEvent (
QEvent *event,
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index);
public: virtual void anchorVtable() const;
};
#endif // GUARD_DBDELEGATE_H_INCLUDE