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 <PhosphorServiceUPower/phosphorserviceupower_export.h>
7
10
11#include <QAbstractListModel>
12
13namespace PhosphorServiceUPower {
14
15class PHOSPHORSERVICEUPOWER_EXPORT UPowerDeviceModel : public QAbstractListModel
16{
17 Q_OBJECT
18 Q_DISABLE_COPY_MOVE(UPowerDeviceModel)
20 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
21
22public:
31 Q_ENUM(Roles)
32
33 explicit UPowerDeviceModel(QObject* parent = nullptr);
34 ~UPowerDeviceModel() override;
35
36 [[nodiscard]] UPowerHost* host() const;
38
39 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
40 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
41 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
42
43Q_SIGNALS:
46
47private Q_SLOTS:
48 void onDeviceAdded(PhosphorServiceUPower::UPowerDevice* device);
49 void onDeviceRemoved(PhosphorServiceUPower::UPowerDevice* device);
50 void onDeviceDataChanged(PhosphorServiceUPower::UPowerDevice* device, const QList<int>& roles);
51
52private:
53 void connectDevice(UPowerDevice* device);
54
55 UPowerHost* m_host = nullptr;
56 // Row mirror owned by the model. rowCount and data index into this
57 // list, never the host's. Keeping a local mirror means the
58 // begin/end-insert/remove transaction boundaries always straddle
59 // the actual mutation regardless of when the host emits
60 // deviceAdded/deviceRemoved relative to its own list.
61 QList<UPowerDevice*> m_rows;
62};
63
64} // namespace PhosphorServiceUPower
Roles
Definition UPowerDeviceModel.h:23
@ PercentageRole
Definition UPowerDeviceModel.h:25
@ DeviceRole
Definition UPowerDeviceModel.h:24
@ IconNameRole
Definition UPowerDeviceModel.h:28
@ TypeRole
Definition UPowerDeviceModel.h:27
@ IsLaptopBatteryRole
Definition UPowerDeviceModel.h:29
@ StateRole
Definition UPowerDeviceModel.h:26
UPowerDeviceModel(QObject *parent=nullptr)
QVariant data(const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames() const override
int rowCount(const QModelIndex &parent={}) const override
Definition UPowerDevice.h:18
Definition UPowerHost.h:19
Definition QmlRegistration.h:8