Ubuntu Pastebin

Paste from mike00 at Wed, 22 Jun 2016 09:51:01 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import QtQuick 2.4
import Ubuntu.Components 1.3
import U1db 1.0 as U1db

MainView {
    width: units.gu(40)
    height: units.gu(71)

    /* ----------------------------------------------------
       Set up the U1DB database
       Declare a named document
       ---------------------------------------------------- */
    U1db.Database { id: db; path: "simpleu1dbdemo.u1db" }
    U1db.Document {
        id: lastPlace
        database: db
        docId: "lastPlace"
        create: true
        defaults: { placename: "" }
    }


    Page {
        header: PageHeader {
            id: ciao
            title: "Simple U1DB mike"
        }

        Column {
            width: parent.width
            spacing: units.gu(1)
            y: units.gu(2)+ciao.height
            Label {
                width: parent.width
                text: "Enter a place"
                horizontalAlignment: Text.AlignHCenter

            }
            Rectangle {
                width: parent.width - units.gu(2)
                height: inp.height * 1.2
                anchors.horizontalCenter: parent.horizontalCenter
                TextArea {
                    id: inp
                    width: parent.width - units.gu(5)
                    anchors.centerIn: parent

                    /* ----------------------------------------------------
                       Important part number one
                       Retrieve the value from the declared U1DB document
                       ---------------------------------------------------- */
                    text: lastPlace.contents.placename || ""

                    /* ----------------------------------------------------
                       Important part number two
                       Save a changed value back to the U1DB document
                       ---------------------------------------------------- */
                    onTextChanged: lastPlace.contents = {placename: text}
                }
            }
        }
    }
}
Download as text