File indexing completed on 2024-05-12 16:59:03
0001 /* 0002 SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef PRODUCT_H 0008 #define PRODUCT_H 0009 0010 #include <QObject> 0011 0012 #include "connection.h" 0013 0014 namespace Bugzilla 0015 { 0016 class ProductVersion : public QObject 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(int id READ id MEMBER m_id NOTIFY changed) 0020 Q_PROPERTY(QString name READ name MEMBER m_name NOTIFY changed) 0021 Q_PROPERTY(bool is_active READ isActive MEMBER m_active NOTIFY changed) 0022 public: 0023 int id() const 0024 { 0025 return m_id; 0026 } 0027 QString name() const 0028 { 0029 return m_name; 0030 } 0031 bool isActive() const 0032 { 0033 return m_active; 0034 } 0035 0036 explicit ProductVersion(const QVariantHash &object, QObject *parent = nullptr); 0037 0038 Q_SIGNALS: 0039 void changed(); 0040 0041 private: 0042 int m_id = -1; 0043 QString m_name = QString(); 0044 bool m_active = false; 0045 }; 0046 0047 class ProductComponent : public QObject 0048 { 0049 Q_OBJECT 0050 Q_PROPERTY(int id READ id MEMBER m_id NOTIFY changed) 0051 Q_PROPERTY(QString name READ name MEMBER m_name NOTIFY changed) 0052 public: 0053 int id() const 0054 { 0055 return m_id; 0056 } 0057 QString name() const 0058 { 0059 return m_name; 0060 } 0061 0062 explicit ProductComponent(const QVariantHash &object, QObject *parent = nullptr); 0063 0064 Q_SIGNALS: 0065 void changed(); 0066 0067 private: 0068 int m_id = -1; 0069 QString m_name = QString(); 0070 }; 0071 0072 class Product final : public QObject 0073 { 0074 Q_OBJECT 0075 Q_PROPERTY(bool is_active READ isActive MEMBER m_active NOTIFY changed) 0076 Q_PROPERTY(QList<Bugzilla::ProductComponent *> components READ components MEMBER m_components NOTIFY changed) 0077 Q_PROPERTY(QList<Bugzilla::ProductVersion *> versions READ versions MEMBER m_versions NOTIFY changed) 0078 public: 0079 using Ptr = QSharedPointer<Product>; 0080 0081 explicit Product(const QVariantHash &object, const Connection &connection = Bugzilla::connection(), QObject *parent = nullptr); 0082 ~Product() final; 0083 0084 bool isActive() const; 0085 QList<ProductComponent *> components() const; 0086 QList<ProductVersion *> versions() const; 0087 0088 // Convenience methods to get useful content out of the 0089 QStringList componentNames() const; 0090 QStringList allVersions() const; 0091 QStringList inactiveVersions() const; 0092 0093 Q_SIGNALS: 0094 void changed(); 0095 0096 private: 0097 static void registerVariantConverters(); 0098 0099 const Connection &m_connection; 0100 0101 bool m_active = false; 0102 QList<ProductComponent *> m_components; 0103 QList<ProductVersion *> m_versions; 0104 0105 Q_DISABLE_COPY_MOVE(Product) 0106 }; 0107 0108 } // namespace Bugzilla 0109 0110 Q_DECLARE_METATYPE(Bugzilla::ProductComponent *) 0111 Q_DECLARE_METATYPE(QList<Bugzilla::ProductComponent *>) 0112 Q_DECLARE_METATYPE(Bugzilla::ProductVersion *) 0113 Q_DECLARE_METATYPE(QList<Bugzilla::ProductVersion *>) 0114 0115 #endif // PRODUCT_H