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

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

RevBy:    TrustMe
parent 0b903294
No related branches found
No related tags found
No related merge requests found
...@@ -269,12 +269,13 @@ ...@@ -269,12 +269,13 @@
\section1 Placing Widgets on the Form \section1 Placing Widgets on the Form
Now that we have the labels and input fields set up, we add push buttons to We shall continue with the form we had from the last chapter; we have the
complete the process of adding a contact. So, we begin by breaking the labels and input fields set up, but we need to add push buttons to complete
existing layouts. Then, we add three push buttons. Double-click on each of the process of adding a contact. So, we begin by breaking the existing
them to set their text to "Add", "Submit", and "Cancel". We now require a layouts. Then, we add three push buttons. Double-click on each of them to
vertical spacer to ensure that the push buttons will be laid out neatly; set their text to "Add", "Submit", and "Cancel". We now require a vertical
drag one from the \gui{Widget Box}. 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 Next, lay out these three push buttons and the spacer vertically, by
selecting all three of them (using the \key{Ctrl + click}) and choosing selecting all three of them (using the \key{Ctrl + click}) and choosing
...@@ -312,6 +313,8 @@ ...@@ -312,6 +313,8 @@
Next, we have to provide private members for the \c AddressBook class so Next, we have to provide private members for the \c AddressBook class so
that we can access these members freely throughout the application. 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 \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 actual object. You can modify them by double-clicking on their names within
\QD's \gui{Object Inspector}. \QD's \gui{Object Inspector}.
...@@ -321,4 +324,34 @@ ...@@ -321,4 +324,34 @@
purpose as it holds a key-value pair: the contact's name as the \e key, and 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. 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) ...@@ -6,14 +6,37 @@ AddressBook::AddressBook(QWidget *parent)
{ {
ui->setupUi(this); 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; addButton = ui->addButton;
submitButton = new QPushButton(); submitButton = new QPushButton;
submitButton = ui->submitButton; submitButton = ui->submitButton;
submitButton->hide();
cancelButton = new QPushButton(); cancelButton = new QPushButton;
cancelButton = ui->cancelButton; 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() AddressBook::~AddressBook()
......
...@@ -17,17 +17,17 @@ ...@@ -17,17 +17,17 @@
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="nameEdit"> <widget class="QLabel" name="nameLabel">
<property name="text"> <property name="text">
<string>Name:</string> <string>Name:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/> <widget class="QLineEdit" name="nameLine"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="addressEdit"> <widget class="QLabel" name="addressLabel">
<property name="text"> <property name="text">
<string>Address:</string> <string>Address:</string>
</property> </property>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QTextEdit" name="textEdit"/> <widget class="QTextEdit" name="addressText"/>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
......
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