Refactoring dialog history. Method Record().

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-11 18:47:05 +03:00
parent 7ae44c600a
commit c7c7f88977
2 changed files with 88 additions and 109 deletions

View File

@ -203,8 +203,8 @@ void DialogHistory::FillTable()
*/ */
QString DialogHistory::Record(const VToolRecord &tool) QString DialogHistory::Record(const VToolRecord &tool)
{ {
const QDomElement domElement = doc->elementById(QString().setNum(tool.getId())); const QDomElement domElem = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement() == false) if (domElem.isElement() == false)
{ {
qDebug()<<"Can't find element by id"<<Q_FUNC_INFO; qDebug()<<"Can't find element by id"<<Q_FUNC_INFO;
return QString(tr("Can't create record.")); return QString(tr("Can't create record."));
@ -218,88 +218,66 @@ QString DialogHistory::Record(const VToolRecord &tool)
break; break;
case Tool::SinglePointTool: case Tool::SinglePointTool:
{ {
const QString name = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - Base point")).arg(PointName(tool.getId()));
return QString(tr("%1 - Base point")).arg(name);
} }
case Tool::EndLineTool: case Tool::EndLineTool:
{ {
const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); return QString(tr("%1_%2 - Line from point %1 to point %2"))
const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint)))
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); .arg(PointName(tool.getId()));
return QString(tr("%1_%2 - Line from point %1 to point %2")).arg(basePointIdName, toolIdName);
} }
case Tool::LineTool: case Tool::LineTool:
{ {
const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); return QString(tr("%1_%2 - Line from point %1 to point %2"))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)));
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
return QString(tr("%1_%2 - Line from point %1 to point %2")).arg(firstPointIdName, secondPointIdName);
} }
case Tool::AlongLineTool: case Tool::AlongLineTool:
{ {
const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); return QString(tr("%3 - Point along line %1_%2"))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)))
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); .arg(PointName(tool.getId()));
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
return QString(tr("%3 - Point along line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName);
} }
case Tool::ShoulderPointTool: case Tool::ShoulderPointTool:
{ {
const QString name = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - Point of shoulder")).arg(PointName(tool.getId()));
return QString(tr("%1 - Point of shoulder")).arg(name);
} }
case Tool::NormalTool: case Tool::NormalTool:
{ {
const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); return QString(tr("%3 - normal to line %1_%2"))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)))
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); .arg(PointName(tool.getId()));
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
return QString(tr("%3 - normal to line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName);
} }
case Tool::BisectorTool: case Tool::BisectorTool:
{ {
const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); return QString(tr("%4 - bisector of angle %1_%2_%3"))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const quint32 thirdPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrThirdPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)))
const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrThirdPoint)))
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); .arg(PointName(tool.getId()));
const QString thirdPointIdName = data->GeometricObject<const VPointF *>(thirdPointId)->name();
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
return QString(tr("%4 - bisector of angle %1_%2_%3")).arg(firstPointIdName, secondPointIdName,
thirdPointIdName, toolIdName);
} }
case Tool::LineIntersectTool: case Tool::LineIntersectTool:
{ {
const quint32 p1Line1 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line1, "0"); return QString(tr("%5 - intersection of lines %1_%2 and %3_%4"))
const quint32 p2Line1 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line1, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line1)))
const quint32 p1Line2 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line2, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line1)))
const quint32 p2Line2 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line2, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line2)))
const QString p1Line1Name = data->GeometricObject<const VPointF *>(p1Line1)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line2)))
const QString p2Line1Name = data->GeometricObject<const VPointF *>(p2Line1)->name(); .arg(PointName(tool.getId()));
const QString p1Line2Name = data->GeometricObject<const VPointF *>(p1Line2)->name();
const QString p2Line2Name = data->GeometricObject<const VPointF *>(p2Line2)->name();
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
return QString(tr("%5 - intersection of lines %1_%2 and %3_%4")).arg(p1Line1Name, p2Line1Name,
p1Line2Name, p2Line2Name,
toolIdName);
} }
case Tool::SplineTool: case Tool::SplineTool:
{ {
const VSpline *spl = data->GeometricObject<const VSpline *>(tool.getId()); const VSpline *spl = data->GeometricObject<const VSpline *>(tool.getId());
SCASSERT(spl != nullptr); SCASSERT(spl != nullptr);
const QString splP1Name = data->GeometricObject<const VPointF *>(spl->GetP1().id())->name(); return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id()));
const QString splP4Name = data->GeometricObject<const VPointF *>(spl->GetP4().id())->name();
return QString(tr("Curve %1_%2")).arg(splP1Name, splP4Name);
} }
case Tool::ArcTool: case Tool::ArcTool:
{ {
const VArc *arc = data->GeometricObject<const VArc *>(tool.getId()); const VArc *arc = data->GeometricObject<const VArc *>(tool.getId());
SCASSERT(arc != nullptr); SCASSERT(arc != nullptr);
const QString arcCenterName = data->GeometricObject<const VPointF *>(arc->GetCenter().id())->name(); return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id()));
return QString(tr("Arc with center in point %1")).arg(arcCenterName);
} }
case Tool::SplinePathTool: case Tool::SplinePathTool:
{ {
@ -309,12 +287,11 @@ QString DialogHistory::Record(const VToolRecord &tool)
QString record; QString record;
if (points.size() != 0 ) if (points.size() != 0 )
{ {
const QString pName = data->GeometricObject<const VPointF *>(points.at(0).P().id())->name(); // We use only first and last point name in curve
record = QString(tr("Curve point %1")).arg(pName); record = QString(tr("Curve point %1")).arg(PointName(points.at(0).P().id()));
if (points.size() > 1) if (points.size() > 1)
{ {
const QString pName = data->GeometricObject<const VPointF *>(points.last().P().id())->name(); record.append(QString("_%1").arg(PointName(points.last().P().id())));
record.append(QString("_%1").arg(pName));
} }
} }
else else
@ -326,87 +303,67 @@ QString DialogHistory::Record(const VToolRecord &tool)
} }
case Tool::PointOfContact: case Tool::PointOfContact:
{ {
const quint32 center = doc->GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0"); return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3"))
const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrCenter)))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)))
const QString centerName = data->GeometricObject<const VPointF *>(center)->name(); .arg(PointName(tool.getId()));
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")).arg(
centerName, firstPointIdName, secondPointIdName, toolIdName);
} }
case Tool::Height: case Tool::Height:
{ {
const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); return QString(tr("Point of perpendicular from point %1 to line %2_%3"))
const quint32 p1LineId = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint)))
const quint32 p2LineId = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line)))
const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line)));
const QString p1LineIdName = data->GeometricObject<const VPointF *>(p1LineId)->name();
const QString p2LineIdName = data->GeometricObject<const VPointF *>(p2LineId)->name();
return QString(tr("Point of perpendicular from point %1 to line %2_%3")).arg(basePointIdName,
p1LineIdName,
p2LineIdName);
} }
case Tool::Triangle: case Tool::Triangle:
{ {
const quint32 axisP1Id = doc->GetParametrUInt(domElement, VAbstractTool::AttrAxisP1, "0"); return QString(tr("Triangle: axis %1_%2, points %3 and %4"))
const quint32 axisP2Id = doc->GetParametrUInt(domElement, VAbstractTool::AttrAxisP2, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrAxisP1)))
const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrAxisP2)))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const QString axisP1IdName = data->GeometricObject<const VPointF *>(axisP1Id)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)));
const QString axisP2IdName = data->GeometricObject<const VPointF *>(axisP2Id)->name();
const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name();
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
return QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg(axisP1IdName, axisP2IdName,
firstPointIdName, secondPointIdName);
} }
case Tool::PointOfIntersection: case Tool::PointOfIntersection:
{ {
const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); return QString(tr("%1 - point of intersection %2 and %3"))
const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); .arg(PointName(tool.getId()))
const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint)))
const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint)));
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
return QString(tr("%1 - point of intersection %2 and %3")).arg(toolIdName, firstPointIdName,
secondPointIdName);
} }
case Tool::CutArcTool: case Tool::CutArcTool:
{ {
const quint32 arcId = doc->GetParametrUInt(domElement, VToolCutArc::AttrArc, "0"); const VArc *arc = data->GeometricObject<const VArc *>(AttrUInt(domElem, VToolCutArc::AttrArc));
const VArc *arc = data->GeometricObject<const VArc *>(arcId);
SCASSERT(arc != nullptr); SCASSERT(arc != nullptr);
const QString arcCenterName = data->GeometricObject<const VArc *>(arc->GetCenter().id())->name(); return QString(tr("%1 - cut arc with center %2"))
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); .arg(PointName(tool.getId()))
return QString(tr("%1 - cut arc with center %2")).arg(toolIdName, arcCenterName); .arg(PointName(arc->GetCenter().id()));
} }
case Tool::CutSplineTool: case Tool::CutSplineTool:
{ {
const quint32 splineId = doc->GetParametrUInt(domElement, VToolCutSpline::AttrSpline, "0"); const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline);
const VSpline *spl = data->GeometricObject<const VSpline *>(splineId); const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
SCASSERT(spl != nullptr); SCASSERT(spl != nullptr);
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - cut curve %2_%3"))
const QString splP1Name = data->GeometricObject<const VPointF *>(spl->GetP1().id())->name(); .arg(PointName(tool.getId()))
const QString splP4Name = data->GeometricObject<const VPointF *>(spl->GetP4().id())->name(); .arg(PointName(spl->GetP1().id()))
return QString(tr("%1 - cut curve %2_%3")).arg(toolIdName, splP1Name, splP4Name); .arg(PointName(spl->GetP4().id()));
} }
case Tool::CutSplinePathTool: case Tool::CutSplinePathTool:
{ {
const quint32 splinePathId = doc->GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, "0"); const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath);
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId); const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
SCASSERT(splPath != nullptr); SCASSERT(splPath != nullptr);
const QVector<VSplinePoint> points = splPath->GetSplinePath(); const QVector<VSplinePoint> points = splPath->GetSplinePath();
QString record; QString record;
if (points.size() != 0 ) if (points.size() != 0 )
{ {
const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); record = QString(tr("%1 - cut curve path %2"))
const QString pName = data->GeometricObject<const VPointF *>(points.at(0).P().id())->name(); .arg(PointName(tool.getId()))
record = QString(tr("%1 - cut curve path %2")).arg(toolIdName, pName); .arg(PointName(points.at(0).P().id()));
if (points.size() > 1) if (points.size() > 1)
{ {
const QString pName = data->GeometricObject<const VPointF *>(points.last().P().id())->name(); record.append(QString("_%1").arg(PointName(points.last().P().id())));
const QString name = QString("_%1").arg(pName);
record.append(name);
} }
} }
else else
@ -432,6 +389,7 @@ QString DialogHistory::Record(const VToolRecord &tool)
break; break;
default: default:
qDebug()<<"Got wrong tool type. Ignore."; qDebug()<<"Got wrong tool type. Ignore.";
return QString(tr("Can't create record."));
break; break;
} }
} }
@ -472,6 +430,25 @@ void DialogHistory::ShowPoint()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogHistory::PointName return point name by id.
*
* Refacoring what hide ugly string getting point name by id.
* @param pointId point if in data.
* @return point name.
*/
QString DialogHistory::PointName(quint32 pointId)
{
return data->GeometricObject<const VPointF *>(pointId)->name();
}
//---------------------------------------------------------------------------------------------------------------------
quint32 DialogHistory::AttrUInt(const QDomElement &domElement, const QString &name)
{
return doc->GetParametrUInt(domElement, name, "0");
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief closeEvent handle when windows is closing * @brief closeEvent handle when windows is closing

View File

@ -86,6 +86,8 @@ private:
QString Record(const VToolRecord &tool); QString Record(const VToolRecord &tool);
void InitialTable(); void InitialTable();
void ShowPoint(); void ShowPoint();
QString PointName(quint32 pointId);
quint32 AttrUInt(const QDomElement &domElement, const QString &name);
}; };
#endif // DIALOGHISTORY_H #endif // DIALOGHISTORY_H