Update copyright headers
[qt:qt.git] / doc / src / examples / factorial.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file.  Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: http://www.gnu.org/copyleft/fdl.html.
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29     \example statemachine/factorial
30     \title Factorial States Example
31
32     \brief The Factorial States example shows how to use \l{The State Machine
33     Framework} to calculate the factorial of an integer.
34
35     The statechart for calculating the factorial looks as follows:
36
37     \img factorial-example.png
38     \omit
39     \caption This is a caption
40     \endomit
41
42     In other words, the state machine calculates the factorial of 6 and prints
43     the result.
44
45     \snippet examples/statemachine/factorial/main.cpp 0
46
47     The Factorial class is used to hold the data of the computation, \c x and
48     \c fac. It also provides a signal that's emitted whenever the value of \c
49     x changes.
50
51     \snippet examples/statemachine/factorial/main.cpp 1
52
53     The FactorialLoopTransition class implements the guard (\c x > 1) and
54     calculations (\c fac = \c x * \c fac; \c x = \c x - 1) of the factorial
55     loop.
56
57     \snippet examples/statemachine/factorial/main.cpp 2
58
59     The FactorialDoneTransition class implements the guard (\c x <= 1) that
60     terminates the factorial computation. It also prints the final result to
61     standard output.
62
63     \snippet examples/statemachine/factorial/main.cpp 3
64
65     The application's main() function first creates the application object, a
66     Factorial object and a state machine.
67
68     \snippet examples/statemachine/factorial/main.cpp 4
69
70     The \c compute state is created, and the initial values of \c x and \c fac
71     are defined. A FactorialLoopTransition object is created and added to the
72     state.
73
74     \snippet examples/statemachine/factorial/main.cpp 5
75
76     A final state, \c done, is created, and a FactorialDoneTransition object
77     is created with \c done as its target state. The transition is then added
78     to the \c compute state.
79
80     \snippet examples/statemachine/factorial/main.cpp 6
81
82     The machine's initial state is set to be the \c compute state. We connect
83     the QStateMachine::finished() signal to the QCoreApplication::quit() slot,
84     so the application will quit when the state machine's work is
85     done. Finally, the state machine is started, and the application's event
86     loop is entered.
87
88  */