[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"
|
#include "LocaleModel.h"
|
||||||
|
|
||||||
LocaleModel::LocaleModel(const QStringList& locales, QObject* parent)
|
LocaleModel::LocaleModel( const QStringList& locales, QObject* parent )
|
||||||
: QAbstractTableModel( parent )
|
: QAbstractTableModel( parent )
|
||||||
{
|
{
|
||||||
Q_ASSERT( locales.count() > 0 );
|
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() );
|
const auto& locale = m_locales.at( index.row() );
|
||||||
switch ( index.column() )
|
switch ( index.column() )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return locale.label();
|
return locale.label();
|
||||||
case 1:
|
case 1:
|
||||||
return locale.englishLabel();
|
return locale.englishLabel();
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CalamaresUtils::LocaleLabel&
|
const CalamaresUtils::LocaleLabel&
|
||||||
LocaleModel::locale(int row)
|
LocaleModel::locale( int row )
|
||||||
{
|
{
|
||||||
if ( ( row < 0 ) || ( row >= m_locales.count() ) )
|
if ( ( row < 0 ) || ( row >= m_locales.count() ) )
|
||||||
{
|
{
|
||||||
@ -79,7 +79,7 @@ LocaleModel::locale(int row)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
LocaleModel::find(std::function<bool (const LocaleLabel &)> predicate) const
|
LocaleModel::find( std::function<bool ( const LocaleLabel& )> predicate ) const
|
||||||
{
|
{
|
||||||
for ( int row = 0; row < m_locales.count() ; ++row )
|
for ( int row = 0; row < m_locales.count() ; ++row )
|
||||||
{
|
{
|
||||||
@ -90,7 +90,19 @@ LocaleModel::find(std::function<bool (const LocaleLabel &)> predicate) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
LocaleModel::find(std::function<bool (const QLocale &)> predicate) const
|
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();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,9 @@ public:
|
|||||||
*
|
*
|
||||||
* Returns the row number of the first match, or -1 if there isn't one.
|
* 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 QLocale& )> predicate ) const;
|
||||||
int find( std::function<bool(const LocaleLabel&)> predicate) const;
|
int find( std::function<bool( const LocaleLabel& )> predicate ) const;
|
||||||
|
int find( const QLocale& ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector< LocaleLabel > m_locales;
|
QVector< LocaleLabel > m_locales;
|
||||||
|
Loading…
Reference in New Issue
Block a user