summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorKavindra Devi Palaraja <kavindra.palaraja@nokia.com>2009-07-01 14:04:05 +0200
committerKavindra Devi Palaraja <kavindra.palaraja@nokia.com>2009-07-01 14:04:05 +0200
commitd37363f3b65b0d2175006123eb2fde893ed98d3e (patch)
treec06190477ba1919678817e9f930a057191c00d9a /doc
parent3264878fe6eee535bc988642324b3ec9e8caf655 (diff)
downloadqt-creator-d37363f3b65b0d2175006123eb2fde893ed98d3e.tar.gz
Doc - Finishing up Part 5, only screenshots pending
Reviewed-By: TrustMe
Diffstat (limited to 'doc')
-rw-r--r--doc/addressbook-sdk.qdoc50
-rw-r--r--doc/examples/addressbook-sdk/part5/addressbook.cpp7
-rw-r--r--doc/examples/addressbook-sdk/part5/addressbook.h6
-rw-r--r--doc/examples/addressbook-sdk/part5/finddialog.cpp3
4 files changed, 60 insertions, 6 deletions
diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc
index 6e457d4181..c7f555fb32 100644
--- a/doc/addressbook-sdk.qdoc
+++ b/doc/addressbook-sdk.qdoc
@@ -804,20 +804,60 @@
\section1 The AddressBook Class
-
To ensure that we can use \c FindDialog from within our \c AddressBook
class, we include \c finddialog.h in the \c addressbook.h file.
- \snippet examples/addressbook-sdk/part5/addressbook.cpp include
+ \snippet examples/addressbook-sdk/part5/addressbook.h include
So far, all our address book features have a QPushButton and a
corresponding slot. Similarly, for the \gui Find feature, we have
\c findButton and \c findContact().
- Within the \c AddressBook class's constructor, we instantiate our private
- objects, \c findButton and \c findDialog:
+ \snippet examples/addressbook-sdk/part5/addressbook.h findContact
+ \dots
+ \snippet examples/addressbook-sdk/part5/addressbook.h findButton
+
+ Lastly, we declare the private variable, \c dialog, which we will use to
+ refer to an instance of \c FindDialog.
+
+ Once we have instantiated a dialog, we might want to use it more than once;
+ using a private variable allows us to refer to it from more than one place
+ in the class.
+
+ Within the \c AddressBook class's constructor, we insantiate our private
+ objects, \c findButton and \c dialog:
+
+ \snippet examples/addressbook-sdk/part5/addressbook.cpp private members
+
+ Next, we connect the \c{findButton}'s \l{QPushButton::}{clicked()} signal
+ to \c findContact().
+
+ \snippet examples/addressbook-sdk/part5/addressbook.cpp signal slot
+
+ Now, all that is left is the code for our \c findContact() function:
+
+ \snippet examples/addressbook-sdk/part5/addressbook.cpp findContact
+
+ We start out by displaying the \c FindDialog instance, \c dialog. This is
+ when the user enters a contact name to look up. Once the user clicks the
+ dialog's \c findButton, the dialog is hidden and the result code is set to
+ QDialog::Accepted. THis ensures that our \c if statement is always true.
+
+ We then proceed to extract the search string, which in this case is
+ \c contactName, using \c{FindDialog}'s \c getFindText() function. If the
+ contact exists in our address book, we display it immediately. Otherwise,
+ we display the QMessageBox shown below to indicate that their search
+ failed.
+
+ # image
+
+ The concept behind finding a contact only applies for cases where we have
+ more than two contacts in our address book. Hence, we implement this
+ behavior by modifying our \c{Navigation Mode} within our
+ \c updateInterface() function, by only enabling the \gui Find button when
+ we have more than two contacts.
- \snippet examples/addressbook-sdk/part5/addressbook.cpp
+ \snippet examples/addressbook-sdk/part5/addressbook.cpp enable
*/
diff --git a/doc/examples/addressbook-sdk/part5/addressbook.cpp b/doc/examples/addressbook-sdk/part5/addressbook.cpp
index 0e7b361ddc..22b0340bc1 100644
--- a/doc/examples/addressbook-sdk/part5/addressbook.cpp
+++ b/doc/examples/addressbook-sdk/part5/addressbook.cpp
@@ -41,10 +41,12 @@ AddressBook::AddressBook(QWidget *parent)
removeButton = ui->removeButton;
removeButton->setEnabled(false);
+//! [private members]
findButton = new QPushButton;
findButton = ui->findButton;
dialog = new FindDialog;
+//! [private members]
connect(addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
@@ -60,8 +62,10 @@ AddressBook::AddressBook(QWidget *parent)
SLOT(editContact()));
connect(removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
+//! [signal slot]
connect(findButton, SIGNAL(clicked()), this,
SLOT(findContact()));
+//! [signal slot]
setWindowTitle(tr("Simple Address Book"));
}
@@ -234,6 +238,9 @@ void AddressBook::updateInterface(Mode mode)
int number = contacts.size();
editButton->setEnabled(number >= 1);
removeButton->setEnabled(number >= 1);
+//! [enable]
+ findButton->setEnabled(number > 2);
+//! [enable]
nextButton->setEnabled(number > 1);
previousButton->setEnabled(number >1);
diff --git a/doc/examples/addressbook-sdk/part5/addressbook.h b/doc/examples/addressbook-sdk/part5/addressbook.h
index c6f9f60728..2a41948351 100644
--- a/doc/examples/addressbook-sdk/part5/addressbook.h
+++ b/doc/examples/addressbook-sdk/part5/addressbook.h
@@ -32,7 +32,9 @@ public slots:
void removeContact();
void next();
void previous();
+//! [findContact]
void findContact();
+//! [findContact]
private:
Ui::AddressBook *ui;
@@ -45,7 +47,9 @@ private:
QPushButton *removeButton;
QPushButton *nextButton;
QPushButton *previousButton;
+//! [findButton]
QPushButton *findButton;
+//! [findButton]
QLineEdit *nameLine;
QTextEdit *addressText;
@@ -53,7 +57,9 @@ private:
QString oldName;
QString oldAddress;
Mode currentMode;
+//! [dialog]
FindDialog *dialog;
+//! [dialog]
};
#endif // ADDRESSBOOK_H
diff --git a/doc/examples/addressbook-sdk/part5/finddialog.cpp b/doc/examples/addressbook-sdk/part5/finddialog.cpp
index 63e04a5103..27914974a1 100644
--- a/doc/examples/addressbook-sdk/part5/finddialog.cpp
+++ b/doc/examples/addressbook-sdk/part5/finddialog.cpp
@@ -1,5 +1,6 @@
#include "finddialog.h"
#include "ui_finddialog.h"
+#include <QMessageBox>
//! [constructor]
FindDialog::FindDialog(QWidget *parent) :
@@ -17,7 +18,7 @@ FindDialog::FindDialog(QWidget *parent) :
connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
- setWindowTItle(tr("Find a Contact"));
+ setWindowTitle(tr("Find a Contact"));
}
//! [constructor]