/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Tools/Libs/GuiFoundation/Action/Action.h
132 строки
3 KB
Ingrater
clang-tidy modernize-use-using check (#956)
22 май 2023, 17:30
Не верифицирован
22 май 2023, 17:30
01da71c
Код
Авторство
О чём код?
#pragma once #include <Foundation/Communication/Event.h> #include <Foundation/Containers/IdTable.h> #include <Foundation/Containers/Map.h> #include <Foundation/Containers/Set.h> #include <Foundation/Strings/HashedString.h> #include <Foundation/Types/Enum.h> #include <Foundation/Types/Variant.h> #include <GuiFoundation/GuiFoundationDLL.h> #include <QKeySequence> #include <ToolsFoundation/Document/DocumentManager.h> class QWidget; struct ezActionDescriptor; class ezAction; struct ezActionContext; using ezActionId = ezGenericId<24, 8>; using CreateActionFunc = ezAction* (*)(const ezActionContext&); using DeleteActionFunc = void (*)(ezAction*); /// \brief Handle for a ezAction. /// /// ezAction can be invalidated at runtime so don't store them. class EZ_GUIFOUNDATION_DLL ezActionDescriptorHandle { public: using StorageType = ezUInt32; EZ_DECLARE_HANDLE_TYPE(ezActionDescriptorHandle, ezActionId); friend class ezActionManager; public: const ezActionDescriptor* GetDescriptor() const; }; /// struct ezActionScope { enum Enum { Global, Document, Window, Default = Global }; using StorageType = ezUInt8; }; /// struct ezActionType { enum Enum { Action, Category, Menu, ActionAndMenu, Default = Action }; using StorageType = ezUInt8; }; /// struct EZ_GUIFOUNDATION_DLL ezActionContext { ezActionContext() = default; ezActionContext(ezDocument* pDoc) { m_pDocument = pDoc; } ezDocument* m_pDocument = nullptr; ezString m_sMapping; QWidget* m_pWindow = nullptr; }; /// struct EZ_GUIFOUNDATION_DLL ezActionDescriptor { ezActionDescriptor() = default; ; ezActionDescriptor(ezActionType::Enum type, ezActionScope::Enum scope, const char* szName, const char* szCategoryPath, const char* szShortcut, CreateActionFunc createAction, DeleteActionFunc deleteAction = nullptr); ezActionDescriptorHandle m_Handle; ezEnum<ezActionType> m_Type; ezEnum<ezActionScope> m_Scope; ezString m_sActionName; ///< Unique within category path, shown in key configuration dialog ezString m_sCategoryPath; ///< Category in key configuration dialog, e.g. "Tree View" or "File" ezString m_sShortcut; ezString m_sDefaultShortcut; ezAction* CreateAction(const ezActionContext& context) const; void DeleteAction(ezAction* pAction) const; void UpdateExistingActions(); private: CreateActionFunc m_CreateAction; DeleteActionFunc m_DeleteAction; mutable ezHybridArray<ezAction*, 4> m_CreatedActions; }; /// class EZ_GUIFOUNDATION_DLL ezAction : public ezReflectedClass { EZ_ADD_DYNAMIC_REFLECTION(ezAction, ezReflectedClass); EZ_DISALLOW_COPY_AND_ASSIGN(ezAction); public: ezAction(const ezActionContext& context) { m_Context = context; } virtual void Execute(const ezVariant& value) = 0; void TriggerUpdate(); const ezActionContext& GetContext() const { return m_Context; } ezActionDescriptorHandle GetDescriptorHandle() { return m_hDescriptorHandle; } public: ezEvent<ezAction*> m_StatusUpdateEvent; ///< Fire when the state of the action changes (enabled, value etc...) protected: ezActionContext m_Context; private: friend struct ezActionDescriptor; ezActionDescriptorHandle m_hDescriptorHandle; };