diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc index ec9c46e6e96..572149c78be 100644 --- a/doc/addressbook-sdk.qdoc +++ b/doc/addressbook-sdk.qdoc @@ -460,10 +460,14 @@ below illustrates what you will see as the button layout approaches the grid layout; drop it then. - \image addressbook-tutorial-part3-drop-into-gridlayout + \image addressbook-tutorial-part3-drop-in-gridlayout Finally, set a top level layout for the widget again. + \note We follow basic conventions for \c next() and \c previous() functions + by placing the \c nextButton on the right and the \c previousButton on the + left. + \section1 The AddressBook Class @@ -477,16 +481,64 @@ \snippet examples/addressbook-sdk/part3/addressbook.h members - To implement these slots, we begin by extracting the push buttons from - the form: + In the \c AddressBook constructor, we extract the push buttons from the + \c ui object and disable them by default. This is because navigation is + only enabled when there is more than one contact in the address book. \snippet examples/addressbook-sdk/part3/addressbook.cpp extract objects - Next, we make the necessary signal-slot connections. + Next, we connect the buttons to their respective slots: \snippet examples/addressbook-sdk/part3/addressbook.cpp signal slot + The screenshot below is our expected graphical user interface. Notice that + it is getting closer to our final application. + Within our \c addContact() function, we have to disable the \gui Next and + \gui Previous buttons so that the user does not attempt to navigate while + adding a contact. + \snippet examples/addressbook-sdk/part3/addressbook.cpp disable navigation + + Also, in our \c submitContact() function, we enable the navigation buttons, + depending on the size of \c contacts. Asmentioned earlier, navigation is + only enabled when there is more than one contact in the address book. The + following lines of code demonstrates how to do this: + + \snippet examples/addressbook-sdk/part3/addressbook.cpp enable navigation + + We also include these lins of code in the \c cancel() function. + + Recall that we intend to emulate a circularly-linked list with our QMap + object, \c contacts. So in the \c next() function, we obtain an iterator + for \c contacts and then: + + \list + \o If the iterator is not at the end of \c contacts, we increment it by + one. + \o If the iterator is at the end of \c contacts, we move it to the + beginning of \c contacts. This gives us the illusion that our QMap + is working like a circularly-linked list. + \endlist + + \snippet examples/addressbook-sdk/part3/addressbook.cpp next + + Once we have iterated to the current object in \c contacts, we display its + contents on \c nameLine and \c addressText. + + Similarly, for the \c previous() function,we obtain an iterator for + \c contacts and then: + + \list + \o If the iterator is at teh end of \c contacts, we clear the display + and return. + \o If the iterator is at the beginning of \c contacts, we move it to + the end. + \o We then decrement the iterator by one. + \endlist + + \snippet examples/addressbook-sdk/part3/addressbook.cpp previous + + Again, we display the contents of the current object in \c contacts. */ diff --git a/doc/examples/addressbook-sdk/part3/addressbook.cpp b/doc/examples/addressbook-sdk/part3/addressbook.cpp index 5eddb82198f..304fd5f7a2b 100644 --- a/doc/examples/addressbook-sdk/part3/addressbook.cpp +++ b/doc/examples/addressbook-sdk/part3/addressbook.cpp @@ -28,9 +28,11 @@ AddressBook::AddressBook(QWidget *parent) //! [extract objects] nextButton = new QPushButton; nextButton = ui->nextButton; + nextButton->setEnabled(false); previousButton = new QPushButton; previousButton = ui->previousButton; + nextButton->setEnabled(false); //! [extract objects] connect(addButton, SIGNAL(clicked()), this, @@ -67,6 +69,10 @@ void AddressBook::addContact() addressText->setReadOnly(false); addButton->setEnabled(false); +//! [disable navigation] + nextButton->setEnabled(false); + previousButton->setEnabled(false); +//! [disable navigation] submitButton->show(); cancelButton->show(); } @@ -101,6 +107,12 @@ void AddressBook::submitContact() nameLine->setReadOnly(true); addressText->setReadOnly(true); addButton->setEnabled(true); + +//! [enable navigation] + int number = contacts.size(); + nextButton->setEnabled(number > 1); + previousButton->setEnabled(number > 1); +//! [enable navigation] submitButton->hide(); cancelButton->hide(); } @@ -112,8 +124,12 @@ void AddressBook::cancel() 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(); } diff --git a/doc/examples/addressbook-sdk/part3/addressbook.ui b/doc/examples/addressbook-sdk/part3/addressbook.ui index 6e313d6bbfb..33f99cc4097 100644 --- a/doc/examples/addressbook-sdk/part3/addressbook.ui +++ b/doc/examples/addressbook-sdk/part3/addressbook.ui @@ -13,97 +13,91 @@ AddressBook - - - - 48 - 28 - 413 - 225 - - - - - - - Name: - - - - - - - - - - Address: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - - - - Add - - - - - - - Submit - - - - - - - Cancel - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Next - - - - - - - Previous - - - - - - - + + + + + + + Name: + + + + + + + + + + Address: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + + + Add + + + + + + + Submit + + + + + + + Cancel + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Previous + + + + + + + Next + + + + + + + +