File indexing completed on 2024-05-19 16:34:54
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2009 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include <QModelIndex> 0013 /** 0014 * @file 0015 * This file defines the class DesktopModel, the model for desktops. 0016 * 0017 * @author Martin Gräßlin <mgraesslin@kde.org> 0018 * @since 4.4 0019 */ 0020 0021 namespace KWin 0022 { 0023 namespace TabBox 0024 { 0025 class ClientModel; 0026 0027 /** 0028 * The model for desktops used in TabBox. 0029 * 0030 * @author Martin Gräßlin <mgraesslin@kde.org> 0031 * @since 4.4 0032 */ 0033 class DesktopModel 0034 : public QAbstractItemModel 0035 { 0036 public: 0037 enum { 0038 DesktopRole = Qt::UserRole, ///< Desktop number 0039 DesktopNameRole = Qt::UserRole + 1, ///< Desktop name 0040 ClientModelRole = Qt::UserRole + 2 ///< Clients on this desktop 0041 }; 0042 explicit DesktopModel(QObject *parent = nullptr); 0043 ~DesktopModel() override; 0044 0045 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0046 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0047 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0048 QModelIndex parent(const QModelIndex &child) const override; 0049 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0050 QHash<int, QByteArray> roleNames() const override; 0051 Q_INVOKABLE QString longestCaption() const; 0052 0053 /** 0054 * Generates a new list of desktops based on the current config. 0055 * Calling this method will reset the model. 0056 */ 0057 void createDesktopList(); 0058 /** 0059 * @return The current list of desktops. 0060 */ 0061 QList<int> desktopList() const 0062 { 0063 return m_desktopList; 0064 } 0065 /** 0066 * @param desktop The desktop whose ModelIndex should be retrieved 0067 * @return The ModelIndex of given desktop or an invalid ModelIndex if 0068 * the desktop is not in the model. 0069 */ 0070 QModelIndex desktopIndex(int desktop) const; 0071 0072 private: 0073 QList<int> m_desktopList; 0074 QMap<int, ClientModel *> m_clientModels; 0075 }; 0076 0077 } // namespace Tabbox 0078 } // namespace KWin