Block moving a spline by dragging if a formula was used.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-02-26 19:44:51 +02:00
parent 773383ec70
commit 679f90d627
2 changed files with 112 additions and 64 deletions

View File

@ -32,6 +32,7 @@
#include "../../../undocommands/movespline.h" #include "../../../undocommands/movespline.h"
#include "../../../visualization/vistoolspline.h" #include "../../../visualization/vistoolspline.h"
#include "../vwidgets/vcontrolpointspline.h" #include "../vwidgets/vcontrolpointspline.h"
#include "../qmuparser/qmutokenparser.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
# include "../vmisc/vmath.h" # include "../vmisc/vmath.h"
@ -334,12 +335,20 @@ void VToolSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
if (qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula()))
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetOverrideCursor(cursorArrowCloseHand, 1, 1);
oldPosition = event->scenePos(); oldPosition = event->scenePos();
event->accept(); event->accept();
} }
} }
}
VAbstractSpline::mousePressEvent(event); VAbstractSpline::mousePressEvent(event);
} }
@ -349,17 +358,32 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
if (qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula()))
{ {
//Disable cursor-arrow-closehand //Disable cursor-arrow-closehand
RestoreOverrideCursor(cursorArrowCloseHand); RestoreOverrideCursor(cursorArrowCloseHand);
} }
} }
}
VAbstractSpline::mouseReleaseEvent(event); VAbstractSpline::mouseReleaseEvent(event);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
if (qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula()))
{
// Don't need check if left mouse button was pressed. According to the Qt documentation "If you do receive this // Don't need check if left mouse button was pressed. According to the Qt documentation "If you do receive this
// event, you can be certain that this item also received a mouse press event, and that this item is the current // event, you can be certain that this item also received a mouse press event, and that this item is the current
// mouse grabber.". // mouse grabber.".
@ -368,7 +392,6 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
// "weight" describes how the influence of the drag should be distributed // "weight" describes how the influence of the drag should be distributed
// among the handles; 0 = front handle only, 1 = back handle only. // among the handles; 0 = front handle only, 1 = back handle only.
const QSharedPointer<VSpline> spline = VAbstractTool::data.GeometricObject<VSpline>(id);
const qreal t = spline->ParamT(oldPosition); const qreal t = spline->ParamT(oldPosition);
if (qFloor(t) == -1) if (qFloor(t) == -1)
@ -429,15 +452,24 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
changeFinished = true; changeFinished = true;
} }
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
if (qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula()))
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetOverrideCursor(cursorArrowOpenHand, 1, 1);
} }
}
VAbstractSpline::hoverEnterEvent(event); VAbstractSpline::hoverEnterEvent(event);
} }
@ -446,10 +478,18 @@ void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
if (qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula()))
{ {
//Disable cursor-arrow-openhand //Disable cursor-arrow-openhand
RestoreOverrideCursor(cursorArrowOpenHand); RestoreOverrideCursor(cursorArrowOpenHand);
} }
}
VAbstractSpline::hoverLeaveEvent(event); VAbstractSpline::hoverLeaveEvent(event);
} }
@ -527,6 +567,8 @@ void VToolSpline::RefreshGeometry()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSpline::SetSplineAttributes(QDomElement &domElement, const VSpline &spl) void VToolSpline::SetSplineAttributes(QDomElement &domElement, const VSpline &spl)
{ {
SCASSERT(doc != nullptr);
if (domElement.attribute(AttrType) == OldToolType) if (domElement.attribute(AttrType) == OldToolType)
{ {
doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrType, ToolType);

View File

@ -52,6 +52,12 @@ void TST_QmuTokenParser::IsSingle_data()
QTest::newRow("Empty string") << "" << false; QTest::newRow("Empty string") << "" << false;
QTest::newRow("Several spaces") << " " << false; QTest::newRow("Several spaces") << " " << false;
QTest::newRow("Invalid formula") << "2*)))" << false; QTest::newRow("Invalid formula") << "2*)))" << false;
QTest::newRow("Incorrect thousand separator 15 500") << "15 500" << false;
QTest::newRow("Correct C locale 15500") << "15500" << true;
QTest::newRow("Correct C locale 15,500") << "15,500" << true;
QTest::newRow("Correct C locale 15,500.1") << "15,500.1" << true;
QTest::newRow("Not C locale 15,5") << "15,5" << false;
QTest::newRow("Not C locale 15.500,1") << "15.500,1" << false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------