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;
}
//---------------------------------------------------------------------------------------------------------------------
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)
{

View File

@ -82,6 +82,9 @@ public:
qreal y() const;
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 FlipPF(const QLineF &axis, const QPointF &point);
static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle);

View File

@ -43,23 +43,23 @@ class VPointFData : public QSharedData
public:
VPointFData()
: _mx(0), _my(0), _x(0), _y(0)
: _mx(0), _my(0), _x(0), _y(0), m_showLabel(true)
{}
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)
:_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)
:_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)
:_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();
@ -76,6 +76,9 @@ public:
/** @brief _y y coordinate */
qreal _y;
/** @brief m_hideLabel show or not label for this point */
bool m_showLabel;
private:
VPointFData &operator=(const VPointFData &) Q_DECL_EQ_DELETE;
};

View File

@ -239,6 +239,11 @@ Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE);
template <typename T>
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>();
if (d->gObjects.contains(id))
{

View File

@ -474,9 +474,9 @@ void VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveTyp
curve->setParentItem(this);
curve->SetType(curveType);
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)
{
@ -576,9 +576,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
});
connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected);
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::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition);

View File

@ -67,7 +67,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin
firstPoint->setParentItem(this);
connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed);
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::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition);
firstPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p1id));
@ -76,7 +76,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin
secondPoint->setParentItem(this);
connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed);
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::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition);
secondPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p2id));

View File

@ -49,6 +49,7 @@
#include "../vwidgets/vmaingraphicsscene.h"
#include "../vwidgets/vmaingraphicsview.h"
#include "../vdatatool.h"
#include "../vgeometry/vpointf.h"
template <class T> class QSharedPointer;
@ -133,7 +134,6 @@ template <typename Dialog>
void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemId, const RemoveOption &showRemove,
const Referens &ref)
{
Q_UNUSED(itemId)
SCASSERT(event != nullptr)
if (m_suppressContextMenu)
@ -144,6 +144,20 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
qCDebug(vTool, "Creating tool context menu.");
QMenu menu;
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"));
if (showRemove == RemoveOption::Enable)
{
@ -187,12 +201,16 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI
m_dialog->show();
}
if (selectedAction == actionRemove)
else if (selectedAction == actionRemove)
{
qCDebug(vTool, "Deleting tool.");
DeleteTool(); // do not catch exception here
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;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event)
{
emit ShowContextMenu(event);
}
//---------------------------------------------------------------------------------------------------------------------
GOType VAbstractSimple::GetType() const
{

View File

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

View File

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