Changeset View
Changeset View
Standalone View
Standalone View
tabbox/desktopmodel.h
Show All 22 Lines | |||||
23 | 23 | | |||
24 | #include <QModelIndex> | 24 | #include <QModelIndex> | ||
25 | /** | 25 | /** | ||
26 | * @file | 26 | * @file | ||
27 | * This file defines the class DesktopModel, the model for desktops. | 27 | * This file defines the class DesktopModel, the model for desktops. | ||
28 | * | 28 | * | ||
29 | * @author Martin Gräßlin <mgraesslin@kde.org> | 29 | * @author Martin Gräßlin <mgraesslin@kde.org> | ||
30 | * @since 4.4 | 30 | * @since 4.4 | ||
31 | */ | 31 | **/ | ||
32 | 32 | | |||
33 | namespace KWin | 33 | namespace KWin | ||
34 | { | 34 | { | ||
35 | namespace TabBox | 35 | namespace TabBox | ||
36 | { | 36 | { | ||
37 | class ClientModel; | 37 | class ClientModel; | ||
38 | 38 | | |||
39 | /** | 39 | /** | ||
40 | * The model for desktops used in TabBox. | 40 | * The model for desktops used in TabBox. | ||
41 | * | 41 | * | ||
42 | * @author Martin Gräßlin <mgraesslin@kde.org> | 42 | * @author Martin Gräßlin <mgraesslin@kde.org> | ||
43 | * @since 4.4 | 43 | * @since 4.4 | ||
44 | */ | 44 | **/ | ||
45 | class DesktopModel | 45 | class DesktopModel | ||
46 | : public QAbstractItemModel | 46 | : public QAbstractItemModel | ||
47 | { | 47 | { | ||
48 | public: | 48 | public: | ||
49 | enum { | 49 | enum { | ||
50 | DesktopRole = Qt::UserRole, ///< Desktop number | 50 | DesktopRole = Qt::UserRole, ///< Desktop number | ||
51 | DesktopNameRole = Qt::UserRole + 1, ///< Desktop name | 51 | DesktopNameRole = Qt::UserRole + 1, ///< Desktop name | ||
52 | ClientModelRole = Qt::UserRole + 2 ///< Clients on this desktop | 52 | ClientModelRole = Qt::UserRole + 2 ///< Clients on this desktop | ||
53 | }; | 53 | }; | ||
54 | explicit DesktopModel(QObject* parent = nullptr); | 54 | explicit DesktopModel(QObject* parent = nullptr); | ||
55 | ~DesktopModel(); | 55 | ~DesktopModel(); | ||
56 | 56 | | |||
57 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; | 57 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; | ||
58 | virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; | 58 | virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; | ||
59 | virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; | 59 | virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; | ||
60 | virtual QModelIndex parent(const QModelIndex& child) const; | 60 | virtual QModelIndex parent(const QModelIndex& child) const; | ||
61 | virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; | 61 | virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; | ||
62 | Q_INVOKABLE QString longestCaption() const; | 62 | Q_INVOKABLE QString longestCaption() const; | ||
63 | 63 | | |||
64 | /** | 64 | /** | ||
65 | * Generates a new list of desktops based on the current config. | 65 | * Generates a new list of desktops based on the current config. | ||
66 | * Calling this method will reset the model. | 66 | * Calling this method will reset the model. | ||
67 | */ | 67 | **/ | ||
68 | void createDesktopList(); | 68 | void createDesktopList(); | ||
69 | /** | 69 | /** | ||
70 | * @return The current list of desktops. | 70 | * @return The current list of desktops. | ||
71 | */ | 71 | **/ | ||
72 | QList< int > desktopList() const { | 72 | QList< int > desktopList() const { | ||
73 | return m_desktopList; | 73 | return m_desktopList; | ||
74 | } | 74 | } | ||
75 | /** | 75 | /** | ||
76 | * @param desktop The desktop whose ModelIndex should be retrieved | 76 | * @param desktop The desktop whose ModelIndex should be retrieved | ||
77 | * @return The ModelIndex of given desktop or an invalid ModelIndex if | 77 | * @return The ModelIndex of given desktop or an invalid ModelIndex if | ||
78 | * the desktop is not in the model. | 78 | * the desktop is not in the model. | ||
79 | */ | 79 | **/ | ||
80 | QModelIndex desktopIndex(int desktop) const; | 80 | QModelIndex desktopIndex(int desktop) const; | ||
81 | 81 | | |||
82 | private: | 82 | private: | ||
83 | QList< int > m_desktopList; | 83 | QList< int > m_desktopList; | ||
84 | QMap< int, ClientModel* > m_clientModels; | 84 | QMap< int, ClientModel* > m_clientModels; | ||
85 | }; | 85 | }; | ||
86 | 86 | | |||
87 | } // namespace Tabbox | 87 | } // namespace Tabbox | ||
88 | } // namespace KWin | 88 | } // namespace KWin | ||
89 | #endif // DESKTOPMODEL_H | 89 | #endif // DESKTOPMODEL_H |