Commit 273d849046de37a5446f00f4e5be6249551d9dfd

  • avatar
  • con <qtc-committer @no…a.com> (Committer)
  • Mon Oct 12 16:34:45 CEST 2009
  • avatar
  • Daniel Molkentin (Author)
  • Mon Oct 12 14:29:40 CEST 2009
Fixes to tutorial, added missing screenshots.

Reviewed-By: con
(cherry picked from commit c48c3cb46679fd9c73311c0d29928d058a228fd1)
  
348348 \snippet examples/addressbook-sdk/part2/addressbook.h members
349349
350350 We also declare two private QString objects, \c oldName and \c oldAddress.
351 These objects are needed to hold the name and address of hte contact that
351 These objects are needed to hold the name and address of the contact that
352352 was last displayed, before the user clicked \gui Add. So, when the user
353353 clicks \gui Cancel, we can revert to displaying the details of the last
354354 contact.
529529
530530 \snippet examples/addressbook-sdk/part3/addressbook.cpp enable navigation
531531
532 We also include these lins of code in the \c cancel() function.
532 We also include these lines of code in the \c cancel() function.
533533
534534 Recall that we intend to emulate a circularly-linked list with our QMap
535535 object, \c contacts. So in the \c next() function, we obtain an iterator
735735 In this chapter, we look at ways to locate contacts and addresses in the
736736 address book application.
737737
738 # image
738 \image addressbook-tutorial-part5-screenshot.png
739739
740740 As we keep adding contacts to our address book, it becomes tedious to
741741 navigate them with the \gui Next and \gui Previous buttons. In this case,
750750
751751 \section1 Designing The FindDialog
752752
753 #image
753 \image addressbook-tutorial-part5-finddialog-in-designer.png
754754
755 We begin by adding a new \c{.ui} file to our project. Right click on your
755 We begin by adding a new \c{.ui} file and a corresponding class to our project. Right click on your
756756 project and select \gui{Add New...}. In the \gui{New File} dialog, select
757 \gui{Qt Designer Form}. In the \gui{Qt Designer Form} dialog, select
758 \e{Dialog without buttons}. Name it \c{finddialog.ui} and add it to your
759 project. The \QD plugin within Qt Creator will now display your new form.
757 \gui{Qt Designer Form Class}. In the \gui{Qt Designer Form Class} dialog, select
758 \e{Dialog without buttons}. Name the class \c{FindDialog} and add the files it to your
759 project. Open your new form in the \QD form editor within Qt Creator by
760 double-clicking on the \c{finddialog.ui} file in the \gui{Project Sidebar}.
760761
761762 To replicate the screenshot above, we need a label, a line edit, and a push
762763 button. Drag these onto your form. Set their text accordingly and name them
782782
783783 \snippet examples/addressbook-sdk/part5/finddialog.cpp constructor
784784
785 We connect our signals to their respective slots. Notice that
786 \c{findButton}'s \l{QPushButton:}{clicked()} signal is connected to
787 \c findClicked() and \l{QDialog::}{accept()}. The \l{QDialog::}{accept()}
788 slot provided by QDialog hides the dialog and sets the result code to
789 \l{QDialog::}{Accepted}. We use this function to help \c{AddressBook}'s
790 \c findContact() function know when the \c FindDialog object has been
791 closed. We will explain this logic in further detail when discussing the
792 \c findContact() function.
793
794 \image addressbook-tutorial-part5-signals-and-slots.png
795
796785 In \c findClicked(), we validate to ensure that the user did not click the
797786 \gui Find button without entering a contact's name. Then, we set
798787 \c findText to the search string, extracted from \c lineEdit. After that,
789789
790790 \snippet examples/addressbook-sdk/part5/finddialog.cpp findClicked
791791
792 The \c findText variable has a public getter function, \c getFindText(),
793 associated with it. Since we only ever set \c findText directly in both
794 the constructor and in hte \c findClicked() function, we do not create a
795 setter function to accompany \c getFindText(). Because \c getFindText() is
796 public, classes instantiating and using \c FindDialog can always access the
797 search string that the user has entered and accepted.
792 \c findText() is public, which makes it easy for classes instantiating
793 and using \c FindDialog to access the search string that the user has entered
794 and accepted.
798795
799796 \snippet examples/addressbook-sdk/part5/finddialog.cpp findText
800797
798 Finally, we connect our signals to their respective slots. Notice that
799 \c{findButton}'s \l{QPushButton::}{clicked()} signal is connected to
800 \c findClicked(), which calls \l{QDialog::}{accept()} or \l{QDialog::}{reject()}.
801 The \l{QDialog::}{accept()} slot provided by QDialog hides the dialog
802 and sets the result code to \l{QDialog::}{Accepted}, while \l{QDialog::}{reject()}
803 sets it to \l{QDialog::}{Rejected} accordingly. We use this function to help
804 \c{AddressBook}'s \c findContact() function know when the \c FindDialog object has been
805 closed. We will explain this logic in further detail when discussing the
806 \c findContact() function.
801807
808 \image addressbook-tutorial-part5-signals-and-slots.png
809
810
802811 \section1 The AddressBook Class
803812
804813 To ensure that we can use \c FindDialog from within our \c AddressBook
817817
818818 So far, all our address book features have a QPushButton and a
819819 corresponding slot. Similarly, for the \gui Find feature, we have
820 \c findButton and \c findContact().
820 \c{ui->findButton} and \c findContact().
821821
822822 \snippet examples/addressbook-sdk/part5/addressbook.h slot definition
823823
837837 We start out by displaying the \c FindDialog instance, \c dialog. This is
838838 when the user enters a contact name to look up. Once the user clicks the
839839 dialog's \c findButton, the dialog is hidden and the result code is set to
840 QDialog::Accepted. THis ensures that our \c if statement is always true.
840 either QDialog::Accepted or QDialog::Rejected by the FindDialog's
841 \c findClicked() method. This ensures that we only search for a contact
842 if the user typed something in the FindDialog's line edit.
841843
842844 We then proceed to extract the search string, which in this case is
843 \c contactName, using \c{FindDialog}'s \c getFindText() function. If the
845 \c contactName, using \c{FindDialog}'s \c findText() function. If the
844846 contact exists in our address book, we display it immediately. Otherwise,
845847 we display the QMessageBox shown below to indicate that their search
846848 failed.
847849
848 # image
850 \image addressbook-tutorial-part5-dialogbox.png
849851
850852 The concept behind finding a contact only applies for cases where we have
851853 more than two contacts in our address book. Hence, we implement this
871871 This chapter covers the file handling features of Qt that we used to write
872872 loading and saving routines for the address book application.
873873
874 # screenshot
874 \image addressbook-tutorial-part6-screenshot.png
875875
876876 Although browsing and searching for contacts are useful features, our
877877 address book is not really ready for use until we can save existing
911911 the push buttons.
912912
913913
914 # screenshot of property editor
914 \image addressbook-tutorial-part6-propertyeditor.png
915915
916916
917917 \section1 The AddressBook Class
936936
937937 The file dialog that pops up is displayed in the screenshot below:
938938
939 #screenshot
939 \image addressbook-tutorial-part6-savedialog.png
940940
941941 If \c fileName is not empty, we create a QFile object, \c file, with
942942 \c fileName. The QFile object works with QDataStream as QFile is a
968968 On Windows, for example, this function pops up a native file dialog, as
969969 shown in the following screenshot.
970970
971 # screenshot
971 \image addressbook-tutorial-part6-opendialog.png
972972
973973 If \c fileName is not empty, again, we use a QFile object, \c file, and
974974 attempt to open it in \l{QIODevice::}{ReadOnly} mode. Similar to our
990990 validate the data obtained to ensure that the file we read from actually
991991 contains address book contacts. If it does, we display the first contact;
992992 otherwise, we display a QMessageBox to inform the user about the problem.
993 Lastly, we update the interface to enable and disable the push buttons
994 accordingly.
993 Lastly, we connect the \c clicked() signal of the push buttons
994 with the \c loadFromFile() and \c saveToFile():
995995
996 \snippet examples/addressbook-sdk/part6/addressbook.cpp connectSlots
997
996998*/
997999
9981000
10171017 \c exportButton as its \c objectName. The \c toolTip property is set to
10181018 \gui{Export as vCard}.
10191019
1020 # screenshot
1020 \image addressbook-tutorial-part7-screenshot.png
10211021
10221022 \section1 The AddressBook Class
10231023
  
1diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc
2index 0441666..7012ea6 100644
3--- a/doc/addressbook-sdk.qdoc
4+++ b/doc/addressbook-sdk.qdoc
5@@ -139,7 +139,7 @@
6 \section1 Placing Widgets on The Form
7
8 In the \gui{Project Sidebar}, double-click on the \c{addressbook.ui} file.
9- The \QD plugin will be launched, allowing you to design your program's user
10+ The \QD form editor will be launched, allowing you to design your program's user
11 interface.
12
13 We require two \l{QLabel}s to label the input fields as well as a QLineEdit
14@@ -156,6 +156,7 @@
15 diagram below shows the layout cells and the position of our widgets. Place
16 your widgets accordingly and save the form by choosing
17 \gui{File | Save} or using the \key{Ctrl+S} shortcut.
18+ (We have to actually layout the widgets in a grid layout, this step seems to be missing to me?)
19
20 \image addressbook-tutorial-part1-labeled-screenshot.png
21
22@@ -311,7 +312,7 @@
23 \snippet examples/addressbook-sdk/part2/addressbook.h slot definition
24
25 Since the \c AddressBook class is a subclass of QWidget, Qt Creator
26- includes QWidget in the hedaer file.
27+ includes QWidget in the header file.
28
29 \snippet examples/addressbook-sdk/part2/addressbook.h include
30
31@@ -323,7 +324,7 @@
32 \snippet examples/addressbook-sdk/part2/addressbook.h members
33
34 We also declare two private QString objects, \c oldName and \c oldAddress.
35- These objects are needed to hold the name and address of hte contact that
36+ These objects are needed to hold the name and address of the contact that
37 was last displayed, before the user clicked \gui Add. So, when the user
38 clicks \gui Cancel, we can revert to displaying the details of the last
39 contact.
40@@ -499,7 +500,7 @@
41
42 \snippet examples/addressbook-sdk/part3/addressbook.cpp enable navigation
43
44- We also include these lins of code in the \c cancel() function.
45+ We also include these lines of code in the \c cancel() function.
46
47 Recall that we intend to emulate a circularly-linked list with our QMap
48 object, \c contacts. So in the \c next() function, we obtain an iterator
49@@ -722,11 +723,12 @@
50
51 #image
52
53- We begin by adding a new \c{.ui} file to our project. Right click on your
54+ We begin by adding a new \c{.ui} file and a corresponding class to our project. Right click on your
55 project and select \gui{Add New...}. In the \gui{New File} dialog, select
56- \gui{Qt Designer Form}. In the \gui{Qt Designer Form} dialog, select
57- \e{Dialog without buttons}. Name it \c{finddialog.ui} and add it to your
58- project. The \QD plugin within Qt Creator will now display your new form.
59+ \gui{Qt Designer Form Class}. In the \gui{Qt Designer Form Class} dialog, select
60+ \e{Dialog without buttons}. Name the class \c{FindDialog} and add the files it to your
61+ project. Open your new form in the \QD form editor within Qt Creator by
62+ double-clicking on the \c{finddialog.ui} file in the \gui{Project Sidebar}.
63
64 To replicate the screenshot above, we need a label, a line edit, and a push
65 button. Drag these onto your form. Set their text accordingly and name them
66@@ -759,6 +761,9 @@
67 \c findContact() function know when the \c FindDialog object has been
68 closed. We will explain this logic in further detail when discussing the
69 \c findContact() function.
70+ (The above paragraph is not up to date, since clicked() is not connected
71+ to accept(). The description of accept() can move below to the implementation
72+ of findClicked().)
73
74 \image addressbook-tutorial-part5-signals-and-slots.png
75
76@@ -766,17 +771,17 @@
77 \gui Find button without entering a contact's name. Then, we set
78 \c findText to the search string, extracted from \c lineEdit. After that,
79 we clear the contents of \c lineEdit and hide the dialog.
80+ (There is no findText member. The description of accept() should move here, together
81+ with words about reject.)
82
83 \snippet examples/addressbook-sdk/part5/finddialog.cpp findClicked
84
85- The \c findText variable has a public getter function, \c getFindText(),
86- associated with it. Since we only ever set \c findText directly in both
87- the constructor and in hte \c findClicked() function, we do not create a
88- setter function to accompany \c getFindText(). Because \c getFindText() is
89+ The \c text of the find dialog's line edit has a public getter function, \c findText(),
90+ associated with it. Because \c findText() is
91 public, classes instantiating and using \c FindDialog can always access the
92 search string that the user has entered and accepted.
93
94- \snippet examples/addressbook-sdk/part5/finddialog.cpp getFindText
95+ \snippet examples/addressbook-sdk/part5/finddialog.cpp findText
96
97
98 \section1 The AddressBook Class
99@@ -788,23 +793,9 @@
100
101 So far, all our address book features have a QPushButton and a
102 corresponding slot. Similarly, for the \gui Find feature, we have
103- \c findButton and \c findContact().
104+ \c {ui->findButton} and \c findContact().
105
106 \snippet examples/addressbook-sdk/part5/addressbook.h slot definition
107- \dots
108- \snippet examples/addressbook-sdk/part5/addressbook.h private members
109-
110- Lastly, we declare the private variable, \c dialog, which we will use to
111- refer to an instance of \c FindDialog.
112-
113- Once we have instantiated a dialog, we might want to use it more than once;
114- using a private variable allows us to refer to it from more than one place
115- in the class.
116-
117- Within the \c AddressBook class's constructor, we insantiate our private
118- objects, \c findButton and \c dialog:
119-
120- \snippet examples/addressbook-sdk/part5/addressbook.cpp private members
121
122 Next, we connect the \c{findButton}'s \l{QPushButton::}{clicked()} signal
123 to \c findContact().
124@@ -818,10 +809,12 @@
125 We start out by displaying the \c FindDialog instance, \c dialog. This is
126 when the user enters a contact name to look up. Once the user clicks the
127 dialog's \c findButton, the dialog is hidden and the result code is set to
128- QDialog::Accepted. THis ensures that our \c if statement is always true.
129+ either QDialog::Accepted or QDialog::Rejected by the FindDialog's
130+ \c findClicked() method. This ensures that we only search for a contact
131+ if the user typed something in the FindDialog's line edit.
132
133 We then proceed to extract the search string, which in this case is
134- \c contactName, using \c{FindDialog}'s \c getFindText() function. If the
135+ \c contactName, using \c{FindDialog}'s \c findText() function. If the
136 contact exists in our address book, we display it immediately. Otherwise,
137 we display the QMessageBox shown below to indicate that their search
138 failed.