From 1ed9983ee7f9336bc4031bf9d3702ace313843ba Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 24 Sep 2016 14:41:05 +0300 Subject: [PATCH] Fix wrong disabling VSimplePoint and VSimpleCurve after changing a pattern piece. --HG-- branch : develop --- src/libs/vwidgets/vabstractsimple.cpp | 15 ++++++++++- src/libs/vwidgets/vabstractsimple.h | 39 +++++---------------------- src/libs/vwidgets/vsimplecurve.cpp | 19 +++++-------- src/libs/vwidgets/vsimplecurve.h | 5 ++-- src/libs/vwidgets/vsimplepoint.cpp | 26 ++++-------------- src/libs/vwidgets/vsimplepoint.h | 3 --- 6 files changed, 34 insertions(+), 73 deletions(-) diff --git a/src/libs/vwidgets/vabstractsimple.cpp b/src/libs/vwidgets/vabstractsimple.cpp index ddf042afa..47796cf74 100644 --- a/src/libs/vwidgets/vabstractsimple.cpp +++ b/src/libs/vwidgets/vabstractsimple.cpp @@ -28,6 +28,8 @@ #include "vabstractsimple.h" +const qreal VAbstractSimple::m_defFactor = 1; + //--------------------------------------------------------------------------------------------------------------------- VAbstractSimple::VAbstractSimple(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) @@ -39,7 +41,12 @@ VAbstractSimple::VAbstractSimple(quint32 id, const QColor ¤tColor, Unit pa patternUnit(patternUnit), selectionType(SelectionType::ByMouseRelease), type(GOType::Unknown) -{} +{ + if (this->factor == nullptr) + { + this->factor = const_cast(&m_defFactor); + } +} //--------------------------------------------------------------------------------------------------------------------- VAbstractSimple::~VAbstractSimple() @@ -71,6 +78,12 @@ QColor VAbstractSimple::GetCurrentColor() const return currentColor; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::SetEnabled(bool enabled) +{ + this->enabled = enabled; +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event) { diff --git a/src/libs/vwidgets/vabstractsimple.h b/src/libs/vwidgets/vabstractsimple.h index 0caf5e974..8181168b6 100644 --- a/src/libs/vwidgets/vabstractsimple.h +++ b/src/libs/vwidgets/vabstractsimple.h @@ -49,14 +49,14 @@ class VAbstractSimple : public QObject Q_OBJECT public: VAbstractSimple(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor = nullptr, - QObject *parent = 0); + QObject *parent = nullptr); virtual ~VAbstractSimple(); virtual void ToolSelectionType(const SelectionType &type); QColor GetCurrentColor() const; - virtual void SetEnabled(bool enabled) { Q_UNUSED(enabled); } + virtual void SetEnabled(bool enabled); GOType GetType() const; void SetType(const GOType &value); @@ -91,45 +91,18 @@ protected: template void SetPen(T *item, const QColor &color, qreal width); - template - void SimpleChangedActivDraw(T *item, const bool &flag); - - template - void SetSimpleCurrentColor(T *item, const QColor &value); - private: Q_DISABLE_COPY(VAbstractSimple) + + const static qreal m_defFactor; }; //--------------------------------------------------------------------------------------------------------------------- template void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width) { - if (factor == nullptr) - { - item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit), Qt::SolidLine, Qt::RoundCap)); - } - else - { - item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor, Qt::SolidLine, Qt::RoundCap)); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VAbstractSimple::SimpleChangedActivDraw(T *item, const bool &flag) -{ - enabled = flag; - item->setEnabled(enabled); - SetPen(item, currentColor, WidthHairLine(patternUnit)); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VAbstractSimple::SetSimpleCurrentColor(T *item, const QColor &value) -{ - currentColor = value; - SetPen(item, CorrectColor(currentColor), item->pen().widthF()); + SCASSERT(item); + item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor, Qt::SolidLine, Qt::RoundCap)); } #endif // VABSTRACTSIMPLE_H diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index 08bf5cebb..79dd55d9d 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -66,18 +66,6 @@ VSimpleCurve::~VSimpleCurve() { } -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::SetCurrentColor(const QColor &value) -{ - SetSimpleCurrentColor(this, value); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::ChangedActivDraw(bool flag) -{ - SimpleChangedActivDraw(this, flag); -} - //--------------------------------------------------------------------------------------------------------------------- void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) { @@ -85,6 +73,13 @@ void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) ShowPath(); } +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::SetEnabled(bool enabled) +{ + VAbstractSimple::SetEnabled(enabled); + SetPen(this, currentColor, WidthHairLine(patternUnit)); +} + //--------------------------------------------------------------------------------------------------------------------- void VSimpleCurve::CurveChoosed() { diff --git a/src/libs/vwidgets/vsimplecurve.h b/src/libs/vwidgets/vsimplecurve.h index 4c5744283..d0847ed16 100644 --- a/src/libs/vwidgets/vsimplecurve.h +++ b/src/libs/vwidgets/vsimplecurve.h @@ -61,10 +61,9 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimpleCurve)}; - void SetCurrentColor(const QColor &value); - - void ChangedActivDraw(bool flag); void RefreshGeometry(const QSharedPointer &curve); + + virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; signals: /** * @brief Choosed send id when clicked. diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 239dd4bee..676dbcf48 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -73,18 +73,6 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternU VSimplePoint::~VSimplePoint() {} -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::SetCurrentColor(const QColor &value) -{ - SetSimpleCurrentColor(this, value); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::ChangedActivDraw(bool flag) -{ - SimpleChangedActivDraw(this, flag); -} - //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::RefreshLine() { @@ -97,7 +85,7 @@ void VSimplePoint::RefreshLine() VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - SetPen(lineName, QColor(Qt::black), WidthHairLine(patternUnit)); + SetPen(lineName, Qt::black, WidthHairLine(patternUnit)); if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm)) { @@ -126,14 +114,7 @@ void VSimplePoint::RefreshGeometry(const VPointF &point) this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); namePoint->blockSignals(true); QFont font = namePoint->font(); - if (factor == nullptr) - { - font.setPointSize(static_cast(namePoint->FontSize())); - } - else - { - font.setPointSize(static_cast(namePoint->FontSize()/ *factor)); - } + font.setPointSize(static_cast(namePoint->FontSize()/ *factor)); namePoint->setFont(font); namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); @@ -145,6 +126,9 @@ void VSimplePoint::RefreshGeometry(const VPointF &point) //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::SetEnabled(bool enabled) { + VAbstractSimple::SetEnabled(enabled); + SetPen(this, currentColor, WidthHairLine(patternUnit)); + SetPen(lineName, Qt::black, WidthHairLine(patternUnit)); namePoint->setEnabled(enabled); } diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index b2d4649d4..009f914e0 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -62,7 +62,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimplePoint)}; - void ChangedActivDraw(bool flag); void RefreshLine(); void RefreshGeometry(const VPointF &point); virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; @@ -70,8 +69,6 @@ public: void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; - - void SetCurrentColor(const QColor &value); signals: /** * @brief Choosed send id when clicked.