Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/batterymodel.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 51 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceRemoved, this, [this](const QString &udi) { | |||
---|---|---|---|---|---|
60 | beginRemoveRows(QModelIndex(), index, index); | 60 | beginRemoveRows(QModelIndex(), index, index); | ||
61 | m_batteries.removeAt(index); | 61 | m_batteries.removeAt(index); | ||
62 | endRemoveRows(); | 62 | endRemoveRows(); | ||
63 | 63 | | |||
64 | emit countChanged(); | 64 | emit countChanged(); | ||
65 | }); | 65 | }); | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | Solid::Battery *BatteryModel::get(int index) const | | |||
69 | { | | |||
70 | if (index < 0 || index >= m_batteries.count()) { | | |||
71 | return nullptr; | | |||
72 | } | | |||
73 | | ||||
74 | Solid::Battery* battery = m_batteries.value(index).as<Solid::Battery>(); | | |||
75 | | ||||
76 | QQmlEngine::setObjectOwnership(battery, QQmlEngine::CppOwnership); | | |||
77 | return battery; | | |||
78 | } | | |||
79 | | ||||
80 | QString BatteryModel::udi(int index) const | | |||
81 | { | | |||
82 | if (index < 0 || index >= m_batteries.count()) { | | |||
83 | return QString(); | | |||
84 | } | | |||
85 | | ||||
86 | return m_batteries.at(index).udi(); | | |||
87 | } | | |||
88 | | ||||
89 | QString BatteryModel::vendor(int index) const { | | |||
90 | | ||||
91 | if (index < 0 || index >= m_batteries.count()) { | | |||
92 | return QString(); | | |||
93 | } | | |||
94 | const Solid::Device device = m_batteries.value(index); | | |||
95 | return device.vendor(); | | |||
96 | } | | |||
97 | | ||||
98 | QString BatteryModel::product(int index) const { | | |||
99 | | ||||
100 | if (index < 0 || index >= m_batteries.count()) { | | |||
101 | return QString(); | | |||
102 | } | | |||
103 | const Solid::Device device = m_batteries.value(index); | | |||
104 | return device.product(); | | |||
105 | } | | |||
106 | | ||||
107 | QVariant BatteryModel::data(const QModelIndex &index, int role) const | 68 | QVariant BatteryModel::data(const QModelIndex &index, int role) const | ||
108 | { | 69 | { | ||
109 | if (index.row() < 0 || index.row() >= m_batteries.count()) { | 70 | if (index.row() < 0 || index.row() >= m_batteries.count()) { | ||
110 | return QVariant(); | 71 | return QVariant(); | ||
111 | } | 72 | } | ||
112 | 73 | | |||
113 | if (role == BatteryRole) { | 74 | if (role == BatteryRole) { | ||
114 | return QVariant::fromValue(m_batteries.value(index.row()).as<Solid::Battery>()); | 75 | return QVariant::fromValue(m_batteries.value(index.row()).as<Solid::Battery>()); | ||
Show All 28 Lines |