Item {
id: productOutdoor
property color accentucationColor:: "#45a785"
}
 
Item {
id: productMyDreamHome
property string skin: "Other"
property color accentucationColor: colorForSkin(skin)
function colorForSkin(skin) {
            if (skin === "MyDreamHomeThemeCanson")

                return Qt.rgba(235 / 255, 130 / 255, 122 / 255, 255 / 255)
            else if (skin === "MyDreamHomeThemeMilli")
                return Qt.rgba(242 / 255, 118 / 255, 82 / 255, 255 / 255)
            else
                return Qt.rgba(145 / 255, 135 / 255, 148 / 255, 255 / 255)        
}
onSkinChanged: accentucationColor = colorForSkin(skin)
}
 
Item {
name: productOther
property color accentucationColor: "#8da7c0"
}
 
Item {
property var currentSkin: null
onCurrentSkinChanged: SkinManager::updateSkin()
}
 
set currentSkin to productOutdoor, productMyDreamHome, or productOther
 
You should get what you want. I personally just use a big JSON object and assign that. 
Sent: Tuesday, August 23, 2016 at 5:36 PM
From: "Xavier Bigand" <flamaros.xav...@gmail.com>
To: "Jason H" <jh...@gmx.com>
Cc: interest@qt-project.org
Subject: Re: [Interest] Force property's binding to be executed from C++
That the problem, I can easily call my SkinManager::updateSkin when the skin changed, because it's a cpp attribut too (the selected skin). But I have to call it when the QmlEngine have reevaluated the properties values not before.
Getting property values directly from cpp code doesn't execute bindings (as much as I know), so I am trying to call this slot (SkinManager::updateSkin) from Qml where it should be easier to fix this calling order issue.
 
If I create a property that depends of all others it be reevaluated after the others, then I will be able to invoke my cpp slot from his onChanged signal.
The difficulty is to create this property.
 
 
 
My QML component looks like to this :
 
HomeDesignSkins.qml :
 
Item {
    id: homeDesignSkins
       readonly property color accentucationColor: {                                                                       // In cpp SkinManager::updateSkin() method can be invoked before the execution of this binding, 
        if (application.product === Product.ProductOutdoor)                                                            // the better way to solve this issue is to create a binding dependency
            return "#45a785"
        else if (application.product === Product.ProductMyDreamHome)
        {
            if (settings.skin === "MyDreamHomeThemeCanson")
                return Qt.rgba(235 / 255, 130 / 255, 122 / 255, 255 / 255)
            else if (settings.skin === "MyDreamHomeThemeMilli")
                return Qt.rgba(242 / 255, 118 / 255, 82 / 255, 255 / 255)
            else
                return Qt.rgba(145 / 255, 135 / 255, 148 / 255, 255 / 255)
        }
        else
            return "#8da7c0"
    }
 
    ...
 
    // Here we have numerous properties used to describe our GUI skin (some are shared with the cpp code for our 3D rendering)
 
    Object {
        property string homeDesignSkinsProperties: {
                   var propertyValues
                   for (var propertyName in homeDesignSkins)
                          propertyValues += propertyName + " "                                 // How retrieving the property values by their names
                   return propertyValues
             }
 
            onHomeDesignSkinsPropertiesChanged: {                                     // This signal should be called once after that all properties of homeDesignSkins where reevaluted when the skin changed
                   skinManager.updateSkin()                                                     // skinManager is the instance of the cpp SkinManager singleton, updateSkin is an Q_INVOKABLE method
            }
    }
}
 
 
 
 
 
2016-08-23 21:29 GMT+02:00 Jason H <jh...@gmx.com>:
If I understand you correctly, and I probably don't, the skin component
 
Skin {
signal skinPropertyChanged();
property color accentucationColor: "red"
onAccentucationColorChanged: skinPropertyChanged()
}
 
SkinManager {// exposed C++ class
    id:skinManager
    property var currentSkin: null;
    onCurrrentSkinChanged: updateSkin(); // handle when the skin switches
}
   Connections {
      target: currentSkin
      onSkinPropertyChanged: id:skinManager.updateSkin() // handle when propterties of the skin change.
   }
 
Will that work?
 
 
Sent: Tuesday, August 23, 2016 at 1:12 PM
From: "Xavier Bigand" <flamaros.xav...@gmail.com>
To: interest@qt-project.org
Subject: [Interest] Force property's binding to be executed from C++
Hi,
 
To skin our GUI we have a dedicated qml component instanced once that contains all necessary values under properties.
I am able to access to those properties from C++ code but they aren't correctly synchronized with the selected skin. 
 
Here is my cpp code :
 
    void SkinManagerWrapper::updateSkin() const
    {
        QObject*    skinItem = mRootObject->findChild<QObject*>("hdGUI", Qt::FindDirectChildrenOnly);
 
        core::SkinManager*  skinManager = core::SkinManager::singleton();
 
        // General
        skinManager->accentuationColor = convert(skinItem->property("accentuationColor").value<QColor>());           // skinManager->accentuationColor is actually a cpp property ;-)
    }
 
The property method return the previous value before the execution of the binding, because in the qml binding the value is depending of the selected skin.
 
As workaround I am trying to create a qml property that depend of all properties of our skin component ("HomeDesignSkins"), but If it is possible to retrieve dynamically properties names of the component, I can't figure out retrieving values of properties by string names.
The Idea is to be able to use the onChanged signal of this property to invoke my cpp updateSkin method, this should resolve dependency order issue.
 
Maybe their is an other way to do it, else I am searching to way to retrieve property values in qml from their names.
 
 
-- 
Xavier
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
 
 
--
Xavier
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to