1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QABSTRACTITEMDELEGATE_H
5#define QABSTRACTITEMDELEGATE_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtCore/qobject.h>
9#include <QtWidgets/qstyleoption.h>
10
11QT_REQUIRE_CONFIG(itemviews);
12
13QT_BEGIN_NAMESPACE
14
15class QPainter;
16class QModelIndex;
17class QAbstractItemModel;
18class QAbstractItemView;
19class QHelpEvent;
20class QAbstractItemDelegatePrivate;
21
22class Q_WIDGETS_EXPORT QAbstractItemDelegate : public QObject
23{
24 Q_OBJECT
25
26public:
27
28 enum EndEditHint {
29 NoHint,
30 EditNextItem,
31 EditPreviousItem,
32 SubmitModelCache,
33 RevertModelCache
34 };
35
36 explicit QAbstractItemDelegate(QObject *parent = nullptr);
37 virtual ~QAbstractItemDelegate();
38
39 // painting
40 virtual void paint(QPainter *painter,
41 const QStyleOptionViewItem &option,
42 const QModelIndex &index) const = 0;
43
44 virtual QSize sizeHint(const QStyleOptionViewItem &option,
45 const QModelIndex &index) const = 0;
46
47 // editing
48 virtual QWidget *createEditor(QWidget *parent,
49 const QStyleOptionViewItem &option,
50 const QModelIndex &index) const;
51
52 virtual void destroyEditor(QWidget *editor, const QModelIndex &index) const;
53
54 virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
55
56 virtual void setModelData(QWidget *editor,
57 QAbstractItemModel *model,
58 const QModelIndex &index) const;
59
60 virtual void updateEditorGeometry(QWidget *editor,
61 const QStyleOptionViewItem &option,
62 const QModelIndex &index) const;
63
64 // for non-widget editors
65 virtual bool editorEvent(QEvent *event,
66 QAbstractItemModel *model,
67 const QStyleOptionViewItem &option,
68 const QModelIndex &index);
69
70 virtual bool helpEvent(QHelpEvent *event,
71 QAbstractItemView *view,
72 const QStyleOptionViewItem &option,
73 const QModelIndex &index);
74
75 virtual QList<int> paintingRoles() const;
76
77Q_SIGNALS:
78 void commitData(QWidget *editor);
79 void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint = NoHint);
80 void sizeHintChanged(const QModelIndex &);
81
82protected:
83 QAbstractItemDelegate(QObjectPrivate &, QObject *parent = nullptr);
84private:
85 Q_DECLARE_PRIVATE(QAbstractItemDelegate)
86 Q_DISABLE_COPY(QAbstractItemDelegate)
87 Q_PRIVATE_SLOT(d_func(), void _q_commitDataAndCloseEditor(QWidget*))
88};
89
90QT_END_NAMESPACE
91
92#endif // QABSTRACTITEMDELEGATE_H
93

source code of qtbase/src/widgets/itemviews/qabstractitemdelegate.h