Toggle piece node point label. ref #755.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-27 11:53:35 +03:00
parent 3df6c09934
commit 29b23bbce3
20 changed files with 1218 additions and 52 deletions

View File

@ -2110,7 +2110,7 @@ void MainWindow::CancelTool()
// https://bitbucket.org/dismine/valentina/issues/454/crash-using-crtl-z-while-using-line-tool
undoAction->setEnabled(false);
redoAction->setEnabled(false);
VInteractiveTool::m_suppressContextMenu = true;
VAbstractTool::m_suppressContextMenu = true;
return;
case Tool::BasePoint:
case Tool::SinglePoint:
@ -2282,7 +2282,7 @@ void MainWindow::ArrowTool()
currentTool = Tool::Arrow;
emit EnableItemMove(true);
emit ItemsSelection(SelectionType::ByMouseRelease);
VInteractiveTool::m_suppressContextMenu = false;
VAbstractTool::m_suppressContextMenu = false;
// Only true for rubber band selection
emit EnableLabelSelection(true);

View File

@ -1665,9 +1665,12 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par
Q_UNUSED(e)
return;// Just ignore
}
initData.data->UpdateGObject(initData.id,
new VPointF(static_cast<QPointF>(*point), point->name(), mx, my, initData.idObject,
QSharedPointer<VPointF> p(new VPointF(static_cast<QPointF>(*point), point->name(), mx, my, initData.idObject,
Draw::Modeling));
p->SetShowLabel(GetParametrBool(domElement, AttrShowLabel, trueStr));
initData.data->UpdateGObject(initData.id, p);
VNodePoint::Create(initData);
}
catch (const VExceptionBadId &e)

View File

@ -42,6 +42,7 @@
<file>schema/pattern/v0.6.5.xsd</file>
<file>schema/pattern/v0.6.6.xsd</file>
<file>schema/pattern/v0.7.0.xsd</file>
<file>schema/pattern/v0.7.1.xsd</file>
<file>schema/standard_measurements/v0.3.0.xsd</file>
<file>schema/standard_measurements/v0.4.0.xsd</file>
<file>schema/standard_measurements/v0.4.1.xsd</file>

File diff suppressed because it is too large Load Diff

View File

@ -58,8 +58,8 @@ class QDomElement;
*/
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.0");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.0.xsd");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.1");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.1.xsd");
//VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
@ -258,6 +258,8 @@ QString VPatternConverter::XSDSchema(int ver) const
case (0x000606):
return QStringLiteral("://schema/pattern/v0.6.6.xsd");
case (0x000700):
return QStringLiteral("://schema/pattern/v0.7.0.xsd");
case (0x000701):
return CurrentSchema;
default:
InvalidVersion(ver);
@ -434,6 +436,10 @@ void VPatternConverter::ApplyPatches()
ValidateXML(XSDSchema(0x000700), m_convertedFileName);
V_FALLTHROUGH
case (0x000700):
ToV0_7_1();
ValidateXML(XSDSchema(0x000701), m_convertedFileName);
V_FALLTHROUGH
case (0x000701):
break;
default:
InvalidVersion(m_ver);
@ -451,7 +457,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion()
bool VPatternConverter::IsReadOnly() const
{
// Check if attribute readOnly was not changed in file format
Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 0),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 1),
"Check attribute readOnly.");
// Possibly in future attribute readOnly will change position etc.
@ -925,6 +931,16 @@ void VPatternConverter::ToV0_7_0()
Save();
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::ToV0_7_1()
{
// TODO. Delete if minimal supported version is 0.7.1
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 1),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.7.1"));
Save();
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::TagUnitToV0_2_0()
{

View File

@ -53,7 +53,7 @@ public:
static const QString PatternMaxVerStr;
static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0);
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 0);
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 1);
protected:
virtual int MinVer() const Q_DECL_OVERRIDE;
@ -113,6 +113,7 @@ private:
void ToV0_6_5();
void ToV0_6_6();
void ToV0_7_0();
void ToV0_7_1();
void TagUnitToV0_2_0();
void TagIncrementToV0_2_0();

View File

@ -100,7 +100,7 @@ void VAbstractOperation::ChangeLabelPosition(quint32 id, const QPointF &pos)
point->setMy(pos.y());
item->RefreshPointGeometry(*(point.data()));
if (QGraphicsScene *sc = scene())
if (QGraphicsScene *sc = item->scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), item);
}
@ -136,6 +136,10 @@ void VAbstractOperation::SetLabelVisible(quint32 id, bool visible)
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
point->SetShowLabel(visible);
item->RefreshPointGeometry(*point);
if (QGraphicsScene *sc = item->scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), item);
}
}
}
}

View File

@ -147,12 +147,20 @@ void VToolDoublePoint::SetLabelVisible(quint32 id, bool visible)
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(p1id);
point->SetShowLabel(visible);
firstPoint->RefreshPointGeometry(*point);
if (QGraphicsScene *sc = firstPoint->scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), firstPoint);
}
}
else if (p2id == id)
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(p2id);
point->SetShowLabel(visible);
secondPoint->RefreshPointGeometry(*point);
if (QGraphicsScene *sc = secondPoint->scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), secondPoint);
}
}
}
@ -229,7 +237,7 @@ void VToolDoublePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
point->setMy(pos.y());
firstPoint->RefreshPointGeometry(*(point.data()));
if (QGraphicsScene *sc = scene())
if (QGraphicsScene *sc = firstPoint->scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), firstPoint);
}
@ -241,7 +249,7 @@ void VToolDoublePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
point->setMy(pos.y());
secondPoint->RefreshPointGeometry(*(point.data()));
if (QGraphicsScene *sc = scene())
if (QGraphicsScene *sc = secondPoint->scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), secondPoint);
}

View File

@ -137,6 +137,10 @@ void VToolSinglePoint::SetLabelVisible(quint32 id, bool visible)
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
point->SetShowLabel(visible);
RefreshPointGeometry(*point);
if (QGraphicsScene *sc = scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this);
}
}
}

View File

@ -262,10 +262,3 @@ bool VDrawTool::IsLabelVisible(quint32 id) const
Q_UNUSED(id)
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VDrawTool::SetLabelVisible(quint32 id, bool visible)
{
Q_UNUSED(id)
Q_UNUSED(visible)
}

View File

@ -68,7 +68,6 @@ public:
virtual void SetTypeLine(const QString &value);
virtual bool IsLabelVisible(quint32 id) const;
virtual void SetLabelVisible(quint32 id, bool visible);
signals:
void ChangedToolSelection(bool selected, quint32 object, quint32 tool);

View File

@ -34,6 +34,8 @@
#include <QGraphicsLineItem>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QIcon>
#include <QMenu>
#include <QPen>
#include <QPoint>
#include <QRectF>
@ -56,6 +58,8 @@
#include "../vdatatool.h"
#include "vabstractnode.h"
#include "../../undocommands/label/movelabel.h"
#include "../../undocommands/label/showlabel.h"
#include "../vtoolseamallowance.h"
const QString VNodePoint::ToolType = QStringLiteral("modeling");
@ -75,7 +79,7 @@ VNodePoint::VNodePoint(const VAbstractNodeInitData &initData, QObject *qoParent,
connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu,
this, [this](QGraphicsSceneContextMenuEvent *event)
{
emit ShowContextMenu(event);
contextMenuEvent(event);
});
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(initData.id));
ToolCreation(initData.typeCreation);
@ -147,6 +151,21 @@ void VNodePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::SetLabelVisible(quint32 id, bool visible)
{
if (m_id == id)
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
point->SetShowLabel(visible);
RefreshPointGeometry(*point);
if (QGraphicsScene *sc = scene())
{
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::PointChoosed()
{
@ -176,6 +195,7 @@ void VNodePoint::AddToFile()
doc->SetAttribute(domElement, AttrIdObject, idNode);
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute<bool>(domElement, AttrShowLabel, point->IsShowLabel());
if (idTool != NULL_ID)
{
doc->SetAttribute(domElement, AttrIdTool, idTool);
@ -241,7 +261,55 @@ void VNodePoint::HideNode()
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
emit ShowContextMenu(event);
if (m_suppressContextMenu)
{
return;
}
if (VToolSeamAllowance *piece = qgraphicsitem_cast<VToolSeamAllowance *>(parentItem()))
{
QMenu menu;
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
QAction *inLayoutOption = menu.addAction(tr("In layout"));
inLayoutOption->setCheckable(true);
const VPiece detail = VAbstractTool::data.GetPiece(piece->getId());
inLayoutOption->setChecked(detail.IsInLayout());
QAction *actionShowLabel = menu.addAction(tr("Show label"));
actionShowLabel->setCheckable(true);
actionShowLabel->setChecked(VAbstractTool::data.GeometricObject<VPointF>(m_id)->IsShowLabel());
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
piece->referens() > 1 ? actionRemove->setEnabled(false) : actionRemove->setEnabled(true);
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
{
emit ShowOptions();
}
else if (selectedAction == inLayoutOption)
{
emit ToggleInLayout(selectedAction->isChecked());
}
else if (selectedAction == actionRemove)
{
try
{
emit Delete();
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
//Leave this method immediately after call!!!
}
else if (selectedAction == actionShowLabel)
{
qApp->getUndoStack()->push(new ShowLabel(doc, m_id, selectedAction->isChecked()));
}
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -58,14 +58,11 @@ public:
virtual QString getTagName() const Q_DECL_OVERRIDE;
virtual void ChangeLabelPosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE;
virtual void SetLabelVisible(quint32 id, bool visible) Q_DECL_OVERRIDE;
signals:
/**
* @brief ShowContextMenu emit when need show tool context menu.
* @param event context menu event.
*/
void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
void ShowOptions();
void ToggleInLayout(bool checked);
void Delete();
public slots:
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
void NameChangePosition(const QPointF &pos);

View File

@ -81,6 +81,7 @@
template <class T> class QSharedPointer;
bool VAbstractTool::m_suppressContextMenu = false;
const QString VAbstractTool::AttrInUse = QStringLiteral("inUse");
//---------------------------------------------------------------------------------------------------------------------
@ -375,6 +376,13 @@ void VAbstractTool::ChangeLabelPosition(quint32 id, const QPointF &pos)
Q_UNUSED(pos)
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractTool::SetLabelVisible(quint32 id, bool visible)
{
Q_UNUSED(id)
Q_UNUSED(visible)
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractTool::ToolSelectionType(const SelectionType &type)
{

View File

@ -89,6 +89,7 @@ public:
virtual ~VAbstractTool() Q_DECL_OVERRIDE;
quint32 getId() const;
static bool m_suppressContextMenu;
static const QString AttrInUse;
static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data);
@ -109,7 +110,7 @@ public:
virtual QString getTagName() const =0;
virtual void ShowVisualization(bool show) =0;
virtual void ChangeLabelPosition(quint32 id, const QPointF &pos);
virtual void SetLabelVisible(quint32 id, bool visible);
public slots:
/**
* @brief FullUpdateFromFile update tool data form file.

View File

@ -28,8 +28,6 @@
#include "vinteractivetool.h"
bool VInteractiveTool::m_suppressContextMenu = false;
//---------------------------------------------------------------------------------------------------------------------
VInteractiveTool::VInteractiveTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent)
: VAbstractTool(doc, data, id, parent),

View File

@ -43,8 +43,6 @@ public:
void DialogLinkDestroy();
static bool m_suppressContextMenu;
public slots:
virtual void FullUpdateFromGuiOk(int result);
virtual void FullUpdateFromGuiApply();

View File

@ -1159,28 +1159,17 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
{
QSharedPointer<DialogSeamAllowance> dialog =
QSharedPointer<DialogSeamAllowance>(new DialogSeamAllowance(getData(), m_id, qApp->getMainWindow()));
dialog->EnableApply(true);
m_dialog = dialog;
m_dialog->setModal(true);
connect(m_dialog.data(), &DialogTool::DialogClosed, this, &VToolSeamAllowance::FullUpdateFromGuiOk);
connect(m_dialog.data(), &DialogTool::DialogApplied, this, &VToolSeamAllowance::FullUpdateFromGuiApply);
SetDialog();
m_dialog->show();
ShowOptions();
}
else if (selectedAction == inLayoutOption)
{
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(m_id, selectedAction->isChecked(),
&(VAbstractTool::data), doc);
connect(togglePrint, &TogglePieceInLayout::UpdateList, doc, &VAbstractPattern::CheckInLayoutList);
qApp->getUndoStack()->push(togglePrint);
ToggleInLayout(selectedAction->isChecked());
}
else if (selectedAction == actionRemove)
{
try
{
DeleteToolWithConfirm();
DeleteFromMenu();
}
catch(const VExceptionToolWasDeleted &e)
{
@ -1381,6 +1370,34 @@ void VToolSeamAllowance::SaveDialogChange(const QString &undoText)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ShowOptions()
{
QSharedPointer<DialogSeamAllowance> dialog =
QSharedPointer<DialogSeamAllowance>(new DialogSeamAllowance(getData(), m_id, qApp->getMainWindow()));
dialog->EnableApply(true);
m_dialog = dialog;
m_dialog->setModal(true);
connect(m_dialog.data(), &DialogTool::DialogClosed, this, &VToolSeamAllowance::FullUpdateFromGuiOk);
connect(m_dialog.data(), &DialogTool::DialogApplied, this, &VToolSeamAllowance::FullUpdateFromGuiApply);
SetDialog();
m_dialog->show();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleInLayout(bool checked)
{
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(m_id, checked, &(VAbstractTool::data), doc);
connect(togglePrint, &TogglePieceInLayout::UpdateList, doc, &VAbstractPattern::CheckInLayoutList);
qApp->getUndoStack()->push(togglePrint);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::DeleteFromMenu()
{
DeleteToolWithConfirm();
}
//---------------------------------------------------------------------------------------------------------------------
VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &rotationAngle,
qreal &labelWidth, qreal &labelHeight, QPointF &pos)
@ -1596,8 +1613,11 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
if (tool->parent() != parent)
{
connect(tool, &VNodePoint::ShowContextMenu, parent, &VToolSeamAllowance::contextMenuEvent);
connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(tool, &VNodePoint::ShowOptions, parent, &VToolSeamAllowance::ShowOptions, Qt::UniqueConnection);
connect(tool, &VNodePoint::ToggleInLayout, parent, &VToolSeamAllowance::ToggleInLayout,
Qt::UniqueConnection);
connect(tool, &VNodePoint::Delete, parent, &VToolSeamAllowance::DeleteFromMenu, Qt::UniqueConnection);
connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem, Qt::UniqueConnection);
tool->setParentItem(parent);
tool->SetParentType(ParentType::Item);
tool->SetExluded(node.IsExcluded());

View File

@ -159,6 +159,11 @@ protected:
virtual void SetDialog() Q_DECL_FINAL;
virtual void SaveDialogChange(const QString &undoText = QString()) Q_DECL_FINAL;
private slots:
void ShowOptions();
void ToggleInLayout(bool checked);
void DeleteFromMenu();
private:
Q_DISABLE_COPY(VToolSeamAllowance)

View File

@ -82,11 +82,10 @@ void ShowLabel::Do(bool visible)
{
doc->SetAttribute<bool>(domElement, AttrShowLabel, visible);
if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(nodeId)))
if (VAbstractTool *tool = qobject_cast<VAbstractTool *>(VAbstractPattern::getTool(nodeId)))
{
tool->SetLabelVisible(nodeId, visible);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
}
else
{