d2d92cdfd2
After porting to KConfigXT settings some time ago, there was still an inefficient and error-prone codepath between the `RuleBook` (which keeps the runtime list of `Rules`) and the `RuleBookSettings` (responsible for config reads and saves), in the form of the `setRules()` method. We can eliminate the `setRules()` codepath, reducing unnecessary runtime process and file access operations, and instead: - Keep track of the config `id` in the `Rules` objects - Keep a single `RuleBookSettings` object as a member - Modify or delete the discarded rules settings directly - Save when necessary This also fixes two bugs/pitfalls of the previous solution: - the config group id for each rule is now preserved instead of creating new ones - no leftovers on the config file for the discarded groups and entries Setting custom configs for the integration tests still works unchanged. BUG: 446381 FIXED-IN: 6.1
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
/*
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
SPDX-FileCopyrightText: 2020 Henri Chain <henri.chain@enioka.com>
|
|
SPDX-FileCopyrightText: 2021 Ismael Asensio <isma.af@gmail.com>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "rulebooksettingsbase.h"
|
|
#include <KSharedConfig>
|
|
|
|
namespace KWin
|
|
{
|
|
class Rules;
|
|
class RuleSettings;
|
|
|
|
class RuleBookSettings : public RuleBookSettingsBase
|
|
{
|
|
public:
|
|
RuleBookSettings(KSharedConfig::Ptr config, QObject *parent = nullptr);
|
|
RuleBookSettings(QObject *parent = nullptr);
|
|
~RuleBookSettings();
|
|
|
|
QList<Rules *> rules() const;
|
|
|
|
bool usrSave() override;
|
|
void usrRead() override;
|
|
bool usrIsSaveNeeded() const;
|
|
|
|
int ruleCount() const;
|
|
std::optional<int> indexForId(const QString &id) const;
|
|
RuleSettings *ruleSettingsAt(int row) const;
|
|
RuleSettings *insertRuleSettingsAt(int row);
|
|
void removeRuleSettingsAt(int row);
|
|
void moveRuleSettings(int srcRow, int destRow);
|
|
|
|
private:
|
|
static QString generateGroupName();
|
|
|
|
private:
|
|
QList<RuleSettings *> m_list;
|
|
QStringList m_storedGroups;
|
|
};
|
|
|
|
}
|