|
DAWorkbench 0.0.1
DAWorkbench API
|
这是带着undostack的GraphicsScene 此QGraphicsScene支持: 更多...
#include <DAGraphicsScene.h>
类 | |
| class | PrivateData |
Public 类型 | |
| enum | LinkMode { LinkModeAutoStartEndFollowMouseClick } |
| 链接模式 更多... | |
Public 槽 | |
| void | setEnableSnapToGrid (bool on=true) |
| 是否允许对齐网格 | |
| void | showGridLine (bool on) |
| 显示网格线 | |
| int | selectAll () |
| 选中所有item | |
| int | unselectAll () |
| 取消选择,把所有item设置为非选中状态 | |
| void | clearSelection () |
| 取消选中item | |
| int | setSelectionState (const QList< QGraphicsItem * > &its, bool isSelect) |
| 设置item的选中状态 | |
| void | setReadOnly (bool on) |
| 设定为只读模式 | |
| void | setupSceneAction (DA::DAAbstractGraphicsSceneAction *act) |
| 激活场景动作 | |
| void | clearSceneAction () |
| 清除场景动作 | |
信号 | |
| void | itemsPositionChanged (const QList< QGraphicsItem * > &items, const QList< QPointF > &oldPos, const QList< QPointF > &newPos) |
| item移动发射的信号 | |
| void | itemBodySizeChanged (DAGraphicsResizeableItem *item, const QSizeF &oldSize, const QSizeF &newSize) |
| 条目bodysize改变触发的信号 | |
| void | itemRotationChanged (DAGraphicsResizeableItem *item, const qreal &rotation) |
| item旋转发出的信号 | |
| void | linkCompleted (DAGraphicsLinkItem *linkItem) |
| 完成了一次链接 | |
| void | selectItemChanged (DAGraphicsItem *item) |
| 选中的item发生了变化,注意,选中的如果是分组,会检查分组内部的item的点击,最终也是发送被点击的item | |
| void | selectLinkChanged (DAGraphicsLinkItem *item) |
| 选中的链接线发生了改变 | |
| void | itemsAdded (const QList< QGraphicsItem * > &its) |
| item添加的信号 | |
| void | itemsRemoved (const QList< QGraphicsItem * > &its) |
| item移除的信号 | |
| void | sceneActionActived (DA::DAAbstractGraphicsSceneAction *act) |
| 一个场景动作被激活的信号 | |
| void | sceneActionDeactived (DA::DAAbstractGraphicsSceneAction *act) |
| 一个场景动作已经解除激活的信号 | |
Public 成员函数 | |
| DAGraphicsScene (QObject *p=nullptr) | |
| DAGraphicsScene (const QRectF &sceneRect, QObject *p=nullptr) | |
| DAGraphicsScene (qreal x, qreal y, qreal width, qreal height, QObject *p=nullptr) | |
| QPointF | getCurrentMouseScenePos () const |
| 获取当前鼠标在scene的位置 | |
| QPointF | getLastMousePressScenePos () const |
| 获取最后鼠标在scene点击的位置 | |
| QList< QGraphicsItem * > | getSelectedMovableItems () |
| 获取选中且能移动的item | |
| QUndoCommand * | addItem_ (QGraphicsItem *item) |
| 等同additem,但使用redo/undo来添加,可以进行redo/undo操作 | |
| QUndoCommand * | addItems_ (const QList< QGraphicsItem * > &its) |
| 等同多次additem,但使用redo/undo来添加,可以进行redo/undo操作 | |
| QUndoCommand * | removeItem_ (QGraphicsItem *item) |
| 等同removeItem,但使用redo/undo来添加,可以进行redo/undo操作 | |
| QUndoCommand * | removeItems_ (const QList< QGraphicsItem * > &its) |
| QPixmap | toPixamp (int dpi=0) |
| 导出为pixmap | |
| QImage | toImage (int dpi=0) |
| 转换为设备相关的图片 | |
| void | beginLink (DAGraphicsLinkItem *linkItem, LinkMode lm=LinkModeAutoStartEndFollowMouseClick) |
| 开始链接模式 | |
| bool | isStartLink () const |
| 判断当前是否是链接模式 | |
| void | endLink () |
| 结束链接模式 | |
| virtual void | cancelLink () |
| 取消链接模式 | |
| virtual void | cancel () |
| DAGraphicsLinkItem * | getCurrentLinkItem () const |
| 获取当前正在进行连线的连接线item | |
| void | setIgnoreLinkEvent (bool on) |
| 设置忽略链接事件的处理,主要忽略mousePressEvent,mouseMoveEvent的链接事件 | |
| bool | isIgnoreLinkEvent () const |
| 判断当前是否忽略链接事件 | |
| void | groupingSelectItems_ () |
| 对选中item的分组 | |
| void | removeSelectItemGroup_ () |
| 移除选中的分组 | |
| bool | isEnableSnapToGrid () const |
| 是否允许对齐网格 | |
| bool | isShowGridLine () |
| 是否显示网格线 | |
| void | setGridSize (const QSize &gs) |
| 设置网格尺寸 | |
| QSize | getGridSize () const |
| 网格尺寸 | |
| void | setGridLinePen (const QPen &p) |
| 设置网格画笔 | |
| QPen | getGridLinePen () const |
| 获取网格画笔 | |
| void | setPaintBackgroundInCache (bool on) |
| 设置绘制背景使用缓冲 | |
| bool | isPaintBackgroundInCache () const |
| 是否绘制背景使用缓冲 | |
| QUndoStack & | undoStack () |
| 获取DANodeGraphicsScene内部维护的undoStack | |
| const QUndoStack & | undoStack () const |
| QUndoStack * | getUndoStack () const |
| 获取undostack指针 | |
| void | setUndoStackActive () |
| 在StackGroup中激活undoStack | |
| void | push (QUndoCommand *cmd) |
| 等同s->undoStack().push(cmd); | |
| QGraphicsItem * | findItemByID (uint64_t id, bool recursion=false) const |
| 通过id查找item,此函数性能为O(n) | |
| QList< QGraphicsItem * > | topItems () const |
| QList< QGraphicsItem * > | topItems (const QPointF &scenePos) const |
| QList< DAGraphicsItem * > | selectedDAItems () const |
| 获取选中的da item | |
| void | setReady (bool on) |
| 设置场景就绪 | |
| bool | isReady () const |
| 场景是否就绪 | |
| bool | isHaveSceneAction () const |
| 判断当前是否存在场景动作 | |
| QList< DAGraphicsLayout * > | getLayouts () const |
| 获取所有图层 | |
| bool | isReadOnly () const |
| DAGraphicsTextItem * | createText_ (const QString &str=QString()) |
| 创建并加入一个文本框 | |
| DAGraphicsRectItem * | createRect_ (const QPointF &p=QPointF()) |
| 在画布中创建一个矩形 | |
| void | registCommandsFactory (DAGraphicsCommandsFactory *fac) |
| 注册命令工厂 | |
| DAGraphicsCommandsFactory * | commandsFactory () |
| 命令工厂 | |
| virtual bool | isItemCanMove (QGraphicsItem *positem, const QPointF &scenePos) |
| 判断点击的item是否可以移动 | |
静态 Public 成员函数 | |
| static QGraphicsItem * | findItemByID (const QList< QGraphicsItem * > &its, uint64_t id, bool recursion=false) |
| 查找id对应的GraphicsItem* | |
| static int | getDefaultDPI () |
| 获取默认的dpi | |
| static int | dpiToPx (int dpi, int r) |
| dpi转为像素 | |
| static void | addItemToGroup (QGraphicsItemGroup *group, const QList< QGraphicsItem * > &willGroupItems) |
| 通用的item分组,此操作和QGraphicsScene::createItemGroup逻辑一致 | |
Protected 成员函数 | |
| void | emitItemsPositionChanged (const QList< QGraphicsItem * > &items, const QList< QPointF > &oldPos, const QList< QPointF > &newPos) |
| 调用此函数 主动触发itemsPositionChanged信号,这个函数用于 继承此类例如实现了键盘移动item,主动触发此信号 | |
| void | emitItemBodySizeChanged (DAGraphicsResizeableItem *item, const QSizeF &oldSize, const QSizeF &newSize) |
| 调用此函数 主动触发itemBodySizeChanged信号 | |
| void | emitItemRotationChanged (DAGraphicsResizeableItem *item, const qreal &rotation) |
| 调用此函数 主动触发itemRotationed信号 | |
| void | addItemWithSignal (QGraphicsItem *item) |
| 带信号的addItm | |
| void | mousePressEvent (QGraphicsSceneMouseEvent *mouseEvent) override |
| void | mouseMoveEvent (QGraphicsSceneMouseEvent *mouseEvent) override |
| void | mouseReleaseEvent (QGraphicsSceneMouseEvent *mouseEvent) override |
| void | drawBackground (QPainter *painter, const QRectF &rect) override |
友元 | |
| class | DAGraphicsResizeableItem |
这是带着undostack的GraphicsScene 此QGraphicsScene支持:
| QUndoCommand * DA::DAGraphicsScene::addItem_ | ( | QGraphicsItem * | item | ) |
等同additem,但使用redo/undo来添加,可以进行redo/undo操作
| item |
| QUndoCommand * DA::DAGraphicsScene::addItems_ | ( | const QList< QGraphicsItem * > & | its | ) |
等同多次additem,但使用redo/undo来添加,可以进行redo/undo操作
| item |
|
static |
通用的item分组,此操作和QGraphicsScene::createItemGroup逻辑一致
| group | |
| willGroupItems |
|
protected |
带信号的addItm
| item |
| void DA::DAGraphicsScene::beginLink | ( | DAGraphicsLinkItem * | linkItem, |
| LinkMode | lm = LinkModeAutoStartEndFollowMouseClick |
||
| ) |
开始链接模式
再开始链接模式,鼠标移动事件会改变当前链接线的末端位置,直到点击鼠标左键进行确认(endLink), 或者点击鼠标右键取消链接(cancelLink)
| linkItem | 连接线图元 |
|
virtual |
取消链接模式
被 DA::DANodeGraphicsScene 重载.
|
slot |
清除场景动作
| DAGraphicsCommandsFactory * DA::DAGraphicsScene::commandsFactory | ( | ) |
命令工厂
| DAGraphicsRectItem * DA::DAGraphicsScene::createRect_ | ( | const QPointF & | p = QPointF() | ) |
在画布中创建一个矩形
| p | 矩形的位置 |
| DAGraphicsTextItem * DA::DAGraphicsScene::createText_ | ( | const QString & | str = QString() | ) |
创建并加入一个文本框
| pos |
|
static |
dpi转为像素
| dpi | |
| r |
|
protected |
调用此函数 主动触发itemBodySizeChanged信号
| item | |
| oldSize | |
| newSize |
|
protected |
调用此函数 主动触发itemRotationed信号
| item | |
| rotation |
|
protected |
调用此函数 主动触发itemsPositionChanged信号,这个函数用于 继承此类例如实现了键盘移动item,主动触发此信号
| items | |
| oldPos | |
| newPos |
| void DA::DAGraphicsScene::endLink | ( | ) |
结束链接模式
结束链接模式会正常记录当前的连线
如果是要取消当前的连接线,使用
此函数结束时会发出
|
static |
查找id对应的GraphicsItem*
目前有
| its | |
| id | |
| recursion |
| QGraphicsItem * DA::DAGraphicsScene::findItemByID | ( | uint64_t | id, |
| bool | recursion = false |
||
| ) | const |
通过id查找item,此函数性能为O(n)
| id | |
| recursion | 递归查找 |
| DAGraphicsLinkItem * DA::DAGraphicsScene::getCurrentLinkItem | ( | ) | const |
获取当前正在进行连线的连接线item
| QPointF DA::DAGraphicsScene::getCurrentMouseScenePos | ( | ) | const |
获取当前鼠标在scene的位置
|
static |
获取默认的dpi
| QPen DA::DAGraphicsScene::getGridLinePen | ( | ) | const |
获取网格画笔
| QSize DA::DAGraphicsScene::getGridSize | ( | ) | const |
网格尺寸
| QPointF DA::DAGraphicsScene::getLastMousePressScenePos | ( | ) | const |
获取最后鼠标在scene点击的位置
| QList< DAGraphicsLayout * > DA::DAGraphicsScene::getLayouts | ( | ) | const |
获取所有图层
| QList< QGraphicsItem * > DA::DAGraphicsScene::getSelectedMovableItems | ( | ) |
获取选中且能移动的item
| QUndoStack * DA::DAGraphicsScene::getUndoStack | ( | ) | const |
获取undostack指针
| bool DA::DAGraphicsScene::isEnableSnapToGrid | ( | ) | const |
是否允许对齐网格
| bool DA::DAGraphicsScene::isHaveSceneAction | ( | ) | const |
判断当前是否存在场景动作
| bool DA::DAGraphicsScene::isIgnoreLinkEvent | ( | ) | const |
判断当前是否忽略链接事件
|
virtual |
判断点击的item是否可以移动
对于一些特殊的item,可以通过继承此函数来否决掉DAGraphicsSceneWithUndoStack对item移动的判断,否则会对item进行移动 最简单的实现如下:
| selitems |
| bool DA::DAGraphicsScene::isPaintBackgroundInCache | ( | ) | const |
是否绘制背景使用缓冲
| bool DA::DAGraphicsScene::isReady | ( | ) | const |
场景是否就绪
| bool DA::DAGraphicsScene::isShowGridLine | ( | ) |
是否显示网格线
| bool DA::DAGraphicsScene::isStartLink | ( | ) | const |
判断当前是否是链接模式
|
signal |
条目bodysize改变触发的信号
| item | |
| rotation |
|
signal |
item旋转发出的信号
| item | |
| rotation |
|
signal |
item添加的信号
| item |
|
signal |
item移动发射的信号
此信号只针对鼠标移动导致的item位置改变
| item | |
| oldPos | |
| newPos |
|
signal |
item移除的信号
| item |
|
signal |
完成了一次链接
这个是最后连接完成的信号,会在endLink回调之后发出
| linkItem | 通过此指针可以获取两个连接点 |
|
overrideprotected |
处理链接事件
处理有移动事件
1.记录选中的所有图元,如果点击的是改变尺寸的点,这个就不执行记录
| void DA::DAGraphicsScene::push | ( | QUndoCommand * | cmd | ) |
等同s->undoStack().push(cmd);
| cmd |
| void DA::DAGraphicsScene::registCommandsFactory | ( | DAGraphicsCommandsFactory * | fac | ) |
注册命令工厂
命令工厂可以生成自己需要的命令,以便对redo/undo定制化
| fac |
| QUndoCommand * DA::DAGraphicsScene::removeItem_ | ( | QGraphicsItem * | item | ) |
等同removeItem,但使用redo/undo来添加,可以进行redo/undo操作
| item | |
| autopush | 自动推入redo/undo栈,对于无需操作返回的cmd,此值需要设置为true,否则需要手动调用push函数,把返回的cmd推入 |
|
signal |
一个场景动作被激活的信号
| act |
|
signal |
一个场景动作已经解除激活的信号
| act |
|
slot |
选中所有item
| QList< DAGraphicsItem * > DA::DAGraphicsScene::selectedDAItems | ( | ) | const |
获取选中的da item
|
signal |
选中的item发生了变化,注意,选中的如果是分组,会检查分组内部的item的点击,最终也是发送被点击的item
| item |
|
signal |
选中的链接线发生了改变
| item |
|
slot |
是否允许对齐网格
| on |
| void DA::DAGraphicsScene::setGridLinePen | ( | const QPen & | p | ) |
设置网格画笔
| p |
| void DA::DAGraphicsScene::setGridSize | ( | const QSize & | gs | ) |
设置网格尺寸
| gs |
| void DA::DAGraphicsScene::setIgnoreLinkEvent | ( | bool | on | ) |
设置忽略链接事件的处理,主要忽略mousePressEvent,mouseMoveEvent的链接事件
这个函数一般是在子类中的重载函数中调用,用于进行一些特殊处理需要暂时屏蔽掉链接事件
| on |
| void DA::DAGraphicsScene::setPaintBackgroundInCache | ( | bool | on | ) |
设置绘制背景使用缓冲
| on |
|
slot |
设定为只读模式
锁定后,无法移动,无法编辑,进入只读模式
| void DA::DAGraphicsScene::setReady | ( | bool | on | ) |
设置场景就绪
如果场景还没加载完成,ready为false,一般这个函数在工程加载的时候应用
| on |
|
slot |
设置item的选中状态
| its | |
| isSelect |
|
slot |
|
slot |
显示网格线
| on |
| QImage DA::DAGraphicsScene::toImage | ( | int | dpi = 0 | ) |
转换为设备相关的图片
| dpi |
| QPixmap DA::DAGraphicsScene::toPixamp | ( | int | dpi = 0 | ) |
导出为pixmap
| QUndoStack & DA::DAGraphicsScene::undoStack | ( | ) |
获取DANodeGraphicsScene内部维护的undoStack
|
slot |
取消选择,把所有item设置为非选中状态