[libcalamares] Expose distanceFunc-find for timezones
This commit is contained in:
parent
0fda1dcf7d
commit
2f871acbfd
@ -337,14 +337,14 @@ ZonesModel::find( const QString& region, const QString& zone ) const
|
||||
}
|
||||
|
||||
STATICTEST const TimeZoneData*
|
||||
find( const ZoneVector& zones, std::function< double( const TimeZoneData* ) > distance )
|
||||
find( const ZoneVector& zones, const std::function< double( const TimeZoneData* ) >& distanceFunc )
|
||||
{
|
||||
double smallestDistance = 1000000.0;
|
||||
const TimeZoneData* closest = nullptr;
|
||||
|
||||
for ( const auto* zone : zones )
|
||||
{
|
||||
double thisDistance = distance( zone );
|
||||
double thisDistance = distanceFunc( zone );
|
||||
if ( thisDistance < smallestDistance )
|
||||
{
|
||||
closest = zone;
|
||||
@ -354,6 +354,12 @@ find( const ZoneVector& zones, std::function< double( const TimeZoneData* ) > di
|
||||
return closest;
|
||||
}
|
||||
|
||||
const TimeZoneData*
|
||||
ZonesModel::find( const std::function< double( const TimeZoneData* ) >& distanceFunc ) const
|
||||
{
|
||||
return CalamaresUtils::Locale::find( m_private->m_zones, distanceFunc );
|
||||
}
|
||||
|
||||
const TimeZoneData*
|
||||
ZonesModel::find( double latitude, double longitude ) const
|
||||
{
|
||||
@ -384,7 +390,7 @@ ZonesModel::find( double latitude, double longitude ) const
|
||||
return latitudeDifference + longitudeDifference;
|
||||
};
|
||||
|
||||
return CalamaresUtils::Locale::find( m_private->m_zones, distance );
|
||||
return find( distance );
|
||||
}
|
||||
|
||||
QObject*
|
||||
|
@ -167,6 +167,17 @@ public:
|
||||
|
||||
Iterator begin() const { return Iterator( m_private ); }
|
||||
|
||||
/** @brief Look up TZ data based on an arbitrary distance function
|
||||
*
|
||||
* This is a generic method that can define distance in whatever
|
||||
* coordinate system is wanted; returns the zone with the smallest
|
||||
* distance. The @p distanceFunc must return "the distance" for
|
||||
* each zone. It would be polite to return something non-negative.
|
||||
*
|
||||
* Note: not a slot, because the parameter isn't moc-able.
|
||||
*/
|
||||
const TimeZoneData* find( const std::function< double( const TimeZoneData* ) >& distanceFunc ) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/** @brief Look up TZ data based on its name.
|
||||
*
|
||||
@ -176,7 +187,10 @@ public Q_SLOTS:
|
||||
|
||||
/** @brief Look up TZ data based on the location.
|
||||
*
|
||||
* Returns the nearest zone to the given lat and lon.
|
||||
* Returns the nearest zone to the given lat and lon. This is a
|
||||
* convenience function for calling find(), below, with a standard
|
||||
* distance function based on the distance between the given
|
||||
* location (lat and lon) and each zone's given location.
|
||||
*/
|
||||
const TimeZoneData* find( double latitude, double longitude ) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user