KWin
Loading...
Searching...
No Matches
rulebookmodel.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5*/
6
7#pragma once
8
9#include "rulebooksettings.h"
10#include "rulesettings.h"
11
12#include <QAbstractListModel>
13
14namespace KWin
15{
16
17class RuleBookModel : public QAbstractListModel
18{
19 Q_OBJECT
20
21public:
22 enum {
23 DescriptionRole = Qt::DisplayRole,
24 };
25
26 explicit RuleBookModel(QObject *parent = nullptr);
28
29 QHash<int, QByteArray> roleNames() const override;
30 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
31 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
32 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
33
34 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
35 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
36 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
37 const QModelIndex &destinationParent, int destinationChild) override;
38
39 QString descriptionAt(int row) const;
40 void setDescriptionAt(int row, const QString &description);
41
42 RuleSettings *ruleSettingsAt(int row) const;
43 void setRuleSettingsAt(int row, const RuleSettings &settings);
44
45 void load();
46 void save();
47 bool isSaveNeeded();
48
49 // Helper function to copy RuleSettings properties
50 static void copySettingsTo(RuleSettings *dest, const RuleSettings &source);
51
52private:
53 RuleBookSettings *m_ruleBook;
54};
55
56} // namespace
QHash< int, QByteArray > roleNames() const override
RuleSettings * ruleSettingsAt(int row) const
void setDescriptionAt(int row, const QString &description)
static void copySettingsTo(RuleSettings *dest, const RuleSettings &source)
QString descriptionAt(int row) const
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
RuleBookModel(QObject *parent=nullptr)
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void setRuleSettingsAt(int row, const RuleSettings &settings)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override