File indexing completed on 2024-05-26 05:38:25
0001 /* 0002 SPDX-FileCopyrightText: 2015 Eike Hein <hein@kde.org> 0003 SPDX-FileCopyrightText: 2017 Ivan Cukic <ivan.cukic@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "abstractmodel.h" 0011 0012 #include <QPointer> 0013 #include <QTimer> 0014 0015 class PlaceholderModel : public AbstractModel 0016 { 0017 Q_OBJECT 0018 0019 Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged) 0020 Q_PROPERTY(int dropPlaceholderIndex READ dropPlaceholderIndex WRITE setDropPlaceholderIndex NOTIFY dropPlaceholderIndexChanged) 0021 0022 public: 0023 explicit PlaceholderModel(QObject *parent = nullptr); 0024 ~PlaceholderModel() override; 0025 0026 QString description() const override; 0027 0028 QAbstractItemModel *sourceModel() const; 0029 virtual void setSourceModel(QAbstractItemModel *sourceModel); 0030 0031 bool canFetchMore(const QModelIndex &parent) const override; 0032 void fetchMore(const QModelIndex &parent) override; 0033 0034 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0035 QModelIndex parent(const QModelIndex &index) const override; 0036 0037 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0038 0039 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0040 0041 Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument) override; 0042 0043 Q_INVOKABLE QString labelForRow(int row) override; 0044 0045 Q_INVOKABLE AbstractModel *modelForRow(int row) override; 0046 0047 AbstractModel *favoritesModel() override; 0048 0049 int separatorCount() const override; 0050 0051 int dropPlaceholderIndex() const; 0052 void setDropPlaceholderIndex(int index); 0053 0054 public Q_SLOTS: 0055 void reset(); 0056 0057 Q_SIGNALS: 0058 void sourceModelChanged() const; 0059 void dropPlaceholderIndexChanged(); 0060 0061 protected: 0062 void inhibitTriggering(); 0063 0064 private: 0065 QModelIndex indexToSourceIndex(const QModelIndex &index) const; 0066 QModelIndex sourceIndexToIndex(const QModelIndex &index) const; 0067 int sourceRowToRow(int sourceRow) const; 0068 int rowToSourceRow(int row) const; 0069 0070 void connectSignals(); 0071 void disconnectSignals(); 0072 0073 QPointer<QAbstractItemModel> m_sourceModel; 0074 0075 int m_dropPlaceholderIndex; 0076 bool m_isTriggerInhibited; 0077 QTimer m_triggerInhibitor; 0078 };