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