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 QABSTRACTPROXYMODEL_H |
5 | #define QABSTRACTPROXYMODEL_H |
6 | |
7 | #include <QtCore/qabstractitemmodel.h> |
8 | |
9 | QT_REQUIRE_CONFIG(proxymodel); |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | class QAbstractProxyModelPrivate; |
14 | class QItemSelection; |
15 | |
16 | class Q_CORE_EXPORT QAbstractProxyModel : public QAbstractItemModel |
17 | { |
18 | Q_OBJECT |
19 | Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel |
20 | NOTIFY sourceModelChanged BINDABLE bindableSourceModel) |
21 | |
22 | public: |
23 | explicit QAbstractProxyModel(QObject *parent = nullptr); |
24 | ~QAbstractProxyModel(); |
25 | |
26 | virtual void setSourceModel(QAbstractItemModel *sourceModel); |
27 | QAbstractItemModel *sourceModel() const; |
28 | QBindable<QAbstractItemModel *> bindableSourceModel(); |
29 | |
30 | Q_INVOKABLE virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const = 0; |
31 | Q_INVOKABLE virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const = 0; |
32 | |
33 | Q_INVOKABLE virtual QItemSelection mapSelectionToSource(const QItemSelection &selection) const; |
34 | Q_INVOKABLE virtual QItemSelection mapSelectionFromSource(const QItemSelection &selection) const; |
35 | |
36 | bool submit() override; |
37 | void revert() override; |
38 | |
39 | QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override; |
40 | QVariant (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
41 | QMap<int, QVariant> itemData(const QModelIndex &index) const override; |
42 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
43 | |
44 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; |
45 | bool setItemData(const QModelIndex& index, const QMap<int, QVariant> &roles) override; |
46 | bool (int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; |
47 | bool clearItemData(const QModelIndex &index) override; |
48 | |
49 | QModelIndex buddy(const QModelIndex &index) const override; |
50 | bool canFetchMore(const QModelIndex &parent) const override; |
51 | void fetchMore(const QModelIndex &parent) override; |
52 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
53 | QSize span(const QModelIndex &index) const override; |
54 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; |
55 | QModelIndex sibling(int row, int column, const QModelIndex &idx) const override; |
56 | |
57 | QMimeData* mimeData(const QModelIndexList &indexes) const override; |
58 | bool canDropMimeData(const QMimeData *data, Qt::DropAction action, |
59 | int row, int column, const QModelIndex &parent) const override; |
60 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, |
61 | int row, int column, const QModelIndex &parent) override; |
62 | QStringList mimeTypes() const override; |
63 | Qt::DropActions supportedDragActions() const override; |
64 | Qt::DropActions supportedDropActions() const override; |
65 | QHash<int, QByteArray> roleNames() const override; |
66 | |
67 | Q_SIGNALS: |
68 | void sourceModelChanged(QPrivateSignal); |
69 | |
70 | protected: |
71 | QModelIndex createSourceIndex(int row, int col, void *internalPtr) const; |
72 | QAbstractProxyModel(QAbstractProxyModelPrivate &, QObject *parent); |
73 | |
74 | private: |
75 | Q_DECLARE_PRIVATE(QAbstractProxyModel) |
76 | Q_DISABLE_COPY(QAbstractProxyModel) |
77 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelDestroyed()) |
78 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelRowsAboutToBeInserted(QModelIndex, int, int)) |
79 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelRowsInserted(QModelIndex, int, int)) |
80 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelRowsRemoved(QModelIndex, int, int)) |
81 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelColumnsAboutToBeInserted(QModelIndex, int, int)) |
82 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelColumnsInserted(QModelIndex, int, int)) |
83 | Q_PRIVATE_SLOT(d_func(), void _q_sourceModelColumnsRemoved(QModelIndex, int, int)) |
84 | }; |
85 | |
86 | QT_END_NAMESPACE |
87 | |
88 | #endif // QABSTRACTPROXYMODEL_H |
89 | |