qstyleditemdelegate.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7class QStyledItemDelegatePrivate : public QAbstractItemDelegatePrivate-
8{-
9 inline QStyledItemDelegate* q_func() { return static_cast<QStyledItemDelegate *>(q_ptr); } inline const QStyledItemDelegate* q_func() const { return static_cast<const QStyledItemDelegate *>(q_ptr); } friend class QStyledItemDelegate;-
10-
11public:-
12 QStyledItemDelegatePrivate() : factory(0) { }
never executed: end of block
0
13-
14 static const QWidget *widget(const QStyleOptionViewItem &option)-
15 {-
16 return
never executed: return option.widget;
option.widget;
never executed: return option.widget;
0
17 }-
18-
19 const QItemEditorFactory *editorFactory() const-
20 {-
21 return
never executed: return factory ? factory : QItemEditorFactory::defaultFactory();
factory ? factory : QItemEditorFactory::defaultFactory();
never executed: return factory ? factory : QItemEditorFactory::defaultFactory();
0
22 }-
23-
24 QItemEditorFactory *factory;-
25};-
26QStyledItemDelegate::QStyledItemDelegate(QObject *parent)-
27 : QAbstractItemDelegate(*new QStyledItemDelegatePrivate(), parent)-
28{-
29}
never executed: end of block
0
30-
31-
32-
33-
34QStyledItemDelegate::~QStyledItemDelegate()-
35{-
36}-
37QString QStyledItemDelegate::displayText(const QVariant &value, const QLocale& locale) const-
38{-
39 return
never executed: return d_func()->textForRole(Qt::DisplayRole, value, locale);
d_func()->textForRole(Qt::DisplayRole, value, locale);
never executed: return d_func()->textForRole(Qt::DisplayRole, value, locale);
0
40}-
41void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option,-
42 const QModelIndex &index) const-
43{-
44 QVariant value = index.data(Qt::FontRole);-
45 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& !value.isNull()
!value.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
46 option->font = qvariant_cast<QFont>(value).resolve(option->font);-
47 option->fontMetrics = QFontMetrics(option->font);-
48 }
never executed: end of block
0
49-
50 value = index.data(Qt::TextAlignmentRole);-
51 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& !value.isNull()
!value.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
52 option->displayAlignment = Qt::Alignment(value.toInt());
never executed: option->displayAlignment = Qt::Alignment(value.toInt());
0
53-
54 value = index.data(Qt::ForegroundRole);-
55 if (value.canConvert<QBrush>()
value.canConvert<QBrush>()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
56 option->palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
never executed: option->palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
0
57-
58 option->index = index;-
59 value = index.data(Qt::CheckStateRole);-
60 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& !value.isNull()
!value.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
61 option->features |= QStyleOptionViewItem::HasCheckIndicator;-
62 option->checkState = static_cast<Qt::CheckState>(value.toInt());-
63 }
never executed: end of block
0
64-
65 value = index.data(Qt::DecorationRole);-
66 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& !value.isNull()
!value.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
67 option->features |= QStyleOptionViewItem::HasDecoration;-
68 switch (value.type()) {-
69 case
never executed: case QVariant::Icon:
QVariant::Icon:
never executed: case QVariant::Icon:
{
0
70 option->icon = qvariant_cast<QIcon>(value);-
71 QIcon::Mode mode;-
72 if (!(option->state & QStyle::State_Enabled)
!(option->stat...State_Enabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
73 mode = QIcon::Disabled;
never executed: mode = QIcon::Disabled;
0
74 else if (option->state & QStyle::State_Selected
option->state ...State_SelectedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
75 mode = QIcon::Selected;
never executed: mode = QIcon::Selected;
0
76 else-
77 mode = QIcon::Normal;
never executed: mode = QIcon::Normal;
0
78 QIcon::State state = option->state & QStyle::State_Open
option->state ...le::State_OpenDescription
TRUEnever evaluated
FALSEnever evaluated
? QIcon::On : QIcon::Off;
0
79 QSize actualSize = option->icon.actualSize(option->decorationSize, mode, state);-
80-
81 option->decorationSize = QSize(qMin(option->decorationSize.width(), actualSize.width()),-
82 qMin(option->decorationSize.height(), actualSize.height()));-
83 break;
never executed: break;
0
84 }-
85 case
never executed: case QVariant::Color:
QVariant::Color:
never executed: case QVariant::Color:
{
0
86 QPixmap pixmap(option->decorationSize);-
87 pixmap.fill(qvariant_cast<QColor>(value));-
88 option->icon = QIcon(pixmap);-
89 break;
never executed: break;
0
90 }-
91 case
never executed: case QVariant::Image:
QVariant::Image:
never executed: case QVariant::Image:
{
0
92 QImage image = qvariant_cast<QImage>(value);-
93 option->icon = QIcon(QPixmap::fromImage(image));-
94 option->decorationSize = image.size() / image.devicePixelRatio();-
95 break;
never executed: break;
0
96 }-
97 case
never executed: case QVariant::Pixmap:
QVariant::Pixmap:
never executed: case QVariant::Pixmap:
{
0
98 QPixmap pixmap = qvariant_cast<QPixmap>(value);-
99 option->icon = QIcon(pixmap);-
100 option->decorationSize = pixmap.size() / pixmap.devicePixelRatio();-
101 break;
never executed: break;
0
102 }-
103 default
never executed: default:
:
never executed: default:
0
104 break;
never executed: break;
0
105 }-
106 }-
107-
108 value = index.data(Qt::DisplayRole);-
109 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& !value.isNull()
!value.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
110 option->features |= QStyleOptionViewItem::HasDisplay;-
111 option->text = displayText(value, option->locale);-
112 }
never executed: end of block
0
113-
114 option->backgroundBrush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));-
115-
116-
117 option->styleObject = 0;-
118}
never executed: end of block
0
119void QStyledItemDelegate::paint(QPainter *painter,-
120 const QStyleOptionViewItem &option, const QModelIndex &index) const-
121{-
122 ((!(index.isValid())) ? qt_assert("index.isValid()",__FILE__,378) : qt_noop());-
123-
124 QStyleOptionViewItem opt = option;-
125 initStyleOption(&opt, index);-
126-
127 const QWidget *widget = QStyledItemDelegatePrivate::widget(option);-
128 QStyle *style = widget
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
? widget->style() : QApplication::style();
0
129 style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);-
130}
never executed: end of block
0
131QSize QStyledItemDelegate::sizeHint(const QStyleOptionViewItem &option,-
132 const QModelIndex &index) const-
133{-
134 QVariant value = index.data(Qt::SizeHintRole);-
135 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
136 return
never executed: return qvariant_cast<QSize>(value);
qvariant_cast<QSize>(value);
never executed: return qvariant_cast<QSize>(value);
0
137-
138 QStyleOptionViewItem opt = option;-
139 initStyleOption(&opt, index);-
140 const QWidget *widget = QStyledItemDelegatePrivate::widget(option);-
141 QStyle *style = widget
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
? widget->style() : QApplication::style();
0
142 return
never executed: return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget);
style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget);
never executed: return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget);
0
143}-
144QWidget *QStyledItemDelegate::createEditor(QWidget *parent,-
145 const QStyleOptionViewItem &,-
146 const QModelIndex &index) const-
147{-
148 const QStyledItemDelegatePrivate * const d = d_func();-
149 if (!index.isValid()
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
150 return
never executed: return 0;
0;
never executed: return 0;
0
151 return
never executed: return d->editorFactory()->createEditor(index.data(Qt::EditRole).userType(), parent);
d->editorFactory()->createEditor(index.data(Qt::EditRole).userType(), parent);
never executed: return d->editorFactory()->createEditor(index.data(Qt::EditRole).userType(), parent);
0
152}-
153void QStyledItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const-
154{-
155-
156-
157-
158-
159 QVariant v = index.data(Qt::EditRole);-
160 QByteArray n = editor->metaObject()->userProperty().name();-
161-
162 if (!n.isEmpty()
!n.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
163 if (!v.isValid()
!v.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
164 v = QVariant(editor->property(n).userType(), (const void *)0);
never executed: v = QVariant(editor->property(n).userType(), (const void *)0);
0
165 editor->setProperty(n, v);-
166 }
never executed: end of block
0
167-
168}
never executed: end of block
0
169void QStyledItemDelegate::setModelData(QWidget *editor,-
170 QAbstractItemModel *model,-
171 const QModelIndex &index) const-
172{-
173-
174-
175-
176-
177-
178 const QStyledItemDelegatePrivate * const d = d_func();-
179 ((!(model)) ? qt_assert("model",__FILE__,475) : qt_noop());-
180 ((!(editor)) ? qt_assert("editor",__FILE__,476) : qt_noop());-
181 QByteArray n = editor->metaObject()->userProperty().name();-
182 if (n.isEmpty()
n.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
183 n = d->editorFactory()->valuePropertyName(
never executed: n = d->editorFactory()->valuePropertyName( model->data(index, Qt::EditRole).userType());
0
184 model->data(index, Qt::EditRole).userType());
never executed: n = d->editorFactory()->valuePropertyName( model->data(index, Qt::EditRole).userType());
0
185 if (!n.isEmpty()
!n.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
186 model->setData(index, editor->property(n), Qt::EditRole);
never executed: model->setData(index, editor->property(n), Qt::EditRole);
0
187-
188}
never executed: end of block
0
189-
190-
191-
192-
193-
194void QStyledItemDelegate::updateEditorGeometry(QWidget *editor,-
195 const QStyleOptionViewItem &option,-
196 const QModelIndex &index) const-
197{-
198 if (!editor
!editorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
199 return;
never executed: return;
0
200 ((!(index.isValid())) ? qt_assert("index.isValid()",__FILE__,496) : qt_noop());-
201 const QWidget *widget = QStyledItemDelegatePrivate::widget(option);-
202-
203 QStyleOptionViewItem opt = option;-
204 initStyleOption(&opt, index);-
205-
206-
207-
208-
209 if (qobject_cast<QExpandingLineEdit*>(editor)
qobject_cast<Q...Edit*>(editor)Description
TRUEnever evaluated
FALSEnever evaluated
&& !qobject_cast<const QTableView*>(widget)
!qobject_cast<...View*>(widget)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
210 opt.showDecorationSelected = editor->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, editor);
never executed: opt.showDecorationSelected = editor->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, editor);
0
211 else-
212-
213 opt.showDecorationSelected = true;
never executed: opt.showDecorationSelected = true;
0
214-
215 QStyle *style = widget
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
? widget->style() : QApplication::style();
0
216 QRect geom = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, widget);-
217 if ( editor->layoutDirection() == Qt::RightToLeft
editor->layout...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
218 const int delta = qSmartMinSize(editor).width() - geom.width();-
219 if (delta > 0
delta > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
220-
221 geom.adjust(-delta, 0, 0, 0);-
222 }
never executed: end of block
0
223 }
never executed: end of block
0
224-
225 editor->setGeometry(geom);-
226}
never executed: end of block
0
227-
228-
229-
230-
231-
232-
233-
234QItemEditorFactory *QStyledItemDelegate::itemEditorFactory() const-
235{-
236 const QStyledItemDelegatePrivate * const d = d_func();-
237 return
never executed: return d->factory;
d->factory;
never executed: return d->factory;
0
238}-
239void QStyledItemDelegate::setItemEditorFactory(QItemEditorFactory *factory)-
240{-
241 QStyledItemDelegatePrivate * const d = d_func();-
242 d->factory = factory;-
243}
never executed: end of block
0
244bool QStyledItemDelegate::eventFilter(QObject *object, QEvent *event)-
245{-
246 QStyledItemDelegatePrivate * const d = d_func();-
247 return
never executed: return d->editorEventFilter(object, event);
d->editorEventFilter(object, event);
never executed: return d->editorEventFilter(object, event);
0
248}-
249-
250-
251-
252-
253bool QStyledItemDelegate::editorEvent(QEvent *event,-
254 QAbstractItemModel *model,-
255 const QStyleOptionViewItem &option,-
256 const QModelIndex &index)-
257{-
258 ((!(event)) ? qt_assert("event",__FILE__,594) : qt_noop());-
259 ((!(model)) ? qt_assert("model",__FILE__,595) : qt_noop());-
260-
261-
262 Qt::ItemFlags flags = model->flags(index);-
263 if (!(flags & Qt::ItemIsUserCheckable)
!(flags & Qt::...UserCheckable)Description
TRUEnever evaluated
FALSEnever evaluated
|| !(option.state & QStyle::State_Enabled)
!(option.state...State_Enabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
264 || !(flags & Qt::ItemIsEnabled)
!(flags & Qt::ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
265 return
never executed: return false;
false;
never executed: return false;
0
266-
267-
268 QVariant value = index.data(Qt::CheckStateRole);-
269 if (!value.isValid()
!value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
270 return
never executed: return false;
false;
never executed: return false;
0
271-
272 const QWidget *widget = QStyledItemDelegatePrivate::widget(option);-
273 QStyle *style = widget
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
? widget->style() : QApplication::style();
0
274-
275-
276 if ((
(event->type()...ButtonRelease)Description
TRUEnever evaluated
FALSEnever evaluated
event->type() == QEvent::MouseButtonRelease)
(event->type()...ButtonRelease)Description
TRUEnever evaluated
FALSEnever evaluated
0
277 || (
(event->type()...uttonDblClick)Description
TRUEnever evaluated
FALSEnever evaluated
event->type() == QEvent::MouseButtonDblClick)
(event->type()...uttonDblClick)Description
TRUEnever evaluated
FALSEnever evaluated
0
278 || (
(event->type()...seButtonPress)Description
TRUEnever evaluated
FALSEnever evaluated
event->type() == QEvent::MouseButtonPress)
(event->type()...seButtonPress)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
279 QStyleOptionViewItem viewOpt(option);-
280 initStyleOption(&viewOpt, index);-
281 QRect checkRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, widget);-
282 QMouseEvent *me = static_cast<QMouseEvent*>(event);-
283 if (me->button() != Qt::LeftButton
me->button() != Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
|| !checkRect.contains(me->pos())
!checkRect.contains(me->pos())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
284 return
never executed: return false;
false;
never executed: return false;
0
285-
286 if ((
(event->type()...seButtonPress)Description
TRUEnever evaluated
FALSEnever evaluated
event->type() == QEvent::MouseButtonPress)
(event->type()...seButtonPress)Description
TRUEnever evaluated
FALSEnever evaluated
0
287 || (
(event->type()...uttonDblClick)Description
TRUEnever evaluated
FALSEnever evaluated
event->type() == QEvent::MouseButtonDblClick)
(event->type()...uttonDblClick)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
288 return
never executed: return true;
true;
never executed: return true;
0
289-
290 }
never executed: end of block
else if (event->type() == QEvent::KeyPress
event->type() ...vent::KeyPressDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
291 if (static_cast<
static_cast<QK... Qt::Key_SpaceDescription
TRUEnever evaluated
FALSEnever evaluated
QKeyEvent*>(event)->key() != Qt::Key_Space
static_cast<QK... Qt::Key_SpaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
292 && static_cast<
static_cast<QK...Qt::Key_SelectDescription
TRUEnever evaluated
FALSEnever evaluated
QKeyEvent*>(event)->key() != Qt::Key_Select
static_cast<QK...Qt::Key_SelectDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
293 return
never executed: return false;
false;
never executed: return false;
0
294 }
never executed: end of block
else {
0
295 return
never executed: return false;
false;
never executed: return false;
0
296 }-
297-
298 Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());-
299 if (flags & Qt::ItemIsUserTristate
flags & Qt::ItemIsUserTristateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
300 state = ((Qt::CheckState)((state + 1) % 3));
never executed: state = ((Qt::CheckState)((state + 1) % 3));
0
301 else-
302 state = (
(state == Qt::Checked)Description
TRUEnever evaluated
FALSEnever evaluated
state == Qt::Checked)
(state == Qt::Checked)Description
TRUEnever evaluated
FALSEnever evaluated
? Qt::Unchecked : Qt::Checked;
never executed: state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
0
303 return
never executed: return model->setData(index, state, Qt::CheckStateRole);
model->setData(index, state, Qt::CheckStateRole);
never executed: return model->setData(index, state, Qt::CheckStateRole);
0
304}-
305-
306-
307-
Switch to Source codePreprocessed file

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