We need one method RefreshLine in VAbstractTool instead of two similar methods in VNodePoint and VToolSinglePoint

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2015-12-11 11:31:21 +02:00
parent d057d336f7
commit ece2c42e5f
4 changed files with 42 additions and 47 deletions

View File

@ -247,32 +247,10 @@ void VToolSinglePoint::RefreshPointGeometry(const VPointF &point)
void VToolSinglePoint::RefreshLine(quint32 id)
{
Q_UNUSED(id)
QPen pen(CorrectColor(Qt::black));
pen.setWidthF(qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor);
QRectF nRec = namePoint->sceneBoundingRect();
nRec.translate(- scenePos());
if (this->rect().intersects(nRec) == false)
{
const QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2);
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos()));
lineName->setPen(QPen(CorrectColor(Qt::black),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
}
else
{
lineName->setVisible(false);
}
VAbstractTool::RefreshLine(this, namePoint, lineName, radius, pen);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -278,26 +278,6 @@ void VNodePoint::RefreshPointGeometry(const VPointF &point)
* @brief RefreshLine refresh label line on scene.
*/
void VNodePoint::RefreshLine()
{ QRectF nRec = namePoint->sceneBoundingRect();
nRec.translate(- scenePos());
if (this->rect().intersects(nRec) == false)
{
QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2);
QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos()));
if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
}
else
{
lineName->setVisible(false);
}
{
VAbstractTool::RefreshLine(this, namePoint, lineName, radius, QPen(Qt::black));
}

View File

@ -315,3 +315,36 @@ void VAbstractTool::AddRecord(const quint32 id, const Tool &toolType, VAbstractP
history->insert(index+1, record);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshLine refresh line to label on scene.
*/
void VAbstractTool::RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, QGraphicsLineItem *lineName,
qreal radius, const QPen pen)
{
QRectF nRec = namePoint->sceneBoundingRect();
nRec.translate(- point->scenePos());
if (point->rect().intersects(nRec) == false)
{
const QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - point->scenePos()), p1, p2);
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(point->scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - point->scenePos()));
lineName->setPen(pen);
if (QLineF(p1, pRec - point->scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
}
else
{
lineName->setVisible(false);
}
}

View File

@ -34,6 +34,7 @@
#include "../vmisc/vabstractapplication.h"
#include "../vwidgets/vmaingraphicsscene.h"
#include "visualization/visualization.h"
#include "../vwidgets/vgraphicssimpletextitem.h"
class QDomElement;
class QLineF;
@ -121,6 +122,9 @@ protected:
virtual void SetVisualization()=0;
void ToolCreation(const Source &typeCreation);
static void RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, QGraphicsLineItem *lineName,
qreal radius, const QPen pen);
private:
Q_DISABLE_COPY(VAbstractTool)
};