mirror of
https://invent.kde.org/plasma/plasma-desktop.git
synced 2026-11-03 22:59:45 -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++.
37 lines
1 KiB
C++
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;
|
|
};
|