Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > ed56237261fa5ad3d1f8082a5fac7e2e > files > 283

qtlocation5-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" />
<!-- places_list.qdoc -->
  <title>Places List (QML) | Qt Location 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="qtlocation-index.html">Qt Location</a></td><td ><a href="qtlocation-examples.html">Qt Location Examples</a></td><td >Places List (QML)</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="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="#performing-a-place-search">Performing a Place Search</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Places List (QML)</h1>
<span class="subtitle"></span>
<!-- $$$places_list-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/places_list.png" alt="" /></p><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>
<p>The <code>Places List</code> example demonstrates how to search for a list of places in a certain area and displays the result using a ListView. In this particular case, a search for places associated with the term <code>pizza</code> is performed.</p>
<a name="performing-a-place-search"></a>
<h2 id="performing-a-place-search">Performing a Place Search</h2>
<p>To write a QML application that will show places in a list, we start by making the following import declarations.</p>
<pre class="qml">

  import QtQuick 2.0
  import QtPositioning 5.5
  import QtLocation 5.6

</pre>
<p>Instantiate a <a href="location-places-qml.html#plugin">Plugin</a> instance. The <a href="location-places-qml.html#plugin">Plugin</a> is effectively the backend from where places are sourced from. Depending on the type of the plugin, some mandatory parameters may be need to be filled in. The most likely type of <a href="qml-qtlocation-pluginparameter.html">PluginParameter</a> are some form of service access token which are documented in the service plugin. As an example see the <a href="location-plugin-here.html#mandatory-parameters">HERE Plugin</a> documentation. In this snippet the <code>osm</code> plugin is used which does not require any further parameter:</p>
<pre class="qml">

  <span class="type"><a href="qml-qtlocation-plugin.html">Plugin</a></span> {
      <span class="name">id</span>: <span class="name">myPlugin</span>
      <span class="name">name</span>: <span class="string">&quot;osm&quot;</span>
      <span class="comment">//specify plugin parameters as necessary</span>
      <span class="comment">//PluginParameter {...}</span>
      <span class="comment">//PluginParameter {...}</span>
      <span class="comment">//...</span>
  }

</pre>
<p>Next we instantiate a <a href="qml-qtlocation-placesearchmodel.html">PlaceSearchModel</a> which we can use to specify search parameters and perform a places search operation. For illustrative purposes, <a href="qml-qtlocation-placesearchmodel.html#update-method">update()</a> is invoked once construction of the model is complete. Typically <a href="qml-qtlocation-placesearchmodel.html#update-method">update()</a> would be invoked in response to a user action such as a button click.</p>
<pre class="qml">

  <span class="type"><a href="qml-qtlocation-placesearchmodel.html">PlaceSearchModel</a></span> {
      <span class="name">id</span>: <span class="name">searchModel</span>

      <span class="name">plugin</span>: <span class="name">myPlugin</span>

      <span class="name">searchTerm</span>: <span class="string">&quot;pizza&quot;</span>
      <span class="name">searchArea</span>: <span class="name">QtPositioning</span>.<span class="name">circle</span>(<span class="name">startCoordinate</span>);

      <span class="name">Component</span>.onCompleted: <span class="name">update</span>()

  }

</pre>
<p>Finally we instantiate a ListView to show the search results found by the model. An inline delegate has been used and we have assumed that every search result is of <a href="qml-qtlocation-placesearchmodel.html#search-result-types">type</a> <code>PlaceSearchesult</code>. Consequently it is assumed that we always have access to the <i>place</i> <a href="qml-qtlocation-placesearchmodel.html#placesearchmodel-roles">role</a>, other search result types may not have a <i>place</i> <a href="qml-qtlocation-placesearchmodel.html#placesearchmodel-roles">role</a>.</p>
<pre class="qml">

  <span class="type">ListView</span> {
      <span class="name">anchors</span>.fill: <span class="name">parent</span>
      <span class="name">model</span>: <span class="name">searchModel</span>
      <span class="name">delegate</span>: <span class="name">Component</span> {
          <span class="type">Row</span> {
              <span class="name">spacing</span>: <span class="number">5</span>
              <span class="type">Marker</span> { <span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span> }
              <span class="type">Column</span> {
                  <span class="type">Text</span> { <span class="name">text</span>: <span class="name">title</span>; <span class="name">font</span>.bold: <span class="number">true</span> }
                  <span class="type">Text</span> { <span class="name">text</span>: <span class="name">place</span>.<span class="name">location</span>.<span class="name">address</span>.<span class="name">text</span> }
              }
          }
      }
  }

</pre>
<p>Files:</p>
<ul>
<li><a href="qtlocation-places-list-marker-qml.html">places_list/Marker.qml</a></li>
<li><a href="qtlocation-places-list-places-list-qml.html">places_list/places_list.qml</a></li>
<li><a href="qtlocation-places-list-main-cpp.html">places_list/main.cpp</a></li>
<li><a href="qtlocation-places-list-places-list-pro.html">places_list/places_list.pro</a></li>
<li><a href="qtlocation-places-list-places-list-qrc.html">places_list/places_list.qrc</a></li>
</ul>
</div>
<!-- @@@places_list -->
        </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>