Commit 0b903294 authored by Kavindra Devi Palaraja's avatar Kavindra Devi Palaraja Committed by con

Fixes: Doc - more of the tutorial

RevBy:    TrustMe
parent de8dcb7b
......@@ -269,7 +269,6 @@
\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
......@@ -292,6 +291,34 @@
on the widget and selecting \gui{Lay out Horizontally} or
\gui{Lay out Vertically}.
The final design of the form is shown in the screenshot below:
## image
\section1 The AddressBook Class
To ensure that the Address Book reacts to user interaction, we need to
write slots for each push button that we added earlier. A slot is a
function that responds to a particular signal. We will discuss this
concept in further detail below. However, for an overview of Qt's signals
and slots concept, you can refer to the \l{Signals and Slots} document.
In the \l{examples/addressbook-sdk/part2/addressbook.h}{\c addressbook.h}
file, we add the following code:
\snippet examples/addressbook-sdk/part2/addressbook.h slot definition
Next, we have to provide private members for the \c AddressBook class so
that we can access these members freely throughout the application.
\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}.
We need a container to store our address book contacts, so that we can
traverse and display them. A QMap object, \c contacts, is used for this
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.
*/
//! [class implementation]
#include "addressbook.h"
#include "ui_addressbook.h"
......@@ -6,10 +5,30 @@ AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBookClass)
{
ui->setupUi(this);
addButton = new QPushButton();
addButton = ui->addButton;
submitButton = new QPushButton();
submitButton = ui->submitButton;
cancelButton = new QPushButton();
cancelButton = ui->cancelButton;
}
AddressBook::~AddressBook()
{
delete ui;
}
//! [class implementation]
void AddressBook::addContact()
{
}
void AddressBook::submitContact()
{
}
void AddressBook::cancel()
{
}
......@@ -3,6 +3,9 @@
#define ADDRESSBOOK_H
#include <QtGui/QWidget>
#include <QtGui/QPushButton>
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
namespace Ui
{
......@@ -17,8 +20,29 @@ public:
AddressBook(QWidget *parent = 0);
~AddressBook();
//! [slot definition]
public slots:
void addContact();
void submitContact();
void cancel();
//! [slot definition]
private:
Ui::AddressBookClass *ui;
//! [members1]
QPushButton *addButton;
QPushButton *submitButton;
QPushButton *cancelButton;
QLineEdit *nameLine;
QTextEdit *addressText;
//! [members1]
//! [members2]
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
//! [members2]
};
#endif // ADDRESSBOOK_H
......
......@@ -13,79 +13,73 @@
<property name="windowTitle">
<string>AddressBook</string>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>413</width>
<height>225</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameEdit">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressEdit">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="textEdit"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameEdit">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressEdit">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="textEdit"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
......
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