diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-18 14:06:19 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-18 17:04:40 +0000 |
commit | 1eeeca9d202ceaf11b2935ebe590a85145d33ef5 (patch) | |
tree | 2feffe49d30a95abd5e30bd480ed684aba969b2b /examples/quickcontrols2/contactlist/ContactDialog.qml | |
parent | 0cfadeb6de542548c45ef485a4452e820cefb401 (diff) |
Overhaul the Contact List example
Some renames, API tweaks, and structural changes. Glue the pieces
(view/model/dialog) together in contactlist.qml.
Change-Id: Id3a31248b391838c6d39f2f0f355e1c35456ccf5
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'examples/quickcontrols2/contactlist/ContactDialog.qml')
-rw-r--r-- | examples/quickcontrols2/contactlist/ContactDialog.qml | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/examples/quickcontrols2/contactlist/ContactDialog.qml b/examples/quickcontrols2/contactlist/ContactDialog.qml index fd0ddbfd..1836ea28 100644 --- a/examples/quickcontrols2/contactlist/ContactDialog.qml +++ b/examples/quickcontrols2/contactlist/ContactDialog.qml @@ -49,52 +49,47 @@ ****************************************************************************/ import QtQuick 2.7 -import QtQuick.Window 2.2 import QtQuick.Controls 2.1 Dialog { id: dialog - x: parent.width / 2 - width / 2 - y: parent.height / 2 - height / 2 - standardButtons: Dialog.Ok | Dialog.Cancel - modal: true - focus: true - - property int lastIndex - property QtObject lastModel - - property alias form: form + property int index: -1 + signal finished(string fullName, string address, string city, string number) - function addContact(model) { + function createContact() { form.fullName.clear(); form.address.clear(); form.city.clear(); form.number.clear(); - lastIndex = -1; - lastModel = model; - dialog.title = qsTr("Add Contact") + dialog.title = qsTr("Add Contact"); + dialog.index = -1; dialog.open(); } - function editContact(model, index) { - form.fullName.text = model.getFullName(index); - form.address.text = model.getAddress(index); - form.city.text = model.getCity(index); - form.number.text = model.getNumber(index); - lastIndex = index; - lastModel = model; + function editContact(index, contact) { + form.fullName.text = contact.fullName; + form.address.text = contact.address; + form.city.text = contact.city; + form.number.text = contact.number; - dialog.title = qsTr("Edit Contact") + dialog.title = qsTr("Edit Contact"); + dialog.index = index; dialog.open(); } - contentItem: ContactDialogForm { + x: parent.width / 2 - width / 2 + y: parent.height / 2 - height / 2 + + focus: true + modal: true + title: qsTr("Add Contact") + standardButtons: Dialog.Ok | Dialog.Cancel + + contentItem: ContactForm { id: form } - onAccepted: lastModel.updateContact(lastIndex, form.fullName.text, - form.address.text, form.city.text, - form.number.text) + onAccepted: finished(form.fullName.text, form.address.text, form.city.text, form.number.text) } |