[libcalamares] Store zones with each region
- move operator< to base class - add each zone to the list held by the region - sort zones at the end
This commit is contained in:
parent
1a8439069e
commit
fc8364ea54
@ -147,8 +147,7 @@ TZRegion::fromFile( const char* fileName )
|
||||
return model;
|
||||
}
|
||||
|
||||
QStringList regions;
|
||||
|
||||
TZRegion* thisRegion = nullptr;
|
||||
QTextStream in( &file );
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
@ -177,10 +176,16 @@ TZRegion::fromFile( const char* fileName )
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !regions.contains( region ) )
|
||||
auto it
|
||||
= std::find_if( model.begin(), model.end(), [®ion]( const TZRegion* r ) { return r->m_key == region; } );
|
||||
if ( it != model.end() )
|
||||
{
|
||||
regions.append( region );
|
||||
model.append( new TZRegion( region.toUtf8().data() ) );
|
||||
thisRegion = *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
thisRegion = new TZRegion( region.toUtf8().data() );
|
||||
model.append( thisRegion );
|
||||
}
|
||||
|
||||
QString countryCode = list.at( 0 ).trimmed();
|
||||
@ -190,11 +195,15 @@ TZRegion::fromFile( const char* fileName )
|
||||
}
|
||||
|
||||
timezoneParts.removeFirst();
|
||||
TZZone z( timezoneParts.join( '/' ).toUtf8().constData(), countryCode, list.at( 1 ) );
|
||||
cDebug() << "Region" << region << z;
|
||||
thisRegion->m_zones.append( new TZZone( timezoneParts.join( '/' ).toUtf8().constData(), countryCode, list.at( 1 ) ) );
|
||||
}
|
||||
|
||||
std::sort( model.begin(), model.end(), []( const TZRegion* l, const TZRegion* r ) { return *l < *r; } );
|
||||
for ( auto& r : model )
|
||||
{
|
||||
std::sort( r->m_zones.begin(), r->m_zones.end(), []( const TZZone* l, const TZZone* r ) { return *l < *r; } );
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,8 @@ public:
|
||||
|
||||
QString key() const { return m_key; }
|
||||
|
||||
bool operator<( const CStringPair& other ) const { return m_key < other.m_key; }
|
||||
|
||||
protected:
|
||||
char* m_human = nullptr;
|
||||
QString m_key;
|
||||
@ -78,8 +80,6 @@ public:
|
||||
virtual ~TZRegion();
|
||||
QString tr() const override;
|
||||
|
||||
bool operator<( const TZRegion& other ) const { return m_key < other.m_key; }
|
||||
|
||||
/** @brief Create model from a zone.tab-like file
|
||||
*
|
||||
* Returns a list of all the regions; each region has a list
|
||||
|
Loading…
Reference in New Issue
Block a user