From b72f5511b4927d8bc4a750f0850c648a577e2b36 Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 17 Aug 2014 18:50:33 +0300 Subject: [PATCH] Refactoring. --HG-- branch : develop --- src/app/options.h | 2 +- src/app/tools/drawTools/vabstractspline.cpp | 17 ++++++++++++++++- src/app/tools/drawTools/vabstractspline.h | 2 ++ src/app/tools/drawTools/vtoolarc.cpp | 16 ++-------------- src/app/tools/drawTools/vtoolarc.h | 1 - src/app/tools/drawTools/vtoolspline.cpp | 16 ++-------------- src/app/tools/drawTools/vtoolspline.h | 1 - src/app/tools/drawTools/vtoolsplinepath.cpp | 16 ++-------------- src/app/tools/drawTools/vtoolsplinepath.h | 1 - 9 files changed, 25 insertions(+), 47 deletions(-) diff --git a/src/app/options.h b/src/app/options.h index acdad9153..66bc8eea0 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -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, diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index ba5baaa41..6d0424355 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -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()) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()), + 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 { diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index 6213420e7..bc3f643be 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -63,6 +63,7 @@ protected: * @brief controlPoints list pointers of control points. */ QVector 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; }; diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index c7c3afe89..b0a3b2180 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -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. diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 9ee5d727f..6e943e7d2 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -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: diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 42938f0e2..1488c72cb 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -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. diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index a75726a94..7d1490c66 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -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: diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 74c9b6a43..c771df84d 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -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. diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index 793bc70fe..c5e39955c 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -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: