mirror of
https://invent.kde.org/plasma/plasma-desktop.git
synced 2026-11-03 14:49:44 -09:00
The list had a few problems, notably an erratic sorting that randomly change during and after searching for a layout. While at it, refactor some code and port the models to C++.
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2024 Evgeny Chesnokov <echesnokov@astralinux.ru>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "layoutmodel.h"
|
|
|
|
#include "debug.h"
|
|
#include "keyboardsettings.h"
|
|
#include "layoutunit.h"
|
|
#include "xkb_rules.h"
|
|
|
|
LayoutModel::LayoutModel() noexcept
|
|
: QAbstractListModel()
|
|
{
|
|
for (const LayoutInfo &layoutInfo : std::as_const(Rules::self().layoutInfos)) {
|
|
m_data.append(Data(layoutInfo.name, layoutInfo.description, QStringLiteral("")));
|
|
|
|
for (const VariantInfo &variantInfo : layoutInfo.variantInfos) {
|
|
m_data.append(Data(layoutInfo.name, variantInfo.description, variantInfo.name));
|
|
}
|
|
}
|
|
}
|
|
|
|
int LayoutModel::rowCount(const QModelIndex & /*parent*/) const
|
|
{
|
|
return m_data.count();
|
|
}
|
|
|
|
QVariant LayoutModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!index.isValid())
|
|
return QVariant();
|
|
|
|
if (index.row() >= m_data.size())
|
|
return QVariant();
|
|
|
|
const auto &layout = m_data.at(index.row());
|
|
|
|
if (role == Roles::DescriptionRole || role == Qt::DisplayRole) {
|
|
return layout.description;
|
|
} else if (role == Roles::ShortNameRole) {
|
|
return layout.name;
|
|
} else if (role == Roles::VariantNameRole) {
|
|
return layout.variantName;
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
QHash<int, QByteArray> LayoutModel::roleNames() const
|
|
{
|
|
return {
|
|
{Qt::DisplayRole, QByteArrayLiteral("display")},
|
|
{Roles::ShortNameRole, QByteArrayLiteral("shortName")},
|
|
{Roles::DescriptionRole, QByteArrayLiteral("description")},
|
|
{Roles::VariantNameRole, QByteArrayLiteral("variantName")},
|
|
};
|
|
}
|
|
|
|
#include "moc_layoutmodel.cpp"
|