Warning, file /graphics/glaxnimate/src/core/model/object.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <memory> 0010 #include <vector> 0011 0012 #include <QObject> 0013 #include <QVariant> 0014 #include <KLocalizedString> 0015 0016 #include "model/animation/frame_time.hpp" 0017 #include "model/factory.hpp" 0018 0019 class QUndoCommand; 0020 0021 0022 /** 0023 * \brief Sets up declarations of concrete Object sub-classes 0024 * \note Call GLAXNIMATE_OBJECT_IMPL for every class declared with GLAXNIMATE_OBJECT 0025 */ 0026 #define GLAXNIMATE_OBJECT(cls) \ 0027 private: \ 0028 Q_OBJECT \ 0029 static bool _reg; \ 0030 std::unique_ptr<Object> clone_impl() const override; \ 0031 public: \ 0032 std::unique_ptr<cls> clone_covariant() const; \ 0033 // macro end 0034 0035 /** 0036 * \brief Registers a class declared with GLAXNIMATE_OBJECT to be constructed 0037 * with model::Factory 0038 */ 0039 #define GLAXNIMATE_OBJECT_IMPL(cls) \ 0040 bool cls::_reg{glaxnimate::model::Factory::instance().register_type<cls>()}; \ 0041 std::unique_ptr<cls> cls::clone_covariant() const \ 0042 { \ 0043 auto object = std::make_unique<cls>(this->document()); \ 0044 this->clone_into(object.get()); \ 0045 return object; \ 0046 } \ 0047 std::unique_ptr<glaxnimate::model::Object> cls::clone_impl() const \ 0048 { \ 0049 return clone_covariant(); \ 0050 } \ 0051 // macro end 0052 0053 namespace glaxnimate::model { 0054 0055 class ObjectListPropertyBase; 0056 class BaseProperty; 0057 class Document; 0058 0059 class Object : public QObject 0060 { 0061 Q_OBJECT 0062 0063 public: 0064 explicit Object(Document* document); 0065 ~Object(); 0066 0067 std::unique_ptr<Object> clone() const 0068 { 0069 return clone_impl(); 0070 } 0071 0072 std::unique_ptr<Object> clone_covariant() const 0073 { 0074 auto object = std::make_unique<Object>(document()); 0075 clone_into(object.get()); 0076 return object; 0077 } 0078 0079 virtual void assign_from(const Object* other); 0080 0081 QVariant get(const QString& property) const; 0082 bool set(const QString& property, const QVariant& value); 0083 bool set_undoable(const QString& property, const QVariant& value); 0084 bool has(const QString& property) const; 0085 0086 const std::vector<BaseProperty*>& properties() const; 0087 BaseProperty* get_property(const QString& property); 0088 0089 virtual QString object_name() const { return type_name_human(); } 0090 virtual QString type_name_human() const { return i18n("Unknown Object"); } 0091 virtual void set_time(FrameTime t); 0092 FrameTime time() const; 0093 0094 QString type_name() const; 0095 0096 Document* document() const; 0097 void transfer(Document* document); 0098 void push_command(QUndoCommand* cmd); 0099 0100 template<class T> T* cast() { return qobject_cast<T*>(this); } 0101 template<class T> const T* cast() const { return qobject_cast<const T*>(this); } 0102 template<class T> bool is_instance() const { return metaObject()->inherits(&T::staticMetaObject); } 0103 0104 virtual void stretch_time(qreal multiplier); 0105 0106 Q_SIGNALS: 0107 void property_changed(const model::BaseProperty* prop, const QVariant& value); 0108 void visual_property_changed(const model::BaseProperty* prop, const QVariant& value); 0109 void removed(); 0110 0111 protected: 0112 virtual void on_property_changed(const BaseProperty* prop, const QVariant& value) 0113 { 0114 Q_UNUSED(prop); 0115 Q_UNUSED(value); 0116 } 0117 void clone_into(Object* dest) const; 0118 virtual void on_transfer(model::Document* doc) {Q_UNUSED(doc)}; 0119 0120 class Autoreg 0121 { 0122 public: 0123 Autoreg(const QMetaObject&); 0124 Autoreg(const Autoreg&) = delete; 0125 Autoreg& operator=(const Autoreg&) = delete; 0126 }; 0127 0128 private: 0129 virtual std::unique_ptr<Object> clone_impl() const 0130 { 0131 return clone_covariant(); 0132 } 0133 0134 void add_property(BaseProperty* prop); 0135 void property_value_changed(const BaseProperty* prop, const QVariant& value); 0136 0137 friend BaseProperty; 0138 class Private; 0139 std::unique_ptr<Private> d; 0140 }; 0141 0142 } // namespace glaxnimate::model