Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/doc/src/tutorials/addressbook.qdoc

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the documentation of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4444
    4545    \startpage {index.html}{Qt Reference Documentation}
     46    \contentspage Tutorials
    4647    \nextpage {tutorials/addressbook/part1}{Chapter 1}
    4748
    4849    \title Address Book Tutorial
    49     \ingroup howto
    50     \ingroup tutorials
    5150    \brief An introduction to GUI programming, showing how to put together a
    5251    simple yet fully-functioning application.
     
    223222    Notice that \c addressLabel is positioned using Qt::AlignTop as an
    224223    additional argument. This is to make sure it is not vertically centered in
    225     cell (1,0). For a basic overview on Qt Layouts, refer to the \l{Layout Classes}
    226     document.
     224    cell (1,0). For a basic overview on Qt Layouts, refer to the
     225    \l{Layout Management} documentation.
    227226
    228227    In order to install the layout object onto the widget, we have to invoke
     
    243242    \snippet tutorials/addressbook/part1/main.cpp main function
    244243
    245     We construct a new \c AddressBook widget on the heap using the \c new
    246     keyword and invoke its \l{QWidget::show()}{show()} function to display it.
     244    We construct a new \c AddressBook widget on the stack and invoke
     245    its \l{QWidget::show()}{show()} function to display it.
    247246    However, the widget will not be shown until the application's event loop
    248247    is started. We start the event loop by calling the application's
    249248    \l{QApplication::}{exec()} function; the result returned by this function
    250     is used as the return value from the \c main() function.
     249    is used as the return value from the \c main() function. At this point,
     250    it becomes apparent why we instanciated \c AddressBook on the stack: It
     251    will now go out of scope. Therefore, \c AddressBook and all its child widgets
     252    will be deleted, thus preventing memory leaks.
    251253*/
    252254
     
    297299    We also declare two private QString objects, \c oldName and \c oldAddress.
    298300    These objects are needed to hold the name and address of the contact that
    299     was last displayed, before the user clicked "Add". So, when the user clicks
    300     "Cancel", we can revert to displaying the details of the last contact.
     301    was last displayed, before the user clicked \gui Add. So, when the user clicks
     302    \gui Cancel, we can revert to displaying the details of the last contact.
    301303
    302304    \section1 Implementing the AddressBook Class
     
    304306    Within the constructor of \c AddressBook, we set the \c nameLine and
    305307    \c addressText to read-only, so that we can only display but not edit
    306     existing cotact details.
     308    existing contact details.
    307309
    308310    \dots
     
    319321    {show()} function, while the \c submitButton and \c cancelButton are
    320322    hidden by invoking \l{QPushButton::hide()}{hide()}. These two push
    321     buttons will only be displayed when the user clicks "Add" and this is
     323    buttons will only be displayed when the user clicks \gui Add and this is
    322324    handled by the \c addContact() function discussed below.
    323325
     
    363365    \o We extract the contact's details from \c nameLine and \c addressText
    364366    and store them in QString objects. We also validate to make sure that the
    365     user did not click "Submit" with empty input fields; otherwise, a
     367    user did not click \gui Submit with empty input fields; otherwise, a
    366368    QMessageBox is displayed to remind the user for a name and address.
    367369
     
    375377
    376378    If the contact already exists, again, we display a QMessageBox to inform
    377     the user about this, to prevent the user from adding duplicate contacts.
    378     Our \c contacts object is based on key-value pairs of name and addresses,
     379    the user about this, preventing the user from adding duplicate contacts.
     380    Our \c contacts object is based on key-value pairs of name and address,
    379381    hence, we want to ensure that \e key is unique.
    380382
     
    397399    \snippet tutorials/addressbook/part2/addressbook.cpp cancel
    398400
    399     The general idea to add a contact is to give the user the flexibility to
    400     click "Submit" or "Cancel" at any time. The flowchart below further
    401     explains this concept:
     401    The general idea behind adding a contact is to give the user the
     402    flexibility to click \gui Submit or \gui Cancel at any time. The flowchart below
     403    further explains this concept:
    402404
    403405    \image addressbook-tutorial-part2-add-flowchart.png
     
    455457
    456458    The image below is our expected graphical user interface. Notice that it
    457     is getting closer to our expected final output.
     459    is getting closer to our final application.
    458460
    459461    \image addressbook-tutorial-part3-screenshot.png
     
    511513        \o If the iterator is at the end of \c contacts, we clear the
    512514        display and return.
    513         \o If the iterator is the beginning of \c contacts, we move it to
     515        \o If the iterator is at the beginning of \c contacts, we move it to
    514516        the end.
    515517        \o We then decrement the iterator by one.
     
    530532    \title Address Book 4 - Editing and Removing Addresses
    531533
    532     In this chapter, we look at ways to modify the contents of contact stored
     534    In this chapter, we look at ways to modify the contents of contacts stored
    533535    in the address book application.
    534536
     
    540542    when needed. However, this requires a little improvement, in the form of
    541543    enums. In our previous chapters, we had two modes: \c{AddingMode} and
    542     \c{NavigationMode} - but they weren't defined as enums. Instead, we
     544    \c{NavigationMode} - but they were not defined as enums. Instead, we
    543545    enabled and disabled the corresponding buttons manually, resulting in
    544546    multiple lines of repeated code.
     
    574576    \snippet tutorials/addressbook/part4/addressbook.h mode declaration
    575577
    576     Lastly, we declare \c currentMode to keep track of the current mode of the
    577     enum.
     578    Lastly, we declare \c currentMode to keep track of the enum's current mode.
    578579
    579580    \section1 Implementing the AddressBook Class
     
    645646    \snippet tutorials/addressbook/part4/addressbook.cpp update interface() part 1
    646647
    647     For \c NavigationMode, however, we include conditions within the
    648     parameters of the QPushButton::setEnabled(). This is to ensure that
    649     the \c editButton and \c removeButton push buttons are enabled when there
    650     is at least one contact in the address book; \c nextButton and \c previousButton
    651     are only enabled when there is more than one contact in the address book.
     648    For \c NavigationMode, however, we include conditions within the parameters
     649    of the QPushButton::setEnabled() function. This is to ensure that
     650    \c editButton and \c removeButton are enabled when there is at least one
     651    contact in the address book; \c nextButton and \c previousButton are only
     652    enabled when there is more than one contact in the address book.
    652653
    653654    \snippet tutorials/addressbook/part4/addressbook.cpp update interface() part 2
     
    696697    \snippet tutorials/addressbook/part5/finddialog.h FindDialog header
    697698
    698     We define a public function, \c getFindText() for use by classes that
    699     instantiate \c FindDialog, which allows them to obtain the text
    700     entered by the user. A public slot, \c findClicked(), is defined to
    701     handle the search string when the user clicks the \gui Find button.
     699    We define a public function, \c getFindText(), to be used by classes that
     700    instantiate \c FindDialog. This function allows these classes to obtain the
     701    search string entered by the user. A public slot, \c findClicked(), is also
     702    defined to handle the search string when the user clicks the \gui Find
     703    button.
    702704
    703705    Lastly, we define the private variables, \c findButton, \c lineEdit
     
    714716    \snippet tutorials/addressbook/part5/finddialog.cpp constructor
    715717
    716     We set the layout and window title, as well as connect the signals
    717     to their respective slots. Notice that \c{findButton}'s
    718     \l{QPushButton::clicked()}{clicked()} signal is connected to to
    719     \c findClicked() and \l{QDialog::accept()}{accept()}. The
    720     \l{QDialog::accept()}{accept()} slot provided by QDialog hides
    721     the dialog and sets the result code to \l{QDialog::}{Accepted}.
    722     We use this function to help \c{AddressBook}'s \c findContact() function
    723     know when the \c FindDialog object has been closed. This will be
    724     further explained when discussing the \c findContact() function.
     718    We set the layout and window title, as well as connect the signals to their
     719    respective slots. Notice that \c{findButton}'s \l{QPushButton::clicked()}
     720    {clicked()} signal is connected to to \c findClicked() and
     721    \l{QDialog::accept()}{accept()}. The \l{QDialog::accept()}{accept()} slot
     722    provided by QDialog hides the dialog and sets the result code to
     723    \l{QDialog::}{Accepted}. We use this function to help \c{AddressBook}'s
     724    \c findContact() function know when the \c FindDialog object has been
     725    closed. We will explain this logic in further detail when discussing the
     726    \c findContact() function.
    725727
    726728    \image addressbook-tutorial-part5-signals-and-slots.png
     
    816818    \image addressbook-tutorial-part6-screenshot.png
    817819
    818     Although browsing and searching for contacts are useful features, our address
    819     book is not really fully ready for use until we can saving existing contacts
    820     and load them again at a later time.
    821     Qt provides a number of classes for \l{Input/Output and Networking}{input and output},
    822     but we have chosen to use two which are simple to use in combination: QFile and
    823     QDataStream.
    824 
    825     A QFile object represents a file on disk that can be read from and written to.
    826     QFile is a subclass of the more general QIODevice class which represents many
    827     different kinds of devices.
    828 
    829     A QDataStream object is used to serialize binary data so that it can be stored
    830     in a QIODevice and retrieved again later. Reading from a QIODevice and writing
    831     to it is as simple as opening the stream - with the respective device as a
    832     parameter - and reading from or writing to it.
     820    Although browsing and searching for contacts are useful features, our
     821    address book is not ready for use until we can save existing contacts and
     822    load them again at a later time.
     823
     824    Qt provides a number of classes for \l{Input/Output and Networking}
     825    {input and output}, but we have chosen to use two which are simple to use
     826    in combination: QFile and QDataStream.
     827
     828    A QFile object represents a file on disk that can be read from and written
     829    to. QFile is a subclass of the more general QIODevice class which
     830    represents many different kinds of devices.
     831
     832    A QDataStream object is used to serialize binary data so that it can be
     833    stored in a QIODevice and retrieved again later. Reading from a QIODevice
     834    and writing to it is as simple as opening the stream - with the respective
     835    device as a parameter - and reading from or writing to it.
     836
    833837
    834838    \section1 Defining the AddressBook Class
     
    872876    \image addressbook-tutorial-part6-save.png
    873877
    874     If \c fileName is not empty, we create a QFile object, \c file with
     878    If \c fileName is not empty, we create a QFile object, \c file, with
    875879    \c fileName. QFile works with QDataStream as QFile is a QIODevice.
    876880
     
    902906
    903907    If \c fileName is not empty, again, we use a QFile object, \c file, and
    904     attempt to open it in \l{QIODevice::}{ReadOnly} mode. In a similar way
    905     to our implementation of \c saveToFile(), if this attempt is unsuccessful,
    906     we display a QMessageBox to inform the user.
     908    attempt to open it in \l{QIODevice::}{ReadOnly} mode. Similar to our
     909    implementation of \c saveToFile(), if this attempt is unsuccessful, we
     910    display a QMessageBox to inform the user.
    907911
    908912    \snippet tutorials/addressbook/part6/addressbook.cpp loadFromFile() function part2
     
    910914    Otherwise, we instantiate a QDataStream object, \c in, set its version as
    911915    above and read the serialized data into the \c contacts data structure.
    912     Note that we empty \c contacts before reading data into it to simplify the
    913     file reading process. A more advanced method would be to read the contacts
    914     into temporary QMap object, and copy only the contacts that do not already
    915     exist in \c contacts.
     916    The \c contacts object is emptied before data is read into it to simplify
     917    the file reading process. A more advanced method would be to read the
     918    contacts into a temporary QMap object, and copy over non-duplicate contacts
     919    into \c contacts.
    916920
    917921    \snippet tutorials/addressbook/part6/addressbook.cpp loadFromFile() function part3
Note: See TracChangeset for help on using the changeset viewer.