/usr/share/qt5/doc/qtpositioning/qtpositioning-logfilepositionsource-example.html is in qtlocation5-doc-html 5.2.1-1ubuntu2.
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 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- logfilepositionsource.qdoc -->
<title>Log File Position Source (C++) | QtPositioning 5.2</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.2</li>
<li><a href="qtpositioning-index.html">Qt Positioning</a></li>
<li>Log File Position Source (C++)</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<h1 class="title">Log File Position Source (C++)</h1>
<span class="subtitle"></span>
<!-- $$$logfilepositionsource-description -->
<div class="descr"> <a name="details"></a>
<p>The Logfile Position Source shows how to create and work with a custom NMEA position source, for platforms without GPS.<p>The data is read from a file which has positional data in NMEA format. The resulting time and position information is then displayed to the screen as simple text in date/time and latitude/longitude format.</p>
<p>This example class reads position data from a text file, <i>log.txt</i>. The file specifies position data using a simple text format: it contains one position update per line, where each line contains a date/time, a latitude and a longitude, separated by spaces. The date/time is in ISO 8601 format and the latitude and longitude are in degrees decimal format. Here is an excerpt from <i>log.txt</i>:</p>
<pre class="cpp"><span class="number">2009</span><span class="operator">-</span><span class="number">08</span><span class="operator">-</span><span class="number">24T22</span>:<span class="number">25</span>:<span class="number">01</span> <span class="operator">-</span><span class="number">27.576082</span> <span class="number">153.092415</span>
<span class="number">2009</span><span class="operator">-</span><span class="number">08</span><span class="operator">-</span><span class="number">24T22</span>:<span class="number">25</span>:<span class="number">02</span> <span class="operator">-</span><span class="number">27.576223</span> <span class="number">153.092530</span>
<span class="number">2009</span><span class="operator">-</span><span class="number">08</span><span class="operator">-</span><span class="number">24T22</span>:<span class="number">25</span>:<span class="number">03</span> <span class="operator">-</span><span class="number">27.576364</span> <span class="number">153.092648</span></pre>
<p>The class reads this data and distributes it via the <a href="qgeopositioninfosource.html#positionUpdated">positionUpdated()</a> signal.</p>
<p>Here is the definition of the <tt>LogFilePositionSource</tt> class:</p>
<pre class="qml"><span class="keyword">class</span> LogFilePositionSource : <span class="keyword">public</span> <span class="type"><a href="qgeopositioninfosource.html">QGeoPositionInfoSource</a></span>
{
Q_OBJECT
<span class="keyword">public</span>:
LogFilePositionSource(<span class="type">QObject</span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);
<span class="type"><a href="qgeopositioninfo.html">QGeoPositionInfo</a></span> lastKnownPosition(bool fromSatellitePositioningMethodsOnly <span class="operator">=</span> <span class="keyword">false</span>) <span class="keyword">const</span>;
PositioningMethods supportedPositioningMethods() <span class="keyword">const</span>;
<span class="type">int</span> minimumUpdateInterval() <span class="keyword">const</span>;
Error error() <span class="keyword">const</span>;
<span class="keyword">public</span> <span class="keyword">slots</span>:
<span class="keyword">virtual</span> <span class="type">void</span> startUpdates();
<span class="keyword">virtual</span> <span class="type">void</span> stopUpdates();
<span class="keyword">virtual</span> <span class="type">void</span> requestUpdate(<span class="type">int</span> timeout <span class="operator">=</span> <span class="number">5000</span>);
<span class="keyword">private</span> <span class="keyword">slots</span>:
<span class="type">void</span> readNextPosition();
<span class="keyword">private</span>:
<span class="type">QFile</span> <span class="operator">*</span>logFile;
<span class="type">QTimer</span> <span class="operator">*</span>timer;
<span class="type"><a href="qgeopositioninfo.html">QGeoPositionInfo</a></span> lastPosition;
};</pre>
<p>The main methods overrided by the subclass are:</p>
<ul>
<li><a href="qgeopositioninfosource.html#startUpdates">startUpdates()</a>: called by client applications to start regular position updates.</li>
<li><a href="qgeopositioninfosource.html#stopUpdates">stopUpdates()</a>: called by client applications to stop regular position updates.</li>
<li><a href="qgeopositioninfosource.html#requestUpdate">requestUpdate()</a>: called by client applications to request a single update, with a specified timeout.</li>
</ul>
<p>When a position update is available, the subclass emits the <a href="qgeopositioninfosource.html#positionUpdated">positionUpdated()</a> signal.</p>
<p>Here are the key methods in the class implementation:</p>
<pre class="qml">LogFilePositionSource<span class="operator">::</span>LogFilePositionSource(<span class="type">QObject</span> <span class="operator">*</span>parent)
: <span class="type"><a href="qgeopositioninfosource.html">QGeoPositionInfoSource</a></span>(parent)<span class="operator">,</span>
logFile(<span class="keyword">new</span> <span class="type">QFile</span>(<span class="keyword">this</span>))<span class="operator">,</span>
timer(<span class="keyword">new</span> <span class="type">QTimer</span>(<span class="keyword">this</span>))
{
connect(timer<span class="operator">,</span> SIGNAL(timeout())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(readNextPosition()));
logFile<span class="operator">-</span><span class="operator">></span>setFileName(<span class="type">QCoreApplication</span><span class="operator">::</span>applicationDirPath()
<span class="operator">+</span> <span class="type">QDir</span><span class="operator">::</span>separator() <span class="operator">+</span> <span class="string">"simplelog.txt"</span>);
<span class="keyword">if</span> (<span class="operator">!</span>logFile<span class="operator">-</span><span class="operator">></span>open(<span class="type">QIODevice</span><span class="operator">::</span>ReadOnly))
qWarning() <span class="operator"><</span><span class="operator"><</span> <span class="string">"Error: cannot open source file"</span> <span class="operator"><</span><span class="operator"><</span> logFile<span class="operator">-</span><span class="operator">></span>fileName();
}
<span class="type">void</span> LogFilePositionSource<span class="operator">::</span>startUpdates()
{
<span class="type">int</span> interval <span class="operator">=</span> updateInterval();
<span class="keyword">if</span> (interval <span class="operator"><</span> minimumUpdateInterval())
interval <span class="operator">=</span> minimumUpdateInterval();
timer<span class="operator">-</span><span class="operator">></span>start(interval);
}
<span class="type">void</span> LogFilePositionSource<span class="operator">::</span>stopUpdates()
{
timer<span class="operator">-</span><span class="operator">></span>stop();
}
<span class="type">void</span> LogFilePositionSource<span class="operator">::</span>requestUpdate(<span class="type">int</span> <span class="comment">/*timeout*/</span>)
{
<span class="comment">// For simplicity, ignore timeout - assume that if data is not available</span>
<span class="comment">// now, no data will be added to the file later</span>
<span class="keyword">if</span> (logFile<span class="operator">-</span><span class="operator">></span>canReadLine())
readNextPosition();
<span class="keyword">else</span>
<span class="keyword">emit</span> updateTimeout();
}
<span class="type">void</span> LogFilePositionSource<span class="operator">::</span>readNextPosition()
{
<span class="type">QByteArray</span> line <span class="operator">=</span> logFile<span class="operator">-</span><span class="operator">></span>readLine()<span class="operator">.</span>trimmed();
<span class="keyword">if</span> (<span class="operator">!</span>line<span class="operator">.</span>isEmpty()) {
<span class="type">QList</span><span class="operator"><</span><span class="type">QByteArray</span><span class="operator">></span> data <span class="operator">=</span> line<span class="operator">.</span>split(<span class="char">' '</span>);
<span class="type">double</span> latitude;
<span class="type">double</span> longitude;
bool hasLatitude <span class="operator">=</span> <span class="keyword">false</span>;
bool hasLongitude <span class="operator">=</span> <span class="keyword">false</span>;
<span class="type">QDateTime</span> timestamp <span class="operator">=</span> <span class="type">QDateTime</span><span class="operator">::</span>fromString(<span class="type">QString</span>(data<span class="operator">.</span>value(<span class="number">0</span>))<span class="operator">,</span> <span class="type">Qt</span><span class="operator">::</span>ISODate);
latitude <span class="operator">=</span> data<span class="operator">.</span>value(<span class="number">1</span>)<span class="operator">.</span>toDouble(<span class="operator">&</span>hasLatitude);
longitude <span class="operator">=</span> data<span class="operator">.</span>value(<span class="number">2</span>)<span class="operator">.</span>toDouble(<span class="operator">&</span>hasLongitude);
<span class="keyword">if</span> (hasLatitude <span class="operator">&</span><span class="operator">&</span> hasLongitude <span class="operator">&</span><span class="operator">&</span> timestamp<span class="operator">.</span>isValid()) {
<span class="type"><a href="qgeocoordinate.html">QGeoCoordinate</a></span> coordinate(latitude<span class="operator">,</span> longitude);
<span class="type"><a href="qgeopositioninfo.html">QGeoPositionInfo</a></span> info(coordinate<span class="operator">,</span> timestamp);
<span class="keyword">if</span> (info<span class="operator">.</span>isValid()) {
lastPosition <span class="operator">=</span> info;
<span class="keyword">emit</span> positionUpdated(info);
}
}
}
}</pre>
<p>Files:</p>
<ul>
<li><a href="qtpositioning-logfilepositionsource-clientapplication-cpp.html">logfilepositionsource/clientapplication.cpp</a></li>
<li><a href="qtpositioning-logfilepositionsource-clientapplication-h.html">logfilepositionsource/clientapplication.h</a></li>
<li><a href="qtpositioning-logfilepositionsource-logfilepositionsource-cpp.html">logfilepositionsource/logfilepositionsource.cpp</a></li>
<li><a href="qtpositioning-logfilepositionsource-logfilepositionsource-h.html">logfilepositionsource/logfilepositionsource.h</a></li>
<li><a href="qtpositioning-logfilepositionsource-main-cpp.html">logfilepositionsource/main.cpp</a></li>
<li><a href="qtpositioning-logfilepositionsource-logfilepositionsource-pro.html">logfilepositionsource/logfilepositionsource.pro</a></li>
</ul>
</div>
<!-- @@@logfilepositionsource -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2013 Digia Plc and/or its
subsidiaries. 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> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|