mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-30 02:45:37 -04:00
[keyboard] Move all the keyboard (AbstractList)Models to the models file
This commit is contained in:
parent
1d696253c3
commit
b54273f904
4 changed files with 212 additions and 211 deletions
|
@ -23,160 +23,6 @@
|
|||
#include <QProcess>
|
||||
#include <QTimer>
|
||||
|
||||
KeyboardModelsModel::KeyboardModelsModel( QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
{
|
||||
detectModels();
|
||||
}
|
||||
|
||||
void
|
||||
KeyboardModelsModel::detectModels()
|
||||
{
|
||||
beginResetModel();
|
||||
const auto models = KeyboardGlobal::getKeyboardModels();
|
||||
auto index = -1;
|
||||
for ( const auto& key : models.keys() )
|
||||
{
|
||||
index++;
|
||||
m_list << QMap< QString, QString > { { "label", key }, { "key", models[ key ] } };
|
||||
if ( models[ key ] == "pc105" )
|
||||
{
|
||||
this->setCurrentIndex( index );
|
||||
}
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void
|
||||
KeyboardModelsModel::refresh()
|
||||
{
|
||||
m_list.clear();
|
||||
setCurrentIndex( -1 );
|
||||
detectModels();
|
||||
}
|
||||
|
||||
QVariant
|
||||
KeyboardModelsModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
const auto item = m_list.at( index.row() );
|
||||
return role == Qt::DisplayRole ? item[ "label" ] : item[ "key" ];
|
||||
}
|
||||
|
||||
int
|
||||
KeyboardModelsModel::rowCount( const QModelIndex& ) const
|
||||
{
|
||||
return m_list.count();
|
||||
}
|
||||
|
||||
QHash< int, QByteArray >
|
||||
KeyboardModelsModel::roleNames() const
|
||||
{
|
||||
return { { Qt::DisplayRole, "label" }, { Qt::UserRole, "key" } };
|
||||
}
|
||||
|
||||
int
|
||||
KeyboardModelsModel::currentIndex() const
|
||||
{
|
||||
return m_currentIndex;
|
||||
}
|
||||
|
||||
const QMap< QString, QString >
|
||||
KeyboardModelsModel::item( const int& index ) const
|
||||
{
|
||||
if ( index >= m_list.count() || index < 0 )
|
||||
{
|
||||
return QMap< QString, QString >();
|
||||
}
|
||||
|
||||
return m_list.at( index );
|
||||
}
|
||||
|
||||
const QMap< QString, QString >
|
||||
KeyboardVariantsModel::item( const int& index ) const
|
||||
{
|
||||
if ( index >= m_list.count() || index < 0 )
|
||||
{
|
||||
return QMap< QString, QString >();
|
||||
}
|
||||
|
||||
return m_list.at( index );
|
||||
}
|
||||
|
||||
void
|
||||
KeyboardModelsModel::setCurrentIndex( const int& index )
|
||||
{
|
||||
if ( index >= m_list.count() || index < 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentIndex = index;
|
||||
emit currentIndexChanged( m_currentIndex );
|
||||
}
|
||||
|
||||
KeyboardVariantsModel::KeyboardVariantsModel( QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
KeyboardVariantsModel::currentIndex() const
|
||||
{
|
||||
return m_currentIndex;
|
||||
}
|
||||
|
||||
void
|
||||
KeyboardVariantsModel::setCurrentIndex( const int& index )
|
||||
{
|
||||
if ( index >= m_list.count() || index < 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentIndex = index;
|
||||
emit currentIndexChanged( m_currentIndex );
|
||||
}
|
||||
|
||||
QVariant
|
||||
KeyboardVariantsModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
const auto item = m_list.at( index.row() );
|
||||
return role == Qt::DisplayRole ? item[ "label" ] : item[ "key" ];
|
||||
}
|
||||
|
||||
int
|
||||
KeyboardVariantsModel::rowCount( const QModelIndex& ) const
|
||||
{
|
||||
return m_list.count();
|
||||
}
|
||||
|
||||
QHash< int, QByteArray >
|
||||
KeyboardVariantsModel::roleNames() const
|
||||
{
|
||||
return { { Qt::DisplayRole, "label" }, { Qt::UserRole, "key" } };
|
||||
}
|
||||
|
||||
void
|
||||
KeyboardVariantsModel::setVariants( QMap< QString, QString > variants )
|
||||
{
|
||||
m_list.clear();
|
||||
beginResetModel();
|
||||
for ( const auto& key : variants.keys() )
|
||||
{
|
||||
const auto item = QMap< QString, QString > { { "label", key }, { "key", variants[ key ] } };
|
||||
m_list << item;
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
/* Returns stringlist with suitable setxkbmap command-line arguments
|
||||
* to set the given @p layout and @p variant.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue