[libcalamares] Add accessors for TZ data and region in the model

It's convenient when e.g. QComboBox::currentData() gets the key
"automatically", and the default role for that method is UserRole,
so let the value of KeyRole overlap.
This commit is contained in:
Adriaan de Groot 2020-08-05 23:26:17 +02:00
parent 245d4a8ef7
commit 7ea2ad7dc6
2 changed files with 17 additions and 7 deletions

View File

@ -262,16 +262,18 @@ ZonesModel::data( const QModelIndex& index, int role ) const
}
const auto* zone = m_private->m_zones[ index.row() ];
if ( role == NameRole )
switch ( role )
{
case NameRole:
return zone->tr();
}
if ( role == KeyRole )
{
case KeyRole:
return zone->key();
}
case RegionRole:
return zone->region();
default:
return QVariant();
}
}
QHash< int, QByteArray >
ZonesModel::roleNames() const

View File

@ -54,11 +54,18 @@ public:
const QString& country,
double latitude,
double longitude );
TimeZoneData( const TimeZoneData& ) = delete;
TimeZoneData( TimeZoneData&& ) = delete;
QString tr() const override;
QString region() const { return m_region; }
QString zone() const { return key(); }
QString country() const { return m_country; }
double latitude() const { return m_latitude; }
double longitude() const { return m_longitude; }
private:
QString m_region;
QString m_country;
@ -80,7 +87,7 @@ public:
enum Roles
{
NameRole = Qt::DisplayRole,
KeyRole = Qt::UserRole + 1
KeyRole = Qt::UserRole // So that currentData() will get the key
};
RegionsModel( QObject* parent = nullptr );
@ -103,7 +110,8 @@ public:
enum Roles
{
NameRole = Qt::DisplayRole,
KeyRole = Qt::UserRole + 1
KeyRole = Qt::UserRole, // So that currentData() will get the key
RegionRole = Qt::UserRole + 1
};
ZonesModel( QObject* parent = nullptr );