Launcher: use new SGGeod <-> string functions
This relies on the latest Simgear to provide these functions.
This commit is contained in:
parent
ca785f01e5
commit
9098e47664
5 changed files with 38 additions and 33 deletions
|
@ -27,6 +27,8 @@
|
|||
#include <QQmlComponent>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
|
||||
#include "AirportDiagram.hxx"
|
||||
#include "NavaidDiagram.hxx"
|
||||
#include "LaunchConfig.hxx"
|
||||
|
@ -121,15 +123,6 @@ QString fixNavaidName(QString s)
|
|||
return changedWords.join(QChar(' '));
|
||||
}
|
||||
|
||||
QString formatGeodAsString(const SGGeod& geod)
|
||||
{
|
||||
QChar ns = (geod.getLatitudeDeg() > 0.0) ? 'N' : 'S';
|
||||
QChar ew = (geod.getLongitudeDeg() > 0.0) ? 'E' : 'W';
|
||||
|
||||
return QString::number(fabs(geod.getLongitudeDeg()), 'f',2 ) + ew + " " +
|
||||
QString::number(fabs(geod.getLatitudeDeg()), 'f',2 ) + ns;
|
||||
}
|
||||
|
||||
QVariant savePositionList(const FGPositionedList& posList)
|
||||
{
|
||||
QVariantList vl;
|
||||
|
@ -590,29 +583,10 @@ void LocationController::showHistoryInSearchModel()
|
|||
m_searchModel->setItems(locs);
|
||||
}
|
||||
|
||||
bool parseStringAsGeod(const QString& s, SGGeod& result)
|
||||
{
|
||||
int commaPos = s.indexOf(QChar(','));
|
||||
if (commaPos < 0)
|
||||
return false;
|
||||
|
||||
bool ok;
|
||||
double lon = s.leftRef(commaPos).toDouble(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
double lat = s.midRef(commaPos+1).toDouble(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
result = SGGeod::fromDeg(lon, lat);
|
||||
return true;
|
||||
}
|
||||
|
||||
QmlGeod LocationController::parseStringAsGeod(QString string) const
|
||||
{
|
||||
SGGeod g;
|
||||
if (!::parseStringAsGeod(string, g)) {
|
||||
if (!simgear::strutils::parseStringAsGeod(string.toStdString(), &g)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1109,7 +1083,10 @@ QString LocationController::description() const
|
|||
{
|
||||
if (!m_location) {
|
||||
if (m_locationIsLatLon) {
|
||||
return tr("at position %1").arg(formatGeodAsString(m_geodLocation));
|
||||
const auto s = simgear::strutils::formatGeodAsString(m_geodLocation,
|
||||
simgear::strutils::LatLonFormat::DECIMAL_DEGREES,
|
||||
simgear::strutils::DegreeSymbol::UTF8_DEGREE);
|
||||
return tr("at position %1").arg(QString::fromStdString(s));
|
||||
}
|
||||
|
||||
return tr("No location selected");
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
|
||||
#include <Navaids/NavDataCache.hxx>
|
||||
#include <Navaids/navrecord.hxx>
|
||||
#include <Airports/airport.hxx>
|
||||
|
@ -29,6 +31,7 @@
|
|||
#include <Airports/runways.hxx>
|
||||
|
||||
using namespace flightgear;
|
||||
using namespace simgear::strutils;
|
||||
|
||||
QmlGeod::QmlGeod() :
|
||||
m_data(SGGeod::fromDeg(-9999.0, -9999.0))
|
||||
|
@ -70,6 +73,21 @@ bool QmlGeod::valid() const
|
|||
return m_data.isValid();
|
||||
}
|
||||
|
||||
QString QmlGeod::toString(QmlGeod::Format fmt) const
|
||||
{
|
||||
if (!m_data.isValid())
|
||||
return "<invalid coordinate>";
|
||||
|
||||
LatLonFormat internalFormat = LatLonFormat::DECIMAL_DEGREES;
|
||||
switch (fmt) {
|
||||
case DecimalDegrees: internalFormat = LatLonFormat::DECIMAL_DEGREES; break;
|
||||
case SignedDecimalDegrees: internalFormat = LatLonFormat::SIGNED_DECIMAL_DEGREES; break;
|
||||
}
|
||||
|
||||
const auto s = formatGeodAsString(m_data, internalFormat, DegreeSymbol::UTF8_DEGREE);
|
||||
return QString::fromStdString(s);
|
||||
}
|
||||
|
||||
double QmlGeod::elevationM() const
|
||||
{
|
||||
return m_data.getElevationM();
|
||||
|
|
|
@ -59,6 +59,16 @@ public:
|
|||
double elevationFt() const;
|
||||
|
||||
bool valid() const;
|
||||
|
||||
enum Format {
|
||||
DecimalDegrees = 0,
|
||||
SignedDecimalDegrees
|
||||
};
|
||||
|
||||
Q_INVOKABLE QString toString(Format fmt) const;
|
||||
|
||||
Q_ENUMS(Format);
|
||||
|
||||
public slots:
|
||||
void setLatitudeDeg(double latitudeDeg);
|
||||
void setLongitudeDeg(double longitudeDeg);
|
||||
|
|
|
@ -195,8 +195,8 @@ Item {
|
|||
wrapMode: Text.WordWrap
|
||||
|
||||
text: qsTr("Enter the name, partial name or ident of a navaid or fix, or an " +
|
||||
"airport name or ICAO identifier. Alternatively, enter a latitude & longitude in " +
|
||||
"decimal notation, i.e. '-3.5, 55.4'")
|
||||
"airport name or ICAO identifier. Alternatively, enter a latitude & longitude: for " +
|
||||
"example 53.4,-3.4 or 18.4S, 87.23W")
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
|
|
|
@ -60,7 +60,7 @@ Item {
|
|||
StyledText { // heading text
|
||||
id: headingText
|
||||
width: parent.width
|
||||
text: "format lat-lon as string!"
|
||||
text: qsTr("Position: %1").arg(geod.toString(0));
|
||||
font.pixelSize: Style.headingFontPixelSize
|
||||
Binding {
|
||||
when: navaidData.valid
|
||||
|
|
Loading…
Add table
Reference in a new issue