logplus/Workflow/WFEngine/Component/WorkflowWidget/include/ModuleGraphicsItem.h
2026-01-16 17:18:41 +08:00

686 lines
20 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file ModuleGraphicsItem.h
* @brief 模块图元的绘制类
* @date 2011-8-17
*/
#ifndef PAI_FRAME_WORKFLOWWIDGET_MODULEGRAPHICSITEM_H
#define PAI_FRAME_WORKFLOWWIDGET_MODULEGRAPHICSITEM_H
#include <QGraphicsObject>
#include "ModulePortGraphicsItem.h"
class QGraphicsView;
class QMimeData;
class QUuid;
namespace pai
{
namespace workflow
{
class CModuleInformation;
}
namespace objectmodel
{
class PaiObject;
class PaiWorkflowDataModel;
}
}
namespace pai
{
namespace gui
{
class PaiJobParameterItem;
class PaiLineEdit;
}
}
namespace pai
{
namespace graphics2d
{
class PaiModuleStyle;
class ModuleGraphicsItem;
class ModuleToolBarGraphicsItem;
class GeneralWorkflowScene;
class ModuleMonitorGraphicsItem;
}
}
namespace pai
{
namespace graphics2d
{
/**
* @class ModuleGraphicsItemEventAgent
* @brief 模块的事件代理
*/
class PAI_WORKFLOWWIDGET_EXPORT ModuleGraphicsItemEventAgent : public QObject
{
Q_OBJECT
public:
/**
* @brief 向外发出模块的端口被选择或取消选择的消息
* @param[in] pItem 模块
* @param[in] selected true 选中模块端口
* false 取消选中模块端口
*/
void ModulePortSelectionChanged(pai::graphics2d::ModuleGraphicsItem *pItem, bool selected);
/**
* @brief 向外发出模块需要被居中的消息
* @param[in] pItem 被居中显示的模块
*/
void ItemNeedCenterOn(pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 向外发出模块需要被删除的消息
* @param[in] pScene 模块所在场景
* @param[in] pItem 将要删除模块
*/
void ItemNeedBeDelete(pai::graphics2d::GeneralWorkflowScene *pScene,
pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 向外发出模块被双击的消息
* @param[in] pInfo 模块信息
* @param[in] readOnly 模块是否来自只读场景
*/
void DoubleClickModule(pai::workflow::CModuleInformation *pInfo, bool readOnly);
/**
* @brief 向外发出模块被点击的消息
* @param[in] pModule模块信息
* @param[in] readOnly 模块是否来自只读场景
*/
void ClickModule(pai::workflow::CModuleInformation *pModule, bool readOnly);
/**
* @brief 向外发出模块是否被使能
* @param[in] pItem 模块
* @param[in] enabled 是否使能
*/
void ItemSetEnabled(pai::graphics2d::ModuleGraphicsItem *pItem, bool enabled);
/**
* @brief 向外发出模块设置名称信号
* @param[in] pItem 被修改名称的模块
*/
void ItemSetName(pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 向外发出模块更新信号
* @param[in] pItem 被更新的模块
*/
void UpdataModule(pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 当处于画连接虚线的状态向外发出模块的端口处于hovering的消息
* @param[in] pItem 模块
* @param[in] hovering 当前端口hover状态
*/
void ModulePortHoveringChanged(pai::graphics2d::ModuleGraphicsItem *pItem, bool hovering);
/**
* @brief 向外发出已选中模块被点击的消息
* @param[in] pModule 被点击的模块
*/
void ClickSelectedModule(pai::workflow::CModuleInformation *pModule);
/**
* @brief 模块监控状态
* @param[in] pItem 当前模块
* @param[in] monitor 监控状态
*/
void SetMonitoring(pai::graphics2d::ModuleGraphicsItem *pItem, bool monitor);
/**
* @brief 显示监控图元的调色板
* @param[in] pMonitor 当前操作监控图元
*/
void ShowColorEditor(ModuleMonitorGraphicsItem *pMonitor);
/**
* @brief 更换监控图元颜色
* @param[in] color 索引
*/
void UpdateMonitorColor(const QString& color);
signals:
/**
* @brief 模块被点击的信号
* @param[in] pModule模块信息
* @param[in] readOnly 模块是否来自只读场景
*/
void ModuleClicked(pai::workflow::CModuleInformation *pItem, bool readOnly);
/**
* @brief 模块的端口选中状态改变信号
* @param[in] pItem 模块
* @param[in] selected true 选中模块端口
* false 取消选中模块端口
*/
void PortSelectionChanged(pai::graphics2d::ModuleGraphicsItem *pItem, bool selected);
/**
* @brief 当处于画连接虚线的状态向外发出模块的端口处于hovering的信号
* @param[in] pItem 模块
* @param[in] hovering 当前端口hover状态
*/
void PortHoveringChanged(pai::graphics2d::ModuleGraphicsItem *pItem, bool hovering);
/**
* @brief 模块需要被居中的信号
* @param[in] pItem 被居中显示的模块
*/
void ModuleCenterOn(QGraphicsItem *pItem);
/**
* @brief 模块被删除的信号
* @param[in] pScene 模块所在场景
* @param[in] pItem 将要删除模块
*/
void DeleteModule(pai::graphics2d::GeneralWorkflowScene *pScene,
pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 模块被双击的信号
* @param[in] pInfo 模块信息
* @param[in] readOnly 模块是否来自只读场景
*/
void DoubleClick(pai::workflow::CModuleInformation *pInfo, bool readOnly);
/**
* @brief 模块是否使能信号
* @param[in] pItem 模块
* @param[in] enable 是否禁用
*/
void SetEnalbed(pai::graphics2d::ModuleGraphicsItem *pItem, bool enabled);
/**
* @brief 模块设置名称信号
* @param[in] pItem 被修改名称的模块
*/
void SetName(pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 模块更新信号
* @param[in] pItem 被更新的模块
*/
void UpdateItem(pai::graphics2d::ModuleGraphicsItem *pItem);
/**
* @brief 已选中模块被点击的信号
* @param[in] pModule 被点击的模块
*/
void ClickSelectedItem(pai::workflow::CModuleInformation *pModule);
/**
* @brief 编辑完成的信号
*/
void EditingFinished();
/**
* @brief 模块监控状态
* @param[in] pItem 当前模块
* @param[in] monitor 监控状态
*/
void SetModuleMonitoring(pai::graphics2d::ModuleGraphicsItem *pItem, bool monitor);
/**
* @brief 显示监控图元的调色板
* @param[in] pMonitor 当前操作监控图元
*/
void ShowMonitorColorEditor(pai::graphics2d::ModuleMonitorGraphicsItem *pMonitor);
/**
* @brief 更换监控图元颜色时发送
* @param[in] color 索引
*/
void ChangeMonitorColor(const QString& color);
};
/**
* @class ModuleGraphicsItem
* @brief 绘制工作流图形中模块的图元
*/
class PAI_WORKFLOWWIDGET_EXPORT ModuleGraphicsItem : public QGraphicsItem
{
public:
friend class ModuleToolBarGraphicsItem;
/**
* @brief 模块类型
*/
enum
{
Type = UserType + 1000 ///< 模块item类型
};
/**
* @brief 构造函数
* @param[in] pParent 父亲
*/
ModuleGraphicsItem(QGraphicsItem *pParent = NULL);
/**
* @brief 构造函数
* @param[in] pModule 模块信息
* @param[in] pStyle 模块风格
* @param[in] job 是否是作业场景模块
* @param[in] pParent 父亲
*/
ModuleGraphicsItem(pai::workflow::CModuleInformation *pModule,
pai::graphics2d::PaiModuleStyle *pStyle,
bool job = false,
QGraphicsItem *pParent = NULL);
/**
* @brief 析构函数
*/
virtual ~ModuleGraphicsItem();
/**
* @brief 获取模块类型
* @return 模块类型
*/
virtual int type() const;
/**
* @brief 设置模块图元绘图参数
* @param[in] pStyle 绘图参数
*/
void SetStyle(pai::graphics2d::PaiModuleStyle *pStyle);
/**
* @brief 设置模块参数信息调用该函数之前必须要保证先调用过SetStyle
* @param[in] pModule 模块句柄
*/
void SetModule(pai::workflow::CModuleInformation *pModule);
/**
* @brief 设置模块使能状态
* @param[in] isDisable true 使能
* false 非使能
*/
void SetDisable(bool isDisable);
/**
* @brief 获取模块是否使能
* @return 使能状态
*/
bool IsDisable() const;
/**
* @brief 设置模块工具栏
* @param[in] pToolBarItem 工具栏图元
*/
void SetToolBarItem(pai::graphics2d::ModuleToolBarGraphicsItem *pToolBarItem);
/**
* @brief 获取模块信息
* @return 模块信息
*/
pai::workflow::CModuleInformation* GetModule() const;
/**
* @brief 获取模块风格信息
* @return 模块风格
*/
pai::graphics2d::PaiModuleStyle* GetModuleStyle() const;
/**
* @brief 获取模块工具栏
* @return 模块工具栏
*/
pai::graphics2d::ModuleToolBarGraphicsItem* GetToolBar() const;
/**
* @brief 获取模块端口的绘图位置
* @param[in] portDirection 端口方向
* @param[in] portIndex 该方向第几个端口
* @return 端口坐标
*/
QPointF GetPortPostion(PortDirection portDirection, int portIndex) const;
/**
* @brief 获得模块端口的绘图区域
* @param[in] portDirection 端口方向
* @param[in] portIndex 该方向第几个端口
* @return 端口绘制区域
*/
QRectF GetPortBoundingRect(PortDirection portDirection, int portIndex) const;
/**
* @brief 得到模块图元的宽和高
* @return 模块的高度和宽度
*/
QSizeF GetSize() const;
/**
* @brief 获取输入端口数量
* @return 模块输入端口数量
*/
int GetInputPortCount() const;
/**
* @brief 获取输出端口数量
* @return 模块输出端口数量
*/
int GetOutputPortCount() const;
/**
* @brief 获取选中的模块端口信息
* @param[out] portDirection 端口方向
* @param[out] portIndex 该方向第几个端口
*/
void GetSelectedPort(PortDirection& portDirection, int& portIndex);
/**
* @brief 获取处于Hovering状态的模块端口信息
* @param[out] portDirection 端口方向
* @param[out] portIndex 该方向第几个端口
*/
void GetHoveringPort(PortDirection& portDirection, int& portIndex);
/**
* @brief 查询该模块是否有端口被选中
* @return true 有端口被选中
* false 无端口被选中
*/
bool HasPortSelected() const;
/**
* @brief 取消该模块端口选中状态
*/
void CancelPortSelect();
/**
* @brief 选中端口
* @param[in] pEvent 鼠标事件
* @return true 被选中
* false 选中失败
*/
bool PortHit(QGraphicsSceneMouseEvent *pEvent);
/**
* @brief 高亮或者取消高亮指定方向的所有端口
* @param[in] portDirection 指定端口方向
* @param[in] light true 高亮false 取消高亮
*/
void HilightPorts(PortDirection portDirection, bool light);
/**
* @brief 模块图元是否做过初始验证
* @return true 做过初始化校验
* false 没有做过初始化校验
*/
bool GetInitialValidated() const;
/**
* @brief 设置初始化校验标志
* @param[in] validated 校验标志
*/
void SetInitialValidated(bool validated);
/**
* @brief 设置模块错误提示信息
* @param[in] error 错误信息
*/
void SetErrorString(QString error);
/**
* @brief 设置模块所属工作流
* @param[in] pWorkflow 工作流对象指针
*/
void SetWorkflow(pai::objectmodel::PaiWorkflowDataModel *pWorkflow);
/**
* @brief 设置模块来源
* @param[in] jobType true 日志场景
* false 作业场景和工作流场景
*/
void SetJobType(bool jobType);
/**
* @brief 设置模块名称下拉菜单中的内容
* @param[in] moduleNameList 模块名称链表
*/
void SetModuleNamePopup(const QList<QString> &moduleNameList);
/**
* @brief 隐藏名称编辑框
*/
void HideModuleNameEditor();
/**
* @brief 隐藏掉非空模块的名称编辑框
*/
void HideNonBlankModuleEditor();
/**
* @brief 模块是否处于名称编辑状态
* @return true正处于编辑状态false处于未编辑状态
*/
bool IsEditingModuleName();
/**
* @brief 获取模块编辑框中的文本
* @return 模块名称
*/
QString GetModuleNameEditorText() const;
/**
* @brief 显示模块名称编辑框
*/
void ShowModuleNameEditor();
/**
* @brief 模块来自只读场景
* @return false 来自可编辑场景(目前工作流场景)
* true 来自只读场景(目前作业或者作业日志场景)
*/
bool IsModuleReadOnly() const;
/**
* @brief 模块的输入端口是否已经被连线
* @param[in] portIndex输入端口索引
* @return true 输入端口被连线false 没有被连线
*/
bool InPortHasBeenLined(int portIndex) const;
/**
* @brief 获取模块没有被连线的输入端口的索引
* @return 没有被连线输入端口索引
*/
int GetFreeInPortIndex() const;
/**
* @breif 设置监控
* @param[in] monitor 监控状态
*/
void SetMonitoring(bool monitor);
/**
* @brief 获取监控状态
* @return true 正在被监控
* false 没有被监控
*/
bool GetMonitoring() const;
/**
* @brief 设置监控图元
* @param[in] pMonitor 监控item
*/
void SetMonitorItem(pai::graphics2d::ModuleMonitorGraphicsItem *pMonitor);
/**
* @brief 获取监控图元
* @return 监控图元
*/
pai::graphics2d::ModuleMonitorGraphicsItem* GetMonitorItem() const;
protected:
/**
* @brief 重写该虚函数,实现鼠标进入覆盖操作
* @param[in] pEvent 鼠标hoverEnter事件
*/
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *pEvent);
/**
* @brief 重写该虚函数,实现鼠标在模块上移动操作
* @param[in] pEvent 鼠标hoverMove事件
*/
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent);
/**
* @brief 重写该虚函数,实现鼠标覆盖离开操作
* @param[in] pEvent 鼠标hoverLeave事件
*/
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent);
/**
* @brief 重写该虚函数,实现鼠标按压操作
* @param[in] pEvent 鼠标mousePress事件
*/
virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent);
/**
* @brief 重写该虚函数,实现鼠标释放操作
* @param[in] pEvent 鼠标mouseRelease事件
*/
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent);
/**
* @brief 实现该虚函数,获取模块图元的包围矩形
* @return 模块的包围矩形区域
*/
virtual QRectF boundingRect() const;
/**
* @brief 实现该虚函数,绘制模块图元
* @param[in] pPainter 画笔
* @param[in] pOption 模块风格参数
* @param[in] pWidget 画布
*/
virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = NULL);
/**
* @brief 重写该虚函数,实现鼠标移动事件
* @param[in] pEvent 鼠标mouseMove事件
*/
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *pEvent);
/**
* @brief 重写该虚函数,实现模块发生变化时操作
* @param[in] change 变化类型
* @param[in] value 新数值
* @return 新数值
*/
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* @brief 重写该虚函数,实现鼠标双击操作
* @param[in] pEvent 鼠标mouseDoubleClick事件
*/
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *pEvent);
/**
* @brief 重写拖拽进入事件,对于不支持的数据类型给出禁止图标
* @param[in] pEvent 拖拽进入事件
*/
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *pEvent);
/**
* @brief 重写拖拽事件,根据拖入的数据给模块参数赋值
* @param[in] pEvent 拖拽放下事件
*/
virtual void dropEvent(QGraphicsSceneDragDropEvent *pEvent);
private:
/**
* @brief 获取模块所在视口
* @return 视口对象指针
*/
QGraphicsView* GetView() const;
/**
* @brief 为模块端口设置提示
* @param[in] isInput 端口类型,输入端口还是输出端口
* @param[in] index 输入或输出的第几个端口,从零开始
*/
void SetPortToolTip(bool isInput, unsigned int index);
/**
* @brief 刷新视口
*/
void UpdateView();
/**
*@brief 初始化模块名称编辑框
*/
void InitModuleNameEdit();
/**
* @brief 初始化被模块支持的拖拽类型
*/
void InitDropType();
/**
* @brief 校验拖拽数据是否有效
* @param[in] pMimeData 拖拽的数据
* @return true,支持的类型false,不支持的类型
*/
bool IsDropTypeValid(const QMimeData *pMimeData);
/**
* @brief 将拖拽到模块的文件放到模块对应的参数中。
* @param[in] pObject 拖拽的对象。
* @return true 添加成功,反之则失败
*/
bool AddFileToModuleParameter(pai::objectmodel::PaiObject* pObject);
public:
static ModuleGraphicsItemEventAgent m_EventAgent; ///< 模块事件代理对象
private:
pai::workflow::CModuleInformation *m_pModule; ///< 模块的数据信息
pai::graphics2d::PaiModuleStyle *m_pStyle; ///< 模块的绘图信息
pai::graphics2d::ModuleToolBarGraphicsItem *m_pToolBarItem; ///< 模块图元的工具条
pai::graphics2d::ModuleMonitorGraphicsItem *m_pMonitorItem; ///< 模块监控图元
pai::objectmodel::PaiWorkflowDataModel *m_pWorkflow; ///< 模块所属工作流
QSizeF m_size; ///< 模块图元大小
QList<ModulePortGraphicsItem> m_InputPorts; ///< 模块输入端口
QList<ModulePortGraphicsItem> m_OutputPorts; ///< 模块的输出端口
bool m_OnMoving; ///< 模块正在被移动
bool m_OnHovering; ///< 鼠标正在模块上
bool m_InitialValidated; ///< 模块是否做过初始验证
bool m_PressedOnPort; ///< 选中端口
bool m_monitoring; ///< 模块监控状态
QString m_error; ///< 错误提示信息
bool m_job; ///< false,工作流场景中的模块true作业或者日志场景中的模块
pai::gui::PaiJobParameterItem *m_pCJobParameterItem; ///< 日志界面的模块参数显示item
bool m_JobType; ///< 作业日志类型true:日志 false:作业
pai::gui::PaiLineEdit *m_pEdit; ///< 模块名称编辑框
QList<QUuid> m_SupportedDropType; ///< 被支持的拖拽类型
};
}
}
/**
* @brief 设置是否处于画连接虚线的状态
* @param[in] drawing 正在画虚线
*/
extern PAI_WORKFLOWWIDGET_EXPORT void SetSceneLineDrawing(bool drawing);
/**
* @brief 获得是否处于画连接虚线的状态
* @return true 正在画虚线
* false 没有画虚线
*/
extern PAI_WORKFLOWWIDGET_EXPORT bool GetSceneLineDrawing();
#endif ///< PAI_FRAME_WORKFLOWWIDGET_MODULEGRAPHICSITEM_H