|
DAWorkbench 0.0.1
DAWorkbench API
|
绘制连接线的item 更多...
#include <DAGraphicsLinkItem.h>
类 | |
| class | PrivateData |
Public 类型 | |
| enum | AnonymousType { anonymous = DA::ItemType_DAGraphicsLinkItem } |
| enum | LinkLineStyle { LinkLineBezier , LinkLineStraight , LinkLineKnuckle } |
| 连接点的样式 更多... | |
| enum | Orientations { OrientationStart = 0 , OrientationEnd , OrientationBoth } |
| 标记方向 更多... | |
| enum | EndPointType { EndPointNone , EndPointTriangType } |
| 端点样式 更多... | |
Public 类型 继承自 DA::DAGraphicsItem | |
| enum | { Type = DA::ItemType_DAGraphicsItem } |
Public 成员函数 | |
| int | type () const override |
| DAGraphicsLinkItem (QGraphicsItem *p=nullptr) | |
| void | setEndPointType (Orientations o, EndPointType epType) |
| 设置连接点端点的样式 | |
| EndPointType | getEndPointType (Orientations o) const |
| 获取端点的样式 | |
| int | getEndPointSize () const |
| 端点大小 | |
| void | setEndPointSize (int v) |
| 设置端点大小 | |
| void | setLinkLineStyle (LinkLineStyle s) |
| 设置连线样式 | |
| LinkLineStyle | getLinkLineStyle () const |
| 获取连线样式 | |
| void | setLinePen (const QPen &p) |
| 设置线的画笔 | |
| QPen | getLinePen () const |
| 返回当前画笔 | |
| virtual QRectF | updateBoundingRect () |
| 更新范围 | |
| void | setBezierControlScale (qreal rate=0.25) |
| 设置贝塞尔曲线的控制点的缩放比例 | |
| qreal | getBezierControlScale () const |
| 获取贝塞尔曲线的控制点的缩放比例 | |
| virtual void | setStartScenePosition (const QPointF &scenepostion) |
| 开始连接点的位置,位置基于scene | |
| QPointF | getStartScenePosition () const |
| 开始连接点的位置,位置基于scene | |
| virtual void | setEndScenePosition (const QPointF &scenepostion) |
| 结束连接点的位置,位置基于scene | |
| QPointF | getEndScenePosition () const |
| 结束连接点的位置,位置基于scene | |
| QPainterPath | getLinkLinePainterPath () const |
| 获取链接线 | |
| QPainterPath | getEndPointPainterPath (Orientations epType) const |
| 获取末端(箭头)的绘图路径 | |
| void | updateEndPoint () |
| 更新末端 | |
| virtual void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override |
| 绘图 | |
| virtual void | paintLinkLine (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget, const QPainterPath &linkPath) |
| 绘制连接线 | |
| virtual void | paintEndPoint (QPainter *painter, const QStyleOptionGraphicsItem *option, const QPointF &pStart, EndPointType etStart, const QPainterPath &startPainterPath, const QPointF &pEnd, EndPointType etEnd, const QPainterPath &endPainterPath, const QPainterPath &linkPath) |
| 绘制箭头 | |
| virtual QRectF | boundingRect () const override |
| virtual QPainterPath | shape () const override |
| virtual QPainterPath | generateLinePainterPath (const QPointF &fromPoint, const QPointF &toPoint, LinkLineStyle linestyle=LinkLineStraight) |
| 生成一个连接线 | |
| virtual QPainterPath | generateEndPointPainterPath (EndPointType epType, int size) |
| 生成箭头,所有生成的箭头箭头尖端需要再原点,箭头朝向x轴正方向 | |
| virtual bool | willCompleteLink () |
| 在将要结束链接的回调,通过此回调可以执行完成链接后的相关操作,例如判断末端链接的图元,从而实现路径调整 | |
| virtual bool | saveToXml (QDomDocument *doc, QDomElement *parentElement, const QVersionNumber &ver) const override |
| 保存到xml中 | |
| virtual bool | loadFromXml (const QDomElement *parentElement, const QVersionNumber &ver) override |
| 从xml中加载 | |
| void | setScenePos (const QPointF &p) |
| void | setScenePos (qreal x, qreal y) |
Public 成员函数 继承自 DA::DAGraphicsItem | |
| DAGraphicsItem (QGraphicsItem *parent=nullptr) | |
| void | setBorderPen (const QPen &p) |
| 设置边框画笔 | |
| QPen | getBorderPen () const |
| 获取当前边框画笔 | |
| void | setShowBorder (bool on) |
| 设置显示边框 | |
| bool | isShowBorder () const |
| 是否显示边框 | |
| void | setSelectable (bool on=true) |
| 设置是否可选中 | |
| bool | isSelectable () const |
| 判断可否被选中 | |
| void | setMovable (bool on=true) |
| 设置为是否可移动 | |
| bool | isMovable () const |
| 判断是否可以移动 | |
| void | setBackgroundBrush (const QBrush &b) |
| 设置背景 | |
| QBrush | getBackgroundBrush () const |
| 获取背景 | |
| void | enableShowBackground (bool on) |
| 设置显示背景 | |
| bool | isShowBackground () const |
| 是否显示背景 | |
| virtual void | groupPositionChanged (const QPointF &p) |
| 分组的位置发生了改变 此函数是在分组后才会回调,分组后,分组的移动对于item来说是不移动的,这时候无法触发ItemPositionChanged的改变,从而导致一些异常,因此需要分组告诉子对象分组移动了 | |
| void | setScenePos (const QPointF &p) |
| void | setScenePos (qreal x, qreal y) |
| uint64_t | getItemID () const |
| void | setItemID (uint64_t id) |
| bool | isSceneReadOnly () const |
| 判断当前场景是否为只读模式,只读模式不允许操作 | |
静态 Public 成员函数 | |
| static qreal | pointLength (const QPointF &a, const QPointF &b) |
| 计算两个点的距离 | |
| static QPointF | elongation (const QPointF &orgPoint, AspectDirection d, qreal externLen) |
| 延长线,以一个方向和距离延伸 | |
| static bool | isDirectionOpposite (AspectDirection d1, AspectDirection d2) |
| 判断两个方向是否相对,也就是东对西,南对北就是相对,相对必定平行 | |
| static bool | isDirectionParallel (AspectDirection d1, AspectDirection d2) |
| 判断两个方向是否平行 | |
| static bool | isPointInFront (const QPointF &p1, AspectDirection d1, const QPointF &p2) |
| 在1d的方向上,点2在点1的方向的前面 | |
| static bool | isPointCanMeet (const QPointF &p1, AspectDirection d1, const QPointF &p2, AspectDirection d2) |
| 判断点能否相遇,针对垂直方向才有意义 | |
| static bool | isParallelPointApproachInDirection (const QPointF &p1, AspectDirection d1, const QPointF &p2, AspectDirection d2) |
| 针对平行点线,沿着方向移动可以接近,此函数只对平行点线有用 | |
| static AspectDirection | oppositeDirection (AspectDirection d) |
| 翻转方向 | |
| static AspectDirection | relativeDirectionOfPoint (const QPointF &p1, const QPointF &p2) |
| 计算点1相对点2的方向 | | p1———p2———— | | 如上面示例,此函数返回West | |
| static QPointF | calcPainterPathEndPoint (const QPainterPath &path, bool fromStart=true, qreal distanceMaxPx=18.0, int maxTryCnt=10) |
| 获取线段的末端,这个函数可以返回末端但有不是终端的点,这个点离终端的距离不会超过distanceMaxPx | |
静态 Public 成员函数 继承自 DA::DAGraphicsItem | |
| static DAGraphicsItem * | cast (QGraphicsItem *i) |
| dynamic_cast为DAGraphicsItem | |
静态 Public 成员函数 继承自 DA::DAXMLFileInterface | |
| template<typename std_container_like > | |
| static QDomElement | makeElement (const std_container_like &v, const QString &tagName, QDomDocument *doc) |
| 生成一个文本 | |
| template<typename std_container_like > | |
| static bool | loadElement (std_container_like &v, const QDomElement *ele) |
| 加载文本 | |
| static QDomElement | makeSysInfoElement (const QString &tagName, QDomDocument *doc) |
| static void | appendElementWithText (QDomElement &parent, const QString &tagName, const QString &text, QDomDocument *doc) |
| 在parent下,插入一个tag,tag下包含文字text | |
Protected 成员函数 | |
| DAGraphicsScene * | daScene () const |
| void | setStartPosition (const QPointF &p) |
| 开始连接点的位置 | |
| const QPointF & | getStartPosition () const |
| 开始连接点的位置 | |
| void | setEndPosition (const QPointF &p) |
| 结束连接点的位置 | |
| const QPointF & | getEndPosition () const |
| 结束连接点的位置 | |
| virtual QPen | getPainterPen (const QStyleOptionGraphicsItem *option) const |
| 获取绘图的画笔 | |
| virtual QPainterPath | generateLinkLineBezierPainterPath (const QPointF &fromPos, AspectDirection fromDirect, const QPointF &toPos, AspectDirection toDirect) |
| 生成贝塞尔曲线 | |
| virtual QPainterPath | generateLinkLineStraightPainterPath (const QPointF &fromPos, const QPointF &toPos) |
| 生成直线 | |
| virtual QPainterPath | generateLinkLineKnucklePainterPath (const QPointF &fromPos, AspectDirection fromDirect, const QPointF &toPos, AspectDirection toDirect) |
| 生成直角连线 | |
Protected 成员函数 继承自 DA::DAGraphicsItem | |
| DAGraphicsScene * | daScene () const |
| virtual QVariant | itemChange (QGraphicsItem::GraphicsItemChange change, const QVariant &value) override |
| 这里主要对只读模式的过滤 | |
绘制连接线的item
|
static |
获取线段的末端,这个函数可以返回末端但有不是终端的点,这个点离终端的距离不会超过distanceMaxPx
这个函数主要是用于绘制箭头,为了决定箭头的旋转角度,获取线段的0.9位置点,这个点和端点的角度就是箭头旋转角度, 但是,对于非常长的线段,0.9的位置可能也比较大,尤其是折线,有可能会异常,因此就要有一个最大像素距离,如果超过最大像素距离, 就要尝试再计算要给更小的值,如变为0.95,如果还不行,就继续变大占比,直到小于最小距离
| path | |
| fromStart | |
| distanceMaxPx | |
| maxTryCnt | 最大尝试次数 |
|
static |
延长线,以一个方向和距离延伸
| orgPoint | 原始点 |
| d | 伸出方向 |
| externLen | 伸出长度 |
|
virtual |
生成箭头,所有生成的箭头箭头尖端需要再原点,箭头朝向x轴正方向
形如:
| | * | * *
-—* *--> | * * | * |
| arrowType | |
| size | 箭头↑的高度 |
|
virtual |
生成一个连接线
| fromPoint | |
| toPoint | |
| strokerWidth | 轮廓扩展,此轮廓扩展会生成一个 |
|
protectedvirtual |
生成贝塞尔曲线
| fromPos | |
| toPos |
1 先求出两个点距离
2.通过伸出方向,得到两个控制点的位置
3.生成贝塞尔曲线
|
protectedvirtual |
生成直角连线
| fromPos | |
| toPos |
|
protectedvirtual |
生成直线
| fromPos | |
| toPos |
| qreal DA::DAGraphicsLinkItem::getBezierControlScale | ( | ) | const |
获取贝塞尔曲线的控制点的缩放比例
| QPainterPath DA::DAGraphicsLinkItem::getEndPointPainterPath | ( | Orientations | epType | ) | const |
获取末端(箭头)的绘图路径
| int DA::DAGraphicsLinkItem::getEndPointSize | ( | ) | const |
端点大小
| DAGraphicsLinkItem::EndPointType DA::DAGraphicsLinkItem::getEndPointType | ( | DAGraphicsLinkItem::Orientations | o | ) | const |
获取端点的样式
| o | 端点的方向,如果为both,若两个端点样式一样,返回端点样式,若不一样,返回EndPointNone |
|
protected |
结束连接点的位置
| QPointF DA::DAGraphicsLinkItem::getEndScenePosition | ( | ) | const |
结束连接点的位置,位置基于scene
| QPen DA::DAGraphicsLinkItem::getLinePen | ( | ) | const |
返回当前画笔
| QPainterPath DA::DAGraphicsLinkItem::getLinkLinePainterPath | ( | ) | const |
获取链接线
| DAGraphicsLinkItem::LinkLineStyle DA::DAGraphicsLinkItem::getLinkLineStyle | ( | ) | const |
获取连线样式
|
protectedvirtual |
获取绘图的画笔
在被选中的时候,画笔会加深加粗
| option |
|
protected |
开始连接点的位置
| QPointF DA::DAGraphicsLinkItem::getStartScenePosition | ( | ) | const |
开始连接点的位置,位置基于scene
|
static |
判断两个方向是否相对,也就是东对西,南对北就是相对,相对必定平行
| d1 | |
| d2 |
|
static |
判断两个方向是否平行
| d1 | |
| d2 |
|
static |
针对平行点线,沿着方向移动可以接近,此函数只对平行点线有用
| p1 | |
| d1 | |
| p2 | |
| d2 |
|
static |
判断点能否相遇,针对垂直方向才有意义
| p1 | |
| d1 | |
| p2 | |
| d2 |
|
static |
在1d的方向上,点2在点1的方向的前面
| p1 | |
| d1 | |
| p2 |
|
overridevirtual |
|
static |
翻转方向
| d |
|
overridevirtual |
绘图
| painter | |
| option | |
| widget |
|
virtual |
绘制箭头
| painter | |
| option | |
| p | 箭头的端点 |
| linkPath | 绘制箭头的路径线,这个路径线用来计算箭头的旋转 |
|
virtual |
绘制连接线
| painter | |
| option | |
| widget | |
| linkPath |
|
static |
计算两个点的距离
| a | |
| b |
|
static |
计算点1相对点2的方向 | | p1———p2———— | | 如上面示例,此函数返回West
| p1 | |
| p2 |
|
overridevirtual |
| void DA::DAGraphicsLinkItem::setBezierControlScale | ( | qreal | rate = 0.25 | ) |
设置贝塞尔曲线的控制点的缩放比例
在连线时按照两个连接点的方向延伸出贝塞尔曲线的控制点,贝塞尔曲线的控制点的长度w = length * bezierControlScale, 其中length是两个连接点的绝对距离,可以通过
| rate | 默认为0.25 |
| void DA::DAGraphicsLinkItem::setEndPointSize | ( | int | v | ) |
设置端点大小
| v |
| void DA::DAGraphicsLinkItem::setEndPointType | ( | DAGraphicsLinkItem::Orientations | o, |
| DAGraphicsLinkItem::EndPointType | epType | ||
| ) |
设置连接点端点的样式
| o | 连接点方向 |
| epType | 样式 |
|
protected |
结束连接点的位置
| p | 相对item自身的位置 |
|
virtual |
结束连接点的位置,位置基于scene
| p | 相对scene的位置 |
| void DA::DAGraphicsLinkItem::setLinePen | ( | const QPen & | p | ) |
设置线的画笔
| p |
| void DA::DAGraphicsLinkItem::setLinkLineStyle | ( | DAGraphicsLinkItem::LinkLineStyle | s | ) |
设置连线样式
| s |
|
protected |
开始连接点的位置
| p | 相对item自身的位置 |
|
virtual |
开始连接点的位置,位置基于scene
默认情况下,开始点就是相对于item的原点(0,0)
| p | 相对scene的位置 |
|
inlineoverridevirtual |
重载 DA::DAGraphicsItem .
|
virtual |
更新范围
这个函数用来生成painterpath,计算BoundingRect等一系列操作
通过调用prepareGeometryChange()通知范围变更,避免出现残影
|
virtual |
在将要结束链接的回调,通过此回调可以执行完成链接后的相关操作,例如判断末端链接的图元,从而实现路径调整