#include <Navaids/navrecord.hxx>
#include <Main/options.hxx>
#include <Main/fg_init.hxx>
+#include <Main/fg_props.hxx> // for fgSetDouble
const int MAX_RECENT_AIRPORTS = 32;
QString::number(fabs(geod.getLatitudeDeg()), 'f',2 ) + ns;
}
+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;
+}
+
class IdentSearchFilter : public FGPositioned::TypeFilter
{
public:
{
flightgear::Options* opt = flightgear::Options::sharedInstance();
+ if (m_locationIsLatLon) {
+ // bypass the options mechanism because converting to deg:min:sec notation
+ // just to parse back again is nasty.
+ fgSetDouble("/sim/presets/latitude-deg", m_geodLocation.getLatitudeDeg());
+ fgSetDouble("/position/latitude-deg", m_geodLocation.getLatitudeDeg());
+ fgSetDouble("/sim/presets/longitude-deg", m_geodLocation.getLongitudeDeg());
+ fgSetDouble("/position/longitude-deg", m_geodLocation.getLongitudeDeg());
+ return;
+ }
+
if (!m_location) {
return;
}
void LocationWidget::onSearch()
{
QString search = m_ui->locationSearchEdit->text();
+
+ m_locationIsLatLon = parseStringAsGeod(search, m_geodLocation);
+ if (m_locationIsLatLon) {
+ m_ui->searchIcon->setVisible(false);
+ m_ui->searchStatusText->setText(QString("Position '%1'").arg(formatGeodAsString(m_geodLocation)));
+ m_location.clear();
+ onLocationChanged();
+ updateDescription();
+ return;
+ }
+
m_searchModel->setSearch(search);
if (m_searchModel->isSearchActive()) {
}
}
-
- } else {// of location is airport
+ } else if (m_locationIsLatLon) {
+ m_ui->stack->setCurrentIndex(1);
+ m_ui->navaidDiagram->setGeod(m_geodLocation);
+ } else {
// navaid
m_ui->stack->setCurrentIndex(1);
m_ui->navaidDiagram->setNavaid(m_location);
void LocationWidget::onOffsetEnabledToggled(bool on)
{
- m_ui->offsetDistanceLabel->setEnabled(on);
+ m_ui->navaidDiagram->setOffsetEnabled(on);
}
void LocationWidget::onAirportDiagramClicked(FGRunwayRef rwy)
QString LocationWidget::locationDescription() const
{
- if (!m_location)
+ if (!m_location) {
+ if (m_locationIsLatLon) {
+ return QString("at position %1").arg(formatGeodAsString(m_geodLocation));
+ }
+
return QString("No location selected");
+ }
bool locIsAirport = FGAirport::isAirportType(m_location.ptr());
QString ident = QString::fromStdString(m_location->ident()),
name = fixNavaidName(name);
if (locIsAirport) {
- FGAirport* apt = static_cast<FGAirport*>(m_location.ptr());
+ //FGAirport* apt = static_cast<FGAirport*>(m_location.ptr());
QString locationOnAirport;
if (m_ui->runwayRadio->isChecked()) {
return QString("at %1 %2 (%3)").arg(navaidType).arg(ident).arg(name);
}
- return QString("Implement Me");
+ return QString("No location selected");
}
m_ui->airportDiagram->setApproachExtensionDistance(m_ui->approachDistanceSpin->value());
} else {
m_ui->airportDiagram->setApproachExtensionDistance(0.0);
- }
+ }
} else {
}
void LocationWidget::onSearchResultSelected(const QModelIndex& index)
{
- qDebug() << "selected result:" << index.data();
setBaseLocation(m_searchModel->itemAtRow(index.row()));
}
void LocationWidget::onOffsetDataChanged()
{
- qDebug() << "implement me";
+ m_ui->navaidDiagram->setOffsetEnabled(m_ui->offsetGroup->isChecked());
+ m_ui->navaidDiagram->setOffsetBearingDeg(m_ui->offsetBearingSpinbox->value());
+ m_ui->navaidDiagram->setOffsetDistanceNm(m_ui->offsetNmSpinbox->value());
}
void LocationWidget::onBackToSearch()