[keyboard] changes to the keyboardmodel to work with qml
This commit is contained in:
parent
0872de7910
commit
1a46e08cc2
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
* 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
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,11 +19,6 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "keyboardwidget/keyboardpreview.h"
|
#include "keyboardwidget/keyboardpreview.h"
|
||||||
#include "SetKeyboardLayoutJob.h"
|
#include "SetKeyboardLayoutJob.h"
|
||||||
|
|
||||||
@ -31,6 +27,10 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
KeyboardModelsModel::KeyboardModelsModel(QObject* parent) : QAbstractListModel(parent)
|
KeyboardModelsModel::KeyboardModelsModel(QObject* parent) : QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
detectModels();
|
detectModels();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
* 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
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,13 +20,14 @@
|
|||||||
#ifndef KEYBOARD_CONFIG_H
|
#ifndef KEYBOARD_CONFIG_H
|
||||||
#define KEYBOARD_CONFIG_H
|
#define KEYBOARD_CONFIG_H
|
||||||
|
|
||||||
|
#include "Job.h"
|
||||||
|
#include "KeyboardLayoutModel.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include "Job.h"
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include "KeyboardLayoutModel.h"
|
|
||||||
|
|
||||||
class KeyboardModelsModel : public QAbstractListModel
|
class KeyboardModelsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,6 @@ KeyboardLayoutModel::KeyboardLayoutModel( QObject* parent )
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
KeyboardLayoutModel::rowCount( const QModelIndex& parent ) const
|
KeyboardLayoutModel::rowCount( const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
@ -56,6 +55,14 @@ KeyboardLayoutModel::data( const QModelIndex& index, int role ) const
|
|||||||
return QVariant();
|
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
|
void
|
||||||
KeyboardLayoutModel::init()
|
KeyboardLayoutModel::init()
|
||||||
@ -72,3 +79,25 @@ KeyboardLayoutModel::init()
|
|||||||
return a.second.description < b.second.description;
|
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;
|
||||||
|
}
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class KeyboardLayoutModel : public QAbstractListModel
|
class KeyboardLayoutModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Roles : int
|
enum Roles : int
|
||||||
@ -42,10 +44,20 @@ public:
|
|||||||
|
|
||||||
QVariant data( const QModelIndex& index, int role ) const override;
|
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:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
int m_currentIndex =-1;
|
||||||
QList< QPair< QString, KeyboardGlobal::KeyboardInfo > > m_layouts;
|
QList< QPair< QString, KeyboardGlobal::KeyboardInfo > > m_layouts;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentIndexChanged(int index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEYBOARDLAYOUTMODEL_H
|
#endif // KEYBOARDLAYOUTMODEL_H
|
||||||
|
Loading…
Reference in New Issue
Block a user