You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Include/nmNum/nmRender/nmVTKViewCommandController.h

105 lines
3.7 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef NMVTKVIEWCOMMANDCONTROLLER_H
#define NMVTKVIEWCOMMANDCONTROLLER_H
#include "nmRender_global.h"
#include <QFlags>
#include <QObject>
#include <QString>
class QAction;
class QMenu;
class QToolBar;
class nmWxVTKRenderContainerWidget;
/**
* @brief 管理单个渲染容器的通用视图命令。
*
* 每个命令只创建一个 QAction工具栏和右键菜单共享该对象。控制器及其
* QAction 均由所属容器独占,不保存任何业务状态。
*/
class NM_RENDER_EXPORT nmVTKViewCommandController : public QObject
{
Q_OBJECT
public:
enum ViewCommand
{
ViewCommand_ZoomIn = 0x0001,
ViewCommand_ZoomOut = 0x0002,
ViewCommand_Fit = 0x0004,
ViewCommand_Top = 0x0008,
ViewCommand_Front = 0x0010,
ViewCommand_Right = 0x0020,
ViewCommand_Isometric = 0x0040,
ViewCommand_ResetRotationCenter = 0x0080,
ViewCommand_SaveImage = 0x0100,
ViewCommand_CopyImage = 0x0200,
ViewCommand_Print = 0x0400,
ViewCommand_PrintPreview = 0x0800,
ViewCommand_SetRotationCenter = 0x1000
};
Q_DECLARE_FLAGS(ViewCommands, ViewCommand)
/**
* @param pContainer 非所有权指针,用作命令接收者且必须比本对象存活更久。
* @param pParent Qt 所有权父对象,通常与 pContainer 为同一对象。
*/
explicit nmVTKViewCommandController(
nmWxVTKRenderContainerWidget* pContainer,
QObject* pParent = nullptr);
virtual ~nmVTKViewCommandController();
/** @brief 返回当前命令集合。 */
ViewCommands getCapabilities() const;
/** @brief 返回长期持有的 QAction调用方不得删除或修改其父对象。 */
QAction* getAction(ViewCommand eCommand) const;
/** @brief 将已启用的导航和复制动作加入工具栏,不创建新 QAction。 */
void populateToolBar(QToolBar* pToolBar) const;
/** @brief 按统一顺序构造右键菜单,并同步请求业务层追加扩展动作。 */
void populateContextMenu(QMenu* pMenu) const;
/** @brief 返回所属容器是否处于可显示画面的就绪状态。 */
bool isViewAvailable() const;
signals:
/** @brief 在视图命令和打印命令之间同步追加业务 QAction。 */
void contextMenuAboutToShow(QMenu* pMenu) const;
private slots:
/** @brief 仅供容器同步一次性拾取状态,不向容器反向发起请求。 */
void setRotationCenterPicking(bool bPicking);
private:
friend class nmWxVTKRenderContainerWidget;
Q_DISABLE_COPY(nmVTKViewCommandController)
enum { ViewCommandCount = 13 };
/** @brief 仅供容器设置当前视图对外提供的命令集合。 */
void setCapabilities(ViewCommands eCommands);
/** @brief 仅供容器同步就绪、空、错误和加载状态。 */
void setViewAvailable(bool bAvailable);
QAction* createAction(ViewCommand eCommand,
const QString& sText,
const QString& sIconFile,
const char* pSlot);
int actionIndex(ViewCommand eCommand) const;
bool supports(ViewCommand eCommand) const;
/** @brief 仅供容器同步拾取目标、标记和交互模式的综合可用状态。 */
void setRotationCenterPickingAvailable(bool bAvailable);
void updateActionStates();
nmWxVTKRenderContainerWidget* m_pContainer; ///< 非所有权命令接收者。
QAction* m_pActions[ViewCommandCount]; ///< 本对象通过 Qt 父子关系拥有。
ViewCommands m_eCapabilities;
bool m_bViewAvailable;
bool m_bRotationCenterPickingAvailable;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(nmVTKViewCommandController::ViewCommands)
#endif // NMVTKVIEWCOMMANDCONTROLLER_H