[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
main
Adriaan de Groot 5 years ago
parent 1a8439069e
commit fc8364ea54

@ -147,8 +147,7 @@ TZRegion::fromFile( const char* fileName )
return model; return model;
} }
QStringList regions; TZRegion* thisRegion = nullptr;
QTextStream in( &file ); QTextStream in( &file );
while ( !in.atEnd() ) while ( !in.atEnd() )
{ {
@ -177,10 +176,16 @@ TZRegion::fromFile( const char* fileName )
continue; continue;
} }
if ( !regions.contains( region ) ) auto it
= std::find_if( model.begin(), model.end(), [&region]( const TZRegion* r ) { return r->m_key == region; } );
if ( it != model.end() )
{
thisRegion = *it;
}
else
{ {
regions.append( region ); thisRegion = new TZRegion( region.toUtf8().data() );
model.append( new TZRegion( region.toUtf8().data() ) ); model.append( thisRegion );
} }
QString countryCode = list.at( 0 ).trimmed(); QString countryCode = list.at( 0 ).trimmed();
@ -190,11 +195,15 @@ TZRegion::fromFile( const char* fileName )
} }
timezoneParts.removeFirst(); timezoneParts.removeFirst();
TZZone z( timezoneParts.join( '/' ).toUtf8().constData(), countryCode, list.at( 1 ) ); thisRegion->m_zones.append( new TZZone( timezoneParts.join( '/' ).toUtf8().constData(), countryCode, list.at( 1 ) ) );
cDebug() << "Region" << region << z;
} }
std::sort( model.begin(), model.end(), []( const TZRegion* l, const TZRegion* r ) { return *l < *r; } ); 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; return model;
} }

@ -60,6 +60,8 @@ public:
QString key() const { return m_key; } QString key() const { return m_key; }
bool operator<( const CStringPair& other ) const { return m_key < other.m_key; }
protected: protected:
char* m_human = nullptr; char* m_human = nullptr;
QString m_key; QString m_key;
@ -78,8 +80,6 @@ public:
virtual ~TZRegion(); virtual ~TZRegion();
QString tr() const override; 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 /** @brief Create model from a zone.tab-like file
* *
* Returns a list of all the regions; each region has a list * Returns a list of all the regions; each region has a list

Loading…
Cancel
Save