Skip to content
Permalink
Browse files

Added function to find QML object in C++

Added two signals to standbyControl to indicate standby on and off
  • Loading branch information
martonborzak committed Nov 23, 2019
1 parent a1e3461 commit bad0b15eab886cc437356958735b291ce6a28aca
Showing with 34 additions and 3 deletions.
  1. +5 −0 StandbyControl.qml
  2. +1 −0 main.qml
  3. +20 −0 sources/config.cpp
  4. +4 −0 sources/config.h
  5. +4 −3 sources/configinterface.h
@@ -29,6 +29,9 @@ Item {
property int screenOnTime: 0
property int screenOffTime: 0

signal standByOn()
signal standByOff()

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TOUCH EVENT DETECTOR
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -207,10 +210,12 @@ Item {
// if mode is on change processor to ondemand
if (mode === "on") {
standbyLauncher.launch("/usr/bin/yio-remote/ondemand.sh");
standByOff();
}
// if mode is standby change processor to powersave
if (mode === "standby") {
standbyLauncher.launch("/usr/bin/yio-remote/powersave.sh");
standByOn();
}
}

@@ -288,6 +288,7 @@ ApplicationWindow {

StandbyControl {
id: standbyControl
objectName: "standbyControl"

Component.onCompleted: {
standbyControl.wifiOffTime = Qt.binding(function () { return config.read.settings.wifitime});
@@ -29,3 +29,23 @@ void Config::writeConfig()
{
m_jsf->write(m_config);
}

QObject *Config::getQMLObject(QList<QObject*> nodes,const QString &name)
{
for (int i=0; i < nodes.size(); i++)
{
if (nodes.at(i) && nodes.at(i)->objectName() == name) {
return dynamic_cast<QObject*>(nodes.at(i));
} else if (nodes.at(i) && nodes.at(i)->children().size() > 0) {
QObject* item = getQMLObject(nodes.at(i)->children(), name);
if (item)
return item;
}
}
return nullptr;
}

QObject *Config::getQMLObject(const QString &name)
{
return getQMLObject(m_engine->rootObjects(), name);
}
@@ -40,6 +40,10 @@ class Config : public QObject, ConfigInterface
return m_engine->rootContext()->contextProperty(name);
}

// get a QML object, you need to have objectName property of the QML object set to be able to use this
QObject *getQMLObject(QList<QObject*> nodes,const QString &name);
QObject *getQMLObject(const QString &name);

// profile
QString profile()
{
@@ -9,9 +9,10 @@ class ConfigInterface
public:
virtual ~ConfigInterface() {}

virtual QVariantMap read () = 0;
virtual void readWrite (QVariantMap config) = 0;
virtual QVariant getContextProperty (const QString& name) = 0;
virtual QVariantMap read () = 0;
virtual void readWrite (QVariantMap config) = 0;
virtual QVariant getContextProperty (const QString& name) = 0;
virtual QObject* getQMLObject (const QString &name) = 0;

private:
QVariantMap m_config;

0 comments on commit bad0b15

Please sign in to comment.
You can’t perform that action at this time.