1 /*  This file is part of the KDE project
2     Copyright (C) 2006 Michael Larouche <michael.larouche@kdemail.net>
3                   2007 Kevin Ottens <ervin@kde.org>
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License version 2 as published by the Free Software Foundation.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 
19 */
20 #ifndef KDEVICELISTMODEL_H
21 #define KDEVICELISTMODEL_H
22 
23 #include <kdelibs4support_export.h>
24 
25 #include <QAbstractItemModel>
26 
27 #include <solid/device.h>
28 #include <solid/predicate.h>
29 
30 /**
31  * @brief Device list model in Qt's Interview framework.
32  *
33  * This class is a tree view model. Each device has a parent
34  * excluding the main device(the computer). Only revelant when
35  * used with QTreeView.
36  *
37  * @author Michaël Larouche <michael.larouche@kdemail.net>
38  */
39 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KDeviceListModel : public QAbstractItemModel
40 {
41     Q_OBJECT
42 public:
43     KDELIBS4SUPPORT_DEPRECATED explicit KDeviceListModel(QObject *parent = nullptr);
44     KDELIBS4SUPPORT_DEPRECATED explicit KDeviceListModel(const QString &predicate, QObject *parent = nullptr);
45     KDELIBS4SUPPORT_DEPRECATED explicit KDeviceListModel(const Solid::Predicate &predicate,
46                               QObject *parent = nullptr);
47     ~KDeviceListModel() override;
48 
49     /**
50      * @brief Get a visible data based on Qt role for the given index.
51      * Return the device information for the give index.
52      *
53      * @param index The QModelIndex which contains the row, column to fetch the data.
54      * @param role The Interview data role(ex: Qt::DisplayRole).
55      *
56      * @return the data for the given index and role.
57      */
58     QVariant data(const QModelIndex &index, int role) const override;
59 
60     /**
61      * @brief Get the header data for a given section, orientation and role.
62      * This method return a value to display in header in a view.
63      * Only support Qt::Horizontal direction and Qt::DisplayRole role.
64      *
65      * @param section Section of Header to get the data of.
66      * @param orientation Orientation of the header.
67      * @param role The Interview data role(ex: Qt::DisplayRole).
68      *
69      * @return the header data for the given section.
70      */
71     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
72 
73     /**
74      * @brief Get the children model index for the given row and column.
75      */
76     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
77 
78     QModelIndex rootIndex() const;
79 
80     /**
81      * @brief Get the parent QModelIndex for the given model child.
82      */
83     QModelIndex parent(const QModelIndex &child) const override;
84 
85     /**
86      * @brief Get the number of rows for a model index.
87      */
88     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
89 
90     /**
91      * @brief Get the number of columns for a model index.
92      */
93     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
94 
95     Solid::Device deviceForIndex(const QModelIndex &index) const;
96 
97 Q_SIGNALS:
98     void modelInitialized();
99 
100 private:
101     Q_PRIVATE_SLOT(d, void _k_initDeviceList())
102     Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString &))
103     Q_PRIVATE_SLOT(d, void _k_deviceRemoved(const QString &))
104 
105     class Private;
106     Private *const d;
107 };
108 
109 #endif
110