1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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: https://www.gnu.org/licenses/fdl-1.3.html.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29    \example weatherinfo
30    \title Weather Info (C++/QML)
31
32    \brief The Weather Info example shows how to use the user's current position
33           to retrieve local content from a web service in a C++ plugin for QML.
34
35    \ingroup qtpositioning-examples
36
37    Key \l{Qt Positioning} classes used in this example:
38
39    \list
40    \li \l{QGeoPositionInfo}
41    \li \l{QGeoPositionInfoSource}
42    \endlist
43
44    \image ../images/example-weatherinfo.png
45
46    \include examples-run.qdocinc
47
48    The example uses weather data provided by \l http://www.openweathermap.org.
49
50    The key part of this example is the application's data model, contained
51    in the WeatherData and AppModel classes. WeatherData represents the weather
52    information taken from the HTTP service. It is a simple data class, but we
53    give it Q_PROPERTies to expose it nicely to QML, later.
54
55    \snippet weatherinfo/appmodel.h 0
56    \snippet weatherinfo/appmodel.h 1
57
58    AppModel models the state of the entire application. At startup, we
59    get the platform's default position source using
60    QGeoPositionInfo::createDefaultSource()
61
62    \snippet weatherinfo/appmodel.cpp 0
63    \snippet weatherinfo/appmodel.cpp 1
64
65    If no default source is available, we take a static position and fetch
66    weather for that. If, however, we do have a position source, we connect
67    its positionUpdated() signal to a slot on the AppModel and call
68    startUpdates(), which begins regular updates of device position.
69
70    When a position update is received, we use the longitude and latitude
71    of the returned coordinate to retrieve the current "city" name for use
72    in the weather lookup.
73
74    \snippet weatherinfo/appmodel.cpp 2
75
76    To inform the UI about this process, the cityChanged() signal is emitted
77    when a new city is used, and the weatherChanged() signal whenever a
78    weather update occurs.
79
80    \snippet weatherinfo/appmodel.h 2
81    \snippet weatherinfo/appmodel.h 3
82    \snippet weatherinfo/appmodel.h 4
83
84    We use a QQmlListProperty for the weather forecast information,
85    which contains the next 4 days of forecast weather. This makes it
86    easy to access from QML.
87
88    To expose these to the QML UI layer, we use the qmlRegisterType()
89    function. We call this once for each type we wish to register, before
90    loading the actual QML file.
91
92    \snippet weatherinfo/main.cpp 0
93    \snippet weatherinfo/main.cpp 1
94
95    Finally, in the actual QML, we instantiate the AppModel.
96
97    \snippet weatherinfo/weatherinfo.qml 0
98    \snippet weatherinfo/weatherinfo.qml 1
99    \snippet weatherinfo/weatherinfo.qml 2
100
101    Once instantiated like this, we can use its properties elsewhere in the
102    QML document:
103
104    \snippet weatherinfo/weatherinfo.qml 3
105    \snippet weatherinfo/weatherinfo.qml 4
106
107    \section1 Files and Attributions
108
109    The example bundles the following images from Third-Party sources:
110
111    \table
112    \row
113        \li \l{weatherinfo-tango-icons}{Tango Icons}
114        \li Public Domain
115    \row
116        \li \l{weatherinfo-tango-weather-pack}{Tango Weather Icon Pack by Darkobra}
117        \li Public Domain
118    \endtable
119*/
120