diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc index 346d7ae4d4a49a813205218618bf2b72f0f31d7a..fc8bc7b29c0c25d8982c1b7210eaa5278e0fa1e9 100644 --- a/doc/addressbook-sdk.qdoc +++ b/doc/addressbook-sdk.qdoc @@ -696,6 +696,12 @@ in the same function, we avoid the possibility of the user interface getting "out of sync" with the internal state of the application. + To maintain consistency, we need to modify our \c addContact() and + \c cancel() functions respectively. Below is the code: + + \snippet examples/addressbook-sdk/part4/addressbook.cpp addContact + \dots + \snippet examples/addressbook-sdk/part4/addressbook.cpp cancel */ /*! diff --git a/doc/examples/addressbook-sdk/part4/addressbook.cpp b/doc/examples/addressbook-sdk/part4/addressbook.cpp index e403f9713fd743384fedd5f818f56c6b883b7fb1..0c49404e9aee81a6f0a422efa0b82c1bc197e2f9 100644 --- a/doc/examples/addressbook-sdk/part4/addressbook.cpp +++ b/doc/examples/addressbook-sdk/part4/addressbook.cpp @@ -68,6 +68,7 @@ AddressBook::~AddressBook() delete ui; } +//! [addContact] void AddressBook::addContact() { oldName = nameLine->text(); @@ -76,16 +77,9 @@ void AddressBook::addContact() nameLine->clear(); addressText->clear(); - nameLine->setReadOnly(false); - nameLine->setFocus(Qt::OtherFocusReason); - addressText->setReadOnly(false); - - addButton->setEnabled(false); - nextButton->setEnabled(false); - previousButton->setEnabled(false); - submitButton->show(); - cancelButton->show(); + updateInterface(AddingMode); } +//! [addContact] //! [submitContact part1] void AddressBook::submitContact() @@ -130,28 +124,20 @@ void AddressBook::submitContact() tr("\"%1\" has been edited in your address book.").arg(name)); contacts[name] = address; } - - updateInterface(NavigationMode); } + updateInterface(NavigationMode); } //! [submitContact part3] +//! [cancel] void AddressBook::cancel() { nameLine->setText(oldName); nameLine->setReadOnly(true); - addressText->setText(oldAddress); - addressText->setReadOnly(true); - addButton->setEnabled(true); - - int number = contacts.size(); - nextButton->setEnabled(number > 1); - previousButton->setEnabled(number > 1); - - submitButton->hide(); - cancelButton->hide(); + updateInterface(NavigationMode); } +//! [cancel] void AddressBook::next() { @@ -233,7 +219,7 @@ void AddressBook::updateInterface(Mode mode) nameLine->setReadOnly(false); nameLine->setFocus(Qt::OtherFocusReason); - addressTExt->setReadOnly(false); + addressText->setReadOnly(false); addButton->setEnabled(false); editButton->setEnabled(false);