From 01bba7b4668954ffdbb328da961e72bd21887c20 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Dec 2019 23:36:05 -1100 Subject: [PATCH] [libcalamares] Make explicit when a model comes from a file --- src/libcalamares/locale/TimeZone.cpp | 22 +++++++++++++++++----- src/libcalamares/locale/TimeZone.h | 9 ++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 97795ab84..86ecd4097 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -101,13 +101,23 @@ TZZone::tr() const return QObject::tr( m_human, "tz_names" ); } -TZRegionModel::TZRegionModel() +TZRegionModel::TZRegionModel() {} + +std::shared_ptr< TZRegionModel > +TZRegionModel::fromZoneTab() { + return TZRegionModel::fromFile( TZ_DATA_FILE ); +} - QFile file( TZ_DATA_FILE ); +std::shared_ptr< TZRegionModel > +TZRegionModel::fromFile( const char* fileName ) +{ + auto model = std::make_shared< TZRegionModel >(); + + QFile file( fileName ); if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { - return; + return model; } QStringList regions; @@ -147,11 +157,13 @@ TZRegionModel::TZRegionModel() } regions.sort(); - m_regions.reserve( regions.length() ); + model->m_regions.reserve( regions.length() ); for ( int i = 0; i < regions.length(); ++i ) { - m_regions.append( TZRegion( regions[ i ].toUtf8().data() ) ); + model->m_regions.append( TZRegion( regions[ i ].toUtf8().data() ) ); } + + return model; } TZRegionModel::~TZRegionModel() {} diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 844e94a47..ef3ba2477 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -25,6 +25,8 @@ #include #include +#include + namespace CalamaresUtils { namespace Locale @@ -85,10 +87,15 @@ public: LabelRole = Qt::DisplayRole }; - /// @brief Create from the zone.tab file + /// @brief Create empty model (useless) TZRegionModel(); virtual ~TZRegionModel() override; + /// @brief Create model from a zone.tab-like file + static std::shared_ptr< TZRegionModel > fromFile( const char* fileName ); + /// @brief Calls fromFile with the standard zone.tab name + static std::shared_ptr< TZRegionModel > fromZoneTab(); + int rowCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override;