diff --git a/Modules/energy/batterymodel.h b/Modules/energy/batterymodel.h --- a/Modules/energy/batterymodel.h +++ b/Modules/energy/batterymodel.h @@ -38,10 +38,14 @@ enum Roles { BatteryRole = Qt::UserRole, - UdiRole + UdiRole, + VendorRole, + ProductRole }; Q_INVOKABLE Solid::Battery *get(int index) const; + Q_INVOKABLE QString vendor(int index) const; + Q_INVOKABLE QString product(int index) const; Q_INVOKABLE QString udi(int index) const; QVariant data(const QModelIndex &index, int role) const override; diff --git a/Modules/energy/batterymodel.cpp b/Modules/energy/batterymodel.cpp --- a/Modules/energy/batterymodel.cpp +++ b/Modules/energy/batterymodel.cpp @@ -86,14 +86,37 @@ return m_batteries.at(index).udi(); } +QString BatteryModel::vendor(int index) const { + + if (index < 0 || index >= m_batteries.count()) { + return QString(); + } + const Solid::Device device = m_batteries.value(index); + return device.vendor(); +} +QString BatteryModel::product(int index) const { + + if (index < 0 || index >= m_batteries.count()) { + return QString(); + } + const Solid::Device device = m_batteries.value(index); + return device.product(); +} + QVariant BatteryModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_batteries.count()) { return QVariant(); } if (role == BatteryRole) { return QVariant::fromValue(m_batteries.value(index.row()).as()); + } else if (role == ProductRole) { + const Solid::Device device = m_batteries.value(index.row()); + return device.product(); + } else if (role == VendorRole) { + const Solid::Device device = m_batteries.value(index.row()); + return device.vendor(); } else if (role == UdiRole) { return m_batteries.at(index.row()).udi(); } @@ -111,6 +134,8 @@ { return { {BatteryRole, "battery"}, + {VendorRole, "vendor"}, + {ProductRole, "product"}, {UdiRole, "udi"} }; } diff --git a/Modules/energy/package/contents/ui/main.qml b/Modules/energy/package/contents/ui/main.qml --- a/Modules/energy/package/contents/ui/main.qml +++ b/Modules/energy/package/contents/ui/main.qml @@ -37,11 +37,15 @@ property QtObject currentBattery: null property string currentUdi: "" + property string currentVendor: "" + property string currentProduct: "" property bool compact: (root.width / units.gridUnit) < 25 onCurrentBatteryChanged: { if (!currentBattery) { - currentBattery = kcm.batteries.get(0) + currentBattery = kcm.batteries.battery(0) + currentVendor = kcm.batteries.vendor(0) + currentProduct = kcm.batteries.product(0) currentUdi = kcm.batteries.udi(0) } } @@ -68,12 +72,6 @@ {label: i18n("Full design"), value: "energyFullDesign", unit: i18nc("Watt-hours", "Wh"), precision: 2} ] }, - { - title: i18n("System"), - data: [ - {label: i18n("Has power supply"), value: "powerSupply"} - ] - }, { title: i18n("Environment"), data: [ @@ -83,8 +81,8 @@ { title: i18n("Manufacturer"), data: [ - {label: i18n("Vendor"), value: "vendor"}, - {label: i18n("Model"), value: "model"}, + {label: i18n("Vendor"), value: "vendor", source:"vendor"}, + {label: i18n("Model"), value: "model", source:"product"}, {label: i18n("Serial Number"), value: "serial"} ] } @@ -101,6 +99,8 @@ Component.onCompleted: { currentBattery = kcm.batteries.get(0) + currentVendor = kcm.batteries.vendor(0) + currentProduct = kcm.batteries.product(0) currentUdi = kcm.batteries.udi(0) } @@ -132,7 +132,10 @@ checkable: true onClicked: { root.currentUdi = model.udi + root.currentVendor = model.vendor + root.currentProduct = model.product root.currentBattery = model.battery + // override checked property checked = Qt.binding(function() { return model.battery == root.currentBattery @@ -428,7 +431,16 @@ id: valueLabel Kirigami.FormData.label: i18n("%1:", modelData.label) text: { - var value = currentBattery[modelData.value] + var value; + if (modelData.source) { + if (modelData.source == "vendor") { + value = currentVendor; + } else { + value = currentProduct; + } + } else { + value = currentBattery[modelData.value] + } if (typeof value === "boolean") { if (value) {