2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2016-05-31 19:05:25 +02:00
|
|
|
*
|
|
|
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
2017-06-07 16:15:13 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2016-05-31 19:05:25 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "KeyboardLayoutModel.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
KeyboardLayoutModel::KeyboardLayoutModel( QObject* parent )
|
|
|
|
: QAbstractListModel( parent )
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
KeyboardLayoutModel::rowCount( const QModelIndex& parent ) const
|
|
|
|
{
|
|
|
|
Q_UNUSED( parent );
|
|
|
|
return m_layouts.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant
|
|
|
|
KeyboardLayoutModel::data( const QModelIndex& index, int role ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch ( role )
|
|
|
|
{
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return m_layouts.at( index.row() ).second.description;
|
|
|
|
case KeyboardVariantsRole:
|
|
|
|
return QVariant::fromValue( m_layouts.at( index.row() ).second.variants );
|
|
|
|
case KeyboardLayoutKeyRole:
|
|
|
|
return m_layouts.at( index.row() ).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyboardLayoutModel::init()
|
|
|
|
{
|
2017-06-07 16:15:13 +02:00
|
|
|
KeyboardGlobal::LayoutsMap layouts =
|
2017-09-26 11:22:51 +02:00
|
|
|
KeyboardGlobal::getKeyboardLayouts();
|
2017-06-07 16:15:13 +02:00
|
|
|
for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin();
|
2017-09-26 11:22:51 +02:00
|
|
|
it != layouts.constEnd(); ++it )
|
2016-05-31 19:05:25 +02:00
|
|
|
m_layouts.append( qMakePair( it.key(), it.value() ) );
|
|
|
|
|
2016-06-13 17:47:54 +02:00
|
|
|
std::stable_sort( m_layouts.begin(), m_layouts.end(), []( const QPair< QString, KeyboardGlobal::KeyboardInfo >& a,
|
2017-09-26 11:22:51 +02:00
|
|
|
const QPair< QString, KeyboardGlobal::KeyboardInfo >& b )
|
2016-05-31 19:05:25 +02:00
|
|
|
{
|
|
|
|
return a.second.description < b.second.description;
|
|
|
|
} );
|
|
|
|
}
|