File indexing completed on 2025-01-19 12:45:15
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Michael Larouche <michael.larouche@kdemail.net> 0003 2007 Kevin Ottens <ervin@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License version 2 as published by the Free Software Foundation. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 0019 */ 0020 #ifndef KDEVICELISTMODEL_H 0021 #define KDEVICELISTMODEL_H 0022 0023 #include <kdelibs4support_export.h> 0024 0025 #include <QAbstractItemModel> 0026 0027 #include <solid/device.h> 0028 #include <solid/predicate.h> 0029 0030 /** 0031 * @brief Device list model in Qt's Interview framework. 0032 * 0033 * This class is a tree view model. Each device has a parent 0034 * excluding the main device(the computer). Only revelant when 0035 * used with QTreeView. 0036 * 0037 * @author Michaƫl Larouche <michael.larouche@kdemail.net> 0038 */ 0039 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KDeviceListModel : public QAbstractItemModel 0040 { 0041 Q_OBJECT 0042 public: 0043 KDELIBS4SUPPORT_DEPRECATED explicit KDeviceListModel(QObject *parent = nullptr); 0044 KDELIBS4SUPPORT_DEPRECATED explicit KDeviceListModel(const QString &predicate, QObject *parent = nullptr); 0045 KDELIBS4SUPPORT_DEPRECATED explicit KDeviceListModel(const Solid::Predicate &predicate, 0046 QObject *parent = nullptr); 0047 ~KDeviceListModel() override; 0048 0049 /** 0050 * @brief Get a visible data based on Qt role for the given index. 0051 * Return the device information for the give index. 0052 * 0053 * @param index The QModelIndex which contains the row, column to fetch the data. 0054 * @param role The Interview data role(ex: Qt::DisplayRole). 0055 * 0056 * @return the data for the given index and role. 0057 */ 0058 QVariant data(const QModelIndex &index, int role) const override; 0059 0060 /** 0061 * @brief Get the header data for a given section, orientation and role. 0062 * This method return a value to display in header in a view. 0063 * Only support Qt::Horizontal direction and Qt::DisplayRole role. 0064 * 0065 * @param section Section of Header to get the data of. 0066 * @param orientation Orientation of the header. 0067 * @param role The Interview data role(ex: Qt::DisplayRole). 0068 * 0069 * @return the header data for the given section. 0070 */ 0071 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0072 0073 /** 0074 * @brief Get the children model index for the given row and column. 0075 */ 0076 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0077 0078 QModelIndex rootIndex() const; 0079 0080 /** 0081 * @brief Get the parent QModelIndex for the given model child. 0082 */ 0083 QModelIndex parent(const QModelIndex &child) const override; 0084 0085 /** 0086 * @brief Get the number of rows for a model index. 0087 */ 0088 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0089 0090 /** 0091 * @brief Get the number of columns for a model index. 0092 */ 0093 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0094 0095 Solid::Device deviceForIndex(const QModelIndex &index) const; 0096 0097 Q_SIGNALS: 0098 void modelInitialized(); 0099 0100 private: 0101 Q_PRIVATE_SLOT(d, void _k_initDeviceList()) 0102 Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString &)) 0103 Q_PRIVATE_SLOT(d, void _k_deviceRemoved(const QString &)) 0104 0105 class Private; 0106 Private *const d; 0107 }; 0108 0109 #endif