itemviews/qitemeditorfactory.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <qplatformdefs.h> -
43#include "qitemeditorfactory.h" -
44#include "qitemeditorfactory_p.h" -
45 -
46#ifndef QT_NO_ITEMVIEWS -
47 -
48#include <qcombobox.h> -
49#include <qdatetimeedit.h> -
50#include <qlabel.h> -
51#include <qlineedit.h> -
52#include <qspinbox.h> -
53#include <limits.h> -
54#include <float.h> -
55#include <qapplication.h> -
56#include <qdebug.h> -
57 -
58QT_BEGIN_NAMESPACE -
59 -
60 -
61#ifndef QT_NO_COMBOBOX -
62 -
63class QBooleanComboBox : public QComboBox -
64{ -
65 Q_OBJECT -
66 Q_PROPERTY(bool value READ value WRITE setValue USER true) -
67 -
68public: -
69 QBooleanComboBox(QWidget *parent); -
70 void setValue(bool); -
71 bool value() const; -
72}; -
73 -
74#endif // QT_NO_COMBOBOX -
75 -
76 -
77#ifndef QT_NO_SPINBOX -
78 -
79class QUIntSpinBox : public QSpinBox -
80{ -
81 Q_OBJECT -
82 Q_PROPERTY(uint value READ uintValue WRITE setUIntValue NOTIFY uintValueChanged USER true) -
83public: -
84 explicit QUIntSpinBox(QWidget *parent = 0) -
85 : QSpinBox(parent) -
86 { -
87 connect(this, SIGNAL(valueChanged(int)), SIGNAL(uintValueChanged()));
executed (the execution status of this line is deduced): connect(this, "2""valueChanged(int)", "2""uintValueChanged()");
-
88 }
executed: }
Execution Count:3
3
89 -
90 uint uintValue() -
91 { -
92 return value();
executed: return value();
Execution Count:2
2
93 } -
94 -
95 void setUIntValue(uint value_) -
96 { -
97 return setValue(value_);
executed: return setValue(value_);
Execution Count:4
4
98 } -
99 -
100Q_SIGNALS: -
101 void uintValueChanged(); -
102}; -
103 -
104#endif // QT_NO_SPINBOX -
105 -
106/*! -
107 \class QItemEditorFactory -
108 \brief The QItemEditorFactory class provides widgets for editing item data -
109 in views and delegates. -
110 \since 4.2 -
111 \ingroup model-view -
112 \inmodule QtWidgets -
113 -
114 When editing data in an item view, editors are created and -
115 displayed by a delegate. QItemDelegate, which is the delegate by -
116 default installed on Qt's item views, uses a QItemEditorFactory to -
117 create editors for it. A default unique instance provided by -
118 QItemEditorFactory is used by all item delegates. If you set a -
119 new default factory with setDefaultFactory(), the new factory will -
120 be used by existing and new delegates. -
121 -
122 A factory keeps a collection of QItemEditorCreatorBase -
123 instances, which are specialized editors that produce editors -
124 for one particular QVariant data type (All Qt models store -
125 their data in \l{QVariant}s). -
126 -
127 \section1 Standard Editing Widgets -
128 -
129 The standard factory implementation provides editors for a variety of data -
130 types. These are created whenever a delegate needs to provide an editor for -
131 data supplied by a model. The following table shows the relationship between -
132 types and the standard editors provided. -
133 -
134 \table -
135 \header \li Type \li Editor Widget -
136 \row \li bool \li QComboBox -
137 \row \li double \li QDoubleSpinBox -
138 \row \li int \li{1,2} QSpinBox -
139 \row \li unsigned int -
140 \row \li QDate \li QDateEdit -
141 \row \li QDateTime \li QDateTimeEdit -
142 \row \li QPixmap \li QLabel -
143 \row \li QString \li QLineEdit -
144 \row \li QTime \li QTimeEdit -
145 \endtable -
146 -
147 Additional editors can be registered with the registerEditor() function. -
148 -
149 \sa QItemDelegate, {Model/View Programming}, {Color Editor Factory Example} -
150*/ -
151 -
152/*! -
153 \fn QItemEditorFactory::QItemEditorFactory() -
154 -
155 Constructs a new item editor factory. -
156*/ -
157 -
158/*! -
159 Creates an editor widget with the given \a parent for the specified \a userType of data, -
160 and returns it as a QWidget. -
161 -
162 \sa registerEditor() -
163*/ -
164QWidget *QItemEditorFactory::createEditor(int userType, QWidget *parent) const -
165{ -
166 QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);
executed (the execution status of this line is deduced): QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);
-
167 if (!creator) {
evaluated: !creator
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
1-2
168 const QItemEditorFactory *dfactory = defaultFactory();
executed (the execution status of this line is deduced): const QItemEditorFactory *dfactory = defaultFactory();
-
169 return dfactory == this ? 0 : dfactory->createEditor(userType, parent);
executed: return dfactory == this ? 0 : dfactory->createEditor(userType, parent);
Execution Count:2
2
170 } -
171 return creator->createWidget(parent);
executed: return creator->createWidget(parent);
Execution Count:1
1
172} -
173 -
174/*! -
175 Returns the property name used to access data for the given \a userType of data. -
176*/ -
177QByteArray QItemEditorFactory::valuePropertyName(int userType) const -
178{ -
179 QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);
never executed (the execution status of this line is deduced): QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);
-
180 if (!creator) {
never evaluated: !creator
0
181 const QItemEditorFactory *dfactory = defaultFactory();
never executed (the execution status of this line is deduced): const QItemEditorFactory *dfactory = defaultFactory();
-
182 return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType);
never executed: return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType);
0
183 } -
184 return creator->valuePropertyName();
never executed: return creator->valuePropertyName();
0
185} -
186 -
187/*! -
188 Destroys the item editor factory. -
189*/ -
190QItemEditorFactory::~QItemEditorFactory() -
191{ -
192 //we make sure we delete all the QItemEditorCreatorBase -
193 //this has to be done only once, hence the QSet -
194 QSet<QItemEditorCreatorBase*> set = creatorMap.values().toSet();
executed (the execution status of this line is deduced): QSet<QItemEditorCreatorBase*> set = creatorMap.values().toSet();
-
195 qDeleteAll(set);
executed (the execution status of this line is deduced): qDeleteAll(set);
-
196}
executed: }
Execution Count:11
11
197 -
198/*! -
199 Registers an item editor creator specified by \a creator for the given \a userType of data. -
200 -
201 \b{Note:} The factory takes ownership of the item editor creator and will destroy -
202 it if a new creator for the same type is registered later. -
203 -
204 \sa createEditor() -
205*/ -
206void QItemEditorFactory::registerEditor(int userType, QItemEditorCreatorBase *creator) -
207{ -
208 QHash<int, QItemEditorCreatorBase *>::iterator it = creatorMap.find(userType);
executed (the execution status of this line is deduced): QHash<int, QItemEditorCreatorBase *>::iterator it = creatorMap.find(userType);
-
209 if (it != creatorMap.end()) {
evaluated: it != creatorMap.end()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
210 QItemEditorCreatorBase *oldCreator = it.value();
executed (the execution status of this line is deduced): QItemEditorCreatorBase *oldCreator = it.value();
-
211 Q_ASSERT(oldCreator);
executed (the execution status of this line is deduced): qt_noop();
-
212 creatorMap.erase(it);
executed (the execution status of this line is deduced): creatorMap.erase(it);
-
213 if (!creatorMap.values().contains(oldCreator))
evaluated: !creatorMap.values().contains(oldCreator)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
214 delete oldCreator; // if it is no more in use we can delete it
executed: delete oldCreator;
Execution Count:1
1
215 }
executed: }
Execution Count:2
2
216 -
217 creatorMap[userType] = creator;
executed (the execution status of this line is deduced): creatorMap[userType] = creator;
-
218}
executed: }
Execution Count:4
4
219 -
220class QDefaultItemEditorFactory : public QItemEditorFactory -
221{ -
222public: -
223 inline QDefaultItemEditorFactory() {} -
224 QWidget *createEditor(int userType, QWidget *parent) const; -
225 QByteArray valuePropertyName(int) const; -
226}; -
227 -
228QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) const -
229{ -
230 switch (userType) { -
231#ifndef QT_NO_COMBOBOX -
232 case QVariant::Bool: { -
233 QBooleanComboBox *cb = new QBooleanComboBox(parent);
executed (the execution status of this line is deduced): QBooleanComboBox *cb = new QBooleanComboBox(parent);
-
234 cb->setFrame(false);
executed (the execution status of this line is deduced): cb->setFrame(false);
-
235 return cb; }
executed: return cb;
Execution Count:1
1
236#endif -
237#ifndef QT_NO_SPINBOX -
238 case QVariant::UInt: { -
239 QSpinBox *sb = new QUIntSpinBox(parent);
executed (the execution status of this line is deduced): QSpinBox *sb = new QUIntSpinBox(parent);
-
240 sb->setFrame(false);
executed (the execution status of this line is deduced): sb->setFrame(false);
-
241 sb->setMinimum(0);
executed (the execution status of this line is deduced): sb->setMinimum(0);
-
242 sb->setMaximum(INT_MAX);
executed (the execution status of this line is deduced): sb->setMaximum(2147483647);
-
243 return sb; }
executed: return sb;
Execution Count:3
3
244 case QVariant::Int: { -
245 QSpinBox *sb = new QSpinBox(parent);
executed (the execution status of this line is deduced): QSpinBox *sb = new QSpinBox(parent);
-
246 sb->setFrame(false);
executed (the execution status of this line is deduced): sb->setFrame(false);
-
247 sb->setMinimum(INT_MIN);
executed (the execution status of this line is deduced): sb->setMinimum((-2147483647 - 1));
-
248 sb->setMaximum(INT_MAX);
executed (the execution status of this line is deduced): sb->setMaximum(2147483647);
-
249 return sb; }
executed: return sb;
Execution Count:3
3
250#endif -
251#ifndef QT_NO_DATETIMEEDIT -
252 case QVariant::Date: { -
253 QDateTimeEdit *ed = new QDateEdit(parent);
executed (the execution status of this line is deduced): QDateTimeEdit *ed = new QDateEdit(parent);
-
254 ed->setFrame(false);
executed (the execution status of this line is deduced): ed->setFrame(false);
-
255 return ed; }
executed: return ed;
Execution Count:2
2
256 case QVariant::Time: { -
257 QDateTimeEdit *ed = new QTimeEdit(parent);
executed (the execution status of this line is deduced): QDateTimeEdit *ed = new QTimeEdit(parent);
-
258 ed->setFrame(false);
executed (the execution status of this line is deduced): ed->setFrame(false);
-
259 return ed; }
executed: return ed;
Execution Count:2
2
260 case QVariant::DateTime: { -
261 QDateTimeEdit *ed = new QDateTimeEdit(parent);
executed (the execution status of this line is deduced): QDateTimeEdit *ed = new QDateTimeEdit(parent);
-
262 ed->setFrame(false);
executed (the execution status of this line is deduced): ed->setFrame(false);
-
263 return ed; }
executed: return ed;
Execution Count:2
2
264#endif -
265 case QVariant::Pixmap: -
266 return new QLabel(parent);
never executed: return new QLabel(parent);
0
267#ifndef QT_NO_SPINBOX -
268 case QVariant::Double: { -
269 QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
executed (the execution status of this line is deduced): QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
-
270 sb->setFrame(false);
executed (the execution status of this line is deduced): sb->setFrame(false);
-
271 sb->setMinimum(-DBL_MAX);
executed (the execution status of this line is deduced): sb->setMinimum(-1.7976931348623157e+308);
-
272 sb->setMaximum(DBL_MAX);
executed (the execution status of this line is deduced): sb->setMaximum(1.7976931348623157e+308);
-
273 return sb; }
executed: return sb;
Execution Count:1
1
274#endif -
275#ifndef QT_NO_LINEEDIT -
276 case QVariant::String: -
277 default: { -
278 // the default editor is a lineedit -
279 QExpandingLineEdit *le = new QExpandingLineEdit(parent);
executed (the execution status of this line is deduced): QExpandingLineEdit *le = new QExpandingLineEdit(parent);
-
280 le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le));
executed (the execution status of this line is deduced): le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le));
-
281 if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le))
partially evaluated: !le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le)
TRUEFALSE
yes
Evaluation Count:85
no
Evaluation Count:0
0-85
282 le->setWidgetOwnsGeometry(true);
executed: le->setWidgetOwnsGeometry(true);
Execution Count:85
85
283 return le; }
executed: return le;
Execution Count:85
85
284#else -
285 default: -
286 break; -
287#endif -
288 } -
289 return 0;
never executed: return 0;
0
290} -
291 -
292QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const -
293{ -
294 switch (userType) { -
295#ifndef QT_NO_COMBOBOX -
296 case QVariant::Bool: -
297 return "currentIndex";
never executed: return "currentIndex";
0
298#endif -
299#ifndef QT_NO_SPINBOX -
300 case QVariant::UInt: -
301 case QVariant::Int: -
302 case QVariant::Double: -
303 return "value";
never executed: return "value";
0
304#endif -
305#ifndef QT_NO_DATETIMEEDIT -
306 case QVariant::Date: -
307 return "date";
never executed: return "date";
0
308 case QVariant::Time: -
309 return "time";
never executed: return "time";
0
310 case QVariant::DateTime: -
311 return "dateTime";
never executed: return "dateTime";
0
312#endif -
313 case QVariant::String: -
314 default: -
315 // the default editor is a lineedit -
316 return "text";
executed: return "text";
Execution Count:3
3
317 } -
318}
never executed: }
0
319 -
320static QItemEditorFactory *q_default_factory = 0; -
321struct QDefaultFactoryCleaner -
322{ -
323 inline QDefaultFactoryCleaner() {} -
324 ~QDefaultFactoryCleaner() { delete q_default_factory; q_default_factory = 0; }
never executed: }
0
325}; -
326 -
327/*! -
328 Returns the default item editor factory. -
329 -
330 \sa setDefaultFactory() -
331*/ -
332const QItemEditorFactory *QItemEditorFactory::defaultFactory() -
333{ -
334 static const QDefaultItemEditorFactory factory; -
335 if (q_default_factory)
partially evaluated: q_default_factory
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:102
0-102
336 return q_default_factory;
never executed: return q_default_factory;
0
337 return &factory;
executed: return &factory;
Execution Count:102
102
338} -
339 -
340/*! -
341 Sets the default item editor factory to the given \a factory. -
342 Both new and existing delegates will use the new factory. -
343 -
344 \sa defaultFactory() -
345*/ -
346void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory) -
347{ -
348 static const QDefaultFactoryCleaner cleaner; -
349 delete q_default_factory;
never executed (the execution status of this line is deduced): delete q_default_factory;
-
350 q_default_factory = factory;
never executed (the execution status of this line is deduced): q_default_factory = factory;
-
351}
never executed: }
0
352 -
353/*! -
354 \class QItemEditorCreatorBase -
355 \brief The QItemEditorCreatorBase class provides an abstract base class that -
356 must be subclassed when implementing new item editor creators. -
357 \since 4.2 -
358 \ingroup model-view -
359 \inmodule QtWidgets -
360 -
361 QItemEditorCreatorBase objects are specialized widget factories that -
362 provide editor widgets for one particular QVariant data type. They -
363 are used by QItemEditorFactory to create editors for -
364 \l{QItemDelegate}s. Creator bases must be registered with -
365 QItemEditorFactory::registerEditor(). -
366 -
367 An editor should provide a user property for the data it edits. -
368 QItemDelagates can then access the property using Qt's -
369 \l{Meta-Object System}{meta-object system} to set and retrieve the -
370 editing data. A property is set as the user property with the USER -
371 keyword: -
372 -
373 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 0 -
374 -
375 If the editor does not provide a user property, it must return the -
376 name of the property from valuePropertyName(); delegates will then -
377 use the name to access the property. If a user property exists, -
378 item delegates will not call valuePropertyName(). -
379 -
380 QStandardItemEditorCreator is a convenience template class that can be used -
381 to register widgets without the need to subclass QItemEditorCreatorBase. -
382 -
383 \sa QStandardItemEditorCreator, QItemEditorFactory, -
384 {Model/View Programming}, {Color Editor Factory Example} -
385*/ -
386 -
387/*! -
388 \fn QItemEditorCreatorBase::~QItemEditorCreatorBase() -
389 -
390 Destroys the editor creator object. -
391*/ -
392QItemEditorCreatorBase::~QItemEditorCreatorBase() -
393{ -
394 -
395} -
396 -
397/*! -
398 \fn QWidget *QItemEditorCreatorBase::createWidget(QWidget *parent) const -
399 -
400 Returns an editor widget with the given \a parent. -
401 -
402 When implementing this function in subclasses of this class, you must -
403 construct and return new editor widgets with the parent widget specified. -
404*/ -
405 -
406/*! -
407 \fn QByteArray QItemEditorCreatorBase::valuePropertyName() const -
408 -
409 Returns the name of the property used to get and set values in the creator's -
410 editor widgets. -
411 -
412 When implementing this function in subclasses, you must ensure that the -
413 editor widget's property specified by this function can accept the type -
414 the creator is registered for. For example, a creator which constructs -
415 QCheckBox widgets to edit boolean values would return the -
416 \l{QCheckBox::checkable}{checkable} property name from this function, -
417 and must be registered in the item editor factory for the QVariant::Bool -
418 type. -
419 -
420 Note: Since Qt 4.2 the item delegates query the user property of widgets, -
421 and only call this function if the widget has no user property. You can -
422 override this behavior by reimplementing QAbstractItemDelegate::setModelData() -
423 and QAbstractItemDelegate::setEditorData(). -
424 -
425 \sa QMetaObject::userProperty(), QItemEditorFactory::registerEditor() -
426*/ -
427 -
428/*! -
429 \class QItemEditorCreator -
430 \brief The QItemEditorCreator class makes it possible to create -
431 item editor creator bases without subclassing -
432 QItemEditorCreatorBase. -
433 -
434 \since 4.2 -
435 \ingroup model-view -
436 \inmodule QtWidgets -
437 -
438 QItemEditorCreator is a convenience template class. It uses -
439 the template class to create editors for QItemEditorFactory. -
440 This way, it is not necessary to subclass -
441 QItemEditorCreatorBase. -
442 -
443 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 1 -
444 -
445 The constructor takes the name of the property that contains the -
446 editing data. QItemDelegate can then access the property by name -
447 when it sets and retrieves editing data. Only use this class if -
448 your editor does not define a user property (using the USER -
449 keyword in the Q_PROPERTY macro). If the widget has a user -
450 property, you should use QStandardItemEditorCreator instead. -
451 -
452 \sa QItemEditorCreatorBase, QStandardItemEditorCreator, -
453 QItemEditorFactory, {Color Editor Factory Example} -
454*/ -
455 -
456/*! -
457 \fn QItemEditorCreator::QItemEditorCreator(const QByteArray &valuePropertyName) -
458 -
459 Constructs an editor creator object using \a valuePropertyName -
460 as the name of the property to be used for editing. The -
461 property name is used by QItemDelegate when setting and -
462 getting editor data. -
463 -
464 Note that the \a valuePropertyName is only used if the editor -
465 widget does not have a user property defined. -
466*/ -
467 -
468/*! -
469 \fn QWidget *QItemEditorCreator::createWidget(QWidget *parent) const -
470 \reimp -
471*/ -
472 -
473/*! -
474 \fn QByteArray QItemEditorCreator::valuePropertyName() const -
475 \reimp -
476*/ -
477 -
478/*! -
479 \class QStandardItemEditorCreator -
480 -
481 \brief The QStandardItemEditorCreator class provides the -
482 possibility to register widgets without having to subclass -
483 QItemEditorCreatorBase. -
484 -
485 \since 4.2 -
486 \ingroup model-view -
487 \inmodule QtWidgets -
488 -
489 This convenience template class makes it possible to register widgets without -
490 having to subclass QItemEditorCreatorBase. -
491 -
492 Example: -
493 -
494 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 2 -
495 -
496 Setting the \c editorFactory created above in an item delegate via -
497 QItemDelegate::setItemEditorFactory() makes sure that all values of type -
498 QVariant::DateTime will be edited in \c{MyFancyDateTimeEdit}. -
499 -
500 The editor must provide a user property that will contain the -
501 editing data. The property is used by \l{QItemDelegate}s to set -
502 and retrieve the data (using Qt's \l{Meta-Object -
503 System}{meta-object system}). You set the user property with -
504 the USER keyword: -
505 -
506 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3 -
507 -
508 \sa QItemEditorCreatorBase, QItemEditorCreator, -
509 QItemEditorFactory, QItemDelegate, {Color Editor Factory Example} -
510*/ -
511 -
512/*! -
513 \fn QStandardItemEditorCreator::QStandardItemEditorCreator() -
514 -
515 Constructs an editor creator object. -
516*/ -
517 -
518/*! -
519 \fn QWidget *QStandardItemEditorCreator::createWidget(QWidget *parent) const -
520 \reimp -
521*/ -
522 -
523/*! -
524 \fn QByteArray QStandardItemEditorCreator::valuePropertyName() const -
525 \reimp -
526*/ -
527 -
528#ifndef QT_NO_LINEEDIT -
529 -
530QExpandingLineEdit::QExpandingLineEdit(QWidget *parent) -
531 : QLineEdit(parent), originalWidth(-1), widgetOwnsGeometry(false) -
532{ -
533 connect(this, SIGNAL(textChanged(QString)), this, SLOT(resizeToContents()));
executed (the execution status of this line is deduced): connect(this, "2""textChanged(QString)", this, "1""resizeToContents()");
-
534 updateMinimumWidth();
executed (the execution status of this line is deduced): updateMinimumWidth();
-
535}
executed: }
Execution Count:85
85
536 -
537void QExpandingLineEdit::changeEvent(QEvent *e) -
538{ -
539 switch (e->type()) -
540 { -
541 case QEvent::FontChange: -
542 case QEvent::StyleChange: -
543 case QEvent::ContentsRectChange: -
544 updateMinimumWidth();
never executed (the execution status of this line is deduced): updateMinimumWidth();
-
545 break;
never executed: break;
0
546 default: -
547 break;
executed: break;
Execution Count:1
1
548 } -
549 -
550 QLineEdit::changeEvent(e);
executed (the execution status of this line is deduced): QLineEdit::changeEvent(e);
-
551}
executed: }
Execution Count:1
1
552 -
553void QExpandingLineEdit::updateMinimumWidth() -
554{ -
555 int left, right;
executed (the execution status of this line is deduced): int left, right;
-
556 getTextMargins(&left, 0, &right, 0);
executed (the execution status of this line is deduced): getTextMargins(&left, 0, &right, 0);
-
557 int width = left + right + 4 /*horizontalMargin in qlineedit.cpp*/;
executed (the execution status of this line is deduced): int width = left + right + 4 ;
-
558 getContentsMargins(&left, 0, &right, 0);
executed (the execution status of this line is deduced): getContentsMargins(&left, 0, &right, 0);
-
559 width += left + right;
executed (the execution status of this line is deduced): width += left + right;
-
560 -
561 QStyleOptionFrameV2 opt;
executed (the execution status of this line is deduced): QStyleOptionFrameV2 opt;
-
562 initStyleOption(&opt);
executed (the execution status of this line is deduced): initStyleOption(&opt);
-
563 -
564 int minWidth = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(width, 0).
executed (the execution status of this line is deduced): int minWidth = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(width, 0).
-
565 expandedTo(QApplication::globalStrut()), this).width();
executed (the execution status of this line is deduced): expandedTo(QApplication::globalStrut()), this).width();
-
566 setMinimumWidth(minWidth);
executed (the execution status of this line is deduced): setMinimumWidth(minWidth);
-
567}
executed: }
Execution Count:85
85
568 -
569void QExpandingLineEdit::resizeToContents() -
570{ -
571 int oldWidth = width();
executed (the execution status of this line is deduced): int oldWidth = width();
-
572 if (originalWidth == -1)
evaluated: originalWidth == -1
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:13
13-67
573 originalWidth = oldWidth;
executed: originalWidth = oldWidth;
Execution Count:67
67
574 if (QWidget *parent = parentWidget()) {
partially evaluated: QWidget *parent = parentWidget()
TRUEFALSE
yes
Evaluation Count:80
no
Evaluation Count:0
0-80
575 QPoint position = pos();
executed (the execution status of this line is deduced): QPoint position = pos();
-
576 int hintWidth = minimumWidth() + fontMetrics().width(displayText());
executed (the execution status of this line is deduced): int hintWidth = minimumWidth() + fontMetrics().width(displayText());
-
577 int parentWidth = parent->width();
executed (the execution status of this line is deduced): int parentWidth = parent->width();
-
578 int maxWidth = isRightToLeft() ? position.x() + oldWidth : parentWidth - position.x();
partially evaluated: isRightToLeft()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:80
0-80
579 int newWidth = qBound(originalWidth, hintWidth, maxWidth);
executed (the execution status of this line is deduced): int newWidth = qBound(originalWidth, hintWidth, maxWidth);
-
580 if (widgetOwnsGeometry)
partially evaluated: widgetOwnsGeometry
TRUEFALSE
yes
Evaluation Count:80
no
Evaluation Count:0
0-80
581 setMaximumWidth(newWidth);
executed: setMaximumWidth(newWidth);
Execution Count:80
80
582 if (isRightToLeft())
partially evaluated: isRightToLeft()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:80
0-80
583 move(position.x() - newWidth + oldWidth, position.y());
never executed: move(position.x() - newWidth + oldWidth, position.y());
0
584 resize(newWidth, height());
executed (the execution status of this line is deduced): resize(newWidth, height());
-
585 }
executed: }
Execution Count:80
80
586}
executed: }
Execution Count:80
80
587 -
588#endif // QT_NO_LINEEDIT -
589 -
590#ifndef QT_NO_COMBOBOX -
591 -
592QBooleanComboBox::QBooleanComboBox(QWidget *parent) -
593 : QComboBox(parent) -
594{ -
595 addItem(QComboBox::tr("False"));
executed (the execution status of this line is deduced): addItem(QComboBox::tr("False"));
-
596 addItem(QComboBox::tr("True"));
executed (the execution status of this line is deduced): addItem(QComboBox::tr("True"));
-
597}
executed: }
Execution Count:1
1
598 -
599void QBooleanComboBox::setValue(bool value) -
600{ -
601 setCurrentIndex(value ? 1 : 0);
executed (the execution status of this line is deduced): setCurrentIndex(value ? 1 : 0);
-
602}
executed: }
Execution Count:2
2
603 -
604bool QBooleanComboBox::value() const -
605{ -
606 return (currentIndex() == 1);
executed: return (currentIndex() == 1);
Execution Count:1
1
607} -
608 -
609#endif // QT_NO_COMBOBOX -
610 -
611QT_END_NAMESPACE -
612 -
613#if !defined(QT_NO_LINEEDIT) || !defined(QT_NO_COMBOBOX) -
614#include "qitemeditorfactory.moc" -
615#endif -
616 -
617#endif // QT_NO_ITEMVIEWS -
618 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial