source: calamares/trunk/fuentes/src/modules/keyboard/KeyboardLayoutModel.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 2.2 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2016, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "KeyboardLayoutModel.h"
21
22#include <algorithm>
23
24
25KeyboardLayoutModel::KeyboardLayoutModel( QObject* parent )
26    : QAbstractListModel( parent )
27{
28    init();
29}
30
31
32int
33KeyboardLayoutModel::rowCount( const QModelIndex& parent ) const
34{
35    Q_UNUSED( parent );
36    return m_layouts.count();
37}
38
39
40QVariant
41KeyboardLayoutModel::data( const QModelIndex& index, int role ) const
42{
43    if ( !index.isValid() )
44        return QVariant();
45
46    switch ( role )
47    {
48    case Qt::DisplayRole:
49        return m_layouts.at( index.row() ).second.description;
50    case KeyboardVariantsRole:
51        return QVariant::fromValue( m_layouts.at( index.row() ).second.variants );
52    case KeyboardLayoutKeyRole:
53        return m_layouts.at( index.row() ).first;
54    }
55
56    return QVariant();
57}
58
59
60void
61KeyboardLayoutModel::init()
62{
63    KeyboardGlobal::LayoutsMap layouts =
64        KeyboardGlobal::getKeyboardLayouts();
65    for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin();
66            it != layouts.constEnd(); ++it )
67        m_layouts.append( qMakePair( it.key(), it.value() ) );
68
69    std::stable_sort( m_layouts.begin(), m_layouts.end(), []( const QPair< QString, KeyboardGlobal::KeyboardInfo >& a,
70                      const QPair< QString, KeyboardGlobal::KeyboardInfo >& b )
71    {
72        return a.second.description < b.second.description;
73    } );
74}
Note: See TracBrowser for help on using the repository browser.