refactoring of if()s in

VDomDocument::ParsePointElement
VDomDocument::ParseSplineElement
VDomDocument::ParseArcElement
VDomDocument::ParseToolsElement
to switch()

--HG--
branch : develop
This commit is contained in:
Sabine Schmaltz 2014-02-16 22:53:32 +01:00
parent c049379c1e
commit 7e5e38d072

View File

@ -723,9 +723,17 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
Q_CHECK_PTR(scene);
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty");
if (type == VToolSinglePoint::ToolType)
{
VToolSinglePoint *spoint = 0;
QStringList points;
points << VToolSinglePoint::ToolType << VToolEndLine::ToolType << VToolAlongLine::ToolType
<< VToolShoulderPoint::ToolType << VToolNormal::ToolType << VToolBisector::ToolType
<< VToolLineIntersect::ToolType << VToolPointOfContact::ToolType << VNodePoint::ToolType
<< VToolHeight::ToolType << VToolTriangle::ToolType << VToolPointOfIntersection::ToolType
<< VToolCutSpline::ToolType << VToolCutSplinePath::ToolType << VToolCutArc::ToolType;
switch(points.indexOf(type)) {
case 0: //VToolSinglePoint::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -760,9 +768,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
delete spoint;
throw excep;
}
}
if (type == VToolEndLine::ToolType)
{
break;
case 1: //VToolEndLine::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -784,9 +791,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolAlongLine::ToolType)
{
break;
case 2: //VToolAlongLine::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -808,9 +814,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolShoulderPoint::ToolType)
{
break;
case 3: //VToolShoulderPoint::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -833,9 +838,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolNormal::ToolType)
{
break;
case 4: //VToolNormal::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -858,9 +862,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolBisector::ToolType)
{
break;
case 5: //VToolBisector::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -883,9 +886,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolLineIntersect::ToolType)
{
break;
case 6: //VToolLineIntersect::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -907,9 +909,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolPointOfContact::ToolType)
{
break;
case 7: //VToolPointOfContact::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -931,9 +932,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VNodePoint::ToolType)
{
break;
case 8: //VNodePoint::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -953,9 +953,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolHeight::ToolType)
{
break;
case 9: //VToolHeight::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -977,9 +976,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolTriangle::ToolType)
{
break;
case 10: //VToolTriangle::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1001,9 +999,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolPointOfIntersection::ToolType)
{
break;
case 11: //VToolPointOfIntersection::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1023,9 +1020,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolCutSpline::ToolType)
{
break;
case 12: //VToolCutSpline::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1044,9 +1040,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolCutSplinePath::ToolType)
{
break;
case 13: //VToolCutSplinePath::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1066,9 +1061,8 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolCutArc::ToolType)
{
break;
case 14: //VToolCutArc::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1087,6 +1081,10 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
break;
default:
qWarning() << "Illegal point type in VDomDocument::ParsePointElement().";
break;
}
}
@ -1118,8 +1116,11 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
Q_CHECK_PTR(scene);
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
if (type == VToolSpline::ToolType)
{
QStringList splines;
splines << VToolSpline::ToolType << VToolSplinePath::ToolType << VNodeSpline::ToolType << VNodeSplinePath::ToolType;
switch(splines.indexOf(type)) {
case 0: //VToolSpline::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1131,8 +1132,7 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
qreal kAsm2 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm2, "1.0");
qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0");
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse,
Tool::FromFile);
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse,Tool::FromFile);
return;
}
catch (const VExceptionBadId &e)
@ -1141,9 +1141,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VToolSplinePath::ToolType)
{
break;
case 1: //VToolSplinePath::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1188,9 +1187,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VNodeSpline::ToolType)
{
break;
case 2: //VNodeSpline::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1210,9 +1208,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VNodeSplinePath::ToolType)
{
break;
case 3: //VNodeSplinePath::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1232,6 +1229,10 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
break;
default:
qWarning() << "Illegal spline type in VDomDocument::ParseSplineElement().";
break;
}
}
@ -1241,8 +1242,12 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
Q_CHECK_PTR(scene);
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
if (type == VToolArc::ToolType)
{
QStringList arcs;
arcs << VToolArc::ToolType << VNodeArc::ToolType;
switch(arcs.indexOf(type)) {
case 0: //VToolArc::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1261,9 +1266,8 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if (type == VNodeArc::ToolType)
{
break;
case 1: //VNodeArc::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1283,6 +1287,10 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
break;
default:
qWarning() << "Illegal arc type in VDomDocument::ParseArcElement().";
break;
}
}
@ -1292,8 +1300,12 @@ void VDomDocument::ParseToolsElement(VMainGraphicsScene *scene, const QDomElemen
Q_CHECK_PTR(scene);
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty");
if (type == VToolUnionDetails::ToolType)
{
QStringList tools;
tools << VToolUnionDetails::ToolType;
switch(tools.indexOf(type)) {
case 0: //VToolUnionDetails::ToolType
try
{
qint64 id = GetParametrId(domElement);
@ -1313,6 +1325,10 @@ void VDomDocument::ParseToolsElement(VMainGraphicsScene *scene, const QDomElemen
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
break;
default:
qWarning() << "Illegal tools type in VDomDocument::ParseToolsElement().";
break;
}
}