summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeena Miettinen <riitta-leena.miettinen@digia.com>2014-02-12 16:36:28 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-13 11:03:56 +0100
commit9e399a7d41da4ff69cd8ec0e335d5777a5274969 (patch)
tree232d1e4d3810b48ef1c38ad687ae37446ad9a345
parent41dae70a7d4916b76ee8213b00ef06795c549f47 (diff)
Doc: replace line numbers with snippets
Task-number: QTBUG-32109 Change-Id: Ifd34e0de579b1dfb1b08cf3d2646960d62f9d9eb Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com> Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
-rw-r--r--doc/src/getting-started/gettingstartedqt.qdoc121
-rw-r--r--doc/src/snippets/gs/notepad1.cpp13
-rw-r--r--doc/src/snippets/gs/notepad1.h12
-rw-r--r--doc/src/snippets/gs/notepad2.h2
-rw-r--r--doc/src/snippets/widgets-tutorial/notepad/main.cpp12
5 files changed, 133 insertions, 27 deletions
diff --git a/doc/src/getting-started/gettingstartedqt.qdoc b/doc/src/getting-started/gettingstartedqt.qdoc
index 67f957a10..1013dba99 100644
--- a/doc/src/getting-started/gettingstartedqt.qdoc
+++ b/doc/src/getting-started/gettingstartedqt.qdoc
@@ -107,38 +107,52 @@
\snippet snippets/widgets-tutorial/notepad/main.cpp all
- Let us go through the code line by line. On the first two lines, we include
+ Let us go through the code line by line. The following lines include
the header files for the Notepad widget and QApplication. All Qt classes
have a header file named after them.
- Line 4 defines the main function that is the entry point for all C and C++
- based applications.
+ \snippet snippets/widgets-tutorial/notepad/main.cpp 1
- Line 6 creates a QApplication object. This object manages
+ The following line defines the main function that is the entry point for
+ all C and C++ based applications:
+
+ \snippet snippets/widgets-tutorial/notepad/main.cpp 2
+
+ The following line creates a QApplication object. This object manages
application-wide resources and is necessary to run any Qt program
that uses Qt Widgets. It constructs an application object with \c argc command
line arguments run in \c argv. (For GUI applications that do not use Qt Widgets, you can use
QGuiApplication instead.)
- Line 7 creates the Notepad object. This is the object for which the wizard
+ \snippet snippets/widgets-tutorial/notepad/main.cpp 3
+
+ The following line creates the Notepad object. This is the object for
+ which the wizard
created the class and the UI file. The user interface contains visual
elements that are called \c widgets in Qt. Examples of widgets are text
edits, scroll bars, labels, and radio buttons. A widget can also be a
container for other widgets; a dialog or a main application window, for
example.
- Line 8 shows the Notepad widget on the screen in its own window.
+ \snippet snippets/widgets-tutorial/notepad/main.cpp 4
+
+ The following line shows the Notepad widget on the screen in its own
+ window.
Since widgets also function as containers (for instance a
QMainWindow, which has toolbars, menus, a status bar, and a few
other widgets), it is possible to show a single widget in its own
window. Widgets are not visible by default; the function
\l{QWidget::}{show()} makes the widget visible.
- Line 10 makes the QApplication enter its event loop. When a Qt
+ \snippet snippets/widgets-tutorial/notepad/main.cpp 5
+
+ The following line makes the QApplication enter its event loop. When a Qt
application is running, events are generated and sent to the
widgets of the application. Examples of events are mouse presses
and key strokes.
+ \snippet snippets/widgets-tutorial/notepad/main.cpp 6
+
\b{Learn More}
\table
@@ -206,18 +220,42 @@
\printuntil QMenuBar
\dots
- Line 1 contains the XML declaration, which specifies the XML version and
- character encoding used in the document.
+ The following line contains the XML declaration, which specifies the XML
+ version and character encoding used in the document:
+
+ \code
+ <?xml version="1.0" encoding="UTF-8"?>
+ \endcode
- Line 2 creates an \c ui element that defines a Notepad widget.
+ The rest of the file specifies an \c ui element that defines a Notepad
+ widget:
- Line 26 creates a QVBoxLayout widget that contains a QTextEdit
+ \code
+ <ui version="4.0">
+ \endcode
+
+ The following snippet creates a QVBoxLayout widget that contains a QTextEdit
and QPushButton widget. As mentioned, widgets can contain
other widgets. It is possible to set the bounds (the location and
size) of child widgets directly, but it is usually easier to use a
layout. A layout manages the bounds of a widget's children.
QVBoxLayout, for instance, places the children in a vertical row.
+ \code
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTextEdit" name="textEdit"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="quitButton">
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ \endcode
+
The UI file is used together with the header and source file of the Notepad
class. We will look at the rest of the UI file in the later sections.
@@ -229,34 +267,48 @@
\snippet snippets/gs/notepad1.h all
- Line 4 includes QMainWindow that provides a main application window.
+ The following line includes QMainWindow that provides a main application
+ window:
+
+ \snippet snippets/gs/notepad1.h 1
- Line 6 declares the Notepad class in the Ui namespace, which is the
+ The following lines declare the Notepad class in the Ui namespace, which is the
standard namespace for the UI classes generated from .ui files by the
- \c uic tool.
+ \c uic tool:
- Line 10 contains the \c Q_OBJECT macro. It must come first in the class
+ \snippet snippets/gs/notepad1.h 2
+
+ The class declaration contains the \c Q_OBJECT macro. It must come first in the class
definition, and declares our class as a QObject. Naturally, it must also
inherit from QObject. A QObject adds several abilities to a normal C++
class. Notably, the class name and slot names can be
queried at run-time. It is also possible to query a slot's
parameter types and invoke it.
- Line 15 declares a constructor that has a default argument called \c parent.
+ \snippet snippets/gs/notepad1.h 3
+
+ The following lines declare a constructor that has a default argument
+ called \c parent.
The value 0 indicates that the widget has no parent (it is a top-level
widget).
- Line 16 declares a virtual destructor to free the resources that were
+ \snippet snippets/gs/notepad1.h 4
+
+ The following line declares a virtual destructor to free the resources that were
acquired by the object during its life-cycle. According to the C++
naming convention, destructors have the same name as the class they are
associated with, prefixed with a tilde (~). In QObject, destructors are
virtual to ensure that the destructors of derived classes are invoked
properly when an object is deleted through a pointer-to-base-class.
- Line 19 declares a member variable which is a pointer to the Notepad UI
+ \snippet snippets/gs/notepad1.h 5
+
+ The following lines declare a member variable which is a pointer to the Notepad UI
class. A member variable is associated with a specific class, and accessible
for all its methods.
+ \snippet snippets/gs/notepad1.h 6
+
\section2 Notepad Source File
The source file that the wizard generated for the Notepad class looks as
@@ -264,19 +316,32 @@
\snippet snippets/gs/notepad1.cpp all
- The first two lines include the Notepad class header file that was generated
- by the wizard and the UI header file that was generated by the \c uic tool.
+ The following lines include the Notepad class header file that was generated
+ by the wizard and the UI header file that was generated by the \c uic tool:
- Line 4 defines the \c {Notepad} constructor and sets up the UI file.
+ \snippet snippets/gs/notepad1.cpp 0
- Line 5 calls the QMainWindow constructor, which is the base class for the
- Notepad class.
+ The following line defines the \c {Notepad} constructor:
- Line 6 creates the UI class instance and assigns it to the \c ui member.
+ \snippet snippets/gs/notepad1.cpp 1
- Line 8 sets up the UI.
+ The following line calls the QMainWindow constructor, which is the base
+ class for the Notepad class:
- Line 11 destructs the \c ui.
+ \snippet snippets/gs/notepad1.cpp 2
+
+ The following line creates the UI class instance and assigns it to the
+ \c ui member:
+
+ \snippet snippets/gs/notepad1.cpp 3
+
+ The following line sets up the UI:
+
+ \snippet snippets/gs/notepad1.cpp 4
+
+ In the destructor, we delete the \c ui:
+
+ \snippet snippets/gs/notepad1.cpp 5
\section2 Project File
@@ -359,7 +424,7 @@
\snippet snippets/gs/notepad2.h all
- Line 14 uses Qt's signals and slots mechanism to make the
+ The following code uses Qt's signals and slots mechanism to make the
application exit when the \b {Quit button} is pushed. Qt Designer uses
QMetaObject \l{designer-using-a-ui-file.html#automatic-connections}
{auto-connection facilities} to connect the button's clicked() signal to a
@@ -367,6 +432,8 @@
the dialog's \c{setupUi()} function to do this, so Qt Designer only needs to
declare and implement a slot with a name that follows a standard convention.
+ \snippet snippets/gs/notepad2.h 1
+
The corresponding code in the source file, notepad.cpp, looks as follows:
\snippet snippets/gs/notepad2.cpp all
diff --git a/doc/src/snippets/gs/notepad1.cpp b/doc/src/snippets/gs/notepad1.cpp
index b4ff493b5..4c27aa854 100644
--- a/doc/src/snippets/gs/notepad1.cpp
+++ b/doc/src/snippets/gs/notepad1.cpp
@@ -39,18 +39,31 @@
****************************************************************************/
//! [all]
+//! [0]
#include "notepad.h"
#include "ui_notepad.h"
+//! [0]
+//! [1]
Notepad::Notepad(QWidget *parent) :
+//! [1]
+//! [2]
QMainWindow(parent),
+//! [2]
+//! [3]
ui(new Ui::Notepad)
+//! [3]
{
+
+//! [4]
ui->setupUi(this);
+//! [4]
}
+//! [5]
Notepad::~Notepad()
{
delete ui;
}
+//! [5]
//! [all]
diff --git a/doc/src/snippets/gs/notepad1.h b/doc/src/snippets/gs/notepad1.h
index df043dd46..50c61a4f3 100644
--- a/doc/src/snippets/gs/notepad1.h
+++ b/doc/src/snippets/gs/notepad1.h
@@ -42,22 +42,34 @@
#define NOTEPAD_H
//! [all]
+//! [1]
#include <QMainWindow>
+//! [1]
+//! [2]
namespace Ui {
class Notepad;
}
+//! [2]
+//! [3]
class Notepad : public QMainWindow
{
Q_OBJECT
+//! [3]
+//! [4]
public:
explicit Notepad(QWidget *parent = 0);
+//! [4]
+//! [5]
~Notepad();
+//! [5]
+//! [6]
private:
Ui::Notepad *ui;
+//! [6]
};
//! [all]
diff --git a/doc/src/snippets/gs/notepad2.h b/doc/src/snippets/gs/notepad2.h
index bac6d43fc..a7e86c2f9 100644
--- a/doc/src/snippets/gs/notepad2.h
+++ b/doc/src/snippets/gs/notepad2.h
@@ -51,8 +51,10 @@ public:
explicit Notepad(QWidget *parent = 0);
~Notepad();
+//! [1]
private slots:
void on_quitButton_clicked();
+//! [1]
private:
Ui::Notepad *ui;
diff --git a/doc/src/snippets/widgets-tutorial/notepad/main.cpp b/doc/src/snippets/widgets-tutorial/notepad/main.cpp
index 7fb83194c..2393eb43f 100644
--- a/doc/src/snippets/widgets-tutorial/notepad/main.cpp
+++ b/doc/src/snippets/widgets-tutorial/notepad/main.cpp
@@ -39,15 +39,27 @@
****************************************************************************/
//! [all]
+//! [1]
#include "notepad.h"
#include <QApplication>
+//! [1]
+//! [2]
int main(int argc, char *argv[])
{
+//! [2]
+//! [3]
QApplication a(argc, argv);
+//! [3]
+//! [4]
Notepad w;
+//! [4]
+//! [5]
w.show();
+//! [5]
+//! [6]
return a.exec();
+//! [6]
}
//! [all]