Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/batterymodel.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | |||||
81 | { | 81 | { | ||
82 | if (index < 0 || index >= m_batteries.count()) { | 82 | if (index < 0 || index >= m_batteries.count()) { | ||
83 | return QString(); | 83 | return QString(); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | return m_batteries.at(index).udi(); | 86 | return m_batteries.at(index).udi(); | ||
87 | } | 87 | } | ||
88 | 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 | | ||||
89 | QVariant BatteryModel::data(const QModelIndex &index, int role) const | 107 | QVariant BatteryModel::data(const QModelIndex &index, int role) const | ||
90 | { | 108 | { | ||
91 | if (index.row() < 0 || index.row() >= m_batteries.count()) { | 109 | if (index.row() < 0 || index.row() >= m_batteries.count()) { | ||
92 | return QVariant(); | 110 | return QVariant(); | ||
93 | } | 111 | } | ||
94 | 112 | | |||
95 | if (role == BatteryRole) { | 113 | if (role == BatteryRole) { | ||
96 | return QVariant::fromValue(m_batteries.value(index.row()).as<Solid::Battery>()); | 114 | return QVariant::fromValue(m_batteries.value(index.row()).as<Solid::Battery>()); | ||
115 | } else if (role == ProductRole) { | ||||
116 | const Solid::Device device = m_batteries.value(index.row()); | ||||
117 | return device.product(); | ||||
118 | } else if (role == VendorRole) { | ||||
119 | const Solid::Device device = m_batteries.value(index.row()); | ||||
120 | return device.vendor(); | ||||
97 | } else if (role == UdiRole) { | 121 | } else if (role == UdiRole) { | ||
98 | return m_batteries.at(index.row()).udi(); | 122 | return m_batteries.at(index.row()).udi(); | ||
99 | } | 123 | } | ||
100 | 124 | | |||
101 | return QVariant(); | 125 | return QVariant(); | ||
102 | } | 126 | } | ||
103 | 127 | | |||
104 | int BatteryModel::rowCount(const QModelIndex &parent) const | 128 | int BatteryModel::rowCount(const QModelIndex &parent) const | ||
105 | { | 129 | { | ||
106 | Q_UNUSED(parent); | 130 | Q_UNUSED(parent); | ||
107 | return m_batteries.count(); | 131 | return m_batteries.count(); | ||
108 | } | 132 | } | ||
109 | 133 | | |||
110 | QHash<int, QByteArray> BatteryModel::roleNames() const | 134 | QHash<int, QByteArray> BatteryModel::roleNames() const | ||
111 | { | 135 | { | ||
112 | return { | 136 | return { | ||
113 | {BatteryRole, "battery"}, | 137 | {BatteryRole, "battery"}, | ||
138 | {VendorRole, "vendor"}, | ||||
139 | {ProductRole, "product"}, | ||||
114 | {UdiRole, "udi"} | 140 | {UdiRole, "udi"} | ||
115 | }; | 141 | }; | ||
116 | } | 142 | } |