summaryrefslogtreecommitdiffstats
path: root/demos/declarative/contacts/Contact.qml
blob: 7297fa6dce271dd11ba3632590ca4083b4c3f623 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Item {
    id: contactDetails
    anchors.fill: parent

    property var contactId: ""
    property var label: ""
    property var phone: ""
    property var email: ""

    onLabelChanged: { labelField.value = label }
    onEmailChanged: { emailField.value = email }
    onPhoneChanged: { phoneField.value = phone }

    resources: [
        SqlQuery {
            id: updateContactQuery
            connection: contactDatabase
            query: "UPDATE contacts SET label = :l, email = :e, phone = :p WHERE recid = :r"
            bindings: SqlBind {
                name: ":r"
                value: contactId
            }
            bindings: SqlBind {
                name: ":l"
                value: labelField.value
            }
            bindings: SqlBind {
                name: ":e"
                value: emailField.value
            }
            bindings: SqlBind {
                name: ":p"
                value: phoneField.value
            }
        },
        SqlQuery {
            id: insertContactQuery
            connection: contactDatabase
            query: "INSERT INTO contacts (label, email, phone) VALUES(:l, :e, :p)"
            bindings: SqlBind {
                name: ":l"
                value: labelField.value
            }
            bindings: SqlBind {
                name: ":e"
                value: emailField.value
            }
            bindings: SqlBind {
                name: ":p"
                value: phoneField.value
            }
        }

    ]
    function refresh() {
        labelField.value = label;
        emailField.value = email;
        phoneField.value = phone;
    }
    function update() {
        updateContactQuery.exec();
    }
    function insert() {
        insertContactQuery.exec();
    }
    VerticalLayout {
        id: layout
        anchors.fill: parent
        spacing: 5
        margin: 5
        ContactField {
            id: labelField
            anchors.left: layout.left
            anchors.leftMargin: 5
            anchors.right: layout.right
            anchors.rightMargin: 5
            label: "Name"
        }
        ContactField {
            id: phoneField
            anchors.left: layout.left
            anchors.leftMargin: 5
            anchors.right: layout.right
            anchors.rightMargin: 5
            icon: "pics/phone.png"
            label: "Phone"
        }
        ContactField {
            id: emailField
            anchors.left: layout.left
            anchors.leftMargin: 5
            anchors.right: layout.right
            anchors.rightMargin: 5
            icon: "pics/email.png"
            label: "Email"
        }
    }
}