[libcalamares] Add a find() to ZonesModel
- Look up TZ data by region and zone name.
This commit is contained in:
parent
478a275764
commit
245d4a8ef7
@ -50,6 +50,7 @@ private Q_SLOTS:
|
||||
void testRegions();
|
||||
void testSimpleZones();
|
||||
void testComplexZones();
|
||||
void testTZLookup();
|
||||
};
|
||||
|
||||
LocaleTests::LocaleTests() {}
|
||||
@ -345,6 +346,21 @@ LocaleTests::testComplexZones()
|
||||
QVERIFY( names.contains( "Abidjan" ) );
|
||||
}
|
||||
|
||||
void
|
||||
LocaleTests::testTZLookup()
|
||||
{
|
||||
using namespace CalamaresUtils::Locale;
|
||||
ZonesModel zones;
|
||||
|
||||
QVERIFY( zones.find( "America", "New_York" ) );
|
||||
QCOMPARE( zones.find( "America", "New_York" )->zone(), QStringLiteral( "New_York" ) );
|
||||
QCOMPARE( zones.find( "America", "New_York" )->tr(), QStringLiteral( "New York" ) );
|
||||
|
||||
QVERIFY( !zones.find( "Europe", "New_York" ) );
|
||||
QVERIFY( !zones.find( "America", "New York" ) );
|
||||
}
|
||||
|
||||
|
||||
QTEST_GUILESS_MAIN( LocaleTests )
|
||||
|
||||
#include "utils/moc-warnings.h"
|
||||
|
@ -279,6 +279,19 @@ ZonesModel::roleNames() const
|
||||
return { { NameRole, "name" }, { KeyRole, "key" } };
|
||||
}
|
||||
|
||||
const TimeZoneData*
|
||||
ZonesModel::find( const QString& region, const QString& zone )
|
||||
{
|
||||
for ( const auto* p : m_private->m_zones )
|
||||
{
|
||||
if ( p->region() == region && p->zone() == zone )
|
||||
{
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RegionalZonesModel::RegionalZonesModel( CalamaresUtils::Locale::ZonesModel* source, QObject* parent )
|
||||
: QSortFilterProxyModel( parent )
|
||||
, m_private( privateInstance() )
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
QString tr() const override;
|
||||
|
||||
QString region() const { return m_region; }
|
||||
QString zone() const { return key(); }
|
||||
|
||||
private:
|
||||
QString m_region;
|
||||
@ -113,6 +114,12 @@ public:
|
||||
|
||||
QHash< int, QByteArray > roleNames() const override;
|
||||
|
||||
/** @brief Look up TZ data based on its name.
|
||||
*
|
||||
* Returns @c nullptr if not found.
|
||||
*/
|
||||
const TimeZoneData* find( const QString& region, const QString& zone );
|
||||
|
||||
private:
|
||||
Private* m_private;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user