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}
}
}
}
}
}