diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 86ecd4097..c03afd833 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -120,6 +120,7 @@ TZRegionModel::fromFile( const char* fileName ) return model; } + model->m_regions.reserve( 12 ); // There's 10 in the file right now QStringList regions; QTextStream in( &file ); @@ -153,20 +154,20 @@ TZRegionModel::fromFile( const char* fileName ) if ( !regions.contains( region ) ) { regions.append( region ); + model->m_regions.append( new TZRegion( region.toUtf8().data() ) ); } } - regions.sort(); - - model->m_regions.reserve( regions.length() ); - for ( int i = 0; i < regions.length(); ++i ) - { - model->m_regions.append( TZRegion( regions[ i ].toUtf8().data() ) ); - } + std::sort( model->m_regions.begin(), model->m_regions.end(), []( const TZRegion* l, const TZRegion* r ) { + return *l < *r; + } ); return model; } -TZRegionModel::~TZRegionModel() {} +TZRegionModel::~TZRegionModel() +{ + qDeleteAll( m_regions ); +} int TZRegionModel::rowCount( const QModelIndex& parent ) const @@ -187,11 +188,11 @@ TZRegionModel::data( const QModelIndex& index, int role ) const return QVariant(); } - const TZRegion& region = m_regions.at( index.row() ); - return role == LabelRole ? region.tr() : region.key(); + const TZRegion* region = m_regions.at( index.row() ); + return role == LabelRole ? region->tr() : region->key(); } -const TZRegion& +const TZRegion* TZRegionModel::region( int index ) const { if ( ( index < 0 ) || ( index >= m_regions.count() ) ) diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index ef3ba2477..db54292c9 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -69,6 +69,8 @@ class TZRegion : public CStringPair public: using CStringPair::CStringPair; QString tr() const override; + + bool operator<( const TZRegion& other ) const { return m_key < other.m_key; } }; /// @brief A pair of strings for specific timezone names (e.g. "New_York") @@ -100,10 +102,10 @@ public: QVariant data( const QModelIndex& index, int role ) const override; - const TZRegion& region( int index ) const; + const TZRegion* region( int index ) const; private: - QVector< TZRegion > m_regions; + QList< TZRegion* > m_regions; }; } // namespace Locale