kwin/src/kcmkwin/kwinrules/rulebookmodel.h
Ismael Asensio b5a58f83ee kcm/kwinrules: Manage RuleSettings instead of Rules objects
The KCM now manages the RuleSettings config objects directly,
instead of using a list of `Rules` objects as an intermediary.

This highly reduces the overhead, improving loading and saving
times, and also enables a better use of KConfig capabilites.

The config state is now automatically tracked by KConfigXT
objects. Whenever the user edits either the rule list, or any
specific property within a rule, the `needsSave` state is
updated accordingly.

BUG: 421564
FIXED-IN: 5.23
2021-06-07 21:03:29 +02:00

57 lines
1.6 KiB
C++

/*
SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include "rulebooksettings.h"
#include "rulesettings.h"
#include <QAbstractListModel>
namespace KWin
{
class RuleBookModel : public QAbstractListModel
{
Q_OBJECT
public:
enum {
DescriptionRole = Qt::DisplayRole,
};
explicit RuleBookModel(QObject *parent = nullptr);
~RuleBookModel();
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
const QModelIndex &destinationParent, int destinationChild) override;
QString descriptionAt(int row) const;
void setDescriptionAt(int row, const QString &description);
RuleSettings *ruleSettingsAt(int row) const;
void setRuleSettingsAt(int row, const RuleSettings &settings);
void load();
void save();
bool isSaveNeeded();
// Helper function to copy RuleSettings properties
static void copySettingsTo(RuleSettings *dest, const RuleSettings &source);
private:
RuleBookSettings *m_ruleBook;
};
} // namespace