mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
Weather data sample
New sample demonstrating how to use the weatherplugins to get and print weatherdata around a geo position refs #556
This commit is contained in:
50
samples/weatherdata/reader.cpp
Normal file
50
samples/weatherdata/reader.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "reader.h"
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
void CLineReader::run()
|
||||
{
|
||||
QFile file;
|
||||
file.open(stdin, QIODevice::ReadOnly | QIODevice::Text);
|
||||
QRegularExpression re("^(\\d+).([0,5])\\s(\\d+).([0,5])$");
|
||||
forever
|
||||
{
|
||||
QString line = file.readLine().trimmed();
|
||||
|
||||
if (line == "x")
|
||||
{
|
||||
emit quit();
|
||||
continue;
|
||||
}
|
||||
|
||||
QRegularExpressionMatch match = re.match(line);
|
||||
if (match.hasMatch())
|
||||
{
|
||||
double latitudeValue = match.captured(1).toDouble();
|
||||
latitudeValue += match.captured(2).toDouble() / 10;
|
||||
double longitudeValue = match.captured(3).toDouble();
|
||||
longitudeValue += match.captured(4).toDouble() / 10;
|
||||
const CLatitude latitude(latitudeValue, CAngleUnit::deg());
|
||||
const CLongitude longitude(longitudeValue, CAngleUnit::deg());
|
||||
emit weatherDataRequest(latitude, longitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream qtout(stdout);
|
||||
qtout << "Invalid command." << endl;
|
||||
qtout << "Usage: <lat> <lon>" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user