/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Editor/EditorFramework/GUI/RawDocumentTreeModel.moc.h
144 строки
6 KB
Jan Krassnigg
Added search by component type in scene tree (#1692)
18 окт 2025, 18:56
Не верифицирован
18 окт 2025, 18:56
4b5113e
Код
Авторство
О чём код?
#pragma once #include <EditorFramework/EditorFrameworkDLL.h> #include <QAbstractItemModel> #include <ToolsFoundation/Object/DocumentObjectManager.h> class ezDragDropInfo; /// \brief Adapter that defines data for specific type in the ezQtDocumentTreeModel. /// /// Adapters are defined for a given type and define the property for child elements (needs to be array or set). /// Furthermore they implement various model functions that will be redirected to it by the model for /// objects of the given type. class EZ_EDITORFRAMEWORK_DLL ezQtDocumentTreeModelAdapter : public QObject { Q_OBJECT; public: /// \brief Constructor. If m_sChildProperty is empty, this type does not have children. ezQtDocumentTreeModelAdapter(const ezDocumentObjectManager* pTree, const ezRTTI* pType, const char* szChildProperty); virtual const ezRTTI* GetType() const; virtual const ezString& GetChildProperty() const; virtual QVariant data(const ezDocumentObject* pObject, int iRow, int iColumn, int iRole = Qt::DisplayRole) const = 0; virtual bool setData(const ezDocumentObject* pObject, int iRow, int iColumn, const QVariant& value, int iRole) const; virtual Qt::ItemFlags flags(const ezDocumentObject* pObject, int iRow, int iColumn) const; Q_SIGNALS: void dataChanged(const ezDocumentObject* pObject, QVector<int> roles); protected: const ezDocumentObjectManager* m_pTree = nullptr; const ezRTTI* m_pType = nullptr; ezString m_sChildProperty; }; /// \brief Convenience class that returns the typename as Qt::DisplayRole. /// Use this for testing or for the document root that can't be seen and is just for defining the hierarchy. /// /// Example: /// ezQtDummyAdapter(pDocument->GetObjectManager(), ezGetStaticRTTI<ezDocumentRoot>(), "Children"); class EZ_EDITORFRAMEWORK_DLL ezQtDummyAdapter : public ezQtDocumentTreeModelAdapter { Q_OBJECT; public: ezQtDummyAdapter(const ezDocumentObjectManager* pTree, const ezRTTI* pType, const char* szChildProperty); virtual QVariant data(const ezDocumentObject* pObject, int iRow, int iColumn, int iRole) const override; }; /// \brief Convenience class that implements getting the name via a property on the object. class EZ_EDITORFRAMEWORK_DLL ezQtNamedAdapter : public ezQtDocumentTreeModelAdapter { Q_OBJECT; public: ezQtNamedAdapter(const ezDocumentObjectManager* pTree, const ezRTTI* pType, const char* szChildProperty, const char* szNameProperty); ~ezQtNamedAdapter(); virtual QVariant data(const ezDocumentObject* pObject, int iRow, int iColumn, int iRole) const override; protected: virtual void TreePropertyEventHandler(const ezDocumentObjectPropertyEvent& e); protected: ezString m_sNameProperty; }; /// \brief Convenience class that implements setting the name via a property on the object. class EZ_EDITORFRAMEWORK_DLL ezQtNameableAdapter : public ezQtNamedAdapter { Q_OBJECT; public: ezQtNameableAdapter(const ezDocumentObjectManager* pTree, const ezRTTI* pType, const char* szChildProperty, const char* szNameProperty); ~ezQtNameableAdapter(); virtual bool setData(const ezDocumentObject* pObject, int iRow, int iColumn, const QVariant& value, int iRole) const override; virtual Qt::ItemFlags flags(const ezDocumentObject* pObject, int iRow, int iColumn) const override; }; /// \brief Model that maps a document to a qt tree model. /// /// Hierarchy is defined by ezQtDocumentTreeModelAdapter that have to be added via AddAdapter. class EZ_EDITORFRAMEWORK_DLL ezQtDocumentTreeModel : public QAbstractItemModel { Q_OBJECT public: ezQtDocumentTreeModel(const ezDocumentObjectManager* pTree, const ezUuid& root = ezUuid()); ~ezQtDocumentTreeModel(); const ezDocumentObjectManager* GetDocumentTree() const { return m_pDocumentTree; } /// \brief Adds an adapter. There can only be one adapter for any object type. /// Added adapters are taken ownership of by the model. void AddAdapter(ezQtDocumentTreeModelAdapter* pAdapter); /// \brief Returns the QModelIndex for the given object. /// Returned value is invalid if object is not mapped in model. QModelIndex ComputeModelIndex(const ezDocumentObject* pObject) const; /// \brief Enable drag&drop support, disabled by default. void SetAllowDragDrop(bool bAllow); static bool MoveObjects(const ezDragDropInfo& info); /// \brief Returns the ezDocumentObject that the index points to. const ezDocumentObject* GetObject(const QModelIndex index) const; public: // QAbstractItemModel virtual QModelIndex index(int iRow, int iColumn, const QModelIndex& parent = QModelIndex()) const override; virtual QModelIndex parent(const QModelIndex& child) const override; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override; virtual Qt::ItemFlags flags(const QModelIndex& index) const override; virtual QVariant data(const QModelIndex& index, int iRole = Qt::DisplayRole) const override; virtual bool setData(const QModelIndex& index, const QVariant& value, int iRole) override; virtual Qt::DropActions supportedDropActions() const override; virtual bool canDropMimeData(const QMimeData* pData, Qt::DropAction action, int iRow, int iColumn, const QModelIndex& parent) const override; virtual bool dropMimeData(const QMimeData* pData, Qt::DropAction action, int iRow, int iColumn, const QModelIndex& parent) override; virtual QStringList mimeTypes() const override; virtual QMimeData* mimeData(const QModelIndexList& indexes) const override; protected: virtual void TreeEventHandler(const ezDocumentObjectStructureEvent& e); private: QModelIndex ComputeParent(const ezDocumentObject* pObject) const; ezInt32 ComputeIndex(const ezDocumentObject* pObject) const; const ezDocumentObject* GetRoot() const; bool IsUnderRoot(const ezDocumentObject* pObject) const; const ezQtDocumentTreeModelAdapter* GetAdapter(const ezRTTI* pType) const; protected: const ezDocumentObjectManager* m_pDocumentTree = nullptr; const ezUuid m_Root; ezHashTable<const ezRTTI*, ezQtDocumentTreeModelAdapter*> m_Adapters; bool m_bAllowDragDrop = false; ezString m_sTargetContext = "scenetree"; };