diff --git a/kcms/cursortheme/kcmcursortheme.cpp b/kcms/cursortheme/kcmcursortheme.cpp --- a/kcms/cursortheme/kcmcursortheme.cpp +++ b/kcms/cursortheme/kcmcursortheme.cpp @@ -55,6 +55,22 @@ # include #endif +// Helper class to allow for easy one-time signal based activation of some function (particularly +// useful when used with lambdas) +class OneTimeAction : public QObject +{ +public: + OneTimeAction(const std::function &func, QObject* parent) : QObject(parent), m_function(func) {} + + void trigger() { + m_function(); + deleteLater(); + } + +private: + std::function m_function; +}; + K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin();) CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) @@ -462,6 +478,15 @@ if (dialog.exec()) { KNS3::Entry::List list = dialog.changedEntries(); if (!list.isEmpty()) { + if (selectedIndex().isValid()) { + const CursorTheme *theme = m_proxyModel->theme(selectedIndex()); + QString currentTheme = theme->name(); + OneTimeAction* action = new OneTimeAction([this,currentTheme](){ + m_appliedIndex = m_proxyModel->findIndex(currentTheme); + setSelectedThemeRow(m_appliedIndex.row()); + }, this); + connect(m_model, &QAbstractItemModel::modelReset, action, &OneTimeAction::trigger); + } m_model->refreshList(); } } diff --git a/kcms/cursortheme/xcursor/thememodel.cpp b/kcms/cursortheme/xcursor/thememodel.cpp --- a/kcms/cursortheme/xcursor/thememodel.cpp +++ b/kcms/cursortheme/xcursor/thememodel.cpp @@ -64,8 +64,8 @@ beginResetModel(); qDeleteAll(list); list.clear(); - endResetModel(); insertThemes(); + endResetModel(); } QVariant CursorThemeModel::headerData(int section, Qt::Orientation orientation, int role) const