Refactoring tool classes.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-05-23 16:10:08 +03:00
parent 10133a7a13
commit 2034f94aa9
21 changed files with 115 additions and 402 deletions

View File

@ -90,6 +90,41 @@ protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const;
virtual void ReadToolAttributes(const QDomElement &domElement);
template <typename T>
void ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (detailsMode)
{
ShowHandles(detailsMode);
}
else
{
ShowHandles(show);
}
}
private:
Q_DISABLE_COPY(VAbstractSpline)
};

View File

@ -190,26 +190,7 @@ void VToolAlongLine::SetSecondPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolAlongLine::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolAlongLine>();
SetVisualization();
}
else
{
if (VisToolAlongLine * visual = qobject_cast<VisToolAlongLine *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolAlongLine>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -288,26 +288,7 @@ void VToolArc::SetFormulaF2(const VFormula &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolArc::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolArc>();
SetVisualization();
}
else
{
if (VisToolArc *visual = qobject_cast<VisToolArc *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolArc>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -359,26 +359,7 @@ void VToolBisector::SetThirdPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolBisector::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolBisector>();
SetVisualization();
}
else
{
if (VisToolBisector *visual = qobject_cast<VisToolBisector *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolBisector>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -222,26 +222,7 @@ void VToolCurveIntersectAxis::setCurveId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolCurveIntersectAxis::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolCurveIntersectAxis>();
SetVisualization();
}
else
{
if (VisToolCurveIntersectAxis *visual = qobject_cast<VisToolCurveIntersectAxis *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolCurveIntersectAxis>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -31,6 +31,7 @@
#include "vtoolpoint.h"
#include "../../visualization/vsimplecurve.h"
#include "vabstractspline.h"
class VFormula;
@ -76,6 +77,42 @@ protected:
void RefreshGeometry();
virtual void RemoveReferens();
void FullUpdateCurveFromFile(const QString &attrCurve);
template <typename T>
void ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{
if (detailsMode)
{
parentCurve->ShowHandles(detailsMode);
}
else
{
parentCurve->ShowHandles(show);
}
}
}
private:
Q_DISABLE_COPY(VToolCut)
};

View File

@ -187,26 +187,7 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS
//---------------------------------------------------------------------------------------------------------------------
void VToolCutArc::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolCutArc>();
SetVisualization();
}
else
{
if (VisToolCutArc *visual = qobject_cast<VisToolCutArc *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolCutArc>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -31,7 +31,6 @@
#include "../../dialogs/tools/dialogcutspline.h"
#include "../../libs/vgeometry/vpointf.h"
#include "../../visualization/vistoolcutspline.h"
#include "vabstractspline.h"
#include "../../libs/vgeometry/vspline.h"
const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline");
@ -197,37 +196,7 @@ VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointNa
//---------------------------------------------------------------------------------------------------------------------
void VToolCutSpline::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolCutSpline>();
SetVisualization();
}
else
{
if (VisToolCutSpline * visual = qobject_cast<VisToolCutSpline *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{
if (detailsMode)
{
parentCurve->ShowHandles(detailsMode);
}
else
{
parentCurve->ShowHandles(show);
}
}
ShowToolVisualization<VisToolCutSpline>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -31,7 +31,6 @@
#include "../../dialogs/tools/dialogcutsplinepath.h"
#include "../../libs/vgeometry/vpointf.h"
#include "../../visualization/vistoolcutsplinepath.h"
#include "vabstractspline.h"
#include "../../libs/vgeometry/vsplinepath.h"
const QString VToolCutSplinePath::ToolType = QStringLiteral("cutSplinePath");
@ -241,37 +240,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString
//---------------------------------------------------------------------------------------------------------------------
void VToolCutSplinePath::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolCutSplinePath>();
SetVisualization();
}
else
{
if (VisToolCutSplinePath *visual = qobject_cast<VisToolCutSplinePath *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{
if (detailsMode)
{
parentCurve->ShowHandles(detailsMode);
}
else
{
parentCurve->ShowHandles(show);
}
}
ShowToolVisualization<VisToolCutSplinePath>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -289,24 +289,5 @@ void VToolEndLine::SetFormulaAngle(const VFormula &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolEndLine::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolEndLine>();
SetVisualization();
}
else
{
if (VisToolEndLine *visual = qobject_cast<VisToolEndLine *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolEndLine>(show);
}

View File

@ -293,26 +293,7 @@ void VToolHeight::SetP2LineId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolHeight::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolHeight>();
SetVisualization();
}
else
{
if (VisToolHeight *visual = qobject_cast<VisToolHeight *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolHeight>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -311,26 +311,7 @@ void VToolLineIntersect::SetP2Line2(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolLineIntersect::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolLineIntersect>();
SetVisualization();
}
else
{
if (VisToolLineIntersect *visual = qobject_cast<VisToolLineIntersect *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolLineIntersect>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -234,26 +234,7 @@ void VToolLineIntersectAxis::SetSecondPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolLineIntersectAxis::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolLineIntersectAxis>();
SetVisualization();
}
else
{
if (VisToolLineIntersectAxis *visual = qobject_cast<VisToolLineIntersectAxis *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolLineIntersectAxis>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -326,24 +326,5 @@ void VToolNormal::SetSecondPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolNormal::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolNormal>();
SetVisualization();
}
else
{
if (VisToolNormal *visual = qobject_cast<VisToolNormal *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolNormal>(show);
}

View File

@ -79,6 +79,31 @@ protected:
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void keyReleaseEvent(QKeyEvent * event);
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
template <typename T>
void ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
}
private:
Q_DISABLE_COPY(VToolPoint)
};

View File

@ -357,26 +357,7 @@ void VToolPointOfContact::SetSecondPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfContact::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolPointOfContact>();
SetVisualization();
}
else
{
if (VisToolPointOfContact *visual = qobject_cast<VisToolPointOfContact *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolPointOfContact>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -262,26 +262,7 @@ void VToolPointOfIntersection::SetSecondPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfIntersection::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolPointOfIntersection>();
SetVisualization();
}
else
{
if (VisToolPointOfIntersection *visual = qobject_cast<VisToolPointOfIntersection *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolPointOfIntersection>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -355,26 +355,7 @@ void VToolShoulderPoint::setPShoulder(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolShoulderPoint::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolShoulderPoint>();
SetVisualization();
}
else
{
if (VisToolShoulderPoint *visual = qobject_cast<VisToolShoulderPoint *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolShoulderPoint>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -232,35 +232,7 @@ void VToolSpline::setSpline(const VSpline &spl)
//---------------------------------------------------------------------------------------------------------------------
void VToolSpline::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolSpline>();
SetVisualization();
}
else
{
if (VisToolSpline *visual = qobject_cast<VisToolSpline *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (detailsMode)
{
ShowHandles(detailsMode);
}
else
{
ShowHandles(show);
}
ShowToolVisualization<VisToolSpline>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -313,35 +313,7 @@ void VToolSplinePath::setSplinePath(const VSplinePath &splPath)
//---------------------------------------------------------------------------------------------------------------------
void VToolSplinePath::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolSplinePath>();
SetVisualization();
}
else
{
if (VisToolSplinePath *visual = qobject_cast<VisToolSplinePath *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (detailsMode)
{
ShowHandles(detailsMode);
}
else
{
ShowHandles(show);
}
ShowToolVisualization<VisToolSplinePath>(show);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -327,26 +327,7 @@ void VToolTriangle::SetSecondPointId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VToolTriangle::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<VisToolTriangle>();
SetVisualization();
}
else
{
if (VisToolTriangle * visual = qobject_cast<VisToolTriangle *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
ShowToolVisualization<VisToolTriangle>(show);
}
//---------------------------------------------------------------------------------------------------------------------