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