qitemeditorfactory.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qitemeditorfactory.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11class 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-
20public:-
21 QBooleanComboBox(QWidget *parent);-
22 void setValue(bool);-
23 bool value() const;-
24};-
25-
26-
27-
28-
29-
30-
31class 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 -
39public:-
40 explicit QUIntSpinBox(QWidget *parent = 0)-
41 : QSpinBox(parent)-
42 {-
43 connect(this, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "79""86"), qFlagLocation("2""uintValueChanged()" "\0" __FILE__ ":" "79""86"));-
44 }-
45-
46 uint uintValue()-
47 {-
48 return value();-
49 }-
50-
51 void setUIntValue(uint value_)-
52 {-
53 return setValue(value_);-
54 }-
55-
56public :-
57 void uintValueChanged();-
58};-
59QWidget *QItemEditorFactory::createEditor(int userType, QWidget *parent) const-
60{-
61 QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);-
62 if (!creator) {-
63 const QItemEditorFactory *dfactory = defaultFactory();-
64 return dfactory == this ? 0 : dfactory->createEditor(userType, parent);-
65 }-
66 return creator->createWidget(parent);-
67}-
68-
69-
70-
71-
72QByteArray QItemEditorFactory::valuePropertyName(int userType) const-
73{-
74 QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);-
75 if (!creator) {-
76 const QItemEditorFactory *dfactory = defaultFactory();-
77 return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType);-
78 }-
79 return creator->valuePropertyName();-
80}-
81-
82-
83-
84-
85QItemEditorFactory::~QItemEditorFactory()-
86{-
87-
88-
89 QSet<QItemEditorCreatorBase*> set = creatorMap.values().toSet();-
90 qDeleteAll(set);-
91}-
92void QItemEditorFactory::registerEditor(int userType, QItemEditorCreatorBase *creator)-
93{-
94 QHash<int, QItemEditorCreatorBase *>::iteratorconst auto it = creatorMap.findconstFind(userType);-
95 if (it != creatorMap.endcend()
it != creatorMap.cend()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
96 QItemEditorCreatorBase *oldCreator = it.value();-
97 ((!(oldCreator)) ? qt_assert("oldCreator",__FILE__,203210) : qt_noop());-
98 creatorMap.erase(it);-
99 if (!(std::find(
std::find(crea...atorMap.cend()Description
TRUEnever evaluated
FALSEnever evaluated
creatorMap.values().contains(cbegin(), creatorMap.cend(), oldCreator))) == creatorMap.cend()
std::find(crea...atorMap.cend()Description
TRUEnever evaluated
FALSEnever evaluated
)
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-
106class QDefaultItemEditorFactory : public QItemEditorFactory-
107{-
108public:-
109 inline QDefaultItemEditorFactory() {}-
110 QWidget *createEditor(int userType, QWidget *parent) const override;-
111 QByteArray valuePropertyName(int) const override;-
112};-
113-
114QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) const-
115{-
116 switch (userType) {-
117-
118 case QVariant::Bool: {-
119 QBooleanComboBox *cb = new QBooleanComboBox(parent);-
120 cb->setFrame(false);-
121 return cb; }-
122-
123-
124 case QVariant::UInt: {-
125 QSpinBox *sb = new QUIntSpinBox(parent);-
126 sb->setFrame(false);-
127 sb->setMinimum(0);-
128 sb->setMaximum(2147483647);-
129 return sb; }-
130 case QVariant::Int: {-
131 QSpinBox *sb = new QSpinBox(parent);-
132 sb->setFrame(false);-
133 sb->setMinimum((-2147483647 - 1));-
134 sb->setMaximum(2147483647);-
135 return sb; }-
136-
137-
138 case QVariant::Date: {-
139 QDateTimeEdit *ed = new QDateEdit(parent);-
140 ed->setFrame(false);-
141 return ed; }-
142 case QVariant::Time: {-
143 QDateTimeEdit *ed = new QTimeEdit(parent);-
144 ed->setFrame(false);-
145 return ed; }-
146 case QVariant::DateTime: {-
147 QDateTimeEdit *ed = new QDateTimeEdit(parent);-
148 ed->setFrame(false);-
149 return ed; }-
150-
151 case QVariant::Pixmap:-
152 return new QLabel(parent);-
153-
154 case QVariant::Double: {-
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 sb; }-
160-
161-
162 case QVariant::String:-
163 default: {-
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))-
168 le->setWidgetOwnsGeometry(true);-
169 return le; }-
170-
171-
172-
173-
174 }-
175 return
dead code: return 0;
0;
dead code: return 0;
-
176}-
177-
178QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const-
179{-
180 switch (userType) {-
181-
182 case QVariant::Bool:-
183 return "currentIndex";-
184-
185-
186 case QVariant::UInt:-
187 case QVariant::Int:-
188 case QVariant::Double:-
189 return "value";-
190-
191-
192 case QVariant::Date:-
193 return "date";-
194 case QVariant::Time:-
195 return "time";-
196 case QVariant::DateTime:-
197 return "dateTime";-
198-
199 case QVariant::String:-
200 default:-
201-
202 return "text";-
203 }-
204}-
205-
206static QItemEditorFactory *q_default_factory = 0;-
207struct QDefaultFactoryCleaner-
208{-
209 inline QDefaultFactoryCleaner() {}-
210 ~QDefaultFactoryCleaner() { delete q_default_factory; q_default_factory = 0; }-
211};-
212-
213-
214-
215-
216-
217-
218const QItemEditorFactory *QItemEditorFactory::defaultFactory()-
219{-
220 static const QDefaultItemEditorFactory factory;-
221 if (q_default_factory)-
222 return q_default_factory;-
223 return &factory;-
224}-
225-
226-
227-
228-
229-
230-
231-
232void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory)-
233{-
234 static const QDefaultFactoryCleaner cleaner;-
235 delete q_default_factory;-
236 q_default_factory = factory;-
237}-
238QItemEditorCreatorBase::~QItemEditorCreatorBase()-
239{-
240-
241}-
242QExpandingLineEdit::QExpandingLineEdit(QWidget *parent)-
243 : QLineEdit(parent), originalWidth(-1), widgetOwnsGeometry(false)-
244{-
245 connect(this, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "525""532"), this, qFlagLocation("1""resizeToContents()" "\0" __FILE__ ":" "525""532"));-
246 updateMinimumWidth();-
247}-
248-
249void QExpandingLineEdit::changeEvent(QEvent *e)-
250{-
251 switch (e->type())-
252 {-
253 case QEvent::FontChange:-
254 case QEvent::StyleChange:-
255 case QEvent::ContentsRectChange:-
256 updateMinimumWidth();-
257 break;-
258 default:-
259 break;-
260 }-
261-
262 QLineEdit::changeEvent(e);-
263}-
264-
265void 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}-
280-
281void QExpandingLineEdit::resizeToContents()-
282{-
283 int oldWidth = width();-
284 if (originalWidth == -1)-
285 originalWidth = oldWidth;-
286 if (QWidget *parent = parentWidget()) {-
287 QPoint position = pos();-
288 int hintWidth = minimumWidth() + fontMetrics().width(displayText());-
289 int parentWidth = parent->width();-
290 int maxWidth = isRightToLeft() ? position.x() + oldWidth : parentWidth - position.x();-
291 int newWidth = qBound(originalWidth, hintWidth, maxWidth);-
292 if (widgetOwnsGeometry)-
293 setMaximumWidth(newWidth);-
294 if (isRightToLeft())-
295 move(position.x() - newWidth + oldWidth, position.y());-
296 resize(newWidth, height());-
297 }-
298}-
299-
300-
301-
302-
303-
304QBooleanComboBox::QBooleanComboBox(QWidget *parent)-
305 : QComboBox(parent)-
306{-
307 addItem(QComboBox::tr("False"));-
308 addItem(QComboBox::tr("True"));-
309}-
310-
311void QBooleanComboBox::setValue(bool value)-
312{-
313 setCurrentIndex(value ? 1 : 0);-
314}-
315-
316bool QBooleanComboBox::value() const-
317{-
318 return (currentIndex() == 1);-
319}-
320-
321-
322-
323-
324-
325-
326-
327-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9