File indexing completed on 2024-05-12 05:36:52

0001 /*
0002  * SPDX-FileCopyrightText: 2018-2019 Daniel Vrátil <dvratil@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef DEVICEMODEL_H_
0008 #define DEVICEMODEL_H_
0009 
0010 #include <QAbstractListModel>
0011 
0012 #include "kbolt_export.h"
0013 #include "manager.h"
0014 namespace Bolt
0015 {
0016 class Device;
0017 class KBOLT_EXPORT DeviceModel : public QAbstractListModel
0018 {
0019     Q_OBJECT
0020     Q_PROPERTY(Bolt::Manager *manager READ manager WRITE setManager NOTIFY managerChanged)
0021 
0022     /** Whether to show only peripherals or display hosts as well */
0023     Q_PROPERTY(bool showHosts READ showHosts WRITE setShowHosts NOTIFY showHostsChanged)
0024 public:
0025     enum Role {
0026         DeviceRole = Qt::UserRole,
0027     };
0028 
0029     using QAbstractListModel::QAbstractListModel;
0030     ~DeviceModel() override = default;
0031 
0032     Manager *manager() const;
0033     void setManager(Manager *manager);
0034 
0035     bool showHosts() const;
0036     void setShowHosts(bool showHosts);
0037 
0038     QHash<int, QByteArray> roleNames() const override;
0039     int rowCount(const QModelIndex &parent) const override;
0040     QVariant data(const QModelIndex &index, int role) const override;
0041 
0042 Q_SIGNALS:
0043     void managerChanged(Bolt::Manager *manager);
0044     void showHostsChanged(bool showHosts);
0045 
0046 private:
0047     void populateWithoutReset();
0048 
0049     Manager *mManager = nullptr;
0050     QList<QSharedPointer<Device>> mDevices;
0051     bool mShowHosts = true;
0052 };
0053 
0054 } // namespace Bolt
0055 
0056 #endif