Fix wrong disabling VSimplePoint and VSimpleCurve after changing a pattern

piece.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-09-24 14:41:05 +03:00
parent 378ec5f4b7
commit 1ed9983ee7
6 changed files with 34 additions and 73 deletions

View File

@ -28,6 +28,8 @@
#include "vabstractsimple.h" #include "vabstractsimple.h"
const qreal VAbstractSimple::m_defFactor = 1;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractSimple::VAbstractSimple(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor, VAbstractSimple::VAbstractSimple(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor,
QObject *parent) QObject *parent)
@ -39,7 +41,12 @@ VAbstractSimple::VAbstractSimple(quint32 id, const QColor &currentColor, Unit pa
patternUnit(patternUnit), patternUnit(patternUnit),
selectionType(SelectionType::ByMouseRelease), selectionType(SelectionType::ByMouseRelease),
type(GOType::Unknown) type(GOType::Unknown)
{} {
if (this->factor == nullptr)
{
this->factor = const_cast<qreal *>(&m_defFactor);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractSimple::~VAbstractSimple() VAbstractSimple::~VAbstractSimple()
@ -71,6 +78,12 @@ QColor VAbstractSimple::GetCurrentColor() const
return currentColor; return currentColor;
} }
//---------------------------------------------------------------------------------------------------------------------
void VAbstractSimple::SetEnabled(bool enabled)
{
this->enabled = enabled;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event) void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event)
{ {

View File

@ -49,14 +49,14 @@ class VAbstractSimple : public QObject
Q_OBJECT Q_OBJECT
public: public:
VAbstractSimple(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor = nullptr, VAbstractSimple(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor = nullptr,
QObject *parent = 0); QObject *parent = nullptr);
virtual ~VAbstractSimple(); virtual ~VAbstractSimple();
virtual void ToolSelectionType(const SelectionType &type); virtual void ToolSelectionType(const SelectionType &type);
QColor GetCurrentColor() const; QColor GetCurrentColor() const;
virtual void SetEnabled(bool enabled) { Q_UNUSED(enabled); } virtual void SetEnabled(bool enabled);
GOType GetType() const; GOType GetType() const;
void SetType(const GOType &value); void SetType(const GOType &value);
@ -91,45 +91,18 @@ protected:
template <class T> template <class T>
void SetPen(T *item, const QColor &color, qreal width); void SetPen(T *item, const QColor &color, qreal width);
template <class T>
void SimpleChangedActivDraw(T *item, const bool &flag);
template <class T>
void SetSimpleCurrentColor(T *item, const QColor &value);
private: private:
Q_DISABLE_COPY(VAbstractSimple) Q_DISABLE_COPY(VAbstractSimple)
const static qreal m_defFactor;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <class T> template <class T>
void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width) void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width)
{ {
if (factor == nullptr) SCASSERT(item);
{
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)); item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor, Qt::SolidLine, Qt::RoundCap));
} }
}
//---------------------------------------------------------------------------------------------------------------------
template <class T>
void VAbstractSimple::SimpleChangedActivDraw(T *item, const bool &flag)
{
enabled = flag;
item->setEnabled(enabled);
SetPen(item, currentColor, WidthHairLine(patternUnit));
}
//---------------------------------------------------------------------------------------------------------------------
template <class T>
void VAbstractSimple::SetSimpleCurrentColor(T *item, const QColor &value)
{
currentColor = value;
SetPen(item, CorrectColor(currentColor), item->pen().widthF());
}
#endif // VABSTRACTSIMPLE_H #endif // VABSTRACTSIMPLE_H

View File

@ -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<VAbstractCurve> &curve) void VSimpleCurve::RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve)
{ {
@ -85,6 +73,13 @@ void VSimpleCurve::RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve)
ShowPath(); ShowPath();
} }
//---------------------------------------------------------------------------------------------------------------------
void VSimpleCurve::SetEnabled(bool enabled)
{
VAbstractSimple::SetEnabled(enabled);
SetPen(this, currentColor, WidthHairLine(patternUnit));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VSimpleCurve::CurveChoosed() void VSimpleCurve::CurveChoosed()
{ {

View File

@ -61,10 +61,9 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::SimpleCurve)}; enum { Type = UserType + static_cast<int>(Vis::SimpleCurve)};
void SetCurrentColor(const QColor &value);
void ChangedActivDraw(bool flag);
void RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve); void RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve);
virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE;
signals: signals:
/** /**
* @brief Choosed send id when clicked. * @brief Choosed send id when clicked.

View File

@ -73,18 +73,6 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor &currentColor, Unit patternU
VSimplePoint::~VSimplePoint() VSimplePoint::~VSimplePoint()
{} {}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::SetCurrentColor(const QColor &value)
{
SetSimpleCurrentColor(this, value);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::ChangedActivDraw(bool flag)
{
SimpleChangedActivDraw(this, flag);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::RefreshLine() void VSimplePoint::RefreshLine()
{ {
@ -97,7 +85,7 @@ void VSimplePoint::RefreshLine()
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2);
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos())); 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)) 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); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
namePoint->blockSignals(true); namePoint->blockSignals(true);
QFont font = namePoint->font(); QFont font = namePoint->font();
if (factor == nullptr)
{
font.setPointSize(static_cast<qint32>(namePoint->FontSize()));
}
else
{
font.setPointSize(static_cast<qint32>(namePoint->FontSize()/ *factor)); font.setPointSize(static_cast<qint32>(namePoint->FontSize()/ *factor));
}
namePoint->setFont(font); namePoint->setFont(font);
namePoint->setText(point.name()); namePoint->setText(point.name());
namePoint->setPos(QPointF(point.mx(), point.my())); namePoint->setPos(QPointF(point.mx(), point.my()));
@ -145,6 +126,9 @@ void VSimplePoint::RefreshGeometry(const VPointF &point)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::SetEnabled(bool enabled) void VSimplePoint::SetEnabled(bool enabled)
{ {
VAbstractSimple::SetEnabled(enabled);
SetPen(this, currentColor, WidthHairLine(patternUnit));
SetPen(lineName, Qt::black, WidthHairLine(patternUnit));
namePoint->setEnabled(enabled); namePoint->setEnabled(enabled);
} }

View File

@ -62,7 +62,6 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::SimplePoint)}; enum { Type = UserType + static_cast<int>(Vis::SimplePoint)};
void ChangedActivDraw(bool flag);
void RefreshLine(); void RefreshLine();
void RefreshGeometry(const VPointF &point); void RefreshGeometry(const VPointF &point);
virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE;
@ -70,8 +69,6 @@ public:
void AllowLabelHover(bool enabled); void AllowLabelHover(bool enabled);
void AllowLabelSelecting(bool enabled); void AllowLabelSelecting(bool enabled);
virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE;
void SetCurrentColor(const QColor &value);
signals: signals:
/** /**
* @brief Choosed send id when clicked. * @brief Choosed send id when clicked.