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.
nmWATI/Include/iPlot/iPlotBase/ZxSceneItem.h

225 lines
6.0 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.

#pragma once
#include "IxRedoUndo.h"
#include "IxRenderItem.h"
#include "ZxTempLayer.h"
#include "iPlotBase_global.h"
class QUndoStack;
class QUndoCommand;
class ZxSelection;
class IxPtyPano;
class ZxRenderItem;
class QSignalMapper;
class QKeyEvent;
/// 图形场景. 具有 图形文档 和 图元树的根节点双重分身
class I_PLOTBASE_EXPORT ZxSceneItem
: public ZxRenderItem
, virtual public IxRedoUndo
{
public:
Q_OBJECT
ZX_DECLARE_DYNAMIC
public:
explicit ZxSceneItem(QObject* parent = 0);
// ZxSceneItem(const ZxSceneItem & c);
// ZxSceneItem* clone() const;
~ZxSceneItem();
virtual void onSerialize(ZxSerializer* ser);
virtual void onDeserialize(ZxSerializer* ser);
/// 获取当前选中的图元
ZxSelection& getSelection();
/// 获取撤销/恢复堆栈
virtual QUndoStack * getUndoStack();
/// 类似于QUndoStack::beginMacro()的功能, 但做了一些特殊处理
/// @see QUndoStack::beginMacro()
virtual void beginUndoStackMacro();
/// 类似于QUndoStack::endMacro()的功能, 但做了一些特殊处理
/// @see QUndoStack::endMacro()
virtual void endUndoStackMacro();
/// 运行一个命令
virtual void pushCommand(QUndoCommand * cmd);
/// 清除widget
virtual void clearEditingWidget();
/// 刷新
virtual void update();
virtual void update(const QRectF& rect);
void paintBack(QPainter* painter, const ZxPaintParam& param);
void paintFront(QPainter* painter, const ZxPaintParam& param);
/// 设置文档路径
virtual void setFilePath(const QString& filePath);
/// 获取文档路径
virtual QString getFilePath() const;
/// 文档是否已修改
virtual bool isModified() const;
/// 文档修改标识
virtual void setModified(bool bModified);
/// 关闭文档
virtual bool close(bool bPromptSave = true);
/// 保存文档
virtual bool save();
/// 保存文档
virtual bool save(const QString& filePath);
/// 另存文档
virtual bool saveAs();
/// 设置属性窗口
virtual void setPtyPano(IxPtyPano* p);
/// 获取属性窗口
virtual IxPtyPano* getPtyPano(bool tryOuter = true) const;
/// 获取背景图层 (不建议使用)
virtual ZxRenderItem* getBackLayer() const;
/// 设置背景图层 (不建议使用)
virtual void setBackLayer(ZxRenderItem* pLayer);
/// 获取主图层
virtual ZxRenderItem* getMainLayer() const;
/// 设置主图层
virtual void setMainLayer(ZxRenderItem* pLayer);
/// 获取前景图层 (不建议使用)
virtual ZxRenderItem* getFrontLayer() const;
/// 设置前景图层 (不建议使用)
virtual void setFrontLayer(ZxRenderItem* pLayer);
/// 获取临时图层
virtual ZxTempLayer * getTempLayer() const;
/// 设置临时图层 (不推荐, 因为改了以后可能和别人的需求冲突)
virtual void setTempLayer(ZxTempLayer * pLayer);
virtual void invariant() const;
/// 获取所有和本场景关联的视图
/// @note 依据的是文档视图管理器里的信息, 即addView()/addDoc()/bindDocView()等函数所建立的关系.
QList<ZxRenderView*> getGraphViews();
/// 往菜单里添加选择图元的actions
virtual void makeSelectItemsMenu(QMenu* pMenu, const QPointF& pt, ZxFilterFun filter = NULL, bool bRecursive = true);
/// 获取文档标题
virtual QString getTitle() const;
virtual QIcon getIcon() const;
/// 是否自动关闭场景.
virtual bool isAutoClose() const;
/// 设置是否自动关闭场景
virtual void setAutoClose(bool bAutoClose);
/// 弹出对话框, 选择保存文件
virtual QString getSaveFileName() const;
virtual void updateEditActionStatus();
/// 设置本场景的属性表配置
/// @param sConfigName 配置文件名(不带扩展名). 如果为空则使用所在模块的配置.
void setPtyTag(const QString& sConfigName);
/// 获取本场景使用的属性表配置
QString getPtyTag() const;
/// 把焦点设到Active View上, 只在Active View是关联到本Scene时起作用.
void trySyncFocusWithActiveView();
signals:
/// 信号: 安装编辑策略, 在收到信号时应为图元安装编辑策略
/// @note 信号的sender是场景, 参数里的图元才是实际需要安装策略的图元.
void sigInstallPolicies(ZxRenderItem* pItem);
/// 信号: 有图元被移出图件树
void sigItemDetached(ZxRenderItem* pItem);
// 对于update函数无法顺利刷新的触发如下信号在View中直接刷新
void sigUpdate();
void sigUpdateRect(const QRect&);
protected:
virtual void emitSigInstallPolicies(ZxRenderItem* pItem);
void notifyItemDetached(ZxRenderItem* pItem);
protected slots:
virtual void slotUndoStackIndexChanged(int);
virtual void slotSelectItem(QObject* p);
virtual void cloneSelection();
virtual void slotEditCopy();
virtual void slotEditPaste();
virtual void slotEditCut();
virtual void slotEditDelete();
virtual void slotEditSelectAll();
protected:
/// 选中列表被改变(即时)
virtual void onSelectionChanged();
/// 选中列表被改变(非即时)
virtual void onSelectionChangedLazy();
virtual void keyPressEvent(QKeyEvent *e);
virtual void keyReleaseEvent(QKeyEvent * e);
protected:
QSignalMapper* m_pSelectMapper;
QUndoStack* m_pUndoStack;
ZxSelection* m_pSelection;
QString m_sSceneFilePath;
int m_nUndoStackMacroNest;
bool m_bAutoClose;
bool m_bModified;
QList<QUndoCommand*> m_listPendingCommand;
ZxRenderView* m_pTheOnlyOwnerView;
QAction* actionUndo;
QAction* actionRedo;
QAction* actionEditCopy;
QAction* actionEditPaste;
QAction* actionEditCut;
QAction* actionEditDelete;
QAction* actionEditSelectAll;
QString m_sPtyTag;
IxPtyPano* m_pPtyPano;
friend class ZxRenderItem;
friend class ZxRenderView;
friend class ZxSelection;
friend class ZxSelectionPrivate;
};