Commit 846a9636 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

ksplash kcm: Sort grid view KCM case insensitively

Since this KCM can display user and distro provided content, we can't
ensure that everything will begin with a capital letter. Accordingly, we
should sort the grid case-insensitively to prevent the entries starting
with lowercase letters from being shunted to the end.

CCBUG: 404608
parent 9574fbb6
......@@ -26,6 +26,7 @@
#include <QDir>
#include <QProcess>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStandardPaths>
......@@ -59,6 +60,11 @@ KCMSplashScreen::KCMSplashScreen(QObject *parent, const QVariantList &args)
roles[PendingDeletionRole] = "pendingDeletion";
m_model->setItemRoleNames(roles);
m_sortModel = new QSortFilterProxyModel(this);
m_sortModel->setSourceModel(m_model);
m_sortModel->setSortLocaleAware(true);
m_sortModel->setSortCaseSensitivity(Qt::CaseInsensitive);
connect(m_model, &QAbstractItemModel::dataChanged, this, [this] {
bool hasPendingDeletions = !pendingDeletions().isEmpty();
setNeedsSave(m_data->settings()->isSaveNeeded() || hasPendingDeletions);
......@@ -94,9 +100,9 @@ SplashScreenSettings *KCMSplashScreen::splashScreenSettings() const
return m_data->settings();
}
QStandardItemModel *KCMSplashScreen::splashModel() const
QAbstractProxyModel *KCMSplashScreen::splashModel() const
{
return m_model;
return m_sortModel;
}
void KCMSplashScreen::ghnsEntriesChanged(const QQmlListReference &changedEntries)
......@@ -123,7 +129,7 @@ void KCMSplashScreen::load()
m_packageRoot = writableLocation + QLatin1Char('/') + pkg.defaultPackageRoot();
m_model->appendRow(row);
}
m_model->sort(0 /*column*/);
m_sortModel->sort(PluginNameRole);
QStandardItem *row = new QStandardItem(i18n("None"));
row->setData("None", PluginNameRole);
......@@ -163,6 +169,11 @@ void KCMSplashScreen::save()
ManagedConfigModule::save();
}
int KCMSplashScreen::sortModelPluginIndex(const QString &pluginName) const
{
return m_sortModel->mapFromSource(m_model->index(pluginIndex(pluginName), 0)).row();
}
int KCMSplashScreen::pluginIndex(const QString &pluginName) const
{
const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, pluginName, 1, Qt::MatchExactly);
......
......@@ -25,6 +25,7 @@
#include <KQuickAddons/ManagedConfigModule>
class QStandardItemModel;
class QSortFilterProxyModel;
class SplashScreenSettings;
class SplashScreenData;
......@@ -32,7 +33,7 @@ class KCMSplashScreen : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(SplashScreenSettings *splashScreenSettings READ splashScreenSettings CONSTANT)
Q_PROPERTY(QStandardItemModel *splashModel READ splashModel CONSTANT)
Q_PROPERTY(QAbstractProxyModel *splashModel READ splashModel CONSTANT)
Q_PROPERTY(bool testing READ testing NOTIFY testingChanged)
public:
......@@ -47,10 +48,10 @@ public:
KCMSplashScreen(QObject *parent, const QVariantList &args);
SplashScreenSettings *splashScreenSettings() const;
QStandardItemModel *splashModel() const;
QAbstractProxyModel *splashModel() const;
bool testing() const;
Q_INVOKABLE int pluginIndex(const QString &pluginName) const;
Q_INVOKABLE int sortModelPluginIndex(const QString &pluginName) const;
QStringList pendingDeletions();
public Q_SLOTS:
......@@ -67,12 +68,14 @@ Q_SIGNALS:
private:
QList<KPackage::Package> availablePackages(const QString &component);
int pluginIndex(const QString &pluginName) const;
SplashScreenData *m_data;
QStandardItemModel *m_model;
QProcess *m_testProcess = nullptr;
QString m_packageRoot;
QSortFilterProxyModel *m_sortModel;
};
#endif
......@@ -36,7 +36,7 @@ KCM.GridViewKCM {
view.model: kcm.splashModel
//NOTE: pay attention to never break this binding
view.currentIndex: kcm.pluginIndex(kcm.splashScreenSettings.theme)
view.currentIndex: kcm.sortModelPluginIndex(kcm.splashScreenSettings.theme)
// putting the InlineMessage as header item causes it to show up initially despite visible false
header: ColumnLayout {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment