QML code style

Gábor Lehel illissius at gmail.com
Wed Feb 23 15:42:40 CET 2011


On Thu, Jan 20, 2011 at 9:57 PM, Artur de Souza <asouza at kde.org> wrote:
>
> Quoting Marco Martin <notmart at gmail.com>:
>> Artur, do you know something more about coding conventions used
>> internally for
>> QML/QtComponents? if sensible we could just steal, ehm, i mean adopt them ;)
>
> In QtComponents we use the links below as a reference:
>
> http://doc.qt.nokia.com/4.7-snapshot/codingconventions.html
> https://developer.mozilla.org/En/Developer_Guide/Coding_Style
>
> and I could also find the guidelines below one e-mail:
>
> 1. avoid using ';', unless strictly needed (just use it if you are writing
> multiple commands on the same line and even in this case avoid the last
> semicolon).
>    target: statusbar; property: "y"
>
> 2. avoid writing more than one command on the same line :-), but this is not
> strict.
> The example below is good, IMO these cases, PropertyChanges and Animation,
> can have their properties on one line.
>        states: State {
>          name: 'hidden'
>          when:  window.statusbarVisible == false
>          PropertyChanges { target: statusbar; y: -statusbar.height }
>      }
>
>      transitions: Transition {
>          NumberAnimation { target: statusbar; property: "y"; duration: 300;
> easing.type: Easing.InOutQuad }
>      }
>
> 3. use a blank space after and before curly braces (when in the same line)
> '{', '}'
>        MouseArea {
>          id: mouseArea
>          anchors.fill: parent
>          onClicked: { button.clicked() }
>      }
>
> 4. use 4 spaces for indentation (no tabs)
>
> 5. use double quotes for strings: "string" instead of 'string'
>
>
>
> I kind of dislike more than one command in the same line and for JS
> stuff I put ";" in every end of line/command (while in QML code we
> avoid them). I can find a link explaining the reason behind ending
> with ";" every JS line if you want.
>
> You are also right that it's going to be very good to setup some
> "naming" guidelines for id's. It can be really a mess if we don't
> follow some guideline.
>
> Ah, something I almost forgot: following some scripting languages,
> properties that we would like to make "private/protected" are declared
> with "__" preprending their names, for example:
>
> property int __protected: 0

Sorry for the necro, but: you can also transplant the d-pointer idiom
into QML for private properties. Like this:

TextOrWhatever
{
    text: d.some_private_property
    QtObject
    {
        id: d
        property string some_private_property
    }
}


>
>
> Cheers,
>
> Artur
>
> -------------------------------------------
>
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel at kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>



-- 
Work is punishment for failing to procrastinate effectively.


More information about the Plasma-devel mailing list