[keyboard] changes to the keyboardmodel to work with qml

This commit is contained in:
Camilo Higuita 2020-04-03 10:18:07 +02:00 committed by Adriaan de Groot
parent 0872de7910
commit 1a46e08cc2
4 changed files with 63 additions and 20 deletions

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
* Copyright 2020, Camilo Higuita <milo.h@aol.com> *
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,11 +19,6 @@
#include "Config.h"
#include <QDebug>
#include <QProcess>
#include <QApplication>
#include <QTimer>
#include "keyboardwidget/keyboardpreview.h"
#include "SetKeyboardLayoutJob.h"
@ -31,6 +27,10 @@
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include <QProcess>
#include <QApplication>
#include <QTimer>
KeyboardModelsModel::KeyboardModelsModel(QObject* parent) : QAbstractListModel(parent)
{
detectModels();

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
* Copyright 2020, Camilo Higuita <milo.h@aol.com>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,13 +20,14 @@
#ifndef KEYBOARD_CONFIG_H
#define KEYBOARD_CONFIG_H
#include "Job.h"
#include "KeyboardLayoutModel.h"
#include <QObject>
#include <QUrl>
#include <QTimer>
#include <QMap>
#include "Job.h"
#include <QAbstractListModel>
#include "KeyboardLayoutModel.h"
class KeyboardModelsModel : public QAbstractListModel
{

View File

@ -28,7 +28,6 @@ KeyboardLayoutModel::KeyboardLayoutModel( QObject* parent )
init();
}
int
KeyboardLayoutModel::rowCount( const QModelIndex& parent ) const
{
@ -56,6 +55,14 @@ KeyboardLayoutModel::data( const QModelIndex& index, int role ) const
return QVariant();
}
const QPair< QString, KeyboardGlobal::KeyboardInfo >
KeyboardLayoutModel::item(const int &index) const
{
if(index >= m_layouts.count() || index < 0)
return QPair< QString, KeyboardGlobal::KeyboardInfo >();
return m_layouts.at(index);
}
void
KeyboardLayoutModel::init()
@ -72,3 +79,25 @@ KeyboardLayoutModel::init()
return a.second.description < b.second.description;
} );
}
QHash<int, QByteArray>
KeyboardLayoutModel::roleNames() const
{
return {{Qt::DisplayRole, "label"}, {KeyboardLayoutKeyRole, "key"}, {KeyboardVariantsRole, "variants"}};
}
void
KeyboardLayoutModel::setCurrentIndex(const int &index)
{
if(index >= m_layouts.count() || index < 0)
return;
m_currentIndex = index;
emit currentIndexChanged(m_currentIndex);
}
int
KeyboardLayoutModel::currentIndex() const
{
return m_currentIndex;
}

View File

@ -24,10 +24,12 @@
#include <QAbstractListModel>
#include <QMap>
#include <QMetaType>
#include <QObject>
class KeyboardLayoutModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
public:
enum Roles : int
@ -42,10 +44,20 @@ public:
QVariant data( const QModelIndex& index, int role ) const override;
void setCurrentIndex(const int &index);
int currentIndex() const;
const QPair< QString, KeyboardGlobal::KeyboardInfo > item(const int &index) const;
protected:
QHash<int, QByteArray> roleNames() const override;
private:
void init();
int m_currentIndex =-1;
QList< QPair< QString, KeyboardGlobal::KeyboardInfo > > m_layouts;
signals:
void currentIndexChanged(int index);
};
#endif // KEYBOARDLAYOUTMODEL_H