diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc index 1974c129edec49962354569525e650d0a2a908e6..3194ad70b2f3d60e55b4519f993f496c763ce77d 100644 --- a/doc/addressbook-sdk.qdoc +++ b/doc/addressbook-sdk.qdoc @@ -315,6 +315,12 @@ \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: + + \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}. @@ -727,6 +733,7 @@ dialog that can prompt the user for a contact's name. Qt provides QDialog, which we subclass in this chapter, to implement a FindDialog class. + \section1 Designing \c FindDialog #image @@ -743,6 +750,7 @@ in a horizontal layout. Then set a top level layout - either horizontal or vertical. + \section1 Implementing \c FindDialog Let's look at \c{FindDialog}'s header file. Here, we need to provide @@ -751,8 +759,38 @@ \snippet examples/addressbook-sdk/part5/finddialog.h private members + We define a public function, \c getFindText(), to be used by classes that + instantiate \c FindDialog. This function allows the these classes to obtain + the search string entered by the user. A public slot, \c findClicked(), is + also defined to handle the search string when the user clicks the \gui Find + button. + + \snippet examples/addressbook-sdk/part5/finddialog.h getFindText + \dots + \snippet examples/addressbook-sdk/part5/finddialog.h findClicked + + Now, lets look at our constructor in the \c{finddialog.cpp} file. Here, we + set up the private variables, \c lineEdit, \c findButton, and \c findText. + + \snippet examples/addressbook-sdk/part5/finddialog.cpp constructor + + We connect our signals to their respective slots. Notice that + \c{findButton}'s \l{QPushButton:}{clicked()} signal is connected to + \c findClicked() and \l{QDialog::}{accept()}. The \l{QDialog::}{accept()} + slot provided by QDialog hides the dialog and sets the result code to + \l{QDialog::}{Accepted}. We use this function to help \c{AddressBook}'s + \c findContact() function know when the \c FindDialog object has been + closed. We will explain this logic in further detail when discussing the + \c findContact() function. + + \image addressbook-tutorial-part5-signals-and-slots.png + In \c findClicked(), we validate to ensure that the user did not click the + \gui Find button without entering a contact's name. Then, we set + \c findText to the search string, extracted from \c lineEdit. After that, + we clear the contents of \c lineEdit and hide the dialog. + \snippet examples/addressbook-sdk/part5/finddialog.cpp findClicked */ diff --git a/doc/examples/addressbook-sdk/part2/addressbook.h b/doc/examples/addressbook-sdk/part2/addressbook.h index efea5d177b3d2f359fb0278441c7a4e373f56b25..69486cb8cf2684d67472f98bc4fe7d1b0d3072ea 100644 --- a/doc/examples/addressbook-sdk/part2/addressbook.h +++ b/doc/examples/addressbook-sdk/part2/addressbook.h @@ -1,13 +1,13 @@ -//! [class definition] #ifndef ADDRESSBOOK_H #define ADDRESSBOOK_H +//! [include] #include <QtGui/QWidget> #include <QtGui/QPushButton> #include <QtGui/QLineEdit> #include <QtGui/QTextEdit> #include <QtGui/QMessageBox> - +//! [include] namespace Ui { @@ -48,4 +48,3 @@ private: }; #endif // ADDRESSBOOK_H -//! [class definition] diff --git a/doc/examples/addressbook-sdk/part5/finddialog.cpp b/doc/examples/addressbook-sdk/part5/finddialog.cpp index 89ee5e083a2e954339dfad0696e53ef5e01a7d5c..1a464b70903511d3680df80657f1cdc42a30d8d1 100644 --- a/doc/examples/addressbook-sdk/part5/finddialog.cpp +++ b/doc/examples/addressbook-sdk/part5/finddialog.cpp @@ -1,6 +1,7 @@ #include "finddialog.h" #include "ui_finddialog.h" +//! [constructor] FindDialog::FindDialog(QWidget *parent) : QDialog(parent), m_ui(new Ui::FindDialog) @@ -18,12 +19,14 @@ FindDialog::FindDialog(QWidget *parent) : setWindowTItle(tr("Find a Contact")); } +//! [constructor] FindDialog::~FindDialog() { delete m_ui; } +//! [findClicked] void FindDialog::findClicked() { QString text = lineEdit->text(); @@ -38,6 +41,7 @@ void FindDialog::findClicked() hide(); } } +//! [findClicked] QString FindDialog::getFindText() { diff --git a/doc/examples/addressbook-sdk/part5/finddialog.h b/doc/examples/addressbook-sdk/part5/finddialog.h index 9df1df899885d98a1759945e085d213fb6561736..aef5aee9fa37e48c8a12435b59640c081f40b78a 100644 --- a/doc/examples/addressbook-sdk/part5/finddialog.h +++ b/doc/examples/addressbook-sdk/part5/finddialog.h @@ -2,8 +2,8 @@ #define FINDDIALOG_H #include <QtGui/QDialog> -#include <QLineEdit> -#include <QPushButton> +#include <QtGui/QLineEdit> +#include <QtGui/QPushButton> namespace Ui { class FindDialog; @@ -14,10 +14,14 @@ class FindDialog : public QDialog { public: FindDialog(QWidget *parent = 0); ~FindDialog(); +//! [getFindText] QString getFindText(); +//! [getFindText] +//! [findClicked] public slots: void findClicked(); +//! [findClicked] //! [private members] private: diff --git a/doc/images/addressbook-tutorial-part5-signals-and-slots.png b/doc/images/addressbook-tutorial-part5-signals-and-slots.png new file mode 100644 index 0000000000000000000000000000000000000000..1771e7bbbf54d69aed3121adf4a96ff8ec7b6353 Binary files /dev/null and b/doc/images/addressbook-tutorial-part5-signals-and-slots.png differ