[locale] Hook tz widget up to the Config's data

This commit is contained in:
Adriaan de Groot 2020-07-20 16:54:44 +02:00
parent 4d5ff6d5c4
commit f0cac7d669
5 changed files with 25 additions and 8 deletions

View File

@ -139,17 +139,29 @@ loadLocales( const QString& localeGenPath )
return localeGenLines;
}
static inline const CalamaresUtils::Locale::CStringPairList&
timezoneData()
{
return CalamaresUtils::Locale::TZRegion::fromZoneTab();
}
Config::Config( QObject* parent )
: QObject( parent )
, m_regionModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >(
CalamaresUtils::Locale::TZRegion::fromZoneTab() ) )
, m_regionModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >( ::timezoneData() ) )
, m_zonesModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >() )
{
}
Config::~Config() {}
const CalamaresUtils::Locale::CStringPairList&
Config::timezoneData() const
{
return ::timezoneData();
}
void
Config::setConfigurationMap( const QVariantMap& configurationMap )
{

View File

@ -33,6 +33,7 @@ class Config : public QObject
Q_PROPERTY( const QStringList& supportedLocales READ supportedLocales CONSTANT FINAL )
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* zonesModel READ zonesModel CONSTANT FINAL )
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* regionModel READ regionModel CONSTANT FINAL )
Q_PROPERTY( const CalamaresUtils::Locale::CStringPairList& timezoneData READ timezoneData CONSTANT FINAL )
public:
Config( QObject* parent = nullptr );
@ -44,6 +45,8 @@ public Q_SLOTS:
const QStringList& supportedLocales() const { return m_localeGenLines; }
CalamaresUtils::Locale::CStringListModel* regionModel() const { return m_regionModel.get(); }
CalamaresUtils::Locale::CStringListModel* zonesModel() const { return m_zonesModel.get(); }
// Underlying data for the models
const CalamaresUtils::Locale::CStringPairList& timezoneData() const;
private:
/// A list of supported locale identifiers (e.g. "en_US.UTF-8")

View File

@ -48,7 +48,7 @@ LocalePage::LocalePage( Config* config, QWidget* parent )
QBoxLayout* mainLayout = new QVBoxLayout;
QBoxLayout* tzwLayout = new QHBoxLayout;
m_tzWidget = new TimeZoneWidget( this );
m_tzWidget = new TimeZoneWidget( config->timezoneData(), this );
tzwLayout->addStretch();
tzwLayout->addWidget( m_tzWidget );
tzwLayout->addStretch();

View File

@ -41,9 +41,10 @@ getLocationPosition( const CalamaresUtils::Locale::TZZone* l )
}
TimeZoneWidget::TimeZoneWidget( QWidget* parent )
TimeZoneWidget::TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& zones, QWidget* parent )
: QWidget( parent )
, timeZoneImages( TimeZoneImageList::fromQRC() )
, m_zonesData( zones )
{
setMouseTracking( false );
setCursor( Qt::PointingHandCursor );
@ -67,8 +68,7 @@ void
TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
{
using namespace CalamaresUtils::Locale;
const auto& regions = TZRegion::fromZoneTab();
auto* region = regions.find< TZRegion >( regionName );
auto* region = m_zonesData.find< TZRegion >( regionName );
if ( !region )
{
return;
@ -201,7 +201,7 @@ TimeZoneWidget::mousePressEvent( QMouseEvent* event )
using namespace CalamaresUtils::Locale;
const TZZone* closest = nullptr;
for ( const auto* region_p : TZRegion::fromZoneTab() )
for ( const auto* region_p : m_zonesData )
{
const auto* region = dynamic_cast< const TZRegion* >( region_p );
if ( region )

View File

@ -53,7 +53,7 @@ class TimeZoneWidget : public QWidget
public:
using TZZone = CalamaresUtils::Locale::TZZone;
explicit TimeZoneWidget( QWidget* parent = nullptr );
explicit TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& zones, QWidget* parent = nullptr );
/** @brief Sets a location by name
*
@ -76,6 +76,8 @@ private:
QFont font;
QImage background, pin, currentZoneImage;
TimeZoneImageList timeZoneImages;
const CalamaresUtils::Locale::CStringPairList& m_zonesData;
const TZZone* m_currentLocation = nullptr; // Not owned by me
void paintEvent( QPaintEvent* event );