From 0c868dbd17f913be449763e2673aec9bec404a1e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 09:39:19 +0200 Subject: [PATCH] [welcome] Another find() overload - Also find a specific locale - While here, apply Calamares coding style --- src/modules/welcome/LocaleModel.cpp | 40 +++++++++++++++++++---------- src/modules/welcome/LocaleModel.h | 13 +++++----- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp index d2517a461..43d13ea6c 100644 --- a/src/modules/welcome/LocaleModel.cpp +++ b/src/modules/welcome/LocaleModel.cpp @@ -18,7 +18,7 @@ #include "LocaleModel.h" -LocaleModel::LocaleModel(const QStringList& locales, QObject* parent) +LocaleModel::LocaleModel( const QStringList& locales, QObject* parent ) : QAbstractTableModel( parent ) { Q_ASSERT( locales.count() > 0 ); @@ -56,17 +56,17 @@ LocaleModel::data( const QModelIndex& index, int role ) const const auto& locale = m_locales.at( index.row() ); switch ( index.column() ) { - case 0: - return locale.label(); - case 1: - return locale.englishLabel(); - default: - return QVariant(); + case 0: + return locale.label(); + case 1: + return locale.englishLabel(); + default: + return QVariant(); } } -const CalamaresUtils::LocaleLabel& -LocaleModel::locale(int row) +const CalamaresUtils::LocaleLabel& +LocaleModel::locale( int row ) { if ( ( row < 0 ) || ( row >= m_locales.count() ) ) { @@ -78,8 +78,8 @@ LocaleModel::locale(int row) return m_locales[row]; } -int -LocaleModel::find(std::function predicate) const +int +LocaleModel::find( std::function predicate ) const { for ( int row = 0; row < m_locales.count() ; ++row ) { @@ -89,8 +89,20 @@ LocaleModel::find(std::function predicate) const return -1; } -int -LocaleModel::find(std::function predicate) const +int +LocaleModel::find( std::function predicate ) const { - return find( [&]( const LocaleLabel& l ){ return predicate( l.locale() ); } ); + return find( [&]( const LocaleLabel& l ) + { + return predicate( l.locale() ); + } ); +} + +int +LocaleModel::find( const QLocale& locale ) const +{ + return find( [&]( const LocaleLabel& l ) + { + return locale == l.locale(); + } ); } diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index 68cede172..4df183048 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -29,7 +29,7 @@ class LocaleModel : public QAbstractTableModel { public: using LocaleLabel = CalamaresUtils::LocaleLabel; - + LocaleModel( const QStringList& locales, QObject* parent = nullptr ); virtual ~LocaleModel() override; @@ -39,18 +39,19 @@ public: QVariant data( const QModelIndex& index, int role ) const override; /** @brief Gets locale information for entry #n - * + * * This is the backing data for the model; if @p row is out-of-range, * returns a reference to en_US. */ const LocaleLabel& locale( int row ); - + /** @brief Searches for an item that matches @p predicate - * + * * Returns the row number of the first match, or -1 if there isn't one. */ - int find( std::function predicate) const; - int find( std::function predicate) const; + int find( std::function predicate ) const; + int find( std::function predicate ) const; + int find( const QLocale& ) const; private: QVector< LocaleLabel > m_locales;