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

94 lines
3.2 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
};
Q_DECLARE_FLAGS(ViewCommands, ViewCommand)
/**
* @param pContainer 非所有权指针,用作命令接收者且必须比本对象存活更久。
* @param pParent Qt 所有权父对象,通常与 pContainer 为同一对象。
*/
explicit nmVTKViewCommandController(
nmWxVTKRenderContainerWidget* pContainer,
QObject* pParent = NULL);
virtual ~nmVTKViewCommandController();
/** @brief 设置当前视图对外提供的命令集合。 */
void setCapabilities(ViewCommands eCommands);
/** @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 就绪状态启用命令,空、错误和加载状态统一禁用命令。 */
void setViewAvailable(bool bAvailable);
bool isViewAvailable() const;
signals:
/** @brief 在视图命令和打印命令之间同步追加业务 QAction。 */
void contextMenuAboutToShow(QMenu* pMenu) const;
private:
Q_DISABLE_COPY(nmVTKViewCommandController)
enum { ViewCommandCount = 12 };
QAction* createAction(ViewCommand eCommand,
const QString& sText,
const QString& sIconFile,
const char* pSlot);
int actionIndex(ViewCommand eCommand) const;
bool supports(ViewCommand eCommand) const;
void updateActionStates();
nmWxVTKRenderContainerWidget* m_pContainer; ///< 非所有权命令接收者。
QAction* m_pActions[ViewCommandCount]; ///< 本对象通过 Qt 父子关系拥有。
ViewCommands m_eCapabilities;
bool m_bViewAvailable;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(nmVTKViewCommandController::ViewCommands)
#endif // NMVTKVIEWCOMMANDCONTROLLER_H