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 QDATAWIDGETMAPPER_H |
5 | #define QDATAWIDGETMAPPER_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include "QtCore/qobject.h" |
9 | |
10 | QT_REQUIRE_CONFIG(datawidgetmapper); |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | class QAbstractItemDelegate; |
15 | class QAbstractItemModel; |
16 | class QModelIndex; |
17 | class QDataWidgetMapperPrivate; |
18 | |
19 | class Q_WIDGETS_EXPORT QDataWidgetMapper: public QObject |
20 | { |
21 | Q_OBJECT |
22 | |
23 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) |
24 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) |
25 | Q_PROPERTY(SubmitPolicy submitPolicy READ submitPolicy WRITE setSubmitPolicy) |
26 | |
27 | public: |
28 | explicit QDataWidgetMapper(QObject *parent = nullptr); |
29 | ~QDataWidgetMapper(); |
30 | |
31 | void setModel(QAbstractItemModel *model); |
32 | QAbstractItemModel *model() const; |
33 | |
34 | void setItemDelegate(QAbstractItemDelegate *delegate); |
35 | QAbstractItemDelegate *itemDelegate() const; |
36 | |
37 | void setRootIndex(const QModelIndex &index); |
38 | QModelIndex rootIndex() const; |
39 | |
40 | void setOrientation(Qt::Orientation aOrientation); |
41 | Qt::Orientation orientation() const; |
42 | |
43 | enum SubmitPolicy { AutoSubmit, ManualSubmit }; |
44 | Q_ENUM(SubmitPolicy) |
45 | void setSubmitPolicy(SubmitPolicy policy); |
46 | SubmitPolicy submitPolicy() const; |
47 | |
48 | void addMapping(QWidget *widget, int section); |
49 | void addMapping(QWidget *widget, int section, const QByteArray &propertyName); |
50 | void removeMapping(QWidget *widget); |
51 | int mappedSection(QWidget *widget) const; |
52 | QByteArray mappedPropertyName(QWidget *widget) const; |
53 | QWidget *mappedWidgetAt(int section) const; |
54 | void clearMapping(); |
55 | |
56 | int currentIndex() const; |
57 | |
58 | public Q_SLOTS: |
59 | void revert(); |
60 | bool submit(); |
61 | |
62 | void toFirst(); |
63 | void toLast(); |
64 | void toNext(); |
65 | void toPrevious(); |
66 | virtual void setCurrentIndex(int index); |
67 | void setCurrentModelIndex(const QModelIndex &index); |
68 | |
69 | Q_SIGNALS: |
70 | void currentIndexChanged(int index); |
71 | |
72 | private: |
73 | Q_DECLARE_PRIVATE(QDataWidgetMapper) |
74 | Q_DISABLE_COPY(QDataWidgetMapper) |
75 | Q_PRIVATE_SLOT(d_func(), |
76 | void _q_dataChanged(const QModelIndex &, const QModelIndex &, |
77 | const QList<int> &)) |
78 | Q_PRIVATE_SLOT(d_func(), void _q_commitData(QWidget *)) |
79 | Q_PRIVATE_SLOT(d_func(), void _q_closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)) |
80 | Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed()) |
81 | }; |
82 | |
83 | QT_END_NAMESPACE |
84 | |
85 | #endif |
86 | |