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/ZxSelection.h

176 lines
4.3 KiB
C++

#pragma once
#include <QObject>
#include <QList>
#include <QRectF>
#include <QMimeData>
#include "ZxPaintParam.h"
#include "ZxRenderAlign.h"
#include "iPlotBase_global.h"
class ZxRenderItem;
class ZxSceneItem;
class QTimer;
class QTime;
class ZxSelectionPrivate;
class ZxSelectionNode;
/// 当前选择的图件列表.
/// 已经为大数据量及频繁选择做了优化.
/// @note 此类的行为类似Qt的shared类.
class I_PLOTBASE_EXPORT ZxSelection
{
public:
public:
ZxSelection();
ZxSelection(const ZxSelection& c);
~ZxSelection();
const ZxSelection& operator=(const ZxSelection& c);
// // 获取实际对象, 以挂接信号
// QObject & operator*();
// // 获取实际对象, 以挂接信号
// const QObject & operator*() const;
/// 获取实际对象, 以挂接信号
QObject* qobject() const;
/// 获取所属的场景
ZxSceneItem* getScene() const;
/// 选择
void add(ZxRenderItem* p, bool force = false);
/// 选择
void add(const QList<ZxRenderItem*> & items, bool force = false);
/// 取消选择
void remove(ZxRenderItem* p);
/// 取消选择
void remove(const QList<ZxRenderItem*> & items);
/// 反选
void invert(ZxRenderItem* p, bool force = false);
/// 反选
void invert(const QList<ZxRenderItem*> & items, bool force = false);
/// 清除选择
void clear();
/// 获取第一个图元
/// @return 列表不为空时返回第一个图元, 列表为空时返回NULL
/// @see begin() end() last()
ZxRenderItem* first() const;
/// 获取最后一个图元
/// @return 列表不为空时最后一个图元, 列表为空时返回NULL
/// @see begin() end() first()
ZxRenderItem* last() const;
/// 转换成list
QList<ZxRenderItem *> toList() const;
class I_PLOTBASE_EXPORT const_iterator
{
ZxSelectionPrivate * imp;
ZxSelectionNode* p;
const_iterator(ZxSelectionPrivate * imp, ZxSelectionNode* p);
public:
const_iterator();
ZxRenderItem* operator*();
bool operator!=( const const_iterator& ) const;
bool operator==( const const_iterator& ) const;
const_iterator& operator++();
friend class ZxSelection;
};
/// Returns an STL-style iterator pointing to the first item in the list.
/// @see first() last() end()
/// @code
/// for(auto it = selection.begin(); it != selection.end(); ++it)
/// {
/// ZxRenderItem* p = *it;
/// // do something
/// }
/// @endcode
const_iterator begin() const;
/// Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
/// @see last() last() begin()
/// @code
/// for(auto it = selection.begin(); it != selection.end(); ++it)
/// {
/// ZxRenderItem* p = *it;
/// // do something
/// }
/// @endcode
const_iterator end() const;
/// 列表是否为空
bool empty() const;
/// 列表是否为空
bool isEmpty() const;
/// 是否单选
bool isSingle() const;
/// 选中的图元数量
int count() const;
// 选中的图元是否相同类型.
// @return 类型相同或列表为空时返回true, 否则返回false.
// @note 根据 item->getClassName() 来判断
//bool isSameType() const;
/// 选中的图元的边框的并集
QRectF getBounds(ZxFilterFun filter = 0);
/// 选中的图元是否有相同父节点
bool hasSameParent() const;
/// 移动选中的图元
void move(double dx, double dy);
/// 查找选中图元的最近公共祖先节点
ZxRenderItem* findCommonAncestor() const;
/// 对齐算法
static QList<QRectF> calcAlign(const QList<QRectF> & rects, const QRectF& box, Zx::ChartObjAlign type);
/// 对齐
void align(Zx::ChartObjAlign mode);
/// 目前选中的对象是否支持指定对齐方式
bool canAlign(Zx::ChartObjAlign mode) const;
/// 复制到剪贴板
bool copy() const;
/// 从剪贴板粘贴
bool paste();
/// 模拟重新选择, 可用来实现刷新属性表等功能
void emulateReSelect();
/// 判断是否含有指定图元.
bool contains(ZxRenderItem* p) const;
private:
ZxSelection(ZxSceneItem* pScene);
ZxSelectionPrivate* imp;
friend class ZxSceneItem;
friend class ZxSelectionPrivate;
};