Files
pilotclient/samples/weatherdata/reader.cpp
Roland Winklmeier c5fab7fb71 Weather data sample
New sample demonstrating how to use the weatherplugins to get and print
weatherdata around a geo position

refs #556
2016-01-28 01:36:35 +01:00

51 lines
1.6 KiB
C++

/* 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;
}
}
}