@ -16,30 +16,33 @@
* along with Calamares . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "L ocale Model.h"
# include "L abel Model.h"
LocaleModel : : LocaleModel ( const QStringList & locales , QObject * parent )
namespace CalamaresUtils : : Locale
{
LabelModel : : LabelModel ( const QStringList & locales , QObject * parent )
: QAbstractListModel ( parent )
{
Q_ASSERT ( locales . count ( ) > 0 ) ;
m_locales . reserve ( locales . count ( ) ) ;
for ( const auto & l : locales )
m_locales . push_back ( CalamaresUtils: : Locale Label( l ) ) ;
m_locales . push_back ( Label( l ) ) ;
}
L ocaleModel: : ~ Locale Model( )
L abelModel: : ~ Label Model( )
{
}
int
L ocale Model: : rowCount ( const QModelIndex & ) const
L abel Model: : rowCount ( const QModelIndex & ) const
{
return m_locales . count ( ) ;
}
QVariant
L ocale Model: : data ( const QModelIndex & index , int role ) const
L abel Model: : data ( const QModelIndex & index , int role ) const
{
if ( ( role ! = LabelRole ) & & ( role ! = EnglishLabelRole ) )
return QVariant ( ) ;
@ -59,8 +62,8 @@ LocaleModel::data( const QModelIndex& index, int role ) const
}
}
const CalamaresUtils: : Locale Label&
L ocale Model: : locale ( int row )
const Label&
L abel Model: : locale ( int row )
{
if ( ( row < 0 ) | | ( row > = m_locales . count ( ) ) )
{
@ -73,7 +76,7 @@ LocaleModel::locale( int row )
}
int
L ocale Model: : find ( std : : function < bool ( const Locale Label& ) > predicate ) const
L abel Model: : find ( std : : function < bool ( const Label& ) > predicate ) const
{
for ( int row = 0 ; row < m_locales . count ( ) ; + + row )
{
@ -84,26 +87,21 @@ LocaleModel::find( std::function<bool ( const LocaleLabel& )> predicate ) const
}
int
L ocale Model: : find ( std : : function < bool ( const QLocale & ) > predicate ) const
L abel Model: : find ( std : : function < bool ( const QLocale & ) > predicate ) const
{
return find ( [ & ] ( const L ocaleL abel& l )
return find ( [ & ] ( const L abel& l )
{
return predicate ( l . locale ( ) ) ;
} ) ;
}
int
L ocale Model: : find ( const QLocale & locale ) const
L abel Model: : find ( const QLocale & locale ) const
{
return find ( [ & ] ( const L ocaleL abel& l )
return find ( [ & ] ( const L abel& l )
{
return locale = = l . locale ( ) ;
} ) ;
}
void
LocaleTwoColumnDelegate : : paint ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const
{
QStyledItemDelegate : : paint ( painter , option , index ) ;
option . widget - > style ( ) - > drawItemText ( painter , option . rect , Qt : : AlignRight | Qt : : AlignVCenter , option . palette , false , index . data ( LocaleModel : : EnglishLabelRole ) . toString ( ) ) ;
}
} // namespace