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