New KeyboardLayoutModel.
This commit is contained in:
parent
f00d1dd654
commit
4a2cd903f7
@ -6,6 +6,7 @@ calamares_add_plugin( keyboard
|
|||||||
SOURCES
|
SOURCES
|
||||||
KeyboardViewStep.cpp
|
KeyboardViewStep.cpp
|
||||||
KeyboardPage.cpp
|
KeyboardPage.cpp
|
||||||
|
KeyboardLayoutModel.cpp
|
||||||
SetKeyboardLayoutJob.cpp
|
SetKeyboardLayoutJob.cpp
|
||||||
keyboardwidget/keyboardglobal.cpp
|
keyboardwidget/keyboardglobal.cpp
|
||||||
keyboardwidget/keyboardpreview.cpp
|
keyboardwidget/keyboardpreview.cpp
|
||||||
|
72
src/modules/keyboard/KeyboardLayoutModel.cpp
Normal file
72
src/modules/keyboard/KeyboardLayoutModel.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* 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()
|
||||||
|
{
|
||||||
|
auto layouts = KeyboardGlobal::getKeyboardLayouts();
|
||||||
|
for ( auto it = layouts.constBegin(); it != layouts.constEnd(); ++it )
|
||||||
|
{
|
||||||
|
m_layouts.append( qMakePair( it.key(), it.value() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stable_sort( m_layouts.begin(), m_layouts.end(), []( auto a, auto b )
|
||||||
|
{
|
||||||
|
return a.second.description < b.second.description;
|
||||||
|
} );
|
||||||
|
}
|
51
src/modules/keyboard/KeyboardLayoutModel.h
Normal file
51
src/modules/keyboard/KeyboardLayoutModel.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KEYBOARDLAYOUTMODEL_H
|
||||||
|
#define KEYBOARDLAYOUTMODEL_H
|
||||||
|
|
||||||
|
#include "keyboardwidget/keyboardglobal.h"
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
class KeyboardLayoutModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Roles : int
|
||||||
|
{
|
||||||
|
KeyboardVariantsRole = Qt::UserRole,
|
||||||
|
KeyboardLayoutKeyRole
|
||||||
|
};
|
||||||
|
|
||||||
|
KeyboardLayoutModel( QObject* parent = nullptr );
|
||||||
|
|
||||||
|
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
||||||
|
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init();
|
||||||
|
|
||||||
|
QList< QPair< QString, KeyboardGlobal::KeyboardInfo > > m_layouts;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KEYBOARDLAYOUTMODEL_H
|
Loading…
Reference in New Issue
Block a user