From 0b90329427742da68d33a403afc62d40932f4702 Mon Sep 17 00:00:00 2001 From: Kavindra Devi Palaraja <kavindra.palaraja@nokia.com> Date: Tue, 2 Jun 2009 17:42:27 +0200 Subject: [PATCH] Fixes: Doc - more of the tutorial RevBy: TrustMe --- doc/addressbook-sdk.qdoc | 29 +++- .../addressbook-sdk/part2/addressbook.cpp | 23 ++- .../addressbook-sdk/part2/addressbook.h | 24 +++ .../addressbook-sdk/part2/addressbook.ui | 140 +++++++++--------- 4 files changed, 140 insertions(+), 76 deletions(-) diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc index c60ad27ee06..6aeff092a6d 100644 --- a/doc/addressbook-sdk.qdoc +++ b/doc/addressbook-sdk.qdoc @@ -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. */ diff --git a/doc/examples/addressbook-sdk/part2/addressbook.cpp b/doc/examples/addressbook-sdk/part2/addressbook.cpp index 38e9404f31a..353c65a70e0 100644 --- a/doc/examples/addressbook-sdk/part2/addressbook.cpp +++ b/doc/examples/addressbook-sdk/part2/addressbook.cpp @@ -1,4 +1,3 @@ -//! [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() +{ +} diff --git a/doc/examples/addressbook-sdk/part2/addressbook.h b/doc/examples/addressbook-sdk/part2/addressbook.h index c5937d435b8..3021d5b9b09 100644 --- a/doc/examples/addressbook-sdk/part2/addressbook.h +++ b/doc/examples/addressbook-sdk/part2/addressbook.h @@ -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 diff --git a/doc/examples/addressbook-sdk/part2/addressbook.ui b/doc/examples/addressbook-sdk/part2/addressbook.ui index c3683933014..1e5bf5ed22c 100644 --- a/doc/examples/addressbook-sdk/part2/addressbook.ui +++ b/doc/examples/addressbook-sdk/part2/addressbook.ui @@ -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/> -- GitLab