qabstractitemdelegate.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qabstractitemdelegate.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6QAbstractItemDelegate::QAbstractItemDelegate(QObject *parent)-
7 : QObject(*new QAbstractItemDelegatePrivate, parent)-
8{-
9-
10}
never executed: end of block
0
11-
12-
13-
14-
15-
16-
17QAbstractItemDelegate::QAbstractItemDelegate(QObjectPrivate &dd, QObject *parent)-
18 : QObject(dd, parent)-
19{-
20-
21}
never executed: end of block
0
22-
23-
24-
25-
26QAbstractItemDelegate::~QAbstractItemDelegate()-
27{-
28-
29}-
30QWidget *QAbstractItemDelegate::createEditor(QWidget *,-
31 const QStyleOptionViewItem &,-
32 const QModelIndex &) const-
33{-
34 return
never executed: return 0;
0;
never executed: return 0;
0
35}-
36void QAbstractItemDelegate::destroyEditor(QWidget *editor, const QModelIndex &index) const-
37{-
38 (void)index;;-
39 editor->deleteLater();-
40}
never executed: end of block
0
41void QAbstractItemDelegate::setEditorData(QWidget *,-
42 const QModelIndex &) const-
43{-
44-
45}-
46void QAbstractItemDelegate::setModelData(QWidget *,-
47 QAbstractItemModel *,-
48 const QModelIndex &) const-
49{-
50-
51}-
52void QAbstractItemDelegate::updateEditorGeometry(QWidget *,-
53 const QStyleOptionViewItem &,-
54 const QModelIndex &) const-
55{-
56-
57}-
58bool QAbstractItemDelegate::editorEvent(QEvent *,-
59 QAbstractItemModel *,-
60 const QStyleOptionViewItem &,-
61 const QModelIndex &)-
62{-
63-
64 return
never executed: return false;
false;
never executed: return false;
0
65}-
66QString QAbstractItemDelegate::elidedText(const QFontMetrics &fontMetrics, int width,-
67 Qt::TextElideMode mode, const QString &text)-
68{-
69 return
never executed: return fontMetrics.elidedText(text, mode, width);
fontMetrics.elidedText(text, mode, width);
never executed: return fontMetrics.elidedText(text, mode, width);
0
70}-
71bool QAbstractItemDelegate::helpEvent(QHelpEvent *event,-
72 QAbstractItemView *view,-
73 const QStyleOptionViewItem &option,-
74 const QModelIndex &index)-
75{-
76 QAbstractItemDelegatePrivate * const d = d_func();-
77 (void)option;;-
78-
79 if (!event
!eventDescription
TRUEnever evaluated
FALSEnever evaluated
|| !view
!viewDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
80 return
never executed: return false;
false;
never executed: return false;
0
81 switch (event->type()) {-
82-
83 case
never executed: case QEvent::ToolTip:
QEvent::ToolTip:
never executed: case QEvent::ToolTip:
{
0
84 QHelpEvent *he = static_cast<QHelpEvent*>(event);-
85 const int precision = inherits("QItemDelegate")
inherits("QItemDelegate")Description
TRUEnever evaluated
FALSEnever evaluated
? 10 : 6;
0
86 const QString tooltip = d->textForRole(Qt::ToolTipRole, index.data(Qt::ToolTipRole), option.locale, precision);-
87 if (!tooltip.isEmpty()
!tooltip.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
88 QToolTip::showText(he->globalPos(), tooltip, view);-
89 return
never executed: return true;
true;
never executed: return true;
0
90 }-
91 break;
never executed: break;
}
0
92-
93-
94 case
never executed: case QEvent::QueryWhatsThis:
QEvent::QueryWhatsThis:
never executed: case QEvent::QueryWhatsThis:
{
0
95 if (index.data(Qt::WhatsThisRole).isValid()
index.data(Qt:...ole).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
96 return
never executed: return true;
true;
never executed: return true;
0
97 break;
never executed: break;
}
0
98 case
never executed: case QEvent::WhatsThis:
QEvent::WhatsThis:
never executed: case QEvent::WhatsThis:
{
0
99 QHelpEvent *he = static_cast<QHelpEvent*>(event);-
100 const int precision = inherits("QItemDelegate")
inherits("QItemDelegate")Description
TRUEnever evaluated
FALSEnever evaluated
? 10 : 6;
0
101 const QString whatsthis = d->textForRole(Qt::WhatsThisRole, index.data(Qt::WhatsThisRole), option.locale, precision);-
102 if (!whatsthis.isEmpty()
!whatsthis.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
103 QWhatsThis::showText(he->globalPos(), whatsthis, view);-
104 return
never executed: return true;
true;
never executed: return true;
0
105 }-
106 break
never executed: break ;
;
never executed: break ;
}
0
107-
108 default
never executed: default:
:
never executed: default:
0
109 break;
never executed: break;
0
110 }-
111 return
never executed: return false;
false;
never executed: return false;
0
112}-
113-
114-
115-
116-
117-
118-
119QVector<int> QAbstractItemDelegate::paintingRoles() const-
120{-
121 return
never executed: return QVector<int>();
QVector<int>();
never executed: return QVector<int>();
0
122}-
123-
124QAbstractItemDelegatePrivate::QAbstractItemDelegatePrivate()-
125 : QObjectPrivate()-
126{-
127}
never executed: end of block
0
128-
129static bool editorHandlesKeyEvent(QWidget *editor, const QKeyEvent *event)-
130{-
131-
132-
133 if (qobject_cast<QTextEdit *>(editor)
qobject_cast<Q...dit *>(editor)Description
TRUEnever evaluated
FALSEnever evaluated
|| qobject_cast<QPlainTextEdit *>(editor)
qobject_cast<Q...dit *>(editor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
134 switch (event->key()) {-
135 case
never executed: case Qt::Key_Tab:
Qt::Key_Tab:
never executed: case Qt::Key_Tab:
0
136 case
never executed: case Qt::Key_Backtab:
Qt::Key_Backtab:
never executed: case Qt::Key_Backtab:
0
137 case
never executed: case Qt::Key_Enter:
Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
138 case
never executed: case Qt::Key_Return:
Qt::Key_Return:
never executed: case Qt::Key_Return:
0
139 return
never executed: return true;
true;
never executed: return true;
0
140-
141 default
never executed: default:
:
never executed: default:
0
142 break;
never executed: break;
0
143 }-
144 }-
145-
146-
147 (void)editor;;-
148 (void)event;;-
149 return
never executed: return false;
false;
never executed: return false;
0
150}-
151-
152bool QAbstractItemDelegatePrivate::editorEventFilter(QObject *object, QEvent *event)-
153{-
154 QAbstractItemDelegate * const q = q_func();-
155-
156 QWidget *editor = qobject_cast<QWidget*>(object);-
157 if (!editor
!editorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
158 return
never executed: return false;
false;
never executed: return false;
0
159 if (event->type() == QEvent::KeyPress
event->type() ...vent::KeyPressDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
160 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);-
161 if (editorHandlesKeyEvent(editor, keyEvent)
editorHandlesK...tor, keyEvent)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
162 return
never executed: return false;
false;
never executed: return false;
0
163-
164 if (keyEvent->matches(QKeySequence::Cancel)
keyEvent->matc...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
165-
166 q->closeEditor(editor, QAbstractItemDelegate::RevertModelCache);-
167 return
never executed: return true;
true;
never executed: return true;
0
168 }-
169-
170 switch (keyEvent->key()) {-
171 case
never executed: case Qt::Key_Tab:
Qt::Key_Tab:
never executed: case Qt::Key_Tab:
0
172 if (tryFixup(editor)
tryFixup(editor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
173 q->commitData(editor);-
174 q->closeEditor(editor, QAbstractItemDelegate::EditNextItem);-
175 }
never executed: end of block
0
176 return
never executed: return true;
true;
never executed: return true;
0
177 case
never executed: case Qt::Key_Backtab:
Qt::Key_Backtab:
never executed: case Qt::Key_Backtab:
0
178 if (tryFixup(editor)
tryFixup(editor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
179 q->commitData(editor);-
180 q->closeEditor(editor, QAbstractItemDelegate::EditPreviousItem);-
181 }
never executed: end of block
0
182 return
never executed: return true;
true;
never executed: return true;
0
183 case
never executed: case Qt::Key_Enter:
Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
184 case
never executed: case Qt::Key_Return:
Qt::Key_Return:
never executed: case Qt::Key_Return:
0
185-
186-
187-
188 if (!tryFixup(editor)
!tryFixup(editor)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
189 return
never executed: return true;
true;
never executed: return true;
0
190-
191 QMetaObject::invokeMethod(q, "_q_commitDataAndCloseEditor",-
192 Qt::QueuedConnection, QArgument<QWidget* >("QWidget*", editor));-
193 return
never executed: return false;
false;
never executed: return false;
0
194 default
never executed: default:
:
never executed: default:
0
195 return
never executed: return false;
false;
never executed: return false;
0
196 }-
197 } else if (event->type() == QEvent::FocusOut
event->type() ...vent::FocusOutDescription
TRUEnever evaluated
FALSEnever evaluated
|| (event->type() == QEvent::Hide
event->type() == QEvent::HideDescription
TRUEnever evaluated
FALSEnever evaluated
&& editor->isWindow()
editor->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
198-
199 if (!editor->isActiveWindow()
!editor->isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(QApplication:...t() != editor)Description
TRUEnever evaluated
FALSEnever evaluated
QApplication::focusWidget() != editor)
(QApplication:...t() != editor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
200 QWidget *w = QApplication::focusWidget();-
201 while (w
wDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
202 if (w == editor
w == editorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
203 return
never executed: return false;
false;
never executed: return false;
0
204 w = w->parentWidget();-
205 }
never executed: end of block
0
206-
207-
208-
209 QPlatformDrag *platformDrag = QGuiApplicationPrivate::instance()->platformIntegration()->drag();-
210 if (platformDrag
platformDragDescription
TRUEnever evaluated
FALSEnever evaluated
&& platformDrag->currentDrag()
platformDrag->currentDrag()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
211 return
never executed: return false;
false;
never executed: return false;
0
212 }-
213-
214 if (tryFixup(editor)
tryFixup(editor)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
215 q->commitData(editor);
never executed: q->commitData(editor);
0
216-
217 q->closeEditor(editor, QAbstractItemDelegate::NoHint);-
218 }
never executed: end of block
0
219 }
never executed: end of block
else if (event->type() == QEvent::ShortcutOverride
event->type() ...ortcutOverrideDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
220 if (static_cast<
static_cast<QK...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
QKeyEvent*>(event)->matches(QKeySequence::Cancel)
static_cast<QK...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
221 event->accept();-
222 return
never executed: return true;
true;
never executed: return true;
0
223 }-
224 }
never executed: end of block
0
225 return
never executed: return false;
false;
never executed: return false;
0
226}-
227-
228bool QAbstractItemDelegatePrivate::tryFixup(QWidget *editor)-
229{-
230-
231 if (QLineEdit *e = qobject_cast<QLineEdit*>(editor)
QLineEdit *e =...Edit*>(editor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
232 if (!e->hasAcceptableInput()
!e->hasAcceptableInput()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
233 if (const
const QValidat...e->validator()Description
TRUEnever evaluated
FALSEnever evaluated
QValidator *validator = e->validator()
const QValidat...e->validator()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
234 QString text = e->text();-
235 validator->fixup(text);-
236 e->setText(text);-
237 }
never executed: end of block
0
238 return
never executed: return e->hasAcceptableInput();
e->hasAcceptableInput();
never executed: return e->hasAcceptableInput();
0
239 }-
240 }
never executed: end of block
0
241-
242-
243 return
never executed: return true;
true;
never executed: return true;
0
244}-
245-
246QString QAbstractItemDelegatePrivate::textForRole(Qt::ItemDataRole role, const QVariant &value, const QLocale &locale, int precision) const-
247{-
248 const QLocale::FormatType formatType = (
(role == Qt::DisplayRole)Description
TRUEnever evaluated
FALSEnever evaluated
role == Qt::DisplayRole)
(role == Qt::DisplayRole)Description
TRUEnever evaluated
FALSEnever evaluated
? QLocale::ShortFormat : QLocale::LongFormat;
0
249 QString text;-
250 switch (value.userType()) {-
251 case
never executed: case QMetaType::Float:
QMetaType::Float:
never executed: case QMetaType::Float:
0
252 text = locale.toString(value.toFloat());-
253 break;
never executed: break;
0
254 case
never executed: case QVariant::Double:
QVariant::Double:
never executed: case QVariant::Double:
0
255 text = locale.toString(value.toDouble(), 'g', precision);-
256 break;
never executed: break;
0
257 case
never executed: case QVariant::Int:
QVariant::Int:
never executed: case QVariant::Int:
0
258 case
never executed: case QVariant::LongLong:
QVariant::LongLong:
never executed: case QVariant::LongLong:
0
259 text = locale.toString(value.toLongLong());-
260 break;
never executed: break;
0
261 case
never executed: case QVariant::UInt:
QVariant::UInt:
never executed: case QVariant::UInt:
0
262 case
never executed: case QVariant::ULongLong:
QVariant::ULongLong:
never executed: case QVariant::ULongLong:
0
263 text = locale.toString(value.toULongLong());-
264 break;
never executed: break;
0
265 case
never executed: case QVariant::Date:
QVariant::Date:
never executed: case QVariant::Date:
0
266 text = locale.toString(value.toDate(), formatType);-
267 break;
never executed: break;
0
268 case
never executed: case QVariant::Time:
QVariant::Time:
never executed: case QVariant::Time:
0
269 text = locale.toString(value.toTime(), formatType);-
270 break;
never executed: break;
0
271 case
never executed: case QVariant::DateTime:
QVariant::DateTime:
never executed: case QVariant::DateTime:
{
0
272 const QDateTime dateTime = value.toDateTime();-
273 text = locale.toString(dateTime.date(), formatType)-
274 + QLatin1Char(' ')-
275 + locale.toString(dateTime.time(), formatType);-
276 break;
never executed: break;
}
0
277 default
never executed: default:
:
never executed: default:
0
278 text = value.toString();-
279 if (role == Qt::DisplayRole
role == Qt::DisplayRoleDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
280 text.replace(QLatin1Char('\n'), QChar::LineSeparator);
never executed: text.replace(QLatin1Char('\n'), QChar::LineSeparator);
0
281 break;
never executed: break;
0
282 }-
283 return
never executed: return text;
text;
never executed: return text;
0
284}-
285-
286void QAbstractItemDelegatePrivate::_q_commitDataAndCloseEditor(QWidget *editor)-
287{-
288 QAbstractItemDelegate * const q = q_func();-
289 q->commitData(editor);-
290 q->closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);-
291}
never executed: end of block
0
292-
293-
294-
Switch to Source codePreprocessed file

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