mirror-kde-plasma-desktop/kcms/keyboard/variantsmodel.h
Tobias Fella dc7b9473f7 kcms/keyboard: Refactor and fix LayoutDialog
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++.
2026-11-03 09:46:31 +00:00

37 lines
1 KiB
C++

// SPDX-FileCopyrightText: 2026 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QSortFilterProxyModel>
class VariantsModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged)
Q_PROPERTY(QString shortName READ shortName WRITE setShortName NOTIFY shortNameChanged)
public:
explicit VariantsModel(QObject *parent = nullptr);
QString searchString() const;
void setSearchString(const QString &searchString);
QString shortName() const;
void setShortName(const QString &shortName);
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
Q_SIGNALS:
void searchStringChanged();
void shortNameChanged();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
QString m_searchString = QStringLiteral("");
QString getFullName(const QModelIndex &idx) const;
QString m_shortName;
};