#pragma once #include #include #include "IxInterface.h" #include "iPlotBase_global.h" class QPainter; class ZxPaintParam; class ZxRenderItem; class ZxHandlePolicy; class ZxPolicy; class ZxTool; class ZxRenderView; class QMenu; class QPointF; class QSizeF; class QKeyEvent; class I_PLOTBASE_EXPORT ZxEdit : virtual public IxInterface { private: ZxEdit(ZxRenderItem* pItem); ~ZxEdit(); public: void updatePolicyHandles(); /// 绘制工具的拖曳线/拖曳框等临时的辅助元素 virtual void onPaint(QPainter* painter, const ZxPaintParam& param); /// 获取所属的GraphItem ZxRenderItem* getItem() const; /// 获取父Item的Edit ZxEdit* getParentEdit() const; /// 获取当前工具 ZxTool* getCurrentTool() const; /// 获取当前视图 ZxRenderView* getCurrentToolView() const; /// 添加Policy(两个接口基本一致) ZxPolicy* add(ZxPolicy* p, bool bAsStatic = false); ZxPolicy* addPolicy(ZxPolicy* p, bool bAsStatic = false); /// 移除policy(两个接口基本一致) ZxPolicy* remove(ZxPolicy* p); ZxPolicy* removePolicy(ZxPolicy* p); //void deletePolicy(ZxPolicy* p); /// 清除全部Policy /// @param bClearAll true时清除全部policy, false时只清除动态的policy void clear(bool bClearAll = false); /// 判断是否有policy bool empty() const; /// 判断是否有动态Policy /// @note 此方法速度较慢 bool containsDynamicPolicy() const; /// 判断是否有静态Policy /// @note 此方法速度较慢 bool containsStaticPolicy() const; /// 判断是否包含指定policy bool containsPolicy(ZxPolicy* p) const; //////////////////////////////////////////// /// 内部使用的遍历器 class I_PLOTBASE_EXPORT const_iterator { const ZxEdit* m_pEdit; int n; const_iterator(const ZxEdit* pEdit, int n); public: ZxPolicy* operator*(); bool operator!=( const const_iterator& ) const; bool operator==( const const_iterator& ) const; const_iterator& operator++(); friend class ZxEdit; }; const_iterator begin() const; const_iterator end() const; /// 内部使用的遍历器 class I_PLOTBASE_EXPORT const_reverse_iterator { const ZxEdit* m_pEdit; int n; const_reverse_iterator(const ZxEdit* pEdit, int n); public: ZxPolicy* operator*(); bool operator!=( const const_reverse_iterator& ) const; bool operator==( const const_reverse_iterator& ) const; const_reverse_iterator& operator++(); friend class ZxEdit; }; const_reverse_iterator rbegin() const; const_reverse_iterator rend() const; //////////////////////////////////////////// ZxHandlePolicy* getHandlePolicy() const; void setHandlePolicy(ZxHandlePolicy* p, bool bAsStatic = false); /// HandlePolicy的数量 int getHandlePoliciesCount() const; virtual void onPrepareContextMenu(QMenu* pMenu, const QPointF& pos); virtual void onItemMove(const QPointF& ptOld, const QPointF& ptNew); virtual void onItemResize(const QSizeF & szOld, const QSizeF & szNew); /// 键 virtual void onKeyPress(QKeyEvent* event); virtual void onKeyRelease(QKeyEvent* event); /// 刷新所有policy virtual void update(); virtual QRectF getBounds() const; private: ZxRenderItem* m_pItem; QVector m_vecPolicies; int m_nHandlePoliciesCount; friend class ZxRenderItem; };