From 9131bf7f12292da68b5eba29d1ec10c5f68a1e5c Mon Sep 17 00:00:00 2001
From: Kavindra Devi Palaraja <kavindra.palaraja@nokia.com>
Date: Thu, 16 Jul 2009 18:20:03 +0200
Subject: [PATCH] Doc - Modifying Part 2 to use ui->element instead of copy the
 ui's element all over the code

Reviewed-By: TrustMe
---
 doc/addressbook-sdk.qdoc                      | 31 +++----
 .../addressbook-sdk/part2/addressbook.cpp     | 84 ++++++++-----------
 .../addressbook-sdk/part2/addressbook.h       | 16 +---
 3 files changed, 48 insertions(+), 83 deletions(-)

diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc
index 259512694f7..f8fbc4c0fd5 100644
--- a/doc/addressbook-sdk.qdoc
+++ b/doc/addressbook-sdk.qdoc
@@ -310,27 +310,17 @@
 
     \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 widgets freely throughout the class.
-
-    \snippet examples/addressbook-sdk/part2/addressbook.h members1
-
-    The Qt types used for our private members, e.g., QPushButton, QLineEdit,
-    QTextEdit, etc., need to be included with the \c include directive, as
-    shown below:
+    Since the \c AddressBook class is a subclass of QWidget, Qt Creator
+    includes QWidget in the hedaer file.
 
     \snippet examples/addressbook-sdk/part2/addressbook.h include
 
-    \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.
 
-    \snippet examples/addressbook-sdk/part2/addressbook.h members2
+    \snippet examples/addressbook-sdk/part2/addressbook.h members
 
     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
@@ -339,16 +329,15 @@
     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.
+    constructor of \c AddressBook, we set up our fields by ensuring that
+    \c nameLine and \c addressText are read-only, so that we can only display
+    but not edit existing contact details.
 
-    \snippet examples/addressbook-sdk/part2/addressbook.cpp extract objects
+    \snippet examples/addressbook-sdk/part2/addressbook.cpp setup fields
 
-    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.
+    We also hide both \c submitButton and \c cancelButton as they will only 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
 
diff --git a/doc/examples/addressbook-sdk/part2/addressbook.cpp b/doc/examples/addressbook-sdk/part2/addressbook.cpp
index 6c68e40d32c..0e47c9002bd 100644
--- a/doc/examples/addressbook-sdk/part2/addressbook.cpp
+++ b/doc/examples/addressbook-sdk/part2/addressbook.cpp
@@ -6,33 +6,19 @@ AddressBook::AddressBook(QWidget *parent)
 {
     ui->setupUi(this);
 
-    //! [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 = ui->submitButton;
-    submitButton->hide();
-
-    cancelButton = new QPushButton;
-    cancelButton = ui->cancelButton;
-    cancelButton->hide();
-    //! [extract objects]
+    //! [setup fields]
+    ui->nameLine->setReadOnly(true);
+    ui->addressText->setReadOnly(true);
+    ui->submitButton->hide();
+    ui->cancelButton->hide();
+    //! [setup fields]
 
     //! [signal slot]
-    connect(addButton, SIGNAL(clicked()), this,
+    connect(ui->addButton, SIGNAL(clicked()), this,
                 SLOT(addContact()));
-    connect(submitButton, SIGNAL(clicked()), this,
+    connect(ui->submitButton, SIGNAL(clicked()), this,
                 SLOT(submitContact()));
-    connect(cancelButton, SIGNAL(clicked()), this,
+    connect(ui->cancelButton, SIGNAL(clicked()), this,
                 SLOT(cancel()));
     //! [signal slot]
 
@@ -49,27 +35,27 @@ AddressBook::~AddressBook()
 //! [addContact]
 void AddressBook::addContact()
 {
-    oldName = nameLine->text();
-    oldAddress = addressText->toPlainText();
+    oldName = ui->nameLine->text();
+    oldAddress = ui->addressText->toPlainText();
 
-    nameLine->clear();
-    addressText->clear();
+    ui->nameLine->clear();
+    ui->addressText->clear();
 
-    nameLine->setReadOnly(false);
-    nameLine->setFocus(Qt::OtherFocusReason);
-    addressText->setReadOnly(false);
+    ui->nameLine->setReadOnly(false);
+    ui->nameLine->setFocus(Qt::OtherFocusReason);
+    ui->addressText->setReadOnly(false);
 
-    addButton->setEnabled(false);
-    submitButton->show();
-    cancelButton->show();
+    ui->addButton->setEnabled(false);
+    ui->submitButton->show();
+    ui->cancelButton->show();
 }
 //! [addContact]
 
 //! [submitContact part1]
 void AddressBook::submitContact()
 {
-    QString name = nameLine->text();
-    QString address = addressText->toPlainText();
+    QString name = ui->nameLine->text();
+    QString address = ui->addressText->toPlainText();
 
     if (name == "" || address == "") {
         QMessageBox::information(this, tr("Empty Field"),
@@ -93,29 +79,29 @@ void AddressBook::submitContact()
 
 //! [submitContact part3]
     if (contacts.isEmpty()) {
-        nameLine->clear();
-        addressText->clear();
+        ui->nameLine->clear();
+        ui->addressText->clear();
     }
 
-    nameLine->setReadOnly(true);
-    addressText->setReadOnly(true);
-    addButton->setEnabled(true);
-    submitButton->hide();
-    cancelButton->hide();
+    ui->nameLine->setReadOnly(true);
+    ui->addressText->setReadOnly(true);
+    ui->addButton->setEnabled(true);
+    ui->submitButton->hide();
+    ui->cancelButton->hide();
 }
 //! [submitContact part3]
 
 //! [cancel]
 void AddressBook::cancel()
 {
-    nameLine->setText(oldName);
-    nameLine->setReadOnly(true);
+    ui->nameLine->setText(oldName);
+    ui->nameLine->setReadOnly(true);
 
-    addressText->setText(oldAddress);
-    addressText->setReadOnly(true);
+    ui->addressText->setText(oldAddress);
+    ui->addressText->setReadOnly(true);
 
-    addButton->setEnabled(true);
-    submitButton->hide();
-    cancelButton->hide();
+    ui->addButton->setEnabled(true);
+    ui->submitButton->hide();
+    ui->cancelButton->hide();
 }
 //! [cancel]
diff --git a/doc/examples/addressbook-sdk/part2/addressbook.h b/doc/examples/addressbook-sdk/part2/addressbook.h
index 69486cb8cf2..6bd34276907 100644
--- a/doc/examples/addressbook-sdk/part2/addressbook.h
+++ b/doc/examples/addressbook-sdk/part2/addressbook.h
@@ -3,9 +3,7 @@
 
 //! [include]
 #include <QtGui/QWidget>
-#include <QtGui/QPushButton>
-#include <QtGui/QLineEdit>
-#include <QtGui/QTextEdit>
+#include <QtCore/QMap>
 #include <QtGui/QMessageBox>
 //! [include]
 
@@ -32,19 +30,11 @@ public slots:
 private:
     Ui::AddressBook *ui;
 
-//! [members1]
-    QPushButton *addButton;
-    QPushButton *submitButton;
-    QPushButton *cancelButton;
-    QLineEdit *nameLine;
-    QTextEdit *addressText;
-//! [members1]
-
-//! [members2]
+//! [members]
     QMap<QString, QString> contacts;
     QString oldName;
     QString oldAddress;
-//! [members2]
+//! [members]
 };
 
 #endif // ADDRESSBOOK_H
-- 
GitLab