Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 19952c5e751bf7e3108c3c59625b0f35 > files > 469

qtcharts5-doc-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>main.qml Example File | 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-qmlweather-example.html">Qml Weather</a></td><td >main.qml Example File</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">main.qml Example File</h1>
<span class="subtitle">qmlweather/qml/qmlweather/main.qml</span>
<!-- $$$qmlweather/qml/qmlweather/main.qml-description -->
<div class="descr"> <a name="details"></a>
<pre class="qml">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the Qt Charts module of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:GPL$
  ** 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 The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** GNU General Public License Usage
  ** Alternatively, this file may be used under the terms of the GNU
  ** General Public License version 3 or (at your option) any later version
  ** approved by the KDE Free Qt Foundation. The licenses are as published by
  ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  ** included in the packaging of this file. Please review the following
  ** information to ensure the GNU General Public License requirements will
  ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  import QtQuick 2.0
  import QtCharts 2.0

  <span class="type">Rectangle</span> {
      <span class="name">width</span>: <span class="number">500</span>
      <span class="name">height</span>: <span class="number">400</span>
      <span class="name">gradient</span>: <span class="name">Gradient</span> {
          <span class="type">GradientStop</span> { <span class="name">position</span>: <span class="number">0.0</span>; <span class="name">color</span>: <span class="string">&quot;lightblue&quot;</span> }
          <span class="type">GradientStop</span> { <span class="name">position</span>: <span class="number">1.0</span>; <span class="name">color</span>: <span class="string">&quot;white&quot;</span> }
      }

      <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">&quot;Weather forecast&quot;</span>
          <span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span> <span class="operator">/</span> <span class="number">4</span> <span class="operator">*</span> <span class="number">3</span>
          <span class="name">anchors</span>.top: <span class="name">parent</span>.<span class="name">top</span>
          <span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span>
          <span class="name">anchors</span>.right: <span class="name">parent</span>.<span class="name">right</span>
          <span class="name">legend</span>.alignment: <span class="name">Qt</span>.<span class="name">AlignTop</span>
          <span class="name">antialiasing</span>: <span class="number">true</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">&quot;Date&quot;</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">&quot;Rainfall [mm]&quot;</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">&quot;Temperature [&amp;deg;C]&quot;</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">&quot;Max. temperature&quot;</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">&quot;Min. temperature&quot;</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">&quot;Rainfall&quot;</span>
              }
          }
      }

      <span class="comment">// A timer to refresh the forecast every 5 minutes</span>
      <span class="type">Timer</span> {
          <span class="name">interval</span>: <span class="number">300000</span>
          <span class="name">repeat</span>: <span class="number">true</span>
          <span class="name">triggeredOnStart</span>: <span class="number">true</span>
          <span class="name">running</span>: <span class="number">true</span>
          <span class="name">onTriggered</span>: {
              <span class="keyword">if</span> (<span class="name">weatherAppKey</span> <span class="operator">!=</span> <span class="string">&quot;&quot;</span>) {
                  <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">&quot;GET&quot;</span>,
                           <span class="string">&quot;http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&amp;format=json&amp;num_of_days=5&amp;key=&quot;</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>();
              } <span class="keyword">else</span> {
                  <span class="comment">// No app key for worldweatheronline.com given by the user -&gt; use dummy static data</span>
                  var <span class="name">responseText</span> = <span class="string">&quot;{ \&quot;data\&quot;: { \&quot;current_condition\&quot;: [ {\&quot;cloudcover\&quot;: \&quot;10\&quot;, \&quot;humidity\&quot;: \&quot;61\&quot;, \&quot;observation_time\&quot;: \&quot;06:26 AM\&quot;, \&quot;precipMM\&quot;: \&quot;0.0\&quot;, \&quot;pressure\&quot;: \&quot;1022\&quot;, \&quot;temp_C\&quot;: \&quot;6\&quot;, \&quot;temp_F\&quot;: \&quot;43\&quot;, \&quot;visibility\&quot;: \&quot;10\&quot;, \&quot;weatherCode\&quot;: \&quot;113\&quot;,  \&quot;weatherDesc\&quot;: [ {\&quot;value\&quot;: \&quot;Sunny\&quot; } ],  \&quot;weatherIconUrl\&quot;: [ {\&quot;value\&quot;: \&quot;http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\&quot; } ], \&quot;winddir16Point\&quot;: \&quot;SE\&quot;, \&quot;winddirDegree\&quot;: \&quot;140\&quot;, \&quot;windspeedKmph\&quot;: \&quot;7\&quot;, \&quot;windspeedMiles\&quot;: \&quot;4\&quot; } ],  \&quot;request\&quot;: [ {\&quot;query\&quot;: \&quot;Jyvaskyla, Finland\&quot;, \&quot;type\&quot;: \&quot;City\&quot; } ],  \&quot;weather\&quot;: [ {\&quot;date\&quot;: \&quot;2012-05-09\&quot;, \&quot;precipMM\&quot;: \&quot;0.4\&quot;, \&quot;tempMaxC\&quot;: \&quot;14\&quot;, \&quot;tempMaxF\&quot;: \&quot;57\&quot;, \&quot;tempMinC\&quot;: \&quot;7\&quot;, \&quot;tempMinF\&quot;: \&quot;45\&quot;, \&quot;weatherCode\&quot;: \&quot;116\&quot;,  \&quot;weatherDesc\&quot;: [ {\&quot;value\&quot;: \&quot;Partly Cloudy\&quot; } ],  \&quot;weatherIconUrl\&quot;: [ {\&quot;value\&quot;: \&quot;http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\&quot; } ], \&quot;winddir16Point\&quot;: \&quot;S\&quot;, \&quot;winddirDegree\&quot;: \&quot;179\&quot;, \&quot;winddirection\&quot;: \&quot;S\&quot;, \&quot;windspeedKmph\&quot;: \&quot;20\&quot;, \&quot;windspeedMiles\&quot;: \&quot;12\&quot; }, {\&quot;date\&quot;: \&quot;2012-05-10\&quot;, \&quot;precipMM\&quot;: \&quot;2.4\&quot;, \&quot;tempMaxC\&quot;: \&quot;13\&quot;, \&quot;tempMaxF\&quot;: \&quot;55\&quot;, \&quot;tempMinC\&quot;: \&quot;8\&quot;, \&quot;tempMinF\&quot;: \&quot;46\&quot;, \&quot;weatherCode\&quot;: \&quot;266\&quot;,  \&quot;weatherDesc\&quot;: [ {\&quot;value\&quot;: \&quot;Light drizzle\&quot; } ],  \&quot;weatherIconUrl\&quot;: [ {\&quot;value\&quot;: \&quot;http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\&quot; } ], \&quot;winddir16Point\&quot;: \&quot;SW\&quot;, \&quot;winddirDegree\&quot;: \&quot;219\&quot;, \&quot;winddirection\&quot;: \&quot;SW\&quot;, \&quot;windspeedKmph\&quot;: \&quot;21\&quot;, \&quot;windspeedMiles\&quot;: \&quot;13\&quot; }, {\&quot;date\&quot;: \&quot;2012-05-11\&quot;, \&quot;precipMM\&quot;: \&quot;11.1\&quot;, \&quot;tempMaxC\&quot;: \&quot;15\&quot;, \&quot;tempMaxF\&quot;: \&quot;59\&quot;, \&quot;tempMinC\&quot;: \&quot;7\&quot;, \&quot;tempMinF\&quot;: \&quot;44\&quot;, \&quot;weatherCode\&quot;: \&quot;266\&quot;,  \&quot;weatherDesc\&quot;: [ {\&quot;value\&quot;: \&quot;Light drizzle\&quot; } ],  \&quot;weatherIconUrl\&quot;: [ {\&quot;value\&quot;: \&quot;http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\&quot; } ], \&quot;winddir16Point\&quot;: \&quot;SSW\&quot;, \&quot;winddirDegree\&quot;: \&quot;200\&quot;, \&quot;winddirection\&quot;: \&quot;SSW\&quot;, \&quot;windspeedKmph\&quot;: \&quot;20\&quot;, \&quot;windspeedMiles\&quot;: \&quot;12\&quot; }, {\&quot;date\&quot;: \&quot;2012-05-12\&quot;, \&quot;precipMM\&quot;: \&quot;2.8\&quot;, \&quot;tempMaxC\&quot;: \&quot;7\&quot;, \&quot;tempMaxF\&quot;: \&quot;44\&quot;, \&quot;tempMinC\&quot;: \&quot;2\&quot;, \&quot;tempMinF\&quot;: \&quot;35\&quot;, \&quot;weatherCode\&quot;: \&quot;317\&quot;,  \&quot;weatherDesc\&quot;: [ {\&quot;value\&quot;: \&quot;Light sleet\&quot; } ],  \&quot;weatherIconUrl\&quot;: [ {\&quot;value\&quot;: \&quot;http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\&quot; } ], \&quot;winddir16Point\&quot;: \&quot;NW\&quot;, \&quot;winddirDegree\&quot;: \&quot;311\&quot;, \&quot;winddirection\&quot;: \&quot;NW\&quot;, \&quot;windspeedKmph\&quot;: \&quot;24\&quot;, \&quot;windspeedMiles\&quot;: \&quot;15\&quot; }, {\&quot;date\&quot;: \&quot;2012-05-13\&quot;, \&quot;precipMM\&quot;: \&quot;0.4\&quot;, \&quot;tempMaxC\&quot;: \&quot;6\&quot;, \&quot;tempMaxF\&quot;: \&quot;42\&quot;, \&quot;tempMinC\&quot;: \&quot;2\&quot;, \&quot;tempMinF\&quot;: \&quot;35\&quot;, \&quot;weatherCode\&quot;: \&quot;116\&quot;,  \&quot;weatherDesc\&quot;: [ {\&quot;value\&quot;: \&quot;Partly Cloudy\&quot; } ],  \&quot;weatherIconUrl\&quot;: [ {\&quot;value\&quot;: \&quot;http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\&quot; } ], \&quot;winddir16Point\&quot;: \&quot;WNW\&quot;, \&quot;winddirDegree\&quot;: \&quot;281\&quot;, \&quot;winddirection\&quot;: \&quot;WNW\&quot;, \&quot;windspeedKmph\&quot;: \&quot;21\&quot;, \&quot;windspeedMiles\&quot;: \&quot;13\&quot; } ] }}&quot;</span>;
                  var <span class="name">a</span> = <span class="name">JSON</span>.<span class="name">parse</span>(<span class="name">responseText</span>);
                  <span class="name">parseWeatherData</span>(<span class="name">a</span>);
              }
          }
      }

      <span class="type">Row</span> {
          <span class="name">id</span>: <span class="name">weatherImageRow</span>
          <span class="name">anchors</span>.top: <span class="name">chartView</span>.<span class="name">bottom</span>
          <span class="name">anchors</span>.topMargin: <span class="number">5</span>
          <span class="name">anchors</span>.bottom: <span class="name">poweredByText</span>.<span class="name">top</span>
          <span class="name">anchors</span>.bottomMargin: <span class="number">5</span>
          <span class="name">anchors</span>.horizontalCenter: <span class="name">parent</span>.<span class="name">horizontalCenter</span>
          <span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span> <span class="operator">-</span> <span class="name">chartView</span>.<span class="name">height</span> <span class="operator">-</span> <span class="name">anchors</span>.<span class="name">topMargin</span>

          <span class="type">ListModel</span> {
              <span class="name">id</span>: <span class="name">weatherImageModel</span>
          }

          <span class="type">Repeater</span> {
              <span class="name">id</span>: <span class="name">repeater</span>
              <span class="name">model</span>: <span class="name">weatherImageModel</span>
              <span class="name">delegate</span>: <span class="name">Image</span> {
                  <span class="name">source</span>: <span class="name">imageSource</span>
                  <span class="name">width</span>: <span class="name">weatherImageRow</span>.<span class="name">height</span>
                  <span class="name">height</span>: <span class="name">width</span>
                  <span class="name">fillMode</span>: <span class="name">Image</span>.<span class="name">PreserveAspectCrop</span>
              }
          }
      }

      <span class="type">Text</span> {
          <span class="name">id</span>: <span class="name">poweredByText</span>
          <span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span>
          <span class="name">anchors</span>.bottomMargin: <span class="number">5</span>
          <span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span>
          <span class="name">anchors</span>.leftMargin: <span class="number">25</span>
          <span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span> <span class="operator">/</span> <span class="number">25</span>
          <span class="name">text</span>: <span class="string">&quot;Powered by World Weather Online&quot;</span>
      }

      <span class="keyword">function</span> <span class="name">parseWeatherData</span>(<span class="name">weatherData</span>) {
          <span class="comment">// Clear previous values</span>
          <span class="name">maxTempSeries</span>.<span class="name">clear</span>();
          <span class="name">minTempSeries</span>.<span class="name">clear</span>();
          <span class="name">weatherImageModel</span>.<span class="name">clear</span>();

          <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>];

              <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>({&quot;imageSource&quot;:<span class="name">weatherObj</span>.<span class="name">weatherIconUrl</span>[<span class="number">0</span>].<span class="name">value</span>});

              <span class="comment">// Update scale of the chart</span>
              <span class="name">valueAxisY</span>.<span class="name">max</span> <span class="operator">=</span> <span class="name">Math</span>.<span class="name">max</span>(<span class="name">chartView</span>.<span class="name">axisY</span>().<span class="name">max</span>,<span class="name">weatherObj</span>.<span class="name">tempMaxC</span>);
              <span class="name">valueAxisX</span>.<span class="name">min</span> <span class="operator">=</span> <span class="number">0</span>;
              <span class="name">valueAxisX</span>.<span class="name">max</span> <span class="operator">=</span> <span class="name">Number</span>(<span class="name">i</span>) <span class="operator">+</span> <span class="number">1</span>;

              <span class="comment">// Set the x-axis labels to the dates of the forecast</span>
              var <span class="name">xLabels</span> = <span class="name">barCategoriesAxis</span>.<span class="name">categories</span>;
              <span class="name">xLabels</span>[<span class="name">Number</span>(<span class="name">i</span>)] <span class="operator">=</span> <span class="name">weatherObj</span>.<span class="name">date</span>.<span class="name">substring</span>(<span class="number">5</span>, <span class="number">10</span>);
              <span class="name">barCategoriesAxis</span>.<span class="name">categories</span> <span class="operator">=</span> <span class="name">xLabels</span>;
              <span class="name">barCategoriesAxis</span>.<span class="name">visible</span> <span class="operator">=</span> <span class="number">true</span>;
              <span class="name">barCategoriesAxis</span>.<span class="name">min</span> <span class="operator">=</span> <span class="number">0</span>;
              <span class="name">barCategoriesAxis</span>.<span class="name">max</span> <span class="operator">=</span> <span class="name">xLabels</span>.<span class="name">length</span> <span class="operator">-</span> <span class="number">1</span>;
          }
      }

  }

</pre>
</div>
<!-- @@@qmlweather/qml/qmlweather/main.qml -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</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>