/usr/share/qt5/doc/qtcharts/qtcharts-qmlweather-example.html is in qtcharts5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- examples-qmlweather.qdoc -->
<title>Qml Weather | Qt Charts 5.9</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td >Qt 5.9</td><td ><a href="qtcharts-index.html">Qt Charts</a></td><td ><a href="qtcharts-examples.html">Qt Charts Examples</a></td><td >Qml Weather</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#using-charts-in-qt-quick-applications">Using Charts in Qt Quick Applications</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qml Weather</h1>
<span class="subtitle"></span>
<!-- $$$qmlweather-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/examples_qmlweather.png" alt="" /></p><p>By default the application uses static test data to mimic a weather forecast. You can also obtain an application id from http://www.worldweatheronline.com/ to get access to weather API provided by World Weather Online. You can then give your application id as a parameter to the Qml Weather executable to make it use live data.</p>
<p>For example:</p>
<pre class="cpp">
bin\qmlweather<span class="operator">.</span>exe <span class="number">1234567890abcdef123456</span>
</pre>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="using-charts-in-qt-quick-applications"></a>
<h2 id="using-charts-in-qt-quick-applications">Using Charts in Qt Quick Applications</h2>
<p>The example application uses a <a href="qml-qtcharts-chartview.html">ChartView</a> and a some series to visualize weather data:</p>
<pre class="qml">
<span class="type"><a href="qml-qtcharts-chartview.html">ChartView</a></span> {
<span class="name">id</span>: <span class="name">chartView</span>
<span class="name">title</span>: <span class="string">"Weather forecast"</span>
<span class="type"><a href="qml-qtcharts-barcategoryaxis.html">BarCategoryAxis</a></span> {
<span class="name">id</span>: <span class="name">barCategoriesAxis</span>
<span class="name">titleText</span>: <span class="string">"Date"</span>
}
<span class="type"><a href="qml-qtcharts-valueaxis.html">ValueAxis</a></span>{
<span class="name">id</span>: <span class="name">valueAxisY2</span>
<span class="name">min</span>: <span class="number">0</span>
<span class="name">max</span>: <span class="number">10</span>
<span class="name">titleText</span>: <span class="string">"Rainfall [mm]"</span>
}
<span class="type"><a href="qml-qtcharts-valueaxis.html">ValueAxis</a></span> {
<span class="name">id</span>: <span class="name">valueAxisX</span>
<span class="comment">// Hide the value axis; it is only used to map the line series to bar categories axis</span>
<span class="name">visible</span>: <span class="number">false</span>
<span class="name">min</span>: <span class="number">0</span>
<span class="name">max</span>: <span class="number">5</span>
}
<span class="type"><a href="qml-qtcharts-valueaxis.html">ValueAxis</a></span>{
<span class="name">id</span>: <span class="name">valueAxisY</span>
<span class="name">min</span>: <span class="number">0</span>
<span class="name">max</span>: <span class="number">15</span>
<span class="name">titleText</span>: <span class="string">"Temperature [&deg;C]"</span>
}
<span class="type"><a href="qml-qtcharts-lineseries.html">LineSeries</a></span> {
<span class="name">id</span>: <span class="name">maxTempSeries</span>
<span class="name">axisX</span>: <span class="name">valueAxisX</span>
<span class="name">axisY</span>: <span class="name">valueAxisY</span>
<span class="name">name</span>: <span class="string">"Max. temperature"</span>
}
<span class="type"><a href="qml-qtcharts-lineseries.html">LineSeries</a></span> {
<span class="name">id</span>: <span class="name">minTempSeries</span>
<span class="name">axisX</span>: <span class="name">valueAxisX</span>
<span class="name">axisY</span>: <span class="name">valueAxisY</span>
<span class="name">name</span>: <span class="string">"Min. temperature"</span>
}
<span class="type"><a href="qml-qtcharts-barseries.html">BarSeries</a></span> {
<span class="name">id</span>: <span class="name">myBarSeries</span>
<span class="name">axisX</span>: <span class="name">barCategoriesAxis</span>
<span class="name">axisYRight</span>: <span class="name">valueAxisY2</span>
<span class="type"><a href="qml-qtcharts-barset.html">BarSet</a></span> {
<span class="name">id</span>: <span class="name">rainfallSet</span>
<span class="name">label</span>: <span class="string">"Rainfall"</span>
}
}
</pre>
<p>To get data with weather forecast data, we make an HTTP GET request to World Weather Online. We request the response in JSON data format.</p>
<pre class="qml">
<span class="comment">// Make HTTP GET request and parse the result</span>
var <span class="name">xhr</span> = new <span class="name">XMLHttpRequest</span>;
<span class="name">xhr</span>.<span class="name">open</span>(<span class="string">"GET"</span>,
<span class="string">"http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key="</span>
<span class="operator">+</span> <span class="name">weatherAppKey</span>);
<span class="name">xhr</span>.<span class="name">onreadystatechange</span> <span class="operator">=</span> <span class="keyword">function</span>() {
<span class="keyword">if</span> (<span class="name">xhr</span>.<span class="name">readyState</span> <span class="operator">==</span> <span class="name">XMLHttpRequest</span>.<span class="name">DONE</span>) {
var <span class="name">a</span> = <span class="name">JSON</span>.<span class="name">parse</span>(<span class="name">xhr</span>.<span class="name">responseText</span>);
<span class="name">parseWeatherData</span>(<span class="name">a</span>);
}
}
<span class="name">xhr</span>.<span class="name">send</span>();
</pre>
<p>The JSON response contains an array of forecast data:</p>
<pre class="qml">
<span class="comment">// Loop through the parsed JSON</span>
<span class="keyword">for</span> (<span class="keyword">var</span> <span class="name">i</span> in <span class="name">weatherData</span>.<span class="name">data</span>.<span class="name">weather</span>) {
var <span class="name">weatherObj</span> = <span class="name">weatherData</span>.<span class="name">data</span>.<span class="name">weather</span>[<span class="name">i</span>];
</pre>
<p>That is then used as input data for our series and a ListModel we use as a container for weather icon URLs:</p>
<pre class="qml">
<span class="comment">// Store temperature values, rainfall and weather icon.</span>
<span class="comment">// The temperature values begin from 0.5 instead of 0.0 to make the start from the</span>
<span class="comment">// middle of the rainfall bars. This makes the temperature lines visually better</span>
<span class="comment">// synchronized with the rainfall bars.</span>
<span class="name">maxTempSeries</span>.<span class="name">append</span>(<span class="name">Number</span>(<span class="name">i</span>) <span class="operator">+</span> <span class="number">0.5</span>, <span class="name">weatherObj</span>.<span class="name">tempMaxC</span>);
<span class="name">minTempSeries</span>.<span class="name">append</span>(<span class="name">Number</span>(<span class="name">i</span>) <span class="operator">+</span> <span class="number">0.5</span>, <span class="name">weatherObj</span>.<span class="name">tempMinC</span>);
<span class="name">rainfallSet</span>.<span class="name">append</span>(<span class="name">i</span>, <span class="name">weatherObj</span>.<span class="name">precipMM</span>);
<span class="name">weatherImageModel</span>.<span class="name">append</span>({"imageSource":<span class="name">weatherObj</span>.<span class="name">weatherIconUrl</span>[<span class="number">0</span>].<span class="name">value</span>});
</pre>
<p>Files:</p>
<ul>
<li><a href="qtcharts-qmlweather-qml-qmlweather-main-qml.html">qmlweather/qml/qmlweather/main.qml</a></li>
<li><a href="qtcharts-qmlweather-main-cpp.html">qmlweather/main.cpp</a></li>
<li><a href="qtcharts-qmlweather-qmlweather-pro.html">qmlweather/qmlweather.pro</a></li>
<li><a href="qtcharts-qmlweather-resources-qrc.html">qmlweather/resources.qrc</a></li>
</ul>
</div>
<!-- @@@qmlweather -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|