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
10QT_REQUIRE_CONFIG(datawidgetmapper);
11
12QT_BEGIN_NAMESPACE
13
14class QAbstractItemDelegate;
15class QAbstractItemModel;
16class QModelIndex;
17class QDataWidgetMapperPrivate;
18
19class 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
27public:
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
58public 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
69Q_SIGNALS:
70 void currentIndexChanged(int index);
71
72private:
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
83QT_END_NAMESPACE
84
85#endif
86

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