From 60b323cf8ec05b6c563a7cd9c392fcd7d497360d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 18 Sep 2018 16:38:16 +0300 Subject: [PATCH] Fixed issue #882. VContainer class doesn't support multi document mode. --HG-- branch : release --- ChangeLog.txt | 1 + src/app/tape/tmainwindow.cpp | 30 +-- .../core/vtooloptionspropertybrowser.cpp | 13 +- .../dialogs/dialogpatternproperties.cpp | 4 +- src/app/valentina/dialogs/vwidgetgroups.cpp | 4 +- src/app/valentina/mainwindow.cpp | 36 ++- src/app/valentina/mainwindowsnogui.cpp | 12 +- src/app/valentina/xml/vpattern.cpp | 12 +- src/libs/ifc/xml/vabstractpattern.cpp | 2 +- src/libs/vformat/vmeasurements.cpp | 31 +-- src/libs/vformat/vmeasurements.h | 6 - src/libs/vlayout/vtextmanager.cpp | 8 +- src/libs/vmisc/def.cpp | 2 + src/libs/vmisc/def.h | 2 + src/libs/vpatterndb/variables/vincrement.cpp | 2 +- src/libs/vpatterndb/variables/vincrement_p.h | 18 +- .../vpatterndb/variables/vmeasurement.cpp | 14 +- src/libs/vpatterndb/variables/vmeasurement.h | 2 - .../vpatterndb/variables/vmeasurement_p.h | 6 +- src/libs/vpatterndb/vcontainer.cpp | 217 ++++++++++++++---- src/libs/vpatterndb/vcontainer.h | 62 +++-- .../dialogs/support/dialogeditlabel.cpp | 8 +- .../dialogs/tools/dialogflippingbyaxis.cpp | 2 +- .../dialogs/tools/dialogflippingbyline.cpp | 2 +- src/libs/vtools/dialogs/tools/dialogmove.cpp | 2 +- .../vtools/dialogs/tools/dialogrotation.cpp | 2 +- .../operation/flipping/vabstractflipping.cpp | 2 +- .../tools/drawTools/operation/vtoolmove.cpp | 2 +- .../drawTools/operation/vtoolrotation.cpp | 2 +- .../tooldoublepoint/vtooltruedarts.cpp | 2 +- .../toolsinglepoint/toolcut/vtoolcutarc.cpp | 4 +- .../toollinepoint/vtoolcurveintersectaxis.cpp | 4 +- src/libs/vtools/tools/drawTools/vtoolline.cpp | 4 +- src/libs/vtools/tools/vtooluniondetails.cpp | 2 +- src/test/ValentinaTest/tst_vmeasurements.cpp | 24 +- src/test/ValentinaTest/tst_vpiece.cpp | 4 +- 36 files changed, 322 insertions(+), 228 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 1167926dd..01ed50751 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -103,6 +103,7 @@ - [#823] SVG Export - seam and cutting line of one piece missing. - Added submenu to quick access to piece node point angle type. - [#880] Fix broken seam allowance angle type. +- [#882] VContainer class doesn't support multi document mode. # Version 0.5.0 May 9, 2017 - [#581] User can now filter input lists by keyword in function wizard. diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 665f0f639..e414c3ae3 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -250,11 +250,9 @@ bool TMainWindow::LoadFile(const QString &path) try { - data = new VContainer(qApp->TrVars(), &mUnit); + data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); m = new VMeasurements(data); - m->SetSize(¤tSize); - m->SetHeight(¤tHeight); m->setXMLContent(path); mType = m->Type(); @@ -335,8 +333,7 @@ bool TMainWindow::LoadFile(const QString &path) } else { - qApp->NewMainWindow(); - return qApp->MainWindow()->LoadFile(path); + return qApp->NewMainWindow()->LoadFile(path); } return true; @@ -364,15 +361,13 @@ void TMainWindow::FileNew() pUnit = mUnit; mType = measurements.Type(); - data = new VContainer(qApp->TrVars(), &mUnit); + data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); currentHeight = measurements.BaseHeight(); currentSize = measurements.BaseSize(); if (mType == MeasurementsType::Multisize) { m = new VMeasurements(mUnit, measurements.BaseSize(), measurements.BaseHeight(), data); - m->SetSize(¤tSize); - m->SetHeight(¤tHeight); m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer; m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr; } @@ -397,8 +392,7 @@ void TMainWindow::FileNew() } else { - qApp->NewMainWindow(); - qApp->MainWindow()->FileNew(); + qApp->NewMainWindow()->FileNew(); } } @@ -2093,13 +2087,13 @@ void TMainWindow::InitWindow() labelGradationHeights = new QLabel(tr("Height:")); gradationHeights = SetGradationList(labelGradationHeights, listHeights); - SetDefaultHeight(static_cast(VContainer::height())); + SetDefaultHeight(static_cast(data->height())); connect(gradationHeights, QOverload::of(&QComboBox::currentIndexChanged), this, &TMainWindow::ChangedHeight); labelGradationSizes = new QLabel(tr("Size:")); gradationSizes = SetGradationList(labelGradationSizes, listSizes); - SetDefaultSize(static_cast(VContainer::size())); + SetDefaultSize(static_cast(data->size())); connect(gradationSizes, QOverload::of(&QComboBox::currentIndexChanged), this, &TMainWindow::ChangedSize); @@ -2433,7 +2427,7 @@ void TMainWindow::SetDefaultSize(int value) //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::RefreshData(bool freshCall) { - VContainer::ClearUniqueNames(); + data->ClearUniqueNames(); data->ClearVariables(VarType::Measurement); m->ReadMeasurements(); @@ -2894,11 +2888,9 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) try { - data = new VContainer(qApp->TrVars(), &mUnit); + data = new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()); m = new VMeasurements(data); - m->SetSize(¤tSize); - m->SetHeight(¤tHeight); m->setXMLContent(path); mType = m->Type(); @@ -2975,8 +2967,7 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) } else { - qApp->NewMainWindow(); - return qApp->MainWindow()->LoadFile(path); + return qApp->NewMainWindow()->LoadFile(path); } return true; @@ -3014,8 +3005,7 @@ void TMainWindow::CreateWindowMenu(QMenu *menu) QAction *action = menu->addAction(tr("&New Window")); connect(action, &QAction::triggered, this, []() { - qApp->NewMainWindow(); - qApp->MainWindow()->activateWindow(); + qApp->NewMainWindow()->activateWindow(); }); action->setMenuRole(QAction::NoRole); menu->addSeparator(); diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index e3cc53600..248cc379c 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -677,7 +677,8 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) } QRegularExpression rx(NameRegExp()); - if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false) + if (name.isEmpty() || VContainer::IsUnique(name, valentinaNamespace) == false + || rx.match(name).hasMatch() == false) { idToProperty[AttrName]->setValue(i->name()); } @@ -704,7 +705,8 @@ void VToolOptionsPropertyBrowser::SetPointName1(const QString &name) } QRegularExpression rx(NameRegExp()); - if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false) + if (name.isEmpty() || VContainer::IsUnique(name, valentinaNamespace) == false + || rx.match(name).hasMatch() == false) { idToProperty[AttrName1]->setValue(i->nameP1()); } @@ -731,7 +733,8 @@ void VToolOptionsPropertyBrowser::SetPointName2(const QString &name) } QRegularExpression rx(NameRegExp()); - if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false) + if (name.isEmpty() || VContainer::IsUnique(name, valentinaNamespace) == false + || rx.match(name).hasMatch() == false) { idToProperty[AttrName2]->setValue(i->nameP2()); } @@ -764,11 +767,11 @@ void VToolOptionsPropertyBrowser::SetOperationSuffix(const QString &suffix) } QRegularExpression rx(NameRegExp()); - const QStringList uniqueNames = VContainer::AllUniqueNames(); + const QStringList uniqueNames = VContainer::AllUniqueNames(valentinaNamespace); for (auto &uniqueName : uniqueNames) { const QString name = uniqueName + suffix; - if (not rx.match(name).hasMatch() || not VContainer::IsUnique(name)) + if (not rx.match(name).hasMatch() || not VContainer::IsUnique(name, valentinaNamespace)) { idToProperty[AttrSuffix]->setValue(item->Suffix()); return; diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 9277a7051..dee43f51d 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -667,7 +667,7 @@ void DialogPatternProperties::SetDefaultHeight(const QString &def) } else { - const int height = static_cast(VContainer::height()); + const int height = static_cast(pattern->height()); index = ui->comboBoxHeight->findText(QString().setNum(height)); if (index != -1) { @@ -688,7 +688,7 @@ void DialogPatternProperties::SetDefaultSize(const QString &def) } else { - const int size = static_cast(VContainer::size()); + const int size = static_cast(pattern->size()); index = ui->comboBoxSize->findText(QString().setNum(size)); if (index != -1) { diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index 70f156457..b5aedac34 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -112,7 +112,9 @@ void VWidgetGroups::CtxMenu(const QPoint &pos) QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); if (selectedAction == actionRename) { - DialogGroup *dialog = new DialogGroup(new VContainer(qApp->TrVars(), qApp->patternUnitP()), NULL_ID, this); + DialogGroup *dialog = new DialogGroup(new VContainer(qApp->TrVars(), qApp->patternUnitP(), + VContainer::UniqueNamespace()), + NULL_ID, this); dialog->SetName(doc->GetGroupName(id)); const int result = dialog->exec(); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index ffc8cba54..06fcc2c5b 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -444,8 +444,8 @@ bool MainWindow::LoadMeasurements(const QString &path) if (m->Type() == MeasurementsType::Multisize) { - VContainer::SetSize(UnitConvertor(m->BaseSize(), m->MUnit(), *m->GetData()->GetPatternUnit())); - VContainer::SetHeight(UnitConvertor(m->BaseHeight(), m->MUnit(), *m->GetData()->GetPatternUnit())); + pattern->SetSize(UnitConvertor(m->BaseSize(), m->MUnit(), *m->GetData()->GetPatternUnit())); + pattern->SetHeight(UnitConvertor(m->BaseHeight(), m->MUnit(), *m->GetData()->GetPatternUnit())); doc->SetPatternWasChanged(true); emit doc->UpdatePatternLabel(); @@ -500,8 +500,8 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) if (m->Type() == MeasurementsType::Multisize) { - VContainer::SetSize(size); - VContainer::SetHeight(height); + pattern->SetSize(size); + pattern->SetHeight(height); doc->SetPatternWasChanged(true); emit doc->UpdatePatternLabel(); @@ -1143,7 +1143,7 @@ void MainWindow::ClosedDialogGroup(int result) { const QPointer dialog = qobject_cast(dialogTool); SCASSERT(not dialog.isNull()) - const QDomElement group = doc->CreateGroup(VContainer::getNextId(), dialog->GetName(), dialog->GetGroup()); + const QDomElement group = doc->CreateGroup(pattern->getNextId(), dialog->GetName(), dialog->GetGroup()); if (not group.isNull()) { AddGroup *addGroup = new AddGroup(group, doc); @@ -1733,9 +1733,9 @@ void MainWindow::ShowMeasurements() << "-u" << UnitsToStr(qApp->patternUnit()) << "-e" - << QString().setNum(static_cast(UnitConvertor(VContainer::height(), doc->MUnit(), Unit::Cm))) + << QString().setNum(static_cast(UnitConvertor(pattern->height(), doc->MUnit(), Unit::Cm))) << "-s" - << QString().setNum(static_cast(UnitConvertor(VContainer::size(), doc->MUnit(), Unit::Cm))); + << QString().setNum(static_cast(UnitConvertor(pattern->size(), doc->MUnit(), Unit::Cm))); } else { @@ -1796,7 +1796,7 @@ void MainWindow::SyncMeasurements() if (mChanges) { const QString path = AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()); - if(UpdateMeasurements(path, static_cast(VContainer::size()), static_cast(VContainer::height()))) + if(UpdateMeasurements(path, static_cast(pattern->size()), static_cast(pattern->height()))) { if (not watcher->files().contains(path)) { @@ -3378,9 +3378,9 @@ void MainWindow::PatternChangesWereSaved(bool saved) */ void MainWindow::ChangedSize(const QString & text) { - const int size = static_cast(VContainer::size()); + const int size = static_cast(pattern->size()); if (UpdateMeasurements(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()), text.toInt(), - static_cast(VContainer::height()))) + static_cast(pattern->height()))) { doc->LiteParseTree(Document::LiteParse); emit sceneDetails->DimensionsChanged(); @@ -3408,8 +3408,8 @@ void MainWindow::ChangedSize(const QString & text) */ void MainWindow::ChangedHeight(const QString &text) { - const int height = static_cast(VContainer::height()); - if (UpdateMeasurements(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()), static_cast(VContainer::size()), + const int height = static_cast(pattern->height()); + if (UpdateMeasurements(AbsoluteMPath(qApp->GetPatternPath(), doc->MPath()), static_cast(pattern->size()), text.toInt())) { doc->LiteParseTree(Document::LiteParse); @@ -3456,13 +3456,13 @@ void MainWindow::SetDefaultHeight() } else { - index = gradationHeights->findText(QString().setNum(VContainer::height())); + index = gradationHeights->findText(QString().setNum(pattern->height())); if (index != -1) { gradationHeights->setCurrentIndex(index); } } - VContainer::SetHeight(gradationHeights->currentText().toInt()); + pattern->SetHeight(gradationHeights->currentText().toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -3476,13 +3476,13 @@ void MainWindow::SetDefaultSize() } else { - index = gradationSizes->findText(QString().setNum(VContainer::size())); + index = gradationSizes->findText(QString().setNum(pattern->size())); if (index != -1) { gradationSizes->setCurrentIndex(index); } } - VContainer::SetSize(gradationSizes->currentText().toInt()); + pattern->SetSize(gradationSizes->currentText().toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -4423,8 +4423,6 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) // Here comes undocumented Valentina's feature. // Because app bundle in Mac OS X doesn't allow setup assosiation for Tape we must do this through Valentina VMeasurements m(pattern); - m.SetSize(VContainer::rsize()); - m.SetHeight(VContainer::rheight()); m.setXMLContent(fileName); if (m.Type() == MeasurementsType::Multisize || m.Type() == MeasurementsType::Individual) @@ -4960,8 +4958,6 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS else { QScopedPointer m(new VMeasurements(pattern)); - m->SetSize(VContainer::rsize()); - m->SetHeight(VContainer::rheight()); m->setXMLContent(mPath); patternType = m->Type(); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 4b97a45fb..06301cf90 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -112,7 +112,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) listDetails(), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), + pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP(), valentinaNamespace)), doc(nullptr), papers(), shadows(), @@ -1665,20 +1665,20 @@ void MainWindowsNoGUI::SetSizeHeightForIndividualM() const if (vars->contains(size_M)) { - VContainer::SetSize(*vars->value(size_M)->GetValue()); + pattern->SetSize(*vars->value(size_M)->GetValue()); } else { - VContainer::SetSize(0); + pattern->SetSize(0); } if (vars->contains(height_M)) { - VContainer::SetHeight(*vars->value(height_M)->GetValue()); + pattern->SetHeight(*vars->value(height_M)->GetValue()); } else { - VContainer::SetHeight(0); + pattern->SetHeight(0); } doc->SetPatternWasChanged(true); @@ -1776,8 +1776,6 @@ QSharedPointer MainWindowsNoGUI::OpenMeasurementFile(const QStrin try { m = QSharedPointer(new VMeasurements(pattern)); - m->SetSize(VContainer::rsize()); - m->SetHeight(VContainer::rheight()); m->setXMLContent(path); if (m->Type() == MeasurementsType::Unknown) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index cdbef7422..2c3d58f1a 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -337,14 +337,14 @@ VContainer VPattern::GetCompleteData() const const int countPP = CountPP(); if (countPP <= 0 || history.isEmpty() || tools.isEmpty()) { - return (data != nullptr ? *data : VContainer(nullptr, nullptr)); + return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace())); } const quint32 id = (countPP == 1 ? history.last().getId() : LastToolId()); if (id == NULL_ID) { - return (data != nullptr ? *data : VContainer(nullptr, nullptr)); + return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace())); } try @@ -354,7 +354,7 @@ VContainer VPattern::GetCompleteData() const catch (VExceptionBadId &e) { Q_UNUSED(e) - return (data != nullptr ? *data : VContainer(nullptr, nullptr)); + return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace())); } const VDataTool *vTool = tools.value(id); @@ -455,7 +455,7 @@ void VPattern::LiteParseIncrements() { emit SetEnabledGUI(true); - VContainer::ClearUniqueIncrementNames(); + data->ClearUniqueIncrementNames(); data->ClearVariables(VarType::Increment); QDomNodeList tags = elementsByTagName(TagIncrements); @@ -3998,7 +3998,7 @@ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedNa QString VPattern::GenerateSuffix() const { const QString suffixBase = GetLabelBase(static_cast(GetIndexActivPP())).toLower(); - const QStringList uniqueNames = VContainer::AllUniqueNames(); + const QStringList uniqueNames = data->AllUniqueNames(); qint32 num = 1; QString suffix; for (;;) @@ -4258,7 +4258,7 @@ void VPattern::PrepareForParse(const Document &parse) } else if (parse == Document::LiteParse) { - VContainer::ClearUniqueNames(); + data->ClearUniqueNames(); Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); data->ClearVariables(QVector({VarType::Increment, VarType::LineAngle, diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 43bf112a3..aa555a0e5 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -447,7 +447,7 @@ void VAbstractPattern::ParseGroups(const QDomElement &domElement) { if (domElement.tagName() == TagGroup) { - VContainer::UpdateId(GetParametrUInt(domElement, AttrId, NULL_ID_STR)); + VContainer::UpdateId(GetParametrUInt(domElement, AttrId, NULL_ID_STR), valentinaNamespace); const QPair > groupData = ParseItemElement(domElement); const QMap group = groupData.second; diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index a9764111d..38f8f576c 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -99,9 +99,7 @@ QString FileComment() VMeasurements::VMeasurements(VContainer *data) :VDomDocument(), data(data), - type(MeasurementsType::Unknown), - m_currentSize(nullptr), - m_currentHeight(nullptr) + type(MeasurementsType::Unknown) { SCASSERT(data != nullptr) } @@ -110,9 +108,7 @@ VMeasurements::VMeasurements(VContainer *data) VMeasurements::VMeasurements(Unit unit, VContainer *data) :VDomDocument(), data(data), - type(MeasurementsType::Individual), - m_currentSize(nullptr), - m_currentHeight(nullptr) + type(MeasurementsType::Individual) { SCASSERT(data != nullptr) @@ -123,9 +119,7 @@ VMeasurements::VMeasurements(Unit unit, VContainer *data) VMeasurements::VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data) :VDomDocument(), data(data), - type(MeasurementsType::Multisize), - m_currentSize(nullptr), - m_currentHeight(nullptr) + type(MeasurementsType::Multisize) { SCASSERT(data != nullptr) @@ -262,7 +256,8 @@ void VMeasurements::ReadMeasurements() const // That's why we need two containers: one for converted values, second for real data. // Container for values in measurement file's unit - QScopedPointer tempData(new VContainer(data->GetTrVars(), data->GetPatternUnit())); + QScopedPointer tempData(new VContainer(data->GetTrVars(), data->GetPatternUnit(), + VContainer::UniqueNamespace())); const QDomNodeList list = elementsByTagName(TagMeasurement); for (int i=0; i < list.size(); ++i) @@ -283,8 +278,6 @@ void VMeasurements::ReadMeasurements() const tempMeash = QSharedPointer(new VMeasurement(static_cast(i), name, BaseSize(), BaseHeight(), base, ksize, kheight)); - tempMeash->SetSize(m_currentSize); - tempMeash->SetHeight(m_currentHeight); tempMeash->SetUnit(data->GetPatternUnit()); base = UnitConvertor(base, MUnit(), *data->GetPatternUnit()); @@ -296,8 +289,6 @@ void VMeasurements::ReadMeasurements() const meash = QSharedPointer(new VMeasurement(static_cast(i), name, baseSize, baseHeight, base, ksize, kheight, fullName, description)); - meash->SetSize(m_currentSize); - meash->SetHeight(m_currentHeight); meash->SetUnit(data->GetPatternUnit()); } else @@ -477,18 +468,6 @@ void VMeasurements::SetReadOnly(bool ro) } } -//--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetSize(qreal *size) -{ - m_currentSize = size; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetHeight(qreal *height) -{ - m_currentHeight = height; -} - //--------------------------------------------------------------------------------------------------------------------- void VMeasurements::SetMName(const QString &name, const QString &text) { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 941257c5b..9ba19442d 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -90,9 +90,6 @@ public: bool IsReadOnly() const; void SetReadOnly(bool ro); - void SetSize(qreal *size); - void SetHeight(qreal *height); - void SetMName(const QString &name, const QString &text); void SetMValue(const QString &name, const QString &text); void SetMBaseValue(const QString &name, double value); @@ -145,9 +142,6 @@ private: VContainer *data; MeasurementsType type; - qreal *m_currentSize; - qreal *m_currentHeight; - void CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHeight); void CreateEmptyIndividualFile(Unit unit); diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 248339e81..e65124ecf 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -96,14 +96,14 @@ QMap PreparePlaceholders(const VAbstractPattern *doc) QString mExt; if (qApp->patternType() == MeasurementsType::Multisize) { - curSize = QString::number(VContainer::size()); - curHeight = QString::number(VContainer::height()); + curSize = QString::number(VContainer::size(valentinaNamespace)); + curHeight = QString::number(VContainer::height(valentinaNamespace)); mExt = "vst"; } else if (qApp->patternType() == MeasurementsType::Individual) { - curSize = QString::number(VContainer::size()); - curHeight = QString::number(VContainer::height()); + curSize = QString::number(VContainer::size(valentinaNamespace)); + curHeight = QString::number(VContainer::height(valentinaNamespace)); mExt = "vit"; } diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index e3f0f906f..0cd21827e 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -202,6 +202,8 @@ const QString unitCM = QStringLiteral("cm"); const QString unitINCH = QStringLiteral("inch"); const QString unitPX = QStringLiteral("px"); +const QString valentinaNamespace = QStringLiteral("valentina"); + //--------------------------------------------------------------------------------------------------------------------- QPixmap QPixmapFromCache(const QString &pixmapPath) { diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index e038e1b4f..7796a6d96 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -417,6 +417,8 @@ extern const QString unitCM; extern const QString unitINCH; extern const QString unitPX; +extern const QString valentinaNamespace; + QPixmap QPixmapFromCache(const QString &pixmapPath); void SetItemOverrideCursor(QGraphicsItem *item, const QString & pixmapPath, int hotX = -1, int hotY = -1); diff --git a/src/libs/vpatterndb/variables/vincrement.cpp b/src/libs/vpatterndb/variables/vincrement.cpp index 718c488fe..0f1cae2f2 100644 --- a/src/libs/vpatterndb/variables/vincrement.cpp +++ b/src/libs/vpatterndb/variables/vincrement.cpp @@ -104,7 +104,7 @@ bool VIncrement::IsFormulaOk() const //--------------------------------------------------------------------------------------------------------------------- VContainer *VIncrement::GetData() { - return &d->data; + return d->data.data(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/variables/vincrement_p.h b/src/libs/vpatterndb/variables/vincrement_p.h index b9e04dedd..4a8c9daf3 100644 --- a/src/libs/vpatterndb/variables/vincrement_p.h +++ b/src/libs/vpatterndb/variables/vincrement_p.h @@ -48,7 +48,7 @@ public: formula(QString()), formulaOk(false), previewCalculation(false), - data(VContainer(nullptr, nullptr)) + data() {} VIncrementData(VContainer *data, quint32 index, const QString &formula, bool ok) @@ -56,17 +56,17 @@ public: formula(formula), formulaOk(ok), previewCalculation(false), - data(*data) + data(QSharedPointer(new VContainer(*data))) { // When we create an increment in the dialog it will get neccesary data. Such data must be removed because will // confuse a user. Increment should not know nothing about internal variables. Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); - this->data.ClearVariables(QVector({VarType::LineAngle, - VarType::LineLength, - VarType::CurveLength, - VarType::CurveCLength, - VarType::ArcRadius, - VarType::CurveAngle})); + this->data->ClearVariables(QVector({VarType::LineAngle, + VarType::LineLength, + VarType::CurveLength, + VarType::CurveCLength, + VarType::ArcRadius, + VarType::CurveAngle})); } VIncrementData(const VIncrementData &incr) @@ -85,7 +85,7 @@ public: QString formula; bool formulaOk; bool previewCalculation; - VContainer data; + QSharedPointer data; private: VIncrementData &operator=(const VIncrementData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index 080d0a517..1f1d877e1 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -307,19 +307,7 @@ qreal *VMeasurement::GetValue() //--------------------------------------------------------------------------------------------------------------------- VContainer *VMeasurement::GetData() { - return &d->data; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::SetSize(qreal *size) -{ - d->currentSize = size; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VMeasurement::SetHeight(qreal *height) -{ - d->currentHeight = height; + return d->data.data(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index 9e9dea817..a4b3af4b5 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -87,8 +87,6 @@ public: VContainer *GetData(); - void SetSize(qreal *size); - void SetHeight(qreal *height); void SetUnit(const Unit *unit); qreal GetBase() const; diff --git a/src/libs/vpatterndb/variables/vmeasurement_p.h b/src/libs/vpatterndb/variables/vmeasurement_p.h index 6917c1ed3..1b77eb703 100644 --- a/src/libs/vpatterndb/variables/vmeasurement_p.h +++ b/src/libs/vpatterndb/variables/vmeasurement_p.h @@ -44,7 +44,7 @@ public: VMeasurementData(quint32 index, const QString &gui_text, const QString &tagName, qreal baseSize, qreal baseHeight, qreal base, qreal ksize, qreal kheight ) - : data(VContainer(nullptr, nullptr)), + : data(), index(index), formula(), gui_text(gui_text), @@ -62,7 +62,7 @@ public: VMeasurementData(VContainer *data, quint32 index, const QString &formula, bool ok, const QString &gui_text, const QString &tagName, qreal base) - : data(*data), + : data(QSharedPointer(new VContainer(*data))), index(index), formula(formula), gui_text(gui_text), @@ -98,7 +98,7 @@ public: virtual ~VMeasurementData(); - VContainer data; + QSharedPointer data; quint32 index; QString formula; QString gui_text; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index ba44d3055..cbfb0c5cc 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "../ifc/exception/vexception.h" #include "../vgeometry/vabstractcubicbezierpath.h" @@ -63,18 +64,54 @@ Q_LOGGING_CATEGORY(vCon, "v.container") QT_WARNING_POP -quint32 VContainer::_id = NULL_ID; -qreal VContainer::_size = 50; -qreal VContainer::_height = 176; -QSet VContainer::uniqueNames = QSet(); +QMap VContainer::_id = QMap(); +QMap VContainer::_size = QMap(); +QMap VContainer::_height = QMap(); +QMap> VContainer::uniqueNames = QMap>(); +QMap VContainer::copyCounter = QMap(); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VContainer create empty container */ -VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit) - :d(new VContainerData(trVars, patternUnit)) -{} +VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace) + :d(new VContainerData(trVars, patternUnit, nspace)) +{ + if (nspace.isEmpty()) + { + qFatal("Namesapce is empty."); + } + + if (VContainer::_id.contains(nspace)) + { + qFatal("Namespace is not unique."); + } + + if (not _id.contains(d->nspace)) + { + _id[d->nspace] = NULL_ID; + } + + if (not _size.contains(d->nspace)) + { + _size[d->nspace] = 50; + } + + if (not _height.contains(d->nspace)) + { + _height[d->nspace] = 176; + } + + if (not uniqueNames.contains(d->nspace)) + { + uniqueNames[d->nspace] = QSet(); + } + + if (not copyCounter.contains(d->nspace)) + { + copyCounter[d->nspace] = 1; + } +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -89,6 +126,7 @@ VContainer &VContainer::operator =(const VContainer &data) return *this; } d = data.d; + ++copyCounter[d->nspace]; return *this; } @@ -99,12 +137,36 @@ VContainer &VContainer::operator =(const VContainer &data) */ VContainer::VContainer(const VContainer &data) :d(data.d) -{} +{ + ++copyCounter[d->nspace]; +} //--------------------------------------------------------------------------------------------------------------------- VContainer::~VContainer() {} +//--------------------------------------------------------------------------------------------------------------------- +QString VContainer::UniqueNamespace() +{ + QString candidate; + do + { + candidate = QUuid::createUuid().toString(); + } + while(_size.contains(candidate)); + + return candidate; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearNamespace(const QString &nspace) +{ + _id.remove(nspace); + _size.remove(nspace); + _height.remove(nspace); + uniqueNames.remove(nspace); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetGObject returns a point by id @@ -203,7 +265,7 @@ quint32 VContainer::AddGObject(const QSharedPointer &obj) return NULL_ID; } - uniqueNames.insert(obj->name()); + uniqueNames[d->nspace].insert(obj->name()); const quint32 id = getNextId(); obj->setId(id); @@ -236,9 +298,9 @@ quint32 VContainer::AddPiecePath(const VPiecePath &path) } //--------------------------------------------------------------------------------------------------------------------- -quint32 VContainer::getId() +quint32 VContainer::getId() const { - return _id; + return _id.value(d->nspace); } //--------------------------------------------------------------------------------------------------------------------- @@ -246,17 +308,33 @@ quint32 VContainer::getId() * @brief getNextId generate next unique id * @return next unique id */ -quint32 VContainer::getNextId() +quint32 VContainer::getNextId() const { //TODO. Current count of ids are very big and allow us save time before someone will reach its max value. //Better way, of cource, is to seek free ids inside the set of values and reuse them. //But for now better to keep it as it is now. - if (_id == UINT_MAX) + if (_id.value(d->nspace) == UINT_MAX) { qCritical()<<(tr("Number of free id exhausted.")); } - _id++; - return _id; + _id[d->nspace]++; + return _id.value(d->nspace); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::UpdateId(quint32 newId, const QString &nspace) +{ + if (_id.contains(nspace)) + { + if (newId > _id.value(nspace)) + { + _id[nspace] = newId; + } + } + else + { + throw VException(QStringLiteral("Unknown namespace")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -264,12 +342,9 @@ quint32 VContainer::getNextId() * @brief UpdateId update id. If new id bigger when current save new like current. * @param newId id */ -void VContainer::UpdateId(quint32 newId) +void VContainer::UpdateId(quint32 newId) const { - if (newId > _id) - { - _id = newId; - } + VContainer::UpdateId(newId, d->nspace); } //--------------------------------------------------------------------------------------------------------------------- @@ -279,7 +354,7 @@ void VContainer::UpdateId(quint32 newId) void VContainer::Clear() { qCDebug(vCon, "Clearing container data."); - _id = NULL_ID; + _id[d->nspace] = NULL_ID; d->pieces->clear(); d->piecePaths->clear(); @@ -292,7 +367,7 @@ void VContainer::Clear() void VContainer::ClearForFullParse() { qCDebug(vCon, "Clearing container data for full parse."); - _id = NULL_ID; + _id[d->nspace] = NULL_ID; d->pieces->clear(); d->piecePaths->clear(); @@ -552,17 +627,43 @@ const QMap > VContainer::DataAnglesCurves() } //--------------------------------------------------------------------------------------------------------------------- -bool VContainer::IsUnique(const QString &name) +bool VContainer::IsUnique(const QString &name) const { - return (!uniqueNames.contains(name) && !builInFunctions.contains(name)); + return VContainer::IsUnique(name, d->nspace); } //--------------------------------------------------------------------------------------------------------------------- -QStringList VContainer::AllUniqueNames() +bool VContainer::IsUnique(const QString &name, const QString &nspace) { - QStringList names = builInFunctions; - names.append(uniqueNames.toList()); - return names; + if (uniqueNames.contains(nspace)) + { + return (!uniqueNames.value(nspace).contains(name) && !builInFunctions.contains(name)); + } + else + { + throw VException(QStringLiteral("Unknown namespace")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VContainer::AllUniqueNames() const +{ + return AllUniqueNames(d->nspace); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VContainer::AllUniqueNames(const QString &nspace) +{ + if (uniqueNames.contains(nspace)) + { + QStringList names = builInFunctions; + names.append(uniqueNames.value(nspace).toList()); + return names; + } + else + { + throw VException(QStringLiteral("Unknown namespace")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -596,22 +697,22 @@ const QMap > VContainer::DataVar(const VarType &type) } //--------------------------------------------------------------------------------------------------------------------- -void VContainer::ClearUniqueNames() +void VContainer::ClearUniqueNames() const { - uniqueNames.clear(); + uniqueNames[d->nspace].clear(); } //--------------------------------------------------------------------------------------------------------------------- -void VContainer::ClearUniqueIncrementNames() +void VContainer::ClearUniqueIncrementNames() const { - const QList list = uniqueNames.toList(); + const QList list = uniqueNames.value(d->nspace).toList(); ClearUniqueNames(); for(auto &name : list) { if (not name.startsWith('#')) { - uniqueNames.insert(name); + uniqueNames[d->nspace].insert(name); } } } @@ -621,9 +722,9 @@ void VContainer::ClearUniqueIncrementNames() * @brief SetSize set value of size * @param size value of size */ -void VContainer::SetSize(qreal size) +void VContainer::SetSize(qreal size) const { - _size = size; + _size[d->nspace] = size; } //--------------------------------------------------------------------------------------------------------------------- @@ -631,9 +732,9 @@ void VContainer::SetSize(qreal size) * @brief SetGrowth set value of growth * @param height value of height */ -void VContainer::SetHeight(qreal height) +void VContainer::SetHeight(qreal height) const { - _height = height; + _height[d->nspace] = height; } //--------------------------------------------------------------------------------------------------------------------- @@ -641,15 +742,22 @@ void VContainer::SetHeight(qreal height) * @brief size return size * @return size in mm */ -qreal VContainer::size() +qreal VContainer::size() const { - return _size; + return VContainer::size(d->nspace); } //--------------------------------------------------------------------------------------------------------------------- -qreal *VContainer::rsize() +qreal VContainer::size(const QString &nspace) { - return &_size; + if (_size.contains(nspace)) + { + return _size.value(nspace); + } + else + { + throw VException(QStringLiteral("Unknown namespace")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -657,15 +765,22 @@ qreal *VContainer::rsize() * @brief height return height * @return height in pattern units */ -qreal VContainer::height() +qreal VContainer::height() const { - return _height; + return VContainer::height(d->nspace); } //--------------------------------------------------------------------------------------------------------------------- -qreal *VContainer::rheight() +qreal VContainer::height(const QString &nspace) { - return &_height; + if (_height.contains(nspace)) + { + return _height.value(nspace); + } + else + { + throw VException(QStringLiteral("Unknown namespace")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -692,4 +807,14 @@ const QHash > *VContainer::DataVariab //--------------------------------------------------------------------------------------------------------------------- VContainerData::~VContainerData() -{} +{ + if (ref == 0) + { + --VContainer::copyCounter[nspace]; + } + + if (VContainer::copyCounter.value(nspace) == 0) + { + VContainer::ClearNamespace(nspace); + } +} diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 264d23adb..77cc8606e 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -68,14 +68,15 @@ class VContainerData : public QSharedData //-V690 { public: - VContainerData(const VTranslateVars *trVars, const Unit *patternUnit) + VContainerData(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace) : calculationObjects(QHash >()), modelingObjects(QSharedPointer>>::create()), variables(QHash > ()), pieces(QSharedPointer>::create()), piecePaths(QSharedPointer>::create()), trVars(trVars), - patternUnit(patternUnit) + patternUnit(patternUnit), + nspace(nspace) {} VContainerData(const VContainerData &data) @@ -86,7 +87,8 @@ public: pieces(data.pieces), piecePaths(data.piecePaths), trVars(data.trVars), - patternUnit(data.patternUnit) + patternUnit(data.patternUnit), + nspace(data.nspace) {} virtual ~VContainerData(); @@ -105,6 +107,9 @@ public: const VTranslateVars *trVars; const Unit *patternUnit; + /** @brief nspace namespace for static variables */ + QString nspace; + private: VContainerData &operator=(const VContainerData &) Q_DECL_EQ_DELETE; }; @@ -118,10 +123,12 @@ class VContainer { Q_DECLARE_TR_FUNCTIONS(VContainer) public: - VContainer(const VTranslateVars *trVars, const Unit *patternUnit); + VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace); VContainer(const VContainer &data); ~VContainer(); + friend class VContainerData; + VContainer &operator=(const VContainer &data); #ifdef Q_COMPILER_RVALUE_REFS VContainer &operator=(VContainer &&data) Q_DECL_NOTHROW { Swap(data); return *this; } @@ -130,6 +137,8 @@ public: inline void Swap(VContainer &data) Q_DECL_NOTHROW { std::swap(d, data.d); } + static QString UniqueNamespace(); + template const QSharedPointer GeometricObject(const quint32 &id) const; const QSharedPointer GetGObject(quint32 id) const; @@ -139,9 +148,10 @@ public: quint32 GetPieceForPiecePath(quint32 id) const; template QSharedPointer GetVariable(QString name) const; - static quint32 getId(); - static quint32 getNextId(); - static void UpdateId(quint32 newId); + quint32 getId() const; + quint32 getNextId() const; + void UpdateId(quint32 newId) const; + static void UpdateId(quint32 newId, const QString &nspace); quint32 AddGObject(VGObject *obj); quint32 AddGObject(const QSharedPointer &obj); @@ -174,15 +184,15 @@ public: void ClearCalculationGObjects(); void ClearVariables(const VarType &type = VarType::Unknown); void ClearVariables(const QVector &types); - static void ClearUniqueNames(); - static void ClearUniqueIncrementNames(); + void ClearUniqueNames() const; + void ClearUniqueIncrementNames() const; - static void SetSize(qreal size); - static void SetHeight(qreal height); - static qreal size(); - static qreal *rsize(); - static qreal height(); - static qreal *rheight(); + void SetSize(qreal size) const; + void SetHeight(qreal height) const; + qreal size() const; + static qreal size(const QString &nspace); + qreal height() const; + static qreal height(const QString &nspace); void RemoveIncrement(const QString& name); @@ -199,8 +209,11 @@ public: const QMap > DataRadiusesArcs() const; const QMap > DataAnglesCurves() const; - static bool IsUnique(const QString &name); - static QStringList AllUniqueNames(); + bool IsUnique(const QString &name) const; + static bool IsUnique(const QString &name, const QString &nspace); + + QStringList AllUniqueNames() const; + static QStringList AllUniqueNames(const QString &nspace); const Unit *GetPatternUnit() const; const VTranslateVars *GetTrVars() const; @@ -209,10 +222,11 @@ private: /** * @brief _id current id. New object will have value +1. For empty class equal 0. */ - static quint32 _id; - static qreal _size; - static qreal _height; - static QSet uniqueNames; + static QMap _id; + static QMap _size; + static QMap _height; + static QMap> uniqueNames; + static QMap copyCounter; QSharedDataPointer d; @@ -226,6 +240,8 @@ private: template const QMap > DataVar(const VarType &type) const; + + static void ClearNamespace(const QString &nspace); }; Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE); @@ -324,7 +340,7 @@ void VContainer::AddVariable(const QString& name, const QSharedPointer &var) d->variables.insert(name, var); } - uniqueNames.insert(name); + uniqueNames[d->nspace].insert(name); } //--------------------------------------------------------------------------------------------------------------------- @@ -353,7 +369,7 @@ void VContainer::UpdateGObject(quint32 id, const QSharedPointer &obj) { SCASSERT(not obj.isNull()) UpdateObject(id, obj); - uniqueNames.insert(obj->name()); + uniqueNames[d->nspace].insert(obj->name()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 64e59481b..01337f153 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -521,14 +521,14 @@ void DialogEditLabel::InitPlaceholders() QString mExt; if (qApp->patternType() == MeasurementsType::Multisize) { - curSize = QString::number(VContainer::size()); - curHeight = QString::number(VContainer::height()); + curSize = QString::number(VContainer::size(valentinaNamespace)); + curHeight = QString::number(VContainer::height(valentinaNamespace)); mExt = "vst"; } else if (qApp->patternType() == MeasurementsType::Individual) { - curSize = QString::number(VContainer::size()); - curHeight = QString::number(VContainer::height()); + curSize = QString::number(VContainer::size(valentinaNamespace)); + curHeight = QString::number(VContainer::height(valentinaNamespace)); mExt = "vit"; } diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp index 8ac04c5c2..ce8f593c0 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp @@ -253,7 +253,7 @@ void DialogFlippingByAxis::SuffixChanged() if (m_suffix != suffix) { QRegularExpression rx(NameRegExp()); - const QStringList uniqueNames = VContainer::AllUniqueNames(); + const QStringList uniqueNames = data->AllUniqueNames(); for (auto &uniqueName : uniqueNames) { const QString name = uniqueName + suffix; diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp index 0131c55ff..c7cdfeb27 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp @@ -280,7 +280,7 @@ void DialogFlippingByLine::SuffixChanged() if (m_suffix != suffix) { QRegularExpression rx(NameRegExp()); - const QStringList uniqueNames = VContainer::AllUniqueNames(); + const QStringList uniqueNames = data->AllUniqueNames(); for (auto &uniqueName : uniqueNames) { const QString name = uniqueName + suffix; diff --git a/src/libs/vtools/dialogs/tools/dialogmove.cpp b/src/libs/vtools/dialogs/tools/dialogmove.cpp index 58fcda56f..69f4a911d 100644 --- a/src/libs/vtools/dialogs/tools/dialogmove.cpp +++ b/src/libs/vtools/dialogs/tools/dialogmove.cpp @@ -473,7 +473,7 @@ void DialogMove::SuffixChanged() if (m_suffix != suffix) { QRegularExpression rx(NameRegExp()); - const QStringList uniqueNames = VContainer::AllUniqueNames(); + const QStringList uniqueNames = data->AllUniqueNames(); for (auto &uniqueName : uniqueNames) { const QString name = uniqueName + suffix; diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 7caafe2d1..018f7ad21 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -335,7 +335,7 @@ void DialogRotation::SuffixChanged() if (m_suffix != suffix) { QRegularExpression rx(NameRegExp()); - const QStringList uniqueNames = VContainer::AllUniqueNames(); + const QStringList uniqueNames = data->AllUniqueNames(); for (auto &uniqueName : uniqueNames) { const QString name = uniqueName + suffix; diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp index 4ca9cfdb4..696b29d10 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -53,7 +53,7 @@ void VAbstractFlipping::CreateDestination(VAbstractOperationInitData &initData, { initData.destination.clear();// Try to avoid mistake, value must be empty - initData.id = VContainer::getNextId();//Just reserve id for tool + initData.id = initData.data->getNextId();//Just reserve id for tool for (auto idObject : qAsConst(initData.source)) { diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 0d9461f7d..ffcb79caf 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -197,7 +197,7 @@ VToolMove *VToolMove::Create(VToolMoveInitData &initData) { initData.destination.clear();// Try to avoid mistake, value must be empty - initData.id = VContainer::getNextId();//Just reserve id for tool + initData.id = initData.data->getNextId();//Just reserve id for tool for (auto idObject : qAsConst(initData.source)) { diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 353be5a85..44e71454f 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -142,7 +142,7 @@ VToolRotation *VToolRotation::Create(VToolRotationInitData &initData) { initData.destination.clear();// Try to avoid mistake, value must be empty - initData.id = VContainer::getNextId();//Just reserve id for tool + initData.id = initData.data->getNextId();//Just reserve id for tool for (auto idObject : qAsConst(initData.source)) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp index c36e26646..3835790da 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp @@ -162,7 +162,7 @@ VToolTrueDarts *VToolTrueDarts::Create(VToolTrueDartsInitData initData) if (initData.typeCreation == Source::FromGui) { - initData.id = VContainer::getNextId();//Just reserve id for tool + initData.id = initData.data->getNextId();//Just reserve id for tool initData.p1id = initData.data->AddGObject(p1); initData.p2id = initData.data->AddGObject(p2); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 129f4539c..3091a56d6 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -139,8 +139,8 @@ VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData) if (initData.typeCreation == Source::FromGui) { initData.id = initData.data->AddGObject(p); - a1->setId(VContainer::getNextId()); - a2->setId(VContainer::getNextId()); + a1->setId(initData.data->getNextId()); + a2->setId(initData.data->getNextId()); initData.data->AddArc(a1, a1->id(), initData.id); initData.data->AddArc(a2, a2->id(), initData.id); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index ae0bf77d8..34abae584 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -155,8 +155,8 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis initData.id = initData.data->AddGObject(p); initData.data->AddLine(initData.basePointId, initData.id); - VContainer::getNextId(); - VContainer::getNextId(); + initData.data->getNextId(); + initData.data->getNextId(); InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); } else diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index 324bcda90..a8452ea12 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -140,12 +140,12 @@ VToolLine * VToolLine::Create(VToolLineInitData initData) SCASSERT(initData.data != nullptr) if (initData.typeCreation == Source::FromGui) { - initData.id = VContainer::getNextId(); + initData.id = initData.data->getNextId(); initData.data->AddLine(initData.firstPoint, initData.secondPoint); } else { - VContainer::UpdateId(initData.id); + initData.data->UpdateId(initData.id); initData.data->AddLine(initData.firstPoint, initData.secondPoint); if (initData.parse != Document::FullParse) { diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index d3033aad1..ef9b10a11 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -1763,7 +1763,7 @@ VToolUnionDetails* VToolUnionDetails::Create(VToolUnionDetailsInitData initData) VToolUnionDetails *unionDetails = nullptr; if (initData.typeCreation == Source::FromGui) { - initData.id = VContainer::getNextId(); + initData.id = initData.data->getNextId(); } else { diff --git a/src/test/ValentinaTest/tst_vmeasurements.cpp b/src/test/ValentinaTest/tst_vmeasurements.cpp index 652cbb82b..69fd07b35 100644 --- a/src/test/ValentinaTest/tst_vmeasurements.cpp +++ b/src/test/ValentinaTest/tst_vmeasurements.cpp @@ -50,14 +50,13 @@ void TST_VMeasurements::CreateEmptyMultisizeFile() const int height = 176; const int size = 50; - QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); - VContainer::SetHeight(height); - VContainer::SetSize(size); + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit, + VContainer::UniqueNamespace())); + data->SetHeight(height); + data->SetSize(size); QSharedPointer m = QSharedPointer(new VMeasurements(mUnit, size, height, data.data())); - m->SetSize(VContainer::rsize()); - m->SetHeight(VContainer::rheight()); QTemporaryFile file; QString fileName; @@ -97,7 +96,8 @@ void TST_VMeasurements::CreateEmptyIndividualFile() { Unit mUnit = Unit::Cm; - QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit, + VContainer::UniqueNamespace())); QSharedPointer m = QSharedPointer(new VMeasurements(mUnit, data.data())); @@ -140,14 +140,13 @@ void TST_VMeasurements::ValidPMCodesMultisizeFile() const int height = 176; const int size = 50; - QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); - VContainer::SetHeight(height); - VContainer::SetSize(size); + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit, + VContainer::UniqueNamespace())); + data->SetHeight(height); + data->SetSize(size); QSharedPointer m = QSharedPointer(new VMeasurements(mUnit, size, height, data.data())); - m->SetSize(VContainer::rsize()); - m->SetHeight(VContainer::rheight()); const QStringList listSystems = ListPMSystems(); for (int i = 0; i < listSystems.size(); ++i) @@ -195,7 +194,8 @@ void TST_VMeasurements::ValidPMCodesIndividualFile() { Unit mUnit = Unit::Cm; - QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit, + VContainer::UniqueNamespace())); QSharedPointer m = QSharedPointer(new VMeasurements(mUnit, data.data())); diff --git a/src/test/ValentinaTest/tst_vpiece.cpp b/src/test/ValentinaTest/tst_vpiece.cpp index acb1d3257..e88f393b5 100644 --- a/src/test/ValentinaTest/tst_vpiece.cpp +++ b/src/test/ValentinaTest/tst_vpiece.cpp @@ -49,7 +49,7 @@ void TST_VPiece::ClearLoop() // See file /src/app/share/collection/jacketМ6_30-110.val // Check correct seam allowance const Unit unit = Unit::Mm; - QScopedPointer data(new VContainer(nullptr, &unit)); + QScopedPointer data(new VContainer(nullptr, &unit, VContainer::UniqueNamespace())); qApp->setPatternUnit(unit); data->UpdateGObject(304, new VPointF(61.866708661417327, 446.92270866141735, "Ф1", 5.0000125984251973, @@ -221,7 +221,7 @@ void TST_VPiece::Issue620() // See file /src/app/share/collection/bugs/Issue_#620.vit // Check main path const Unit unit = Unit::Cm; - QScopedPointer data(new VContainer(nullptr, &unit)); + QScopedPointer data(new VContainer(nullptr, &unit, VContainer::UniqueNamespace())); qApp->setPatternUnit(unit); data->UpdateGObject(1, new VPointF(30, 39.999874015748034, "A", 5.0000125984251973, 9.9999874015748045));