Doc: Update Extension example

-language review
-rewrite some paragraphs

Task-number: QTBUG-60635
Change-Id: I96154cd5d78b9517409ac67ec416c53031dcb909
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
This commit is contained in:
Nico Vertriest 2018-03-07 13:02:42 +01:00
parent de6b81399e
commit 26ff9aac8e

View File

@ -36,23 +36,21 @@
\image extension-example.png Screenshot of the Extension example \image extension-example.png Screenshot of the Extension example
The Extension application is a dialog that allows the user to The Extension application lets the user add search parameters in
perform a simple search as well as a more advanced search. a dialog and launch a simple or advanced search.
The simple search has two options: \uicontrol {Match case} and \uicontrol The simple search has two options: \uicontrol {Match case} and \uicontrol
{Search from start}. The advanced search options include the {Search from start}. The advanced search offers search for \uicontrol {Whole words},
possibilities to search for \uicontrol {Whole words}, \uicontrol {Search \uicontrol {Search backward}, and \uicontrol {Search selection}. The
backward} and \uicontrol {Search selection}. Only the simple search is application starts with simple search as the default. Click the \uicontrol More button
visible when the application starts. The advanced search options to show the advanced search options:
are located in the application's extension part, and can be made
visible by pressing the \uicontrol More button:
\image extension_more.png Screenshot of the Extension example \image extension_more.png Screenshot of the Extension example
\section1 FindDialog Class Definition \section1 FindDialog Class Definition
The \c FindDialog class inherits QDialog. The QDialog class is the The \c FindDialog class inherits QDialog. QDialog is the
base class of dialog windows. A dialog window is a top-level base class for dialog windows. A dialog window is a top-level
window mostly used for short-term tasks and brief communications window mostly used for short-term tasks and brief communications
with the user. with the user.
@ -62,45 +60,53 @@
displays the application's search options and controlling displays the application's search options and controlling
buttons. buttons.
In addition to a constructor, we declare the several child In addition to the constructor, there are several child widgets:
widgets: We need a QLineEdit with an associated QLabel to let the
user type a word to search for, we need several \l \list
{QCheckBox}{QCheckBox}es to facilitate the search options, and we \li A QLineEdit with an associated QLabel to let the
need three \l {QPushButton}{QPushButton}s: the \uicontrol Find button to user type a word to search for.
start a search and the \uicontrol More button to enable an advanced search. \li Several \l {QCheckBox}{QCheckBox}es to facilitate the search options.
Finally, we need a QWidget representing the application's extension \li Three \l {QPushButton}{QPushButton}s:
part. \list
\li the \uicontrol Find button to start a search
\li the \uicontrol More button to enable an advanced search
\li a QWidget representing the application's extension part
\endlist
\endlist
\section1 FindDialog Class Implementation \section1 FindDialog Class Implementation
In the constructor we first create the standard child widgets for Create the standard child widgets for the simple search in the constructor:
the simple search: the QLineEdit with the associated QLabel, two the QLineEdit with the associated QLabel, two {QCheckBox}es and all the
of the \l {QCheckBox}{QCheckBox}es and all the \l \l {QPushButton}{QPushButton}s.
{QPushButton}{QPushButton}s.
\snippet dialogs/extension/finddialog.cpp 0 \snippet dialogs/extension/finddialog.cpp 0
We give the options and buttons a shortcut key using the & This snippet illustrates how you can define a shortcut key
character. In the \uicontrol {Find what} option's case, we also need to for a widget. A shortcut should be defined by putting the ampersand
use the QLabel::setBuddy() function to make the shortcut key work character (\c &) in front of the letter that should
as expected; then, when the user presses the shortcut key become the shortcut.
indicated by the label, the keyboard focus is transferred to the For example, for \uicontrol {Find what}, pressing \uicontrol Alt
label's buddy widget, the QLineEdit. and \uicontrol w transfers focus to the QLineEdit widget.
Shortcuts can also be used for checking on or off a checkmark.
For example, pressing \uicontrol Alt and \uicontrol c puts the check mark
on \uicontrol {Match Case} if it was unchecked and vice versa.
It is the QLabel::setBuddy() method that links a widget to the shortcut
character if it has been defined.
We set the \uicontrol Find button's default property to true, using the Set the \uicontrol Find button's default property to true, using the
QPushButton::setDefault() function. Then the push button will be QPushButton::setDefault() function. Then the push button will be
pressed if the user presses the Enter (or Return) key. Note that a pressed if the user presses the Enter (or Return) key. Note that a
QDialog can only have one default button. QDialog can only have one default button.
\snippet dialogs/extension/finddialog.cpp 2 \snippet dialogs/extension/finddialog.cpp 2
Then we create the extension widget, and the \l Create the extension widget, and the \l {QCheckBox}{QCheckBox}es associated
{QCheckBox}{QCheckBox}es associated with the advanced search with the advanced search options.
options.
\snippet dialogs/extension/finddialog.cpp 3 \snippet dialogs/extension/finddialog.cpp 3
Now that the extension widget is created, we can connect the \uicontrol Now that the extension widget is created, connect the \uicontrol
More button's \l{QAbstractButton::toggled()}{toggled()} signal to More button's \l{QAbstractButton::toggled()}{toggled()} signal to
the extension widget's \l{QWidget::setVisible()}{setVisible()} slot. the extension widget's \l{QWidget::setVisible()}{setVisible()} slot.
@ -111,26 +117,26 @@
the status is true the widget is shown, otherwise the widget is the status is true the widget is shown, otherwise the widget is
hidden. hidden.
Since we made the \uicontrol More button checkable when we created it, Since the \uicontrol More button is checkable, the connection makes
the connection makes sure that the extension widget is shown sure that the extension widget is shown depending on the state of
depending on the state of \uicontrol More button. the \uicontrol More button.
We also put the check boxes associated with the advanced Create checkboxes associated with the advanced search options in
search options into a layout we install on the extension widget. a layout installed on the extension widget.
\snippet dialogs/extension/finddialog.cpp 4 \snippet dialogs/extension/finddialog.cpp 4
Before we create the main layout, we create several child layouts Before creating the main layout, create several child layouts
for the widgets: First we align the QLabel and its buddy, the for the widgets. First align the QLabel and its buddy, the
QLineEdit, using a QHBoxLayout. Then we vertically align the QLineEdit, using a QHBoxLayout. Then align the QLabel and the QLineEdit
QLabel and QLineEdit with the check boxes associated with the vertically with the checkboxes associated with the simple search,
simple search, using a QVBoxLayout. We also create a QVBoxLayout using a QVBoxLayout. Create also a QVBoxLayout for the buttons.
for the buttons. In the end we lay out the two latter layouts and Finally, lay out the two latter layouts and the extension widget
the extension widget using a QGridLayout. using a QGridLayout.
\snippet dialogs/extension/finddialog.cpp 5 \snippet dialogs/extension/finddialog.cpp 5
Finally, we hide the extension widget using the QWidget::hide() Hide the extension widget using the QWidget::hide()
function, making the application only show the simple search function, making the application only show the simple search
options when it starts. When the user wants to access the advanced options when it starts. When the user wants to access the advanced
search options, the dialog only needs to change the visibility of search options, the dialog only needs to change the visibility of