Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/placeholdermodel.h
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2015 by Eike Hein <hein@kde.org> * | ||||
3 | * Copyright (C) 2017 by Ivan Cukic <ivan.cukic@kde.org> * | ||||
4 | * * | ||||
5 | * This program is free software; you can redistribute it and/or modify * | ||||
6 | * it under the terms of the GNU General Public License as published by * | ||||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||||
8 | * (at your option) any later version. * | ||||
9 | * * | ||||
10 | * This program is distributed in the hope that it will be useful, * | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
13 | * GNU General Public License for more details. * | ||||
14 | * * | ||||
15 | * You should have received a copy of the GNU General Public License * | ||||
16 | * along with this program; if not, write to the * | ||||
17 | * Free Software Foundation, Inc., * | ||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
19 | ***************************************************************************/ | ||||
20 | | ||||
21 | #ifndef PLACEHOLDERMODEL_H | ||||
22 | #define PLACEHOLDERMODEL_H | ||||
23 | | ||||
24 | #include "abstractmodel.h" | ||||
25 | | ||||
26 | #include <QPointer> | ||||
27 | #include <QTimer> | ||||
28 | | ||||
29 | class PlaceholderModel : public AbstractModel | ||||
30 | { | ||||
31 | Q_OBJECT | ||||
32 | | ||||
33 | Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged); | ||||
34 | Q_PROPERTY(int dropPlaceholderIndex READ dropPlaceholderIndex WRITE setDropPlaceholderIndex NOTIFY dropPlaceholderIndexChanged) | ||||
35 | | ||||
36 | public: | ||||
37 | explicit PlaceholderModel(QObject *parent = 0); | ||||
38 | ~PlaceholderModel(); | ||||
39 | | ||||
40 | QString description() const; | ||||
41 | | ||||
42 | QAbstractItemModel *sourceModel() const; | ||||
43 | virtual void setSourceModel(QAbstractItemModel *sourceModel); | ||||
44 | | ||||
45 | bool canFetchMore(const QModelIndex &parent) const; | ||||
46 | void fetchMore(const QModelIndex &parent); | ||||
47 | | ||||
48 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | ||||
49 | QModelIndex parent(const QModelIndex &index) const; | ||||
50 | | ||||
51 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||||
52 | | ||||
53 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | ||||
54 | | ||||
55 | Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument); | ||||
56 | | ||||
57 | Q_INVOKABLE QString labelForRow(int row); | ||||
58 | | ||||
59 | Q_INVOKABLE AbstractModel *modelForRow(int row); | ||||
60 | | ||||
61 | AbstractModel* favoritesModel(); | ||||
62 | | ||||
63 | int separatorCount() const; | ||||
64 | | ||||
65 | int dropPlaceholderIndex() const; | ||||
66 | void setDropPlaceholderIndex(int index); | ||||
67 | | ||||
68 | public Q_SLOTS: | ||||
69 | void reset(); | ||||
70 | | ||||
71 | Q_SIGNALS: | ||||
72 | void sourceModelChanged() const; | ||||
73 | void dropPlaceholderIndexChanged(); | ||||
74 | | ||||
75 | protected: | ||||
76 | void inhibitTriggering(); | ||||
77 | | ||||
78 | private: | ||||
79 | QModelIndex indexToSourceIndex(const QModelIndex &index) const; | ||||
80 | QModelIndex sourceIndexToIndex(const QModelIndex &index) const; | ||||
81 | int sourceRowToRow(int sourceRow) const; | ||||
82 | int rowToSourceRow(int row) const; | ||||
83 | | ||||
84 | void connectSignals(); | ||||
85 | void disconnectSignals(); | ||||
86 | | ||||
87 | QPointer<QAbstractItemModel> m_sourceModel; | ||||
88 | | ||||
89 | int m_dropPlaceholderIndex; | ||||
90 | bool m_isTriggerInhibited; | ||||
91 | QTimer m_triggerInhibitor; | ||||
92 | }; | ||||
93 | | ||||
94 | #endif |