Doc: add missing files for Qt UI Tools docs
authorLeena Miettinen <riitta-leena.miettinen@digia.com>
Tue, 11 Dec 2012 11:46:17 +0000 (12:46 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 11 Dec 2012 16:04:08 +0000 (17:04 +0100)
The files were ignored by Git, so they did not get
submitted as part of I156dbf0a071137e1e6f3ba99cc390aa88c80b836.

Change-Id: Icb3a35d24993ea77077ee3a2e09f347c48c583bd
Reviewed-by: David Schulz <david.schulz@digia.com>
examples/uitools/doc/images/multipleinheritance-example.png [new file with mode: 0644]
examples/uitools/doc/src/multipleinheritance.qdoc [new file with mode: 0644]
examples/uitools/doc/src/textfinder.qdoc [new file with mode: 0644]

diff --git a/examples/uitools/doc/images/multipleinheritance-example.png b/examples/uitools/doc/images/multipleinheritance-example.png
new file mode 100644 (file)
index 0000000..9e89292
Binary files /dev/null and b/examples/uitools/doc/images/multipleinheritance-example.png differ
diff --git a/examples/uitools/doc/src/multipleinheritance.qdoc b/examples/uitools/doc/src/multipleinheritance.qdoc
new file mode 100644 (file)
index 0000000..aec4da9
--- /dev/null
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.  Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+    \example multipleinheritance
+    \title Multiple Inheritance Example
+
+    The Multiple Inheritance Example shows how to use a form created with
+    Qt Designer in an application by subclassing both QWidget and the user
+    interface class, which is \c{Ui::CalculatorForm}.
+
+    \image multipleinheritance-example.png
+
+    To subclass the \c calculatorform.ui file and ensure that \c qmake
+    processes it with the \c uic, we have to include \c calculatorform.ui
+    in the \c .pro file, as shown below:
+
+    \snippet multipleinheritance/multipleinheritance.pro 0
+
+    When the project is compiled, the \c uic will generate a corresponding
+    \c ui_calculatorform.h.
+
+    \section1 CalculatorForm Definition
+
+    In the \c CalculatorForm definition, we include the \c ui_calculatorform.h
+    that was generated earlier.
+
+    \snippet multipleinheritance/calculatorform.h 0
+
+    As mentioned earlier, the class is a subclass of both QWidget and
+    \c{Ui::CalculatorForm}.
+
+    \snippet multipleinheritance/calculatorform.h 1
+
+    Two slots are defined according to the \l{Automatic Connections}
+    {automatic connection} naming convention required by \c uic. This is
+    to ensure that \l{QMetaObject}'s auto-connection facilities connect
+    all the signals and slots involved automatically.
+
+    \section1 CalculatorForm Implementation
+
+    In the constructor, we call \c setupUi() to load the user interface file.
+    Note that we do not need the \c{ui} prefix as \c CalculatorForm is a
+    subclass of the user interface class.
+
+    \snippet multipleinheritance/calculatorform.cpp 0
+
+    We include two slots, \c{on_inputSpinBox1_valueChanged()} and
+    \c{on_inputSpinBox2_valueChanged()}. These slots respond to the
+    \l{QSpinBox::valueChanged()}{valueChanged()} signal that both spin boxes
+    emit. Whenever there is a change in one spin box's value, we take that
+    value and add it to whatever value the other spin box has.
+
+    \snippet multipleinheritance/calculatorform.cpp 1
+    \codeline
+    \snippet multipleinheritance/calculatorform.cpp 2
+
+    \section1 \c main() Function
+
+    The \c main() function instantiates QApplication and \c CalculatorForm.
+    The \c calculator object is displayed by invoking the \l{QWidget::show()}
+    {show()} function.
+
+    \snippet multipleinheritance/main.cpp 0
+
+    There are various approaches to include forms into applications. The
+    Multiple Inheritance approach is just one of them. See
+    \l{Using a Designer UI File in Your Application} for more information on
+    the other approaches available.
+*/
diff --git a/examples/uitools/doc/src/textfinder.qdoc b/examples/uitools/doc/src/textfinder.qdoc
new file mode 100644 (file)
index 0000000..c05e350
--- /dev/null
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.  Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+    \example textfinder
+    \title Text Finder Example
+
+    \brief The Text Finder example demonstrates how to dynamically process forms
+    using the Qt UI Tools module. Dynamic form processing enables a form to
+    be processed at run-time only by changing the UI file for the project.
+    The program allows the user to look up a particular word within the
+    contents of a text file. This text file is included in the project's
+    resource and is loaded into the display at startup.
+
+    \table
+    \row \li \inlineimage textfinder-example-find.png
+         \li \inlineimage textfinder-example-find2.png
+    \endtable
+
+    \section1 Setting Up The Resource File
+
+    The resources required for Text Finder are:
+    \list
+        \li \e{textfinder.ui} - the user interface file created in QtDesigner
+        \li \e{input.txt} - a text file containing some text to be displayed
+                           in the QTextEdit
+    \endlist
+
+    \e{textfinder.ui} contains all the necessary QWidget objects for the
+    Text Finder. A QLineEdit is used for the user input, a QTextEdit is
+    used to display the contents of \e{input.txt}, a QLabel is used to
+    display the text "Keyword", and a QPushButton is used for the "Find"
+    button. The screenshot below shows the preview obtained in QtDesigner.
+
+    \image textfinder-example-userinterface.png
+
+    A \e{textfinder.qrc} file is used to store both the \e{textfinder.ui}
+    and \e{input.txt} in the application's executable. The file contains
+    the following code:
+
+    \quotefile textfinder/textfinder.qrc
+
+    For more information on resource files, see \l{The Qt Resource System}.
+
+    To generate a form at run-time, the example is linked against the
+    QtUiTools module library. This is done in the \c{textfinder.pro} file
+    that contains the following lines:
+
+    \snippet textfinder/doc_src_examples_textfinder.pro 0
+
+    \section1 TextFinder Class Definition
+
+    The \c TextFinder class is a subclass of QWidget and it hosts the
+    \l{QWidget}s we need to access in the user interface. The QLabel in the
+    user interface is not declared here as we do not need to access it.
+
+    \snippet textfinder/textfinder.h 0
+
+    The slot \c{on_findButton_clicked()} is a slot named according to the
+    \l{Using a Designer UI File in Your Application#Automatic Connections}
+    {Automatic Connection} naming convention required
+    by \c uic.
+
+    \section1 TextFinder Class Implementation
+
+    The \c TextFinder class's constructor calls the \c loadUiFile() function
+    and then uses \c qFindChild() to access the user interface's
+    \l{QWidget}s.
+
+    \snippet textfinder/textfinder.cpp 0
+
+    We then use QMetaObject's system to enable signal and slot connections.
+
+    \snippet textfinder/textfinder.cpp 2
+
+    The loadTextFile() function is called to load \c{input.txt} into
+    QTextEdit to displays its contents.
+
+    \snippet textfinder/textfinder.cpp 3a
+
+    The \c{TextFinder}'s layout is set with \l{QWidget::}{setLayout()}.
+
+    \snippet textfinder/textfinder.cpp 3b
+
+    Finally, the window title is set to \e {Text Finder} and \c isFirstTime is
+    set to true.
+
+    \c isFirstTime is used as a flag to indicate whether the search operation
+    has been performed more than once. This is further explained with the
+    \c{on_findButton_clicked()} function.
+
+    The \c{loadUiFile()} function is used to load the user interface file
+    previously created in QtDesigner. The QUiLoader class is instantiated
+    and its \c load() function is used to load the form into \c{formWidget}
+    that acts as a place holder for the user interface. The function then
+    returns \c{formWidget} to its caller.
+
+    \snippet textfinder/textfinder.cpp 4
+
+    As mentioned earlier, the loadTextFile() function loads \e{input.txt}
+    into QTextEdit to display its contents. Data is read using QTextStream
+    into a QString object, \c line with the QTextStream::readAll() function.
+    The contents of \c line are then appended to \c{ui_textEdit}.
+
+    \snippet textfinder/textfinder.cpp 5
+
+    The \c{on_findButton_clicked()} function is a slot that is connected to
+    \c{ui_findButton}'s \c clicked() signal. The \c searchString is extracted
+    from the \c ui_lineEdit and the \c document is extracted from \c textEdit.
+    In event there is an empty \c searchString, a QMessageBox is used,
+    requesting the user to enter a word. Otherwise, we traverse through the
+    words in \c ui_textEdit, and highlight all ocurrences of the
+    \c searchString . Two QTextCursor objects are used: One to traverse through
+    the words in \c line and another to keep track of the edit blocks.
+
+    \snippet textfinder/textfinder.cpp 7
+
+    The \c isFirstTime flag is set to false the moment \c findButton is
+    clicked. This is necessary to undo the previous text highlight before
+    highlighting the user's next search string. Also, the \c found flag
+    is used to indicate if the \c searchString was found within the contents
+    of \c ui_textEdit. If it was not found, a QMessageBox is used
+    to inform the user.
+
+    \snippet textfinder/textfinder.cpp 9
+
+    \section1 \c main() Function
+
+    \snippet textfinder/main.cpp 0
+
+    The \c main() function initialises the \e{textfinder.qrc} resource file
+    and instantiates as well as displays \c TextFinder.
+
+    \sa {Calculator Builder Example}, {World Time Clock Builder Example}
+    */