diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-03-10 15:09:37 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-03-12 15:03:03 +0100 |
commit | 26c5243491f495194f04b449128dae36118e28da (patch) | |
tree | 7fb14678a6fc9e44a10c9224d005e2cbdc6bcb63 /examples/quick/localstorage | |
parent | 1c7d264e3b2e9a2f0021786ea6967185f8282af0 (diff) | |
parent | c24c5baeda4101b0058689adf9200b77a722c3a2 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Conflicts:
dependencies.yaml
src/qml/qml/qqmlengine.cpp
Change-Id: I6a73fd1064286f4a2232de85c2ce7f80452d4641
Diffstat (limited to 'examples/quick/localstorage')
3 files changed, 38 insertions, 21 deletions
diff --git a/examples/quick/localstorage/localstorage/Header.qml b/examples/quick/localstorage/localstorage/Header.qml index e9446de55e..47879500a7 100644 --- a/examples/quick/localstorage/localstorage/Header.qml +++ b/examples/quick/localstorage/localstorage/Header.qml @@ -59,6 +59,9 @@ Item { width: Screen.width / 2 height: Screen.height / 7 + required property ListView listView + required property Text statusText + function insertrec() { var rowid = parseInt(JS.dbInsert(dateInput.text, descInput.text, distInput.text), 10) if (rowid) { @@ -148,7 +151,7 @@ Item { } onEditingFinished: { if (dateInput.text == "") { - statustext.text = "Please fill in the date" + root.statusText.text = "Please fill in the date" dateInput.forceActiveFocus() } } @@ -161,10 +164,10 @@ Item { activeFocusOnTab: true onEditingFinished: { if (descInput.text.length < 8) { - statustext.text = "Enter a description of minimum 8 characters" + root.statusText.text = "Enter a description of minimum 8 characters" descInput.forceActiveFocus() } else { - statustext.text = "" + root.statusText.text = "" } } } @@ -179,7 +182,7 @@ Item { } onEditingFinished: { if (distInput.text == "") { - statustext.text = "Please fill in the distance" + root.statusText.text = "Please fill in the distance" distInput.forceActiveFocus() } } diff --git a/examples/quick/localstorage/localstorage/MyDelegate.qml b/examples/quick/localstorage/localstorage/MyDelegate.qml index 63a83bfbae..e8575d4f7a 100644 --- a/examples/quick/localstorage/localstorage/MyDelegate.qml +++ b/examples/quick/localstorage/localstorage/MyDelegate.qml @@ -54,18 +54,27 @@ import QtQuick.Layouts 1.1 import "Database.js" as JS Item { + id: delegate + width: parent.width height: rDate.implicitHeight + required property int index + required property int distance + required property string trip_desc + required property string date + + signal clicked() + Rectangle { id: baseRec anchors.fill: parent opacity: 0.8 - color: index % 2 ? "lightgrey" : "grey" + color: delegate.index % 2 ? "lightgrey" : "grey" MouseArea { anchors.fill: parent - onClicked: listView.currentIndex = index + onClicked: delegate.clicked() } GridLayout { anchors.fill:parent @@ -73,21 +82,21 @@ Item { Text { id: rDate - text: date + text: delegate.date font.pixelSize: 22 Layout.preferredWidth: parent.width / 4 color: "black" } Text { id: rDesc - text: trip_desc + text: delegate.trip_desc Layout.fillWidth: true font.pixelSize: 22 color: "black" } Text { id: rDistance - text: distance + text: delegate.distance font.pixelSize: 22 Layout.alignment: Qt.AlignRight color: "black" diff --git a/examples/quick/localstorage/localstorage/localstorage.qml b/examples/quick/localstorage/localstorage/localstorage.qml index 41f5cbd561..418aab838e 100644 --- a/examples/quick/localstorage/localstorage/localstorage.qml +++ b/examples/quick/localstorage/localstorage/localstorage.qml @@ -55,6 +55,7 @@ import QtQuick.LocalStorage 2.0 import "Database.js" as JS Window { + id: window visible: true width: Screen.width / 2 height: Screen.height / 1.8 @@ -72,19 +73,21 @@ Window { Header { id: input Layout.fillWidth: true + listView: listView + statusText: statustext } RowLayout { MyButton { text: "New" onClicked: { input.initrec_new() - creatingNewEntry = true + window.creatingNewEntry = true listView.model.setProperty(listView.currentIndex, "id", 0) } } MyButton { id: saveButton - enabled: (creatingNewEntry || editingEntry) && listView.currentIndex != -1 + enabled: (window.creatingNewEntry || window.editingEntry) && listView.currentIndex != -1 text: "Save" onClicked: { var insertedRow = false; @@ -109,8 +112,8 @@ Window { if (insertedRow) { input.initrec() - creatingNewEntry = false - editingEntry = false + window.creatingNewEntry = false + window.editingEntry = false listView.forceLayout() } } @@ -118,20 +121,20 @@ Window { MyButton { id: editButton text: "Edit" - enabled: !creatingNewEntry && !editingEntry && listView.currentIndex != -1 + enabled: !window.creatingNewEntry && !window.editingEntry && listView.currentIndex != -1 onClicked: { input.editrec(listView.model.get(listView.currentIndex).date, listView.model.get(listView.currentIndex).trip_desc, listView.model.get(listView.currentIndex).distance, listView.model.get(listView.currentIndex).id) - editingEntry = true + window.editingEntry = true } } MyButton { id: deleteButton text: "Delete" - enabled: !creatingNewEntry && listView.currentIndex != -1 + enabled: !window.creatingNewEntry && listView.currentIndex != -1 onClicked: { JS.dbDeleteRow(listView.model.get(listView.currentIndex).id) listView.model.remove(listView.currentIndex, 1) @@ -145,7 +148,7 @@ Window { MyButton { id: cancelButton text: "Cancel" - enabled: (creatingNewEntry || editingEntry) && listView.currentIndex != -1 + enabled: (window.creatingNewEntry || window.editingEntry) && listView.currentIndex != -1 onClicked: { if (listView.model.get(listView.currentIndex).id === 0) { // This entry had an id of 0, which means it was being created and hadn't @@ -153,8 +156,8 @@ Window { listView.model.remove(listView.currentIndex, 1) } listView.forceLayout() - creatingNewEntry = false - editingEntry = false + window.creatingNewEntry = false + window.editingEntry = false input.initrec() } } @@ -176,9 +179,11 @@ Window { Layout.fillWidth: true Layout.fillHeight: true model: MyModel {} - delegate: MyDelegate {} + delegate: MyDelegate { + onClicked: listView.currentIndex = index + } // Don't allow changing the currentIndex while the user is creating/editing values. - enabled: !creatingNewEntry && !editingEntry + enabled: !window.creatingNewEntry && !window.editingEntry highlight: highlightBar highlightFollowsCurrentItem: true |