[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:
parent
245d4a8ef7
commit
7ea2ad7dc6
@ -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
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user