Commit 273d849046de37a5446f00f4e5be6249551d9dfd
- Diff rendering mode:
- inline
- side by side
doc/addressbook-sdk.qdoc
(39 / 36)
|   | |||
| 348 | 348 | \snippet examples/addressbook-sdk/part2/addressbook.h members | |
| 349 | 349 | ||
| 350 | 350 | 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 | ||
| 352 | 352 | was last displayed, before the user clicked \gui Add. So, when the user | |
| 353 | 353 | clicks \gui Cancel, we can revert to displaying the details of the last | |
| 354 | 354 | contact. | |
| … | … | ||
| 529 | 529 | ||
| 530 | 530 | \snippet examples/addressbook-sdk/part3/addressbook.cpp enable navigation | |
| 531 | 531 | ||
| 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. | ||
| 533 | 533 | ||
| 534 | 534 | Recall that we intend to emulate a circularly-linked list with our QMap | |
| 535 | 535 | object, \c contacts. So in the \c next() function, we obtain an iterator | |
| … | … | ||
| 735 | 735 | In this chapter, we look at ways to locate contacts and addresses in the | |
| 736 | 736 | address book application. | |
| 737 | 737 | ||
| 738 | # image | ||
| 738 | \image addressbook-tutorial-part5-screenshot.png | ||
| 739 | 739 | ||
| 740 | 740 | As we keep adding contacts to our address book, it becomes tedious to | |
| 741 | 741 | navigate them with the \gui Next and \gui Previous buttons. In this case, | |
| … | … | ||
| 750 | 750 | ||
| 751 | 751 | \section1 Designing The FindDialog | |
| 752 | 752 | ||
| 753 | #image | ||
| 753 | \image addressbook-tutorial-part5-finddialog-in-designer.png | ||
| 754 | 754 | ||
| 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 | ||
| 756 | 756 | 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}. | ||
| 760 | 761 | ||
| 761 | 762 | To replicate the screenshot above, we need a label, a line edit, and a push | |
| 762 | 763 | button. Drag these onto your form. Set their text accordingly and name them | |
| … | … | ||
| 782 | 782 | ||
| 783 | 783 | \snippet examples/addressbook-sdk/part5/finddialog.cpp constructor | |
| 784 | 784 | ||
| 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 | |||
| 796 | 785 | In \c findClicked(), we validate to ensure that the user did not click the | |
| 797 | 786 | \gui Find button without entering a contact's name. Then, we set | |
| 798 | 787 | \c findText to the search string, extracted from \c lineEdit. After that, | |
| … | … | ||
| 789 | 789 | ||
| 790 | 790 | \snippet examples/addressbook-sdk/part5/finddialog.cpp findClicked | |
| 791 | 791 | ||
| 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. | ||
| 798 | 795 | ||
| 799 | 796 | \snippet examples/addressbook-sdk/part5/finddialog.cpp findText | |
| 800 | 797 | ||
| 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. | ||
| 801 | 807 | ||
| 808 | \image addressbook-tutorial-part5-signals-and-slots.png | ||
| 809 | |||
| 810 | |||
| 802 | 811 | \section1 The AddressBook Class | |
| 803 | 812 | ||
| 804 | 813 | To ensure that we can use \c FindDialog from within our \c AddressBook | |
| … | … | ||
| 817 | 817 | ||
| 818 | 818 | So far, all our address book features have a QPushButton and a | |
| 819 | 819 | corresponding slot. Similarly, for the \gui Find feature, we have | |
| 820 | \c findButton and \c findContact(). | ||
| 820 | \c{ui->findButton} and \c findContact(). | ||
| 821 | 821 | ||
| 822 | 822 | \snippet examples/addressbook-sdk/part5/addressbook.h slot definition | |
| 823 | 823 | ||
| … | … | ||
| 837 | 837 | We start out by displaying the \c FindDialog instance, \c dialog. This is | |
| 838 | 838 | when the user enters a contact name to look up. Once the user clicks the | |
| 839 | 839 | 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. | ||
| 841 | 843 | ||
| 842 | 844 | 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 | ||
| 844 | 846 | contact exists in our address book, we display it immediately. Otherwise, | |
| 845 | 847 | we display the QMessageBox shown below to indicate that their search | |
| 846 | 848 | failed. | |
| 847 | 849 | ||
| 848 | # image | ||
| 850 | \image addressbook-tutorial-part5-dialogbox.png | ||
| 849 | 851 | ||
| 850 | 852 | The concept behind finding a contact only applies for cases where we have | |
| 851 | 853 | more than two contacts in our address book. Hence, we implement this | |
| … | … | ||
| 871 | 871 | This chapter covers the file handling features of Qt that we used to write | |
| 872 | 872 | loading and saving routines for the address book application. | |
| 873 | 873 | ||
| 874 | # screenshot | ||
| 874 | \image addressbook-tutorial-part6-screenshot.png | ||
| 875 | 875 | ||
| 876 | 876 | Although browsing and searching for contacts are useful features, our | |
| 877 | 877 | address book is not really ready for use until we can save existing | |
| … | … | ||
| 911 | 911 | the push buttons. | |
| 912 | 912 | ||
| 913 | 913 | ||
| 914 | # screenshot of property editor | ||
| 914 | \image addressbook-tutorial-part6-propertyeditor.png | ||
| 915 | 915 | ||
| 916 | 916 | ||
| 917 | 917 | \section1 The AddressBook Class | |
| … | … | ||
| 936 | 936 | ||
| 937 | 937 | The file dialog that pops up is displayed in the screenshot below: | |
| 938 | 938 | ||
| 939 | #screenshot | ||
| 939 | \image addressbook-tutorial-part6-savedialog.png | ||
| 940 | 940 | ||
| 941 | 941 | If \c fileName is not empty, we create a QFile object, \c file, with | |
| 942 | 942 | \c fileName. The QFile object works with QDataStream as QFile is a | |
| … | … | ||
| 968 | 968 | On Windows, for example, this function pops up a native file dialog, as | |
| 969 | 969 | shown in the following screenshot. | |
| 970 | 970 | ||
| 971 | # screenshot | ||
| 971 | \image addressbook-tutorial-part6-opendialog.png | ||
| 972 | 972 | ||
| 973 | 973 | If \c fileName is not empty, again, we use a QFile object, \c file, and | |
| 974 | 974 | attempt to open it in \l{QIODevice::}{ReadOnly} mode. Similar to our | |
| … | … | ||
| 990 | 990 | validate the data obtained to ensure that the file we read from actually | |
| 991 | 991 | contains address book contacts. If it does, we display the first contact; | |
| 992 | 992 | 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(): | ||
| 995 | 995 | ||
| 996 | \snippet examples/addressbook-sdk/part6/addressbook.cpp connectSlots | ||
| 997 | |||
| 996 | 998 | */ | |
| 997 | 999 | ||
| 998 | 1000 | ||
| … | … | ||
| 1017 | 1017 | \c exportButton as its \c objectName. The \c toolTip property is set to | |
| 1018 | 1018 | \gui{Export as vCard}. | |
| 1019 | 1019 | ||
| 1020 | # screenshot | ||
| 1020 | \image addressbook-tutorial-part7-screenshot.png | ||
| 1021 | 1021 | ||
| 1022 | 1022 | \section1 The AddressBook Class | |
| 1023 | 1023 |
doc/eike_doc.patch
(138 / 0)
|   | |||
| 1 | diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc | ||
| 2 | index 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. |
Binary files differ
Binary files differ
Binary files differ
Binary files differ
Binary files differ
Binary files differ
Binary files differ
Binary files differ

