Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-17 18:50:33 +03:00
parent a33ab27909
commit b72f5511b4
9 changed files with 25 additions and 47 deletions

View File

@ -41,7 +41,7 @@ class QString;
#define DefPointRadius 2.0//mm
#define NULL_ID 0//use this value for initialization variables that keeps id values. 0 mean uknown id value.
enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail };
enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown };
enum class Tool : char
{
ArrowTool,

View File

@ -33,7 +33,8 @@ const QString VAbstractSpline::TagName = QStringLiteral("spline");
//---------------------------------------------------------------------------------------------------------------------
VAbstractSpline::VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent)
:VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector<VControlPointSpline *>())
:VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector<VControlPointSpline *>()),
sceneType(SceneObject::Unknown)
{
ignoreFullUpdate = true;
}
@ -183,6 +184,20 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event)
QGraphicsItem::keyReleaseEvent ( event );
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @param event mouse release event.
*/
void VAbstractSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit ChoosedTool(id, sceneType);
}
QGraphicsItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VAbstractSpline::ToolPath(PathDirection direction) const
{

View File

@ -63,6 +63,7 @@ protected:
* @brief controlPoints list pointers of control points.
*/
QVector<VControlPointSpline *> controlPoints;
SceneObject sceneType;
/**
* @brief RefreshGeometry refresh item on scene.
*/
@ -74,6 +75,7 @@ protected:
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void keyReleaseEvent(QKeyEvent * event);
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const;
};

View File

@ -47,6 +47,8 @@ const QString VToolArc::ToolType = QStringLiteral("simple");
VToolArc::VToolArc(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{
sceneType = SceneObject::Arc;
this->setPath(ToolPath());
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -217,20 +219,6 @@ void VToolArc::RefreshDataInFile()
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @param event mouse release event.
*/
void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit ChoosedTool(id, SceneObject::Arc);
}
QGraphicsItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement value of reference.

View File

@ -52,7 +52,6 @@ protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
virtual void RefreshDataInFile();
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void RemoveReferens();
virtual void SaveDialog(QDomElement &domElement);
private:

View File

@ -46,6 +46,8 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Sour
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{
sceneType = SceneObject::Spline;
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
@ -255,20 +257,6 @@ void VToolSpline::RefreshDataInFile()
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @param event context menu event.
*/
void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit ChoosedTool(id, SceneObject::Spline);
}
QGraphicsItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement value of reference.

View File

@ -55,7 +55,6 @@ protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile ();
virtual void RefreshDataInFile();
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void RemoveReferens();
virtual void SaveDialog(QDomElement &domElement);
private:

View File

@ -45,6 +45,8 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{
sceneType = SceneObject::SplinePath;
this->setPath(ToolPath());
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -321,20 +323,6 @@ void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &
domElement.appendChild(pathPoint);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @param event mouse release event.
*/
void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit ChoosedTool(id, SceneObject::SplinePath);
}
QGraphicsItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement value of reference.

View File

@ -69,7 +69,6 @@ protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
virtual void RefreshDataInFile();
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void RemoveReferens();
virtual void SaveDialog(QDomElement &domElement);
private: