Show option Show label.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-09-16 17:25:14 +03:00
parent 2864be7342
commit f6923a92f4
10 changed files with 57 additions and 25 deletions

View file

@ -214,6 +214,18 @@ void VPointF::setY(const qreal &value)
d->_y = value; d->_y = value;
} }
//---------------------------------------------------------------------------------------------------------------------
bool VPointF::IsShowLabel() const
{
return d->m_showLabel;
}
//---------------------------------------------------------------------------------------------------------------------
void VPointF::SetHideLabel(bool hide)
{
d->m_showLabel = hide;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees) QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees)
{ {

View file

@ -82,6 +82,9 @@ public:
qreal y() const; qreal y() const;
void setY(const qreal &value); void setY(const qreal &value);
bool IsShowLabel() const;
void SetHideLabel(bool hide);
static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees);
static QPointF FlipPF(const QLineF &axis, const QPointF &point); static QPointF FlipPF(const QLineF &axis, const QPointF &point);
static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle); static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle);

View file

@ -43,23 +43,23 @@ class VPointFData : public QSharedData
public: public:
VPointFData() VPointFData()
: _mx(0), _my(0), _x(0), _y(0) : _mx(0), _my(0), _x(0), _y(0), m_showLabel(true)
{} {}
VPointFData(const VPointFData &point) VPointFData(const VPointFData &point)
:QSharedData(point), _mx(point._mx), _my(point._my), _x(point._x), _y(point._y) :QSharedData(point), _mx(point._mx), _my(point._my), _x(point._x), _y(point._y), m_showLabel(point.m_showLabel)
{} {}
explicit VPointFData(const QPointF &point) explicit VPointFData(const QPointF &point)
:_mx(0), _my(0), _x(point.x()), _y(point.y()) :_mx(0), _my(0), _x(point.x()), _y(point.y()), m_showLabel(true)
{} {}
VPointFData(qreal x, qreal y, qreal mx, qreal my) VPointFData(qreal x, qreal y, qreal mx, qreal my)
:_mx(mx), _my(my), _x(x), _y(y) :_mx(mx), _my(my), _x(x), _y(y), m_showLabel(true)
{} {}
VPointFData(const QPointF &point, qreal mx, qreal my) VPointFData(const QPointF &point, qreal mx, qreal my)
:_mx(mx), _my(my), _x(point.x()), _y(point.y()) :_mx(mx), _my(my), _x(point.x()), _y(point.y()), m_showLabel(true)
{} {}
virtual ~VPointFData(); virtual ~VPointFData();
@ -76,6 +76,9 @@ public:
/** @brief _y y coordinate */ /** @brief _y y coordinate */
qreal _y; qreal _y;
/** @brief m_hideLabel show or not label for this point */
bool m_showLabel;
private: private:
VPointFData &operator=(const VPointFData &) Q_DECL_EQ_DELETE; VPointFData &operator=(const VPointFData &) Q_DECL_EQ_DELETE;
}; };

View file

@ -239,6 +239,11 @@ Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE);
template <typename T> template <typename T>
const QSharedPointer<T> VContainer::GeometricObject(const quint32 &id) const const QSharedPointer<T> VContainer::GeometricObject(const quint32 &id) const
{ {
if (id == NULL_ID)
{
throw VExceptionBadId(tr("Can't find object"), id);
}
QSharedPointer<VGObject> gObj = QSharedPointer<VGObject>(); QSharedPointer<VGObject> gObj = QSharedPointer<VGObject>();
if (d->gObjects.contains(id)) if (d->gObjects.contains(id))
{ {

View file

@ -474,9 +474,9 @@ void VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveTyp
curve->setParentItem(this); curve->setParentItem(this);
curve->SetType(curveType); curve->SetType(curveType);
connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected); connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected);
connect(curve, &VSimpleCurve::ShowContextMenu, this, [this](QGraphicsSceneContextMenuEvent * event) connect(curve, &VSimpleCurve::ShowContextMenu, this, [this](QGraphicsSceneContextMenuEvent * event, quint32 id)
{ {
contextMenuEvent(event); ShowContextMenu(event, id);
}); });
connect(curve, &VSimpleCurve::Choosed, this, [this, sceneType](quint32 id) connect(curve, &VSimpleCurve::Choosed, this, [this, sceneType](quint32 id)
{ {
@ -576,9 +576,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
}); });
connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected); connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected);
connect(point, &VSimplePoint::ShowContextMenu, connect(point, &VSimplePoint::ShowContextMenu,
this, [this](QGraphicsSceneContextMenuEvent * event) this, [this](QGraphicsSceneContextMenuEvent * event, quint32 id)
{ {
contextMenuEvent(event); ShowContextMenu(event, id);
}); });
connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel); connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel);
connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition); connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition);

View file

@ -67,7 +67,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin
firstPoint->setParentItem(this); firstPoint->setParentItem(this);
connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed); connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed);
connect(firstPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point1Selected); connect(firstPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point1Selected);
connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::ShowContextMenu);
connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel);
connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition); connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition);
firstPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p1id)); firstPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p1id));
@ -76,7 +76,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin
secondPoint->setParentItem(this); secondPoint->setParentItem(this);
connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed); connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed);
connect(secondPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point2Selected); connect(secondPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point2Selected);
connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::ShowContextMenu);
connect(secondPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(secondPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel);
connect(secondPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition); connect(secondPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition);
secondPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p2id)); secondPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p2id));

View file

@ -49,6 +49,7 @@
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include "../vwidgets/vmaingraphicsview.h" #include "../vwidgets/vmaingraphicsview.h"
#include "../vdatatool.h" #include "../vdatatool.h"
#include "../vgeometry/vpointf.h"
template <class T> class QSharedPointer; template <class T> class QSharedPointer;
@ -133,7 +134,6 @@ template <typename Dialog>
void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemId, const RemoveOption &showRemove, void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemId, const RemoveOption &showRemove,
const Referens &ref) const Referens &ref)
{ {
Q_UNUSED(itemId)
SCASSERT(event != nullptr) SCASSERT(event != nullptr)
if (m_suppressContextMenu) if (m_suppressContextMenu)
@ -144,6 +144,20 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
qCDebug(vTool, "Creating tool context menu."); qCDebug(vTool, "Creating tool context menu.");
QMenu menu; QMenu menu;
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
QAction *actionShowLabel = menu.addAction(tr("Show label"));
actionShowLabel->setCheckable(true);
try
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(itemId);
actionShowLabel->setChecked(point->IsShowLabel());
}
catch(const VExceptionBadId &)
{
actionShowLabel->setVisible(false);
}
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
if (showRemove == RemoveOption::Enable) if (showRemove == RemoveOption::Enable)
{ {
@ -187,12 +201,16 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
m_dialog->show(); m_dialog->show();
} }
if (selectedAction == actionRemove) else if (selectedAction == actionRemove)
{ {
qCDebug(vTool, "Deleting tool."); qCDebug(vTool, "Deleting tool.");
DeleteTool(); // do not catch exception here DeleteTool(); // do not catch exception here
return; //Leave this method immediately after call!!! return; //Leave this method immediately after call!!!
} }
else if (selectedAction == actionShowLabel)
{
// do something here to show/hide a label
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -43,12 +43,6 @@ void VAbstractSimple::ToolSelectionType(const SelectionType &type)
selectionType = type; selectionType = type;
} }
//---------------------------------------------------------------------------------------------------------------------
void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event)
{
emit ShowContextMenu(event);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
GOType VAbstractSimple::GetType() const GOType VAbstractSimple::GetType() const
{ {

View file

@ -56,12 +56,9 @@ public:
void SetType(const GOType &value); void SetType(const GOType &value);
signals: signals:
void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); void ShowContextMenu(QGraphicsSceneContextMenuEvent * event, quint32 id = NULL_ID);
void Delete(); void Delete();
public slots:
void ContextMenu(QGraphicsSceneContextMenuEvent * event);
protected: protected:
/** @brief id spline id. */ /** @brief id spline id. */
quint32 id; quint32 id;

View file

@ -55,7 +55,7 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor &currentColor, QObject *pare
m_alwaysHovered(false) m_alwaysHovered(false)
{ {
m_baseColor = currentColor; m_baseColor = currentColor;
connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::contextMenuEvent);
connect(m_namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel); connect(m_namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel);
connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed); connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed);
connect(m_namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected); connect(m_namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected);
@ -234,5 +234,5 @@ QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, cons
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VSimplePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
emit ShowContextMenu(event); emit ShowContextMenu(event, id);
} }