Commit c9a00bff authored by Kavindra Devi Palaraja's avatar Kavindra Devi Palaraja Committed by con

Fixes: Doc - more of Part2, hoping to finish it today

RevBy:    TrustMe
parent 0b903294
......@@ -269,12 +269,13 @@
\section1 Placing Widgets on the Form
Now that we have the labels and input fields set up, we add push buttons to
complete the process of adding a contact. So, we begin by breaking the
existing layouts. Then, we add three push buttons. Double-click on each of
them to set their text to "Add", "Submit", and "Cancel". We now require a
vertical spacer to ensure that the push buttons will be laid out neatly;
drag one from the \gui{Widget Box}.
We shall continue with the form we had from the last chapter; we have the
labels and input fields set up, but we need to add push buttons to complete
the process of adding a contact. So, we begin by breaking the existing
layouts. Then, we add three push buttons. Double-click on each of them to
set their text to "Add", "Submit", and "Cancel". We now require a vertical
spacer to ensure that the push buttons will be laid out neatly; drag one
from the \gui{Widget Box}.
Next, lay out these three push buttons and the spacer vertically, by
selecting all three of them (using the \key{Ctrl + click}) and choosing
......@@ -312,6 +313,8 @@
Next, we have to provide private members for the \c AddressBook class so
that we can access these members freely throughout the application.
\snippet examples/addressbook-sdk/part2/addressbook.h members1
\note The names, e.g., \c addButton etc., correspond to the name of the
actual object. You can modify them by double-clicking on their names within
\QD's \gui{Object Inspector}.
......@@ -321,4 +324,34 @@
purpose as it holds a key-value pair: the contact's name as the \e key, and
the contact's address as the \e value.
\snippet examples/addressbook-sdk/part2/addressbook.h members2
We also declare two private QString objects, \c oldName and \c oldAddress.
These objects are needed to hold the name and address of hte contact that
was last displayed, before the user clicked \gui Add. So, when the user
clicks \gui Cancel, we can revert to displaying the details of the last
contact.
Let's move on to implementing the slots we defined earlier. Within the
constructor of \c AddressBook, we extract the widgets from the form using
the \c ui object by pointing our private members to them.
\snippet examples/addressbook-sdk/part2/addressbook.cpp extract objects
Then we set \c nameLine and \c addressText to read-only, so that we can
only display but not edit existing contact details. We also hide
\c submitButton and \c cancelButton as they will only be be displayed
when the user clicks \gui Add, and this is handled by the \c addContact()
function discussed below.
\snippet examples/addressbook-sdk/part2/addressbook.cpp signal slot
We connect the push buttons' \l{QAbstractButton::clicked()}{clicked()}
signal to their respective slots. The figure below illustrates this.
#image
\section2 The \c{addContact()} Function
*/
......@@ -6,14 +6,37 @@ AddressBook::AddressBook(QWidget *parent)
{
ui->setupUi(this);
addButton = new QPushButton();
//! [extract objects]
nameLine = new QLineEdit;
nameLine = ui->nameLine;
nameLine->setReadOnly(true);
addressText = new QTextEdit;
addressText = ui->addressText;
addressText->setReadOnly(true);
addButton = new QPushButton;
addButton = ui->addButton;
submitButton = new QPushButton();
submitButton = new QPushButton;
submitButton = ui->submitButton;
submitButton->hide();
cancelButton = new QPushButton();
cancelButton = new QPushButton;
cancelButton = ui->cancelButton;
cancelButton->hide();
//! [extract objects]
//! [signal slot]
connect(addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
//! [signal slot]
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
......
......@@ -17,17 +17,17 @@
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameEdit">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressEdit">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
......@@ -37,7 +37,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="textEdit"/>
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment