Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
UPowerDeviceModel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServices/phosphorservices_export.h>
7
10
11#include <QAbstractListModel>
12
13namespace PhosphorServices {
14
15class PHOSPHORSERVICES_EXPORT UPowerDeviceModel : public QAbstractListModel
16{
17 Q_OBJECT
18 Q_PROPERTY(PhosphorServices::UPowerHost* host READ host WRITE setHost NOTIFY hostChanged)
19 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
20
21public:
30 Q_ENUM(Roles)
31
32 explicit UPowerDeviceModel(QObject* parent = nullptr);
33 ~UPowerDeviceModel() override;
34
35 [[nodiscard]] UPowerHost* host() const;
36 void setHost(UPowerHost* host);
37
38 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
39 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
40 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
41
42Q_SIGNALS:
45
46private Q_SLOTS:
47 void onDeviceAdded(PhosphorServices::UPowerDevice* device);
48 void onDeviceRemoved(PhosphorServices::UPowerDevice* device);
49 void onDeviceDataChanged(PhosphorServices::UPowerDevice* device);
50
51private:
52 void connectDevice(UPowerDevice* device);
53
54 UPowerHost* m_host = nullptr;
55 // Row mirror owned by the model — see MprisPlayerModel for rationale:
56 // keeps the begin/end transaction boundaries correct independent of
57 // the host's list-mutation timing.
58 QList<UPowerDevice*> m_rows;
59};
60
61} // namespace PhosphorServices
Definition UPowerDeviceModel.h:16
QHash< int, QByteArray > roleNames() const override
Roles
Definition UPowerDeviceModel.h:22
@ PercentageRole
Definition UPowerDeviceModel.h:24
@ StateRole
Definition UPowerDeviceModel.h:25
@ IsLaptopBatteryRole
Definition UPowerDeviceModel.h:28
@ IconNameRole
Definition UPowerDeviceModel.h:27
@ TypeRole
Definition UPowerDeviceModel.h:26
QVariant data(const QModelIndex &index, int role) const override
Definition UPowerDevice.h:16
Definition UPowerHost.h:17
Definition DBusMenuModel.h:15