diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 816246699..02583df8b 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -33,9 +33,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : QObject( parent ) , m_locale( Label::getLocale( locale ) ) , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) - { - //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); QString languageName = m_locale.nativeLanguageName(); diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index d7fa14453..bd596f53d 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -40,10 +40,6 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY( QString label READ label CONSTANT FINAL ) - Q_PROPERTY( QString englishLabel READ englishLabel CONSTANT FINAL ) - Q_PROPERTY( QString localeId MEMBER m_localeId CONSTANT FINAL ) - public: /** @brief Formatting option for label -- add (country) to label. */ enum class LabelFormat @@ -65,6 +61,7 @@ public: LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr ); + /** @brief Define a sorting order. * * Locales are sorted by their id, which means the ISO 2-letter code + country. diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 58695ee0e..fb224f9c4 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -239,7 +239,12 @@ CStringListModel::CStringListModel( CStringPairList l ) { } -CStringListModel::~CStringListModel() {} +void CStringListModel::setList(CalamaresUtils::Locale::CStringPairList l) +{ + beginResetModel(); + m_list = l; + endResetModel(); +} int CStringListModel::rowCount( const QModelIndex& ) const @@ -264,6 +269,28 @@ CStringListModel::data( const QModelIndex& index, int role ) const return item ? ( role == Qt::DisplayRole ? item->tr() : item->key() ) : QVariant(); } +void +CStringListModel::setCurrentIndex(const int &index) +{ + if ( ( index < 0 ) || ( index >= m_list.count() ) ) + return; + + m_currentIndex = index; + emit currentIndexChanged(); +} + +int +CStringListModel::currentIndex() const +{ + return m_currentIndex; +} + +QHash +CStringListModel::roleNames() const +{ + return {{Qt::DisplayRole,"label"}, {Qt::UserRole, "key"}}; +} + const CStringPair* CStringListModel::item( int index ) const { diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 3345e61f8..32c4622cf 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -44,8 +44,9 @@ namespace Locale * QPair because there is API that needs * C-style strings. */ -class CStringPair +class CStringPair : public QObject { + Q_OBJECT public: /// @brief An empty pair CStringPair() {} @@ -86,6 +87,7 @@ public: /// @brief A pair of strings for timezone regions (e.g. "America") class TZRegion : public CStringPair { + Q_OBJECT public: using CStringPair::CStringPair; virtual ~TZRegion() override; @@ -117,6 +119,7 @@ private: /// @brief A pair of strings for specific timezone names (e.g. "New_York") class TZZone : public CStringPair { + Q_OBJECT public: using CStringPair::CStringPair; QString tr() const override; @@ -137,21 +140,47 @@ protected: class CStringListModel : public QAbstractListModel { + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + public: /// @brief Create empty model - CStringListModel(); + CStringListModel() {}; /// @brief Create model from list (non-owning) CStringListModel( CStringPairList ); - virtual ~CStringListModel() override; int rowCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; const CStringPair* item( int index ) const; + QHash roleNames() const override; + + void setCurrentIndex(const int &index); + int currentIndex() const; + + void setList(CStringPairList); + + inline int indexOf(const QString &key) + { + const auto it = std::find_if(m_list.constBegin(), m_list.constEnd(), [&](const CalamaresUtils::Locale::CStringPair *item) -> bool + { + return item->key() == key; + + }); + + if(it != m_list.constEnd()) + return std::distance(m_list.constBegin(), it); + else return -1; + } + private: CStringPairList m_list; + int m_currentIndex = -1; + +signals: + void currentIndexChanged(); }; } // namespace Locale