Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qitemeditorfactory.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | - | |||||||
10 | - | |||||||
11 | class QBooleanComboBox : public QComboBox | - | ||||||
12 | { | - | ||||||
13 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||
14 | #pragma GCC diagnostic push | - | ||||||
15 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||
16 | #pragma GCC diagnostic pop | - | ||||||
17 | struct QPrivateSignal {}; | - | ||||||
18 | - | |||||||
19 | - | |||||||
20 | public: | - | ||||||
21 | QBooleanComboBox(QWidget *parent); | - | ||||||
22 | void setValue(bool); | - | ||||||
23 | bool value() const; | - | ||||||
24 | }; | - | ||||||
25 | - | |||||||
26 | - | |||||||
27 | - | |||||||
28 | - | |||||||
29 | - | |||||||
30 | - | |||||||
31 | class QUIntSpinBox : public QSpinBox | - | ||||||
32 | { | - | ||||||
33 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||
34 | #pragma GCC diagnostic push | - | ||||||
35 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||
36 | #pragma GCC diagnostic pop | - | ||||||
37 | struct QPrivateSignal {}; | - | ||||||
38 | - | |||||||
39 | public: | - | ||||||
40 | explicit QUIntSpinBox(QWidget *parent = 0) | - | ||||||
41 | : QSpinBox(parent) | - | ||||||
42 | { | - | ||||||
43 | connect(this, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "86"), qFlagLocation("2""uintValueChanged()" "\0" __FILE__ ":" "86")); | - | ||||||
44 | } never executed: end of block | 0 | ||||||
45 | - | |||||||
46 | uint uintValue() | - | ||||||
47 | { | - | ||||||
48 | return never executed: value();return value(); never executed: return value(); | 0 | ||||||
49 | } | - | ||||||
50 | - | |||||||
51 | void setUIntValue(uint value_) | - | ||||||
52 | { | - | ||||||
53 | return never executed: setValue(value_);return setValue(value_); never executed: return setValue(value_); | 0 | ||||||
54 | } | - | ||||||
55 | - | |||||||
56 | public : | - | ||||||
57 | void uintValueChanged(); | - | ||||||
58 | }; | - | ||||||
59 | QWidget *QItemEditorFactory::createEditor(int userType, QWidget *parent) const | - | ||||||
60 | { | - | ||||||
61 | QItemEditorCreatorBase *creator = creatorMap.value(userType, 0); | - | ||||||
62 | if (!creator
| 0 | ||||||
63 | const QItemEditorFactory *dfactory = defaultFactory(); | - | ||||||
64 | return never executed: dfactory == this ? 0 : dfactory->createEditor(userType, parent);return dfactory == this ? 0 : dfactory->createEditor(userType, parent); never executed: return dfactory == this ? 0 : dfactory->createEditor(userType, parent); | 0 | ||||||
65 | } | - | ||||||
66 | return never executed: creator->createWidget(parent);return creator->createWidget(parent); never executed: return creator->createWidget(parent); | 0 | ||||||
67 | } | - | ||||||
68 | - | |||||||
69 | - | |||||||
70 | - | |||||||
71 | - | |||||||
72 | QByteArray QItemEditorFactory::valuePropertyName(int userType) const | - | ||||||
73 | { | - | ||||||
74 | QItemEditorCreatorBase *creator = creatorMap.value(userType, 0); | - | ||||||
75 | if (!creator
| 0 | ||||||
76 | const QItemEditorFactory *dfactory = defaultFactory(); | - | ||||||
77 | return never executed: dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType);return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType); never executed: return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType); | 0 | ||||||
78 | } | - | ||||||
79 | return never executed: creator->valuePropertyName();return creator->valuePropertyName(); never executed: return creator->valuePropertyName(); | 0 | ||||||
80 | } | - | ||||||
81 | - | |||||||
82 | - | |||||||
83 | - | |||||||
84 | - | |||||||
85 | QItemEditorFactory::~QItemEditorFactory() | - | ||||||
86 | { | - | ||||||
87 | - | |||||||
88 | - | |||||||
89 | QSet<QItemEditorCreatorBase*> set = creatorMap.values().toSet(); | - | ||||||
90 | qDeleteAll(set); | - | ||||||
91 | } never executed: end of block | 0 | ||||||
92 | void QItemEditorFactory::registerEditor(int userType, QItemEditorCreatorBase *creator) | - | ||||||
93 | { | - | ||||||
94 | const auto it = creatorMap.constFind(userType); | - | ||||||
95 | if (it != creatorMap.cend()
| 0 | ||||||
96 | QItemEditorCreatorBase *oldCreator = it.value(); | - | ||||||
97 | ((!(oldCreator)) ? qt_assert("oldCreator",__FILE__,210) : qt_noop()); | - | ||||||
98 | creatorMap.erase(it); | - | ||||||
99 | if (std::find(creatorMap.cbegin(), creatorMap.cend(), oldCreator) == creatorMap.cend()
| 0 | ||||||
100 | delete oldCreator; never executed: delete oldCreator; | 0 | ||||||
101 | } never executed: end of block | 0 | ||||||
102 | - | |||||||
103 | creatorMap[userType] = creator; | - | ||||||
104 | } never executed: end of block | 0 | ||||||
105 | - | |||||||
106 | class QDefaultItemEditorFactory : public QItemEditorFactory | - | ||||||
107 | { | - | ||||||
108 | public: | - | ||||||
109 | inline QDefaultItemEditorFactory() {} | - | ||||||
110 | QWidget *createEditor(int userType, QWidget *parent) const override; | - | ||||||
111 | QByteArray valuePropertyName(int) const override; | - | ||||||
112 | }; | - | ||||||
113 | - | |||||||
114 | QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) const | - | ||||||
115 | { | - | ||||||
116 | switch (userType) { | - | ||||||
117 | - | |||||||
118 | case never executed: QVariant::Bool:case QVariant::Bool: never executed: {case QVariant::Bool: | 0 | ||||||
119 | QBooleanComboBox *cb = new QBooleanComboBox(parent); | - | ||||||
120 | cb->setFrame(false); | - | ||||||
121 | return never executed: cb;return cb; never executed: }return cb; | 0 | ||||||
122 | - | |||||||
123 | - | |||||||
124 | case never executed: QVariant::UInt:case QVariant::UInt: never executed: {case QVariant::UInt: | 0 | ||||||
125 | QSpinBox *sb = new QUIntSpinBox(parent); | - | ||||||
126 | sb->setFrame(false); | - | ||||||
127 | sb->setMinimum(0); | - | ||||||
128 | sb->setMaximum(2147483647); | - | ||||||
129 | return never executed: sb;return sb; never executed: }return sb; | 0 | ||||||
130 | case never executed: QVariant::Int:case QVariant::Int: never executed: {case QVariant::Int: | 0 | ||||||
131 | QSpinBox *sb = new QSpinBox(parent); | - | ||||||
132 | sb->setFrame(false); | - | ||||||
133 | sb->setMinimum((-2147483647 - 1)); | - | ||||||
134 | sb->setMaximum(2147483647); | - | ||||||
135 | return never executed: sb;return sb; never executed: }return sb; | 0 | ||||||
136 | - | |||||||
137 | - | |||||||
138 | case never executed: QVariant::Date:case QVariant::Date: never executed: {case QVariant::Date: | 0 | ||||||
139 | QDateTimeEdit *ed = new QDateEdit(parent); | - | ||||||
140 | ed->setFrame(false); | - | ||||||
141 | return never executed: ed;return ed; never executed: }return ed; | 0 | ||||||
142 | case never executed: QVariant::Time:case QVariant::Time: never executed: {case QVariant::Time: | 0 | ||||||
143 | QDateTimeEdit *ed = new QTimeEdit(parent); | - | ||||||
144 | ed->setFrame(false); | - | ||||||
145 | return never executed: ed;return ed; never executed: }return ed; | 0 | ||||||
146 | case never executed: QVariant::DateTime:case QVariant::DateTime: never executed: {case QVariant::DateTime: | 0 | ||||||
147 | QDateTimeEdit *ed = new QDateTimeEdit(parent); | - | ||||||
148 | ed->setFrame(false); | - | ||||||
149 | return never executed: ed;return ed; never executed: }return ed; | 0 | ||||||
150 | - | |||||||
151 | case never executed: QVariant::Pixmap:case QVariant::Pixmap: never executed: case QVariant::Pixmap: | 0 | ||||||
152 | return never executed: new QLabel(parent);return new QLabel(parent); never executed: return new QLabel(parent); | 0 | ||||||
153 | - | |||||||
154 | case never executed: QVariant::Double:case QVariant::Double: never executed: {case QVariant::Double: | 0 | ||||||
155 | QDoubleSpinBox *sb = new QDoubleSpinBox(parent); | - | ||||||
156 | sb->setFrame(false); | - | ||||||
157 | sb->setMinimum(-double(1.79769313486231570815e+308L)); | - | ||||||
158 | sb->setMaximum(double(1.79769313486231570815e+308L)); | - | ||||||
159 | return never executed: sb;return sb; never executed: }return sb; | 0 | ||||||
160 | - | |||||||
161 | - | |||||||
162 | case never executed: QVariant::String:case QVariant::String: never executed: case QVariant::String: | 0 | ||||||
163 | default never executed: :default: never executed: {default: | 0 | ||||||
164 | - | |||||||
165 | QExpandingLineEdit *le = new QExpandingLineEdit(parent); | - | ||||||
166 | le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le)); | - | ||||||
167 | if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le)
| 0 | ||||||
168 | le->setWidgetOwnsGeometry(true); never executed: le->setWidgetOwnsGeometry(true); | 0 | ||||||
169 | return never executed: le;return le; never executed: }return le; | 0 | ||||||
170 | - | |||||||
171 | - | |||||||
172 | - | |||||||
173 | - | |||||||
174 | } | - | ||||||
175 | return dead code: 0;return 0; dead code: return 0; | - | ||||||
176 | } | - | ||||||
177 | - | |||||||
178 | QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const | - | ||||||
179 | { | - | ||||||
180 | switch (userType) { | - | ||||||
181 | - | |||||||
182 | case never executed: QVariant::Bool:case QVariant::Bool: never executed: case QVariant::Bool: | 0 | ||||||
183 | return never executed: "currentIndex";return "currentIndex"; never executed: return "currentIndex"; | 0 | ||||||
184 | - | |||||||
185 | - | |||||||
186 | case never executed: QVariant::UInt:case QVariant::UInt: never executed: case QVariant::UInt: | 0 | ||||||
187 | case never executed: QVariant::Int:case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||
188 | case never executed: QVariant::Double:case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||
189 | return never executed: "value";return "value"; never executed: return "value"; | 0 | ||||||
190 | - | |||||||
191 | - | |||||||
192 | case never executed: QVariant::Date:case QVariant::Date: never executed: case QVariant::Date: | 0 | ||||||
193 | return never executed: "date";return "date"; never executed: return "date"; | 0 | ||||||
194 | case never executed: QVariant::Time:case QVariant::Time: never executed: case QVariant::Time: | 0 | ||||||
195 | return never executed: "time";return "time"; never executed: return "time"; | 0 | ||||||
196 | case never executed: QVariant::DateTime:case QVariant::DateTime: never executed: case QVariant::DateTime: | 0 | ||||||
197 | return never executed: "dateTime";return "dateTime"; never executed: return "dateTime"; | 0 | ||||||
198 | - | |||||||
199 | case never executed: QVariant::String:case QVariant::String: never executed: case QVariant::String: | 0 | ||||||
200 | default never executed: :default: never executed: default: | 0 | ||||||
201 | - | |||||||
202 | return never executed: "text";return "text"; never executed: return "text"; | 0 | ||||||
203 | } | - | ||||||
204 | } | - | ||||||
205 | - | |||||||
206 | static QItemEditorFactory *q_default_factory = 0; | - | ||||||
207 | struct QDefaultFactoryCleaner | - | ||||||
208 | { | - | ||||||
209 | inline QDefaultFactoryCleaner() {} | - | ||||||
210 | ~QDefaultFactoryCleaner() { delete q_default_factory; q_default_factory = 0; } never executed: end of block | 0 | ||||||
211 | }; | - | ||||||
212 | - | |||||||
213 | - | |||||||
214 | - | |||||||
215 | - | |||||||
216 | - | |||||||
217 | - | |||||||
218 | const QItemEditorFactory *QItemEditorFactory::defaultFactory() | - | ||||||
219 | { | - | ||||||
220 | static const QDefaultItemEditorFactory factory; | - | ||||||
221 | if (q_default_factory
| 0 | ||||||
222 | return never executed: q_default_factory;return q_default_factory; never executed: return q_default_factory; | 0 | ||||||
223 | return never executed: &factory;return &factory; never executed: return &factory; | 0 | ||||||
224 | } | - | ||||||
225 | - | |||||||
226 | - | |||||||
227 | - | |||||||
228 | - | |||||||
229 | - | |||||||
230 | - | |||||||
231 | - | |||||||
232 | void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory) | - | ||||||
233 | { | - | ||||||
234 | static const QDefaultFactoryCleaner cleaner; | - | ||||||
235 | delete q_default_factory; | - | ||||||
236 | q_default_factory = factory; | - | ||||||
237 | } never executed: end of block | 0 | ||||||
238 | QItemEditorCreatorBase::~QItemEditorCreatorBase() | - | ||||||
239 | { | - | ||||||
240 | - | |||||||
241 | } | - | ||||||
242 | QExpandingLineEdit::QExpandingLineEdit(QWidget *parent) | - | ||||||
243 | : QLineEdit(parent), originalWidth(-1), widgetOwnsGeometry(false) | - | ||||||
244 | { | - | ||||||
245 | connect(this, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "532"), this, qFlagLocation("1""resizeToContents()" "\0" __FILE__ ":" "532")); | - | ||||||
246 | updateMinimumWidth(); | - | ||||||
247 | } never executed: end of block | 0 | ||||||
248 | - | |||||||
249 | void QExpandingLineEdit::changeEvent(QEvent *e) | - | ||||||
250 | { | - | ||||||
251 | switch (e->type()) | - | ||||||
252 | { | - | ||||||
253 | case never executed: QEvent::FontChange:case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||
254 | case never executed: QEvent::StyleChange:case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||
255 | case never executed: QEvent::ContentsRectChange:case QEvent::ContentsRectChange: never executed: case QEvent::ContentsRectChange: | 0 | ||||||
256 | updateMinimumWidth(); | - | ||||||
257 | break; never executed: break; | 0 | ||||||
258 | default never executed: :default: never executed: default: | 0 | ||||||
259 | break; never executed: break; | 0 | ||||||
260 | } | - | ||||||
261 | - | |||||||
262 | QLineEdit::changeEvent(e); | - | ||||||
263 | } never executed: end of block | 0 | ||||||
264 | - | |||||||
265 | void QExpandingLineEdit::updateMinimumWidth() | - | ||||||
266 | { | - | ||||||
267 | int left, right; | - | ||||||
268 | getTextMargins(&left, 0, &right, 0); | - | ||||||
269 | int width = left + right + 4 ; | - | ||||||
270 | getContentsMargins(&left, 0, &right, 0); | - | ||||||
271 | width += left + right; | - | ||||||
272 | - | |||||||
273 | QStyleOptionFrame opt; | - | ||||||
274 | initStyleOption(&opt); | - | ||||||
275 | - | |||||||
276 | int minWidth = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(width, 0). | - | ||||||
277 | expandedTo(QApplication::globalStrut()), this).width(); | - | ||||||
278 | setMinimumWidth(minWidth); | - | ||||||
279 | } never executed: end of block | 0 | ||||||
280 | - | |||||||
281 | void QExpandingLineEdit::resizeToContents() | - | ||||||
282 | { | - | ||||||
283 | int oldWidth = width(); | - | ||||||
284 | if (originalWidth == -1
| 0 | ||||||
285 | originalWidth = oldWidth; never executed: originalWidth = oldWidth; | 0 | ||||||
286 | if (QWidget *parent = parentWidget()
| 0 | ||||||
287 | QPoint position = pos(); | - | ||||||
288 | int hintWidth = minimumWidth() + fontMetrics().width(displayText()); | - | ||||||
289 | int parentWidth = parent->width(); | - | ||||||
290 | int maxWidth = isRightToLeft()
| 0 | ||||||
291 | int newWidth = qBound(originalWidth, hintWidth, maxWidth); | - | ||||||
292 | if (widgetOwnsGeometry
| 0 | ||||||
293 | setMaximumWidth(newWidth); never executed: setMaximumWidth(newWidth); | 0 | ||||||
294 | if (isRightToLeft()
| 0 | ||||||
295 | move(position.x() - newWidth + oldWidth, position.y()); never executed: move(position.x() - newWidth + oldWidth, position.y()); | 0 | ||||||
296 | resize(newWidth, height()); | - | ||||||
297 | } never executed: end of block | 0 | ||||||
298 | } never executed: end of block | 0 | ||||||
299 | - | |||||||
300 | - | |||||||
301 | - | |||||||
302 | - | |||||||
303 | - | |||||||
304 | QBooleanComboBox::QBooleanComboBox(QWidget *parent) | - | ||||||
305 | : QComboBox(parent) | - | ||||||
306 | { | - | ||||||
307 | addItem(QComboBox::tr("False")); | - | ||||||
308 | addItem(QComboBox::tr("True")); | - | ||||||
309 | } never executed: end of block | 0 | ||||||
310 | - | |||||||
311 | void QBooleanComboBox::setValue(bool value) | - | ||||||
312 | { | - | ||||||
313 | setCurrentIndex(value ? 1 : 0); | - | ||||||
314 | } never executed: end of block | 0 | ||||||
315 | - | |||||||
316 | bool QBooleanComboBox::value() const | - | ||||||
317 | { | - | ||||||
318 | return never executed: (currentIndex() == 1);return (currentIndex() == 1); never executed: return (currentIndex() == 1); | 0 | ||||||
319 | } | - | ||||||
320 | - | |||||||
321 | - | |||||||
322 | - | |||||||
323 | - | |||||||
324 | - | |||||||
325 | - | |||||||
326 | - | |||||||
327 | - | |||||||
Switch to Source code | Preprocessed file |