File indexing completed on 2025-03-09 04:06:00
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef PROPERTYCONTAINER_H 0008 #define PROPERTYCONTAINER_H 0009 0010 #include <QObject> 0011 #include <QVariant> 0012 #include <kis_cubic_curve.h> 0013 0014 /** 0015 * The only purpose of this class is to expose the dynamic property 0016 * system of Qt to QML, so we can set and get properties on a generic 0017 * object. It is a little bit of a hack, but QML deliberately does 0018 * not have access to this (according to the developers). 0019 */ 0020 class PropertyContainer : public QObject 0021 { 0022 Q_OBJECT 0023 public: 0024 PropertyContainer(QString name, QObject* parent = 0); 0025 virtual ~PropertyContainer(); 0026 0027 // As QObject already as setProperty and property() functions, we must 0028 // name ours differently 0029 Q_INVOKABLE void writeProperty(QString name, QVariant value); 0030 Q_INVOKABLE QVariant readProperty(QString name); 0031 0032 // This set of functions makes sure we can also handle curve options 0033 // It goes beyond the originally intended simplistic approach to 0034 // property handling, but given the API elsewhere, while this could 0035 // be introduced as a magic option based on string matching in the 0036 // two functions above, this makes for more explicit handling, 0037 // which, while it does expand the API, makes it clearer in use. 0038 Q_INVOKABLE void setCurve(const KisCubicCurve &curve); 0039 Q_INVOKABLE const KisCubicCurve& curve() const; 0040 Q_INVOKABLE void setCurves(const QList<KisCubicCurve>& curves); 0041 Q_INVOKABLE QList<KisCubicCurve>& curves() const; 0042 Q_INVOKABLE int curveCount() const; 0043 Q_INVOKABLE KisCubicCurve specificCurve(int index) const; 0044 Q_INVOKABLE QString specificCurveName(int index) const; 0045 Q_INVOKABLE void setSpecificCurve(int index, const KisCubicCurve& curve) const; 0046 0047 Q_INVOKABLE QString name(); 0048 private: 0049 QString m_name; 0050 KisCubicCurve m_curve; 0051 mutable QList<KisCubicCurve> m_curves; 0052 }; 0053 0054 #endif // PROPERTYCONTAINER_H