Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/batterymodel.cpp
Show All 22 Lines | |||||
23 | #include <Solid/DeviceNotifier> | 23 | #include <Solid/DeviceNotifier> | ||
24 | 24 | | |||
25 | #include <QtQml> | 25 | #include <QtQml> | ||
26 | #include <QQmlEngine> | 26 | #include <QQmlEngine> | ||
27 | 27 | | |||
28 | 28 | | |||
29 | BatteryModel::BatteryModel(QObject *parent) : QAbstractListModel(parent) | 29 | BatteryModel::BatteryModel(QObject *parent) : QAbstractListModel(parent) | ||
30 | { | 30 | { | ||
31 | qmlRegisterType<Solid::Battery>(); | 31 | qmlRegisterUncreatableType<Solid::Battery>("org.kde.kinfocenter.energy.private", 1, 0, "Battery", | ||
32 | QStringLiteral("Use Solid::Battery")); | ||||
meven: Used this nice documentation to choose the right method : https://doc.qt.io/qt-5/qtqml… | |||||
32 | 33 | | |||
33 | m_batteries = Solid::Device::listFromType(Solid::DeviceInterface::Battery); | 34 | m_batteries = Solid::Device::listFromType(Solid::DeviceInterface::Battery); | ||
34 | 35 | | |||
35 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, [this](const QString &udi) { | 36 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, [this](const QString &udi) { | ||
36 | 37 | | |||
37 | auto it = std::find_if(m_batteries.constBegin(), m_batteries.constEnd(), [&udi](const Solid::Device &dev) {return dev.udi() == udi;}); | 38 | auto it = std::find_if(m_batteries.constBegin(), m_batteries.constEnd(), [&udi](const Solid::Device &dev) {return dev.udi() == udi;}); | ||
38 | if (it != m_batteries.constEnd()) { | 39 | if (it != m_batteries.constEnd()) { | ||
39 | return; | 40 | return; | ||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |
Used this nice documentation to choose the right method : https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html#choosing-the-correct-integration-method-between-c-and-qml