File indexing completed on 2024-05-12 17:08:29
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QQmlListProperty> 0010 #include <QQmlPropertyMap> 0011 0012 #include <KSharedConfig> 0013 0014 class FaceLoader; 0015 0016 class PageDataObject : public QQmlPropertyMap 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(QQmlListProperty<PageDataObject> children READ childrenProperty NOTIFY childrenChanged) 0020 Q_PROPERTY(bool dirty READ dirty NOTIFY dirtyChanged) 0021 Q_PROPERTY(QString fileName READ fileName CONSTANT) 0022 0023 public: 0024 explicit PageDataObject(const KSharedConfig::Ptr &config, QObject *parent = nullptr); 0025 0026 QQmlListProperty<PageDataObject> childrenProperty() const; 0027 QVector<PageDataObject *> children() const; 0028 0029 KSharedConfig::Ptr config() const; 0030 0031 void setValue(const QString &name, const QVariant &value); 0032 0033 Q_INVOKABLE bool resetPage(); 0034 Q_INVOKABLE bool savePage(); 0035 Q_INVOKABLE void saveAs(const QUrl &destination); 0036 0037 bool load(const KConfigBase &config, const QString &groupName); 0038 Q_SIGNAL void loaded(); 0039 bool save(KConfigBase &config, const QString &groupName, const QStringList &ignoreProperties = {QStringLiteral("children")}); 0040 Q_SIGNAL void saved(); 0041 0042 void reset(); 0043 0044 Q_INVOKABLE PageDataObject *insertChild(int index, const QVariantMap &properties); 0045 Q_INVOKABLE void removeChild(int index); 0046 Q_INVOKABLE void moveChild(int from, int to); 0047 0048 PageDataObject *childAt(int index) const; 0049 int childCount() const; 0050 0051 Q_SIGNAL void childrenChanged(); 0052 Q_SIGNAL void childInserted(int index); 0053 Q_SIGNAL void childRemoved(int index); 0054 Q_SIGNAL void childMoved(int from, int to); 0055 0056 bool dirty() const; 0057 Q_INVOKABLE void markDirty(); 0058 Q_INVOKABLE void markClean(); 0059 Q_SIGNAL void dirtyChanged(); 0060 0061 FaceLoader *faceLoader(); 0062 void setFaceLoader(FaceLoader *faceLoader); 0063 0064 QString fileName() const; 0065 0066 private: 0067 bool isGroupEmpty(const KConfigGroup &group); 0068 void updateNames(); 0069 0070 QQmlListProperty<PageDataObject> m_childrenProperty; 0071 QVector<PageDataObject *> m_children; 0072 KSharedConfig::Ptr m_config; 0073 bool m_dirty = false; 0074 FaceLoader *m_faceLoader = nullptr; 0075 };