diff --git a/kcmkwin/kwincompositing/model.cpp b/kcmkwin/kwincompositing/model.cpp index 00a74a9e87..c6160388ba 100644 --- a/kcmkwin/kwincompositing/model.cpp +++ b/kcmkwin/kwincompositing/model.cpp @@ -130,6 +130,19 @@ void EffectModel::loadEffects() { endResetModel(); } +bool EffectModel::setData(const QModelIndex& index, const QVariant& value, int role) { + if (!index.isValid()) + return QAbstractItemModel::setData(index, value, role); + + if (role == EffectModel::EffectStatusRole) { + m_effectsList[index.row()].effectStatus = value.toBool(); + emit dataChanged(index, index); + return true; + } + + return QAbstractItemModel::setData(index, value, role); +} + QString EffectModel::serviceName(const QString &effectName) { //The effect name is something like "Show Fps" and //we want something like "showfps" @@ -147,6 +160,27 @@ void EffectModel::reload() { loadEffects(); } +void EffectModel::effectStatus(const QModelIndex &index, bool effectState) { + setData(index, effectState, EffectStatusRole); +} + +void EffectModel::syncConfig() { + KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); + + for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) { + EffectData effect = *(it); + bool effectConfigStatus = kwinConfig.readEntry(effect.serviceName + "Enabled", false); + + if (effect.effectStatus) { + kwinConfig.writeEntry(effect.serviceName + "Enabled", effect.effectStatus); + } else if (effect.effectStatus != effectConfigStatus) { + kwinConfig.writeEntry(effect.serviceName + "Enabled", effect.effectStatus); + } + } + + kwinConfig.sync(); +} + EffectView::EffectView(QWindow *parent) : QQuickView(parent) { @@ -159,27 +193,8 @@ EffectView::EffectView(QWindow *parent) void EffectView::init() { QString mainFile = QStandardPaths::locate(QStandardPaths::DataLocation, "qml/main.qml", QStandardPaths::LocateFile); setResizeMode(QQuickView::SizeRootObjectToView); - rootContext()->setContextProperty("engineObject", this); setSource(QUrl(mainFile)); } -void EffectView::effectStatus(const QString &effectName, bool status) { - m_effectStatus[effectName] = status; -} - -void EffectView::syncConfig() { - KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); - QHash effectsChanged; - - for (auto it = m_effectStatus.constBegin(); it != m_effectStatus.constEnd(); it++) { - QVariant boolToString(it.value()); - QString effectName = it.key().toLower(); - QString effectEntry = effectName.remove(" "); - kwinConfig.writeEntry("kwin4_effect_" + effectEntry + "Enabled", boolToString.toString()); - effectsChanged["kwin4_effect_" + effectEntry] = boolToString.toBool(); - } - kwinConfig.sync(); -} - }//end namespace Compositing }//end namespace KWin diff --git a/kcmkwin/kwincompositing/model.h b/kcmkwin/kwincompositing/model.h index d2cf6b2a12..3edb52b29c 100644 --- a/kcmkwin/kwincompositing/model.h +++ b/kcmkwin/kwincompositing/model.h @@ -62,10 +62,13 @@ public: explicit EffectModel(QObject *parent = 0); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); QString serviceName(const QString &effectName); + Q_INVOKABLE void effectStatus(const QModelIndex &index, bool effectState); Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128); Q_INVOKABLE void reload(); + Q_INVOKABLE void syncConfig(); private: void loadEffects(); @@ -79,13 +82,6 @@ class EffectView : public QQuickView { public: EffectView(QWindow *parent = 0); void init(); - void loadKWinEffects(const QHash &effectsChanged); - - Q_INVOKABLE void effectStatus(const QString &effectName, bool status); - Q_INVOKABLE void syncConfig(); - -private: - QHash m_effectStatus; }; } diff --git a/kcmkwin/kwincompositing/qml/Effect.qml b/kcmkwin/kwincompositing/qml/Effect.qml index 4c4c143fff..e383ec0919 100644 --- a/kcmkwin/kwincompositing/qml/Effect.qml +++ b/kcmkwin/kwincompositing/qml/Effect.qml @@ -41,7 +41,7 @@ Component { checked: model.EffectStatusRole onClicked: { apply.enabled = true; - engineObject.effectStatus(model.NameRole, checked); + effectModel.effectStatus(effectView.model.modelIndex(index),checked); } onCheckedChanged: { diff --git a/kcmkwin/kwincompositing/qml/main.qml b/kcmkwin/kwincompositing/qml/main.qml index ea03c5fa1f..6b6a303ef1 100644 --- a/kcmkwin/kwincompositing/qml/main.qml +++ b/kcmkwin/kwincompositing/qml/main.qml @@ -88,8 +88,10 @@ Item { id: effectView Layout.fillWidth: true anchors.fill: parent - model: searchModel - delegate: Effect {} + model: VisualDataModel{ + model: searchModel + delegate: Effect{} + } section.property: "CategoryRole" section.delegate: sectionHeading @@ -105,7 +107,7 @@ Item { } onClicked: { - engineObject.syncConfig(); + effectModel.syncConfig(); effectModel.reload(); apply.enabled = false; }