Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
d37363f3
Commit
d37363f3
authored
Jul 01, 2009
by
Kavindra Devi Palaraja
Browse files
Doc - Finishing up Part 5, only screenshots pending
Reviewed-By: TrustMe
parent
3264878f
Changes
4
Hide whitespace changes
Inline
Side-by-side
doc/addressbook-sdk.qdoc
View file @
d37363f3
...
...
@@ -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
*/
...
...
doc/examples/addressbook-sdk/part5/addressbook.cpp
View file @
d37363f3
...
...
@@ -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
);
...
...
doc/examples/addressbook-sdk/part5/addressbook.h
View file @
d37363f3
...
...
@@ -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
doc/examples/addressbook-sdk/part5/finddialog.cpp
View file @
d37363f3
#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
()));
setWindowT
I
tle
(
tr
(
"Find a Contact"
));
setWindowT
i
tle
(
tr
(
"Find a Contact"
));
}
//! [constructor]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment