[libcalamares] Add API for geographical lookup

- find a zone given lat, lon -- with a failing test and a bogus
  implementation.
This commit is contained in:
Adriaan de Groot 2020-08-06 01:52:50 +02:00
parent 626dd038da
commit ab69e7c83a
3 changed files with 22 additions and 0 deletions

View File

@ -52,6 +52,7 @@ private Q_SLOTS:
void testComplexZones(); void testComplexZones();
void testTZLookup(); void testTZLookup();
void testTZIterator(); void testTZIterator();
void testLocationLookup();
}; };
LocaleTests::LocaleTests() {} LocaleTests::LocaleTests() {}
@ -389,6 +390,15 @@ LocaleTests::testTZIterator()
QCOMPARE( ( *zones.begin() )->zone(), QStringLiteral( "Abidjan" ) ); QCOMPARE( ( *zones.begin() )->zone(), QStringLiteral( "Abidjan" ) );
} }
void
LocaleTests::testLocationLookup()
{
const CalamaresUtils::Locale::ZonesModel zones;
QVERIFY( zones.find( 50.0, 0.0 ) );
QCOMPARE( zones.find( 50.0, 0.0 )->zone(), QStringLiteral( "London" ) );
}
QTEST_GUILESS_MAIN( LocaleTests ) QTEST_GUILESS_MAIN( LocaleTests )

View File

@ -316,6 +316,12 @@ ZonesModel::find( const QString& region, const QString& zone ) const
return nullptr; return nullptr;
} }
const TimeZoneData*
ZonesModel::find( double latitude, double longitude ) const
{
return nullptr;
}
ZonesModel::Iterator::operator bool() const ZonesModel::Iterator::operator bool() const
{ {
return 0 <= m_index && m_index < m_p->m_zones.count(); return 0 <= m_index && m_index < m_p->m_zones.count();

View File

@ -128,6 +128,12 @@ public:
*/ */
const TimeZoneData* find( const QString& region, const QString& zone ) const; const TimeZoneData* find( const QString& region, const QString& zone ) const;
/** @brief Look up TZ data based on the location.
*
* Returns the nearest zone to the given lat and lon.
*/
const TimeZoneData* find( double latitude, double longitude ) const;
/** @brief Iterator for testing purposes /** @brief Iterator for testing purposes
* *
* This is primarily for testing, but who knows, it might be useful * This is primarily for testing, but who knows, it might be useful