> Question to the list; are there better techniques for exposing properties to 
> a common element from a specific implementation - and be able to use such 
> properties in the implementation effectively? Can attached properties be used 
> for this without breaking the ability to deploy the App to a different 
> platform that doesn't have this property?

We could provide some elements to handle these platform specific parts
in a more declarative way, using bindings and connections. A possible
approach would be as follows:

===
Button {
    id: button

    // active binding when platform is meego
    PlatformProperty { target: button; platform: "meego"; name:
"color"; value: "red"; }

    // active binding when platform is symbian
    PlatformProperty { target: button; platform: "symbian"; name:
"foobar"; value: 1; }
    PlatformProperty { target: button; platform: "symbian"; name:
"font.pixelSize"; value: 30; }

    // listen for signals when platform is symbian
    PlatformConnections { target: button; platform: "symbian";
onFooBarChanged: print(button.platform.foobar); }
}
===

So we could handle these 'ifdefs' in an more elegant way, providing a
portable source code.

Accessing these properties directly would result in a non-portable or
a non-declarative source code. Like the following:

===
Button {
    platform.color: "red"
    platform.foobar: 4 // this will crash on meego, since foobar does not exist

    onFooBarChanged: {
        // this will crash on meego, since foobar does not exist
    }
}

Button {
    Component.onCompleted: {
        if (qt_components_platform == "meego")
            platform.color = "red";
        else if (qt_components_platform == "symbian")
            platform.foobar = 4;

        // handle specific connections
    }
}
===

A possible implementation for the PlatformProperty can be as follows:

===
import Qt 4.7

Binding {
    id: binding
    property string name
    property string platform

    property: "platform." + name
    when: binding.platform == qt_components_platform // global context
}
===

However, I dislike the idea of having to handle multiple platforms in
the source code. IMO Nokia needs to converge to a single API for all
platforms Symbian, Meego and future ones.
Currently, if the difference between these APIs are small. I would
prefer to have a few redundant properties/signals in the common API,
instead of having to handle these extensions in my code.

Br,
Adriano
_______________________________________________
Qt-components mailing list
Qt-components@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-components

Reply via email to