#pragma once #include #include #include #include #include class ZxRenderItem; class ZxSceneItem; class QTimer; class QTime; /// 当前选择的图件列表. /// 已经为大数据量及频繁选择做了优化. class I_PLOTBASE_EXPORT ZxRenderSelection : public QObject { Q_OBJECT struct Node { ZxRenderItem * item; Node * prev; Node * next; }; static Node * alloc(); bool m_bChanged; Node * head; Node * tail; QHash dict; void listAdd(Node * n); void listRemove(Node * n); void doAdd(ZxRenderItem * w, bool force); void doRemove(Node * n); void setChanged(); QTime * m_pLazyChangedTime; QTimer * m_pTimer; public: ZxRenderSelection(ZxSceneItem * pScene); ZxSceneItem * getScene(); /// 选择 void add(ZxRenderItem * p, bool force = false); /// 取消选择 void remove(ZxRenderItem * p); /// 反选 void invert(ZxRenderItem * p, bool force = false); void clear(); ZxRenderItem * first() const; ZxRenderItem * last() const; QList toList(); class I_PLOTBASE_EXPORT const_iterator { Node * p; const_iterator(Node * p); public: ZxRenderItem * operator*(); bool operator!=( const const_iterator& ) const; bool operator==( const const_iterator& ) const; const_iterator& operator++(); friend class ZxRenderSelection; }; const_iterator begin() const; const_iterator end() const; bool empty() const; bool isEmpty() const; bool isSingle() const; int count() const; QRectF getBounds(); bool hasSameParent() const; void move(float dx, float dy); signals: /// 个别图件被加进列表 void sigItemAdded(ZxRenderItem * p); /// 个别图件被从列表移除 void sigItemRemoved(ZxRenderItem * p); /// 选中列表被改变(即时) void sigSelectionChanged(); /// 选中列表被改变(非即时) void sigSelectionChangedLazy(); protected: friend class ZxRenderView; // ZxRenderSelection(); // ~ZxRenderSelection(); protected slots: virtual void onTimer(); private: ZxSceneItem * m_pScene; ZxRenderSelection(const ZxRenderSelection & c); };