[welcome] Another find() overload
- Also find a specific locale - While here, apply Calamares coding style
This commit is contained in:
parent
314aee8d68
commit
0c868dbd17
@ -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<bool (const LocaleLabel &)> predicate) const
|
||||
int
|
||||
LocaleModel::find( std::function<bool ( const LocaleLabel& )> predicate ) const
|
||||
{
|
||||
for ( int row = 0; row < m_locales.count() ; ++row )
|
||||
{
|
||||
@ -89,8 +89,20 @@ LocaleModel::find(std::function<bool (const LocaleLabel &)> predicate) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
LocaleModel::find(std::function<bool (const QLocale &)> predicate) const
|
||||
int
|
||||
LocaleModel::find( std::function<bool ( const QLocale& )> 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();
|
||||
} );
|
||||
}
|
||||
|
@ -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<bool(const QLocale&)> predicate) const;
|
||||
int find( std::function<bool(const LocaleLabel&)> predicate) const;
|
||||
int find( std::function<bool( const QLocale& )> predicate ) const;
|
||||
int find( std::function<bool( const LocaleLabel& )> predicate ) const;
|
||||
int find( const QLocale& ) const;
|
||||
|
||||
private:
|
||||
QVector< LocaleLabel > m_locales;
|
||||
|
Loading…
Reference in New Issue
Block a user