| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | // |
| 5 | // W A R N I N G |
| 6 | // ------------- |
| 7 | // |
| 8 | // This file is not part of the QtGraphs API. It exists purely as an |
| 9 | // implementation detail. This header file may change from version to |
| 10 | // version without notice, or even be removed. |
| 11 | // |
| 12 | // We mean it. |
| 13 | |
| 14 | #ifndef ABSTRACTITEMMODELHANDLER_P_H |
| 15 | #define ABSTRACTITEMMODELHANDLER_P_H |
| 16 | |
| 17 | #include <QtGraphs/private/qgraphsglobal_p.h> |
| 18 | #include <QtCore/QAbstractItemModel> |
| 19 | #include <QtCore/QPointer> |
| 20 | #include <QtCore/QTimer> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class AbstractItemModelHandler : public QObject |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | public: |
| 28 | AbstractItemModelHandler(QObject *parent = 0); |
| 29 | ~AbstractItemModelHandler() override; |
| 30 | |
| 31 | virtual void setItemModel(QAbstractItemModel *itemModel); |
| 32 | virtual QAbstractItemModel *itemModel() const; |
| 33 | |
| 34 | public Q_SLOTS: |
| 35 | virtual void handleColumnsInserted(const QModelIndex &parent, int start, int end); |
| 36 | virtual void handleColumnsMoved(const QModelIndex &sourceParent, |
| 37 | int sourceStart, |
| 38 | int sourceEnd, |
| 39 | const QModelIndex &destinationParent, |
| 40 | int destinationColumn); |
| 41 | virtual void handleColumnsRemoved(const QModelIndex &parent, int start, int end); |
| 42 | virtual void handleDataChanged(const QModelIndex &topLeft, |
| 43 | const QModelIndex &bottomRight, |
| 44 | const QList<int> &roles = QList<int>()); |
| 45 | virtual void handleLayoutChanged( |
| 46 | const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), |
| 47 | QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint); |
| 48 | virtual void handleModelReset(); |
| 49 | virtual void handleRowsInserted(const QModelIndex &parent, int start, int end); |
| 50 | virtual void handleRowsMoved(const QModelIndex &sourceParent, |
| 51 | int sourceStart, |
| 52 | int sourceEnd, |
| 53 | const QModelIndex &destinationParent, |
| 54 | int destinationRow); |
| 55 | virtual void handleRowsRemoved(const QModelIndex &parent, int start, int end); |
| 56 | |
| 57 | virtual void handleMappingChanged(); |
| 58 | virtual void handlePendingResolve(); |
| 59 | |
| 60 | Q_SIGNALS: |
| 61 | void itemModelChanged(const QAbstractItemModel *itemModel); |
| 62 | |
| 63 | protected: |
| 64 | virtual void resolveModel() = 0; |
| 65 | |
| 66 | QPointer<QAbstractItemModel> m_itemModel; // Not owned |
| 67 | bool resolvePending; |
| 68 | QTimer m_resolveTimer; |
| 69 | bool m_fullReset; |
| 70 | const int noRoleIndex = -1; |
| 71 | |
| 72 | private: |
| 73 | Q_DISABLE_COPY(AbstractItemModelHandler) |
| 74 | }; |
| 75 | |
| 76 | QT_END_NAMESPACE |
| 77 | |
| 78 | #endif |
| 79 | |