Commit 4ba2fe65 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Fix changed signal for plugin selector

parent 0d4ea515
......@@ -359,6 +359,7 @@ void KPluginSelector::load()
d->pluginModel->setData(index, pluginEntry->pluginInfo.isPluginEnabled(), Qt::CheckStateRole);
}
static_cast<KPluginSelector::Private::PluginDelegate*>(d->listView->itemDelegate())->clearChangedEntries();
emit changed(false);
}
......@@ -372,17 +373,24 @@ void KPluginSelector::save()
pluginEntry->cfgGroup.sync();
}
static_cast<KPluginSelector::Private::PluginDelegate*>(d->listView->itemDelegate())->clearChangedEntries();
emit changed(false);
}
void KPluginSelector::defaults()
{
bool isChanged = false;
auto delegate = static_cast<KPluginSelector::Private::PluginDelegate*>(d->listView->itemDelegate());
delegate->clearChangedEntries();
for (int i = 0; i < d->pluginModel->rowCount(); i++) {
const QModelIndex index = d->pluginModel->index(i, 0);
PluginEntry *pluginEntry = static_cast<PluginEntry *>(index.internalPointer());
isChanged |= pluginEntry->pluginInfo.isPluginEnabled() != pluginEntry->pluginInfo.isPluginEnabledByDefault();
bool entryChanged = pluginEntry->pluginInfo.isPluginEnabled() != pluginEntry->pluginInfo.isPluginEnabledByDefault();
isChanged |= entryChanged;
d->pluginModel->setData(index, pluginEntry->pluginInfo.isPluginEnabledByDefault(), Qt::CheckStateRole);
if (entryChanged) {
delegate->addChangedEntry(pluginEntry);
}
}
emit changed(isChanged);
......@@ -403,6 +411,7 @@ bool KPluginSelector::isDefault() const
void KPluginSelector::updatePluginsState()
{
static_cast<KPluginSelector::Private::PluginDelegate*>(d->listView->itemDelegate())->clearChangedEntries();
for (int i = 0; i < d->pluginModel->rowCount(); i++) {
const QModelIndex index = d->pluginModel->index(i, 0);
PluginEntry *pluginEntry = static_cast<PluginEntry *>(index.internalPointer());
......@@ -803,8 +812,12 @@ void KPluginSelector::Private::PluginDelegate::emitChanged(bool state)
{
const QModelIndex index = focusedIndex();
PluginEntry *pluginEntry = index.model()->data(index, PluginEntryRole).value<PluginEntry *>();
emit changed(pluginEntry->pluginInfo.isPluginEnabled() != state);
if (pluginEntry->pluginInfo.isPluginEnabled() != state) {
changedEntries << pluginEntry;
} else {
changedEntries.remove(pluginEntry);
}
emit changed(!changedEntries.isEmpty());
}
void KPluginSelector::Private::PluginDelegate::slotAboutClicked()
......
......@@ -22,6 +22,7 @@
#define KPLUGINSELECTOR_P_H
#include <QAbstractListModel>
#include <QSet>
#include <kconfiggroup.h>
#include <kplugininfo.h>
......@@ -189,6 +190,8 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void configure(const QModelIndex &idx);
inline void clearChangedEntries() { changedEntries.clear(); };
inline void addChangedEntry(PluginEntry *entry) { changedEntries << entry; };
Q_SIGNALS:
void changed(bool hasChanged);
......@@ -213,6 +216,7 @@ private:
QCheckBox *checkBox;
QPushButton *pushButton;
QList<KCModuleProxy *> moduleProxyList;
QSet<PluginEntry *> changedEntries;
KPluginSelector::Private *pluginSelector_d;
};
......
Markdown is supported
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