Skip to content
Snippets Groups Projects
Commit 72d3f255 authored by Kavindra Devi Palaraja's avatar Kavindra Devi Palaraja Committed by con
Browse files

Fixes: Doc - finishing up Part 3

RevBy:    TrustMe
parent 324476fd
No related branches found
No related tags found
No related merge requests found
...@@ -460,10 +460,14 @@ ...@@ -460,10 +460,14 @@
below illustrates what you will see as the button layout approaches the below illustrates what you will see as the button layout approaches the
grid layout; drop it then. 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. 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 \section1 The AddressBook Class
...@@ -477,16 +481,64 @@ ...@@ -477,16 +481,64 @@
\snippet examples/addressbook-sdk/part3/addressbook.h members \snippet examples/addressbook-sdk/part3/addressbook.h members
To implement these slots, we begin by extracting the push buttons from In the \c AddressBook constructor, we extract the push buttons from the
the form: \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 \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 \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.
*/ */
...@@ -28,9 +28,11 @@ AddressBook::AddressBook(QWidget *parent) ...@@ -28,9 +28,11 @@ AddressBook::AddressBook(QWidget *parent)
//! [extract objects] //! [extract objects]
nextButton = new QPushButton; nextButton = new QPushButton;
nextButton = ui->nextButton; nextButton = ui->nextButton;
nextButton->setEnabled(false);
previousButton = new QPushButton; previousButton = new QPushButton;
previousButton = ui->previousButton; previousButton = ui->previousButton;
nextButton->setEnabled(false);
//! [extract objects] //! [extract objects]
connect(addButton, SIGNAL(clicked()), this, connect(addButton, SIGNAL(clicked()), this,
...@@ -67,6 +69,10 @@ void AddressBook::addContact() ...@@ -67,6 +69,10 @@ void AddressBook::addContact()
addressText->setReadOnly(false); addressText->setReadOnly(false);
addButton->setEnabled(false); addButton->setEnabled(false);
//! [disable navigation]
nextButton->setEnabled(false);
previousButton->setEnabled(false);
//! [disable navigation]
submitButton->show(); submitButton->show();
cancelButton->show(); cancelButton->show();
} }
...@@ -101,6 +107,12 @@ void AddressBook::submitContact() ...@@ -101,6 +107,12 @@ void AddressBook::submitContact()
nameLine->setReadOnly(true); nameLine->setReadOnly(true);
addressText->setReadOnly(true); addressText->setReadOnly(true);
addButton->setEnabled(true); addButton->setEnabled(true);
//! [enable navigation]
int number = contacts.size();
nextButton->setEnabled(number > 1);
previousButton->setEnabled(number > 1);
//! [enable navigation]
submitButton->hide(); submitButton->hide();
cancelButton->hide(); cancelButton->hide();
} }
...@@ -112,8 +124,12 @@ void AddressBook::cancel() ...@@ -112,8 +124,12 @@ void AddressBook::cancel()
addressText->setText(oldAddress); addressText->setText(oldAddress);
addressText->setReadOnly(true); addressText->setReadOnly(true);
addButton->setEnabled(true); addButton->setEnabled(true);
int number = contacts.size();
nextButton->setEnabled(number > 1);
previousButton->setEnabled(number > 1);
submitButton->hide(); submitButton->hide();
cancelButton->hide(); cancelButton->hide();
} }
......
...@@ -13,97 +13,91 @@ ...@@ -13,97 +13,91 @@
<property name="windowTitle"> <property name="windowTitle">
<string>AddressBook</string> <string>AddressBook</string>
</property> </property>
<widget class="QWidget" name="layoutWidget"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="geometry"> <item>
<rect> <layout class="QGridLayout" name="gridLayout">
<x>48</x> <item row="0" column="0">
<y>28</y> <widget class="QLabel" name="nameLabel">
<width>413</width> <property name="text">
<height>225</height> <string>Name:</string>
</rect> </property>
</property> </widget>
<layout class="QGridLayout" name="gridLayout"> </item>
<item row="0" column="0"> <item row="0" column="1">
<widget class="QLabel" name="nameLabel"> <widget class="QLineEdit" name="nameLine"/>
<property name="text"> </item>
<string>Name:</string> <item row="1" column="0">
</property> <widget class="QLabel" name="addressLabel">
</widget> <property name="text">
</item> <string>Address:</string>
<item row="0" column="1"> </property>
<widget class="QLineEdit" name="nameLine"/> <property name="alignment">
</item> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<item row="1" column="0"> </property>
<widget class="QLabel" name="addressLabel"> </widget>
<property name="text"> </item>
<string>Address:</string> <item row="1" column="1">
</property> <widget class="QTextEdit" name="addressText"/>
<property name="alignment"> </item>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <item row="1" column="2">
</property> <layout class="QVBoxLayout" name="verticalLayout">
</widget> <item>
</item> <widget class="QPushButton" name="addButton">
<item row="1" column="1"> <property name="text">
<widget class="QTextEdit" name="addressText"/> <string>Add</string>
</item> </property>
<item row="1" column="2"> </widget>
<layout class="QVBoxLayout" name="verticalLayout"> </item>
<item> <item>
<widget class="QPushButton" name="addButton"> <widget class="QPushButton" name="submitButton">
<property name="text"> <property name="text">
<string>Add</string> <string>Submit</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="submitButton"> <widget class="QPushButton" name="cancelButton">
<property name="text"> <property name="text">
<string>Submit</string> <string>Cancel</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="cancelButton"> <spacer name="verticalSpacer">
<property name="text"> <property name="orientation">
<string>Cancel</string> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
</item> <size>
<item> <width>20</width>
<spacer name="verticalSpacer"> <height>40</height>
<property name="orientation"> </size>
<enum>Qt::Vertical</enum> </property>
</property> </spacer>
<property name="sizeHint" stdset="0"> </item>
<size> </layout>
<width>20</width> </item>
<height>40</height> <item row="2" column="1">
</size> <layout class="QHBoxLayout" name="horizontalLayout">
</property> <item>
</spacer> <widget class="QPushButton" name="nextButton">
</item> <property name="text">
</layout> <string>Previous</string>
</item> </property>
<item row="2" column="1"> </widget>
<layout class="QHBoxLayout" name="horizontalLayout"> </item>
<item> <item>
<widget class="QPushButton" name="nextButton"> <widget class="QPushButton" name="previousButton">
<property name="text"> <property name="text">
<string>Next</string> <string>Next</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<widget class="QPushButton" name="previousButton"> </item>
<property name="text"> </layout>
<string>Previous</string> </item>
</property> </layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment