diff --git a/ChangeLog.txt b/ChangeLog.txt index 7b774bb4b..0584eaf8a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -31,6 +31,7 @@ - [#409] New feature: Export measurement file to Excel .csv. - [#180] New feature: Search field in tape app and dialog Increments. - [#514] Read only setting not working properly. +- [#480] New tool: Midpoint between two points. # Version 0.4.5 - [#435] Valentina doesn't change the cursor. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 7e440d8a3..17f984845 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -75,7 +75,7 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in switch."); switch (item->type()) { @@ -199,7 +199,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -334,7 +334,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in switch."); switch (currentItem->type()) { diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index bd431689e..a70a3aaab 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -208,7 +208,7 @@ void DialogHistory::FillTable() QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -226,6 +226,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::LinePoint: case Tool::AbstractSpline: case Tool::Cut: + case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type case Tool::LAST_ONE_DO_NOT_USE: Q_UNREACHABLE(); //-V501 break; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 7bfc2906d..fc7d16472 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -610,6 +610,11 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur helpLabel->setText(toolTip); dialogTool = new Dialog(pattern, NULL_ID, this); + if (t == Tool::Midpoint) + { + dialogTool->Build(t); + } + VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr); @@ -750,6 +755,16 @@ void MainWindow::ToolAlongLine(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolMidpoint(bool checked) +{ + ToolSelectPointByRelease(); + // Reuse DialogAlongLine and VToolAlongLine but with different cursor + SetToolButtonWithApply(checked, Tool::Midpoint, ":/cursor/midpoint_cursor.png", + tr("Select point"), &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolShoulderPoint handler tool shoulderPoint. @@ -1750,6 +1765,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); + connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); } //--------------------------------------------------------------------------------------------------------------------- @@ -1790,7 +1806,7 @@ void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::CancelTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1836,6 +1852,9 @@ void MainWindow::CancelTool() case Tool::AlongLine: ui->toolButtonAlongLine->setChecked(false); break; + case Tool::Midpoint: + ui->toolButtonMidpoint->setChecked(false); + break; case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(false); break; @@ -3133,6 +3152,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); ui->toolButtonRotation->setEnabled(drawTools); + ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3412,7 +3432,7 @@ void MainWindow::CreateMenus() void MainWindow::LastUsedTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3451,6 +3471,10 @@ void MainWindow::LastUsedTool() ui->toolButtonAlongLine->setChecked(true); ToolAlongLine(true); break; + case Tool::Midpoint: + ui->toolButtonMidpoint->setChecked(true); + ToolMidpoint(true); + break; case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(true); ToolShoulderPoint(true); diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 6708c07dd..943245dc9 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -104,6 +104,7 @@ public slots: void ToolEndLine(bool checked); void ToolLine(bool checked); void ToolAlongLine(bool checked); + void ToolMidpoint(bool checked); void ToolShoulderPoint(bool checked); void ToolNormal(bool checked); void ToolBisector(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 1da863969..f0904c225 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,7 +48,7 @@ Tools - 4 + 0 @@ -368,6 +368,32 @@ + + + + false + + + Midpoint between two points + + + ... + + + + :/toolicon/32x32/midpoint.png:/toolicon/32x32/midpoint.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index cfd41aa80..95f4ef5ae 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -68,5 +68,7 @@ cursor/group_plus_cursor@2x.png cursor/rotation_cursor.png cursor/rotation_cursor@2x.png + cursor/midpoint_cursor.png + cursor/midpoint_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/midpoint_cursor.png b/src/app/valentina/share/resources/cursor/midpoint_cursor.png new file mode 100644 index 000000000..4c34e88e8 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/midpoint_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/midpoint_cursor@2x.png b/src/app/valentina/share/resources/cursor/midpoint_cursor@2x.png new file mode 100644 index 000000000..6fd81b0a8 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/midpoint_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 89e67fe78..9c3014f08 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -66,5 +66,7 @@ toolicon/32x32/group_plus@2x.png toolicon/32x32/rotation.png toolicon/32x32/rotation@2x.png + toolicon/32x32/midpoint.png + toolicon/32x32/midpoint@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/midpoint.png b/src/app/valentina/share/resources/toolicon/32x32/midpoint.png new file mode 100644 index 000000000..7f3436206 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/midpoint.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/midpoint@2x.png b/src/app/valentina/share/resources/toolicon/32x32/midpoint@2x.png new file mode 100644 index 000000000..b35c06d0b Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/midpoint@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/midpoint.svg b/src/app/valentina/share/resources/toolicon/svg/midpoint.svg new file mode 100644 index 000000000..1be5d299b --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/midpoint.svg @@ -0,0 +1,89 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d6fd0c0c4..324bf97c7 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -263,6 +263,8 @@ void VPattern::setCurrentData() const VDataTool *vTool = tools.value(id); *data = vTool->getData(); + //Delete special variable if exist + data->RemoveVariable(currentLength); qCDebug(vXML, "Data successfully updated."); } else @@ -3204,7 +3206,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id) QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used."); QRectF rec; @@ -3221,6 +3223,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::LinePoint: case Tool::AbstractSpline: case Tool::Cut: + case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type case Tool::LAST_ONE_DO_NOT_USE: Q_UNREACHABLE(); break; diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 65d74d3ff..53b3e1587 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -163,6 +163,7 @@ const QString angle2Spl_ = angle2_V + spl_; const QString angle1SplPath = angle1_V + splPath; const QString angle2SplPath = angle2_V + splPath; const QString seg_ = QStringLiteral("Seg_"); +const QString currentLength = QStringLiteral("CurrentLength"); const QStringList builInVariables = QStringList() << line_ << angleLine_ @@ -179,4 +180,5 @@ const QStringList builInVariables = QStringList() << line_ << angle2Spl_ << angle1SplPath << angle2SplPath - << seg_; + << seg_ + << currentLength; diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 39d65b2f9..93399b39d 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -170,6 +170,7 @@ extern const QString angle2Spl_; extern const QString angle1SplPath; extern const QString angle2SplPath; extern const QString seg_; +extern const QString currentLength; extern const QStringList builInVariables; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index a8bc66609..2facbd16f 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1235,7 +1235,7 @@ QStringList VAbstractPattern::ListPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1306,7 +1306,7 @@ QStringList VAbstractPattern::ListArcExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1367,7 +1367,7 @@ QStringList VAbstractPattern::ListPathPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1433,7 +1433,7 @@ QStringList VAbstractPattern::ListOperationExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index dbb079861..df6f28300 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -103,6 +103,7 @@ enum class Tool : ToolVisHolderType UnionDetails, Group, Rotation, + Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index b28ca3120..1d6fa8fe1 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -420,6 +420,12 @@ void VContainer::AddCurveWithSegments(const QSharedPointervariables.remove(name); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddObject add object to container diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index dce71b92f..2309dccb0 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -129,6 +129,7 @@ public: template void AddVariable(const QString& name, T *var); + void RemoveVariable(const QString& name); void UpdateGObject(quint32 id, VGObject* obj); void UpdateDetail(quint32 id, const VDetail &detail); diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index a2274b857..102b67165 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -380,6 +380,7 @@ void VTranslateVars::InitVariables() variables.insert(angle2SplPath, translate("VTranslateVars", "Angle2SplPath", "Do not add symbol _ to the end of the name")); variables.insert(seg_, translate("VTranslateVars", "Seg_", "Segment. Left symbol _ in the name")); + variables.insert(currentLength, translate("VTranslateVars", "CurrentLength", "Do not add space between words")); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index 99dfef4be..f9ddcb36d 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -33,6 +33,7 @@ #include "../../../vwidgets/vmaingraphicsscene.h" #include "../../../vpatterndb/vtranslatevars.h" #include "../support/dialogeditwrongformula.h" +#include "../vgeometry/vpointf.h" #include @@ -44,7 +45,7 @@ */ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), - formula(QString()), formulaBaseHeight(0) + formula(QString()), formulaBaseHeight(0), buildMidpoint(false) { ui->setupUi(this); @@ -93,7 +94,7 @@ void DialogAlongLine::FormulaTextChanged() void DialogAlongLine::PointChanged() { QColor color = okColor; - if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) + if (GetFirstPointId() == GetSecondPointId()) { flagError = false; color = errorColor; @@ -103,6 +104,7 @@ void DialogAlongLine::PointChanged() flagError = true; color = okColor; } + SetCurrentLength(); ChangeColor(ui->labelFirstPoint, color); ChangeColor(ui->labelSecondPoint, color); CheckState(); @@ -137,6 +139,9 @@ void DialogAlongLine::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogAlongLine::~DialogAlongLine() { + VContainer *locData = const_cast (data); + locData->RemoveVariable(currentLength); + DeleteVisualization(); delete ui; } @@ -173,6 +178,10 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type) { line->setObject2Id(id); line->RefreshGeometry(); + if (buildMidpoint) + { + SetFormula(currentLength + QLatin1Literal("/2")); + } prepare = true; this->setModal(true); this->show(); @@ -215,6 +224,20 @@ void DialogAlongLine::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::SetCurrentLength() +{ + const QSharedPointer p1 = data->GeometricObject(GetFirstPointId()); + const QSharedPointer p2 = data->GeometricObject(GetSecondPointId()); + + VLengthLine *length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), + GetSecondPointId(), *data->GetPatternUnit()); + length->SetName(currentLength); + + VContainer *locData = const_cast (data); + locData->AddVariable(currentLength, length); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetSecondPointId set id second point of line @@ -229,6 +252,15 @@ void DialogAlongLine::SetSecondPointId(const quint32 &value) line->setObject2Id(value); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::Build(const Tool &type) +{ + if (type == Tool::Midpoint) + { + buildMidpoint = true; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetFirstPointId set id first point of line diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.h b/src/libs/vtools/dialogs/tools/dialogalongline.h index 64965133a..641eef5e1 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.h +++ b/src/libs/vtools/dialogs/tools/dialogalongline.h @@ -62,6 +62,8 @@ public: quint32 GetSecondPointId() const; void SetSecondPointId(const quint32 &value); + + virtual void Build(const Tool &type) Q_DECL_OVERRIDE; public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; /** @@ -93,6 +95,10 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + bool buildMidpoint; + + void SetCurrentLength(); }; #endif // DIALOGALONGLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 200a52287..809635e4d 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -919,6 +919,12 @@ void DialogTool::ShowDialog(bool click) Q_UNUSED(click); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::Build(const Tool &type) +{ + Q_UNUSED(type); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogTool::SetAssociatedTool(VAbstractTool *tool) { diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index e1c51a5da..ee47436bc 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -69,6 +69,7 @@ public: void SetAssociatedTool(VAbstractTool* tool); virtual void ShowDialog(bool click); + virtual void Build(const Tool &type); quint32 GetToolId() const; void SetToolId(const quint32 &value); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 2fbca8c73..124d9b4af 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -250,6 +250,12 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa const QSharedPointer secondPoint = data->GeometricObject(secondPointId); QLineF line = QLineF(*firstPoint, *secondPoint); + //Declare special variable "CurrentLength" + VLengthLine *length = new VLengthLine(firstPoint.data(), firstPointId, secondPoint.data(), + secondPointId, *data->GetPatternUnit()); + length->SetName(currentLength); + data->AddVariable(currentLength, length); + line.setLength(qApp->toPixel(CheckFormula(_id, formula, data))); quint32 id = _id; @@ -270,16 +276,18 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa } } VDrawTool::AddRecord(id, Tool::AlongLine, doc); + VToolAlongLine *point = nullptr; if (parse == Document::FullParse) { - VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, - lineColor, typeCreation); + point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, lineColor, + typeCreation); scene->addItem(point); InitToolConnections(scene, point); doc->AddTool(id, point); doc->IncrementReferens(firstPoint->getIdTool()); doc->IncrementReferens(secondPoint->getIdTool()); - return point; } - return nullptr; + //Very important to delete it. Only this tool need this special variable. + data->RemoveVariable(currentLength); + return point; } diff --git a/src/test/ValentinaTest/tst_measurementregexp.cpp b/src/test/ValentinaTest/tst_measurementregexp.cpp index 44ba83479..f71d54a91 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.cpp +++ b/src/test/ValentinaTest/tst_measurementregexp.cpp @@ -651,6 +651,7 @@ void TST_MeasurementRegExp::CheckUnderlineExists() const data.insert(angle1SplPath, false); data.insert(angle2SplPath, false); data.insert(seg_, true); + data.insert(currentLength, false); //Catch case when new internal variable appears. QCOMPARE(data.size(), builInVariables.size());