diff --git a/ChangeLog.txt b/ChangeLog.txt index 4d392008b..adb80ad8d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,7 @@ - New command line option --landscapeOrientation. - Added ability to search measurements by regex. - [#927] Freeze prefix language on pattern/project creation. +- [#929] New variable type: Separator. # Version 0.6.2 (unreleased) - [#903] Bug in tool Cut Spline path. diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index 6b9dc2d9a..8eb1c8ce1 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #define DIALOG_MAX_FORMULA_HEIGHT 64 @@ -107,16 +108,18 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); ui->tabWidget->setCurrentIndex(0); - ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression( - QLatin1String("^$|")+NameRegExp()), this)); - ui->lineEditNamePC->setValidator( new QRegularExpressionValidator(QRegularExpression( - QLatin1String("^$|")+NameRegExp()), this)); + auto validator = new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^$|")+NameRegExp()), this); + ui->lineEditName->setValidator(validator); + ui->lineEditNamePC->setValidator(validator); connect(ui->tableWidgetIncrement, &QTableWidget::itemSelectionChanged, this, &DialogIncrements::ShowIncrementDetails); connect(ui->tableWidgetPC, &QTableWidget::itemSelectionChanged, this, &DialogIncrements::ShowIncrementDetails); + InitIncrementVarTypeMenu(); + InitPreviewCalculationVarTypeMenu(); + connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogIncrements::AddIncrement); connect(ui->toolButtonAddPC, &QToolButton::clicked, this, &DialogIncrements::AddIncrement); connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogIncrements::RemoveIncrement); @@ -181,13 +184,13 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par */ void DialogIncrements::FillIncrements(bool freshCall) { - FillIncrementsTable(ui->tableWidgetIncrement, data->DataIncrements(), false, freshCall); + FillIncrementsTable(ui->tableWidgetIncrement, data->DataIncrementsWithSeparators(), false, freshCall); } //--------------------------------------------------------------------------------------------------------------------- void DialogIncrements::FillPreviewCalculations(bool freshCall) { - FillIncrementsTable(ui->tableWidgetPC, data->DataIncrements(), true, freshCall); + FillIncrementsTable(ui->tableWidgetPC, data->DataIncrementsWithSeparators(), true, freshCall); } //--------------------------------------------------------------------------------------------------------------------- @@ -553,6 +556,33 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->plainTextEditDescriptionPC->setEnabled(enabled); ui->plainTextEditFormulaPC->setEnabled(enabled); } + + if (table->rowCount() > 0) + { + const QTableWidgetItem *nameField = table->item(table->currentRow(), 0); + SCASSERT(nameField != nullptr) + QSharedPointer incr = data->GetVariable(nameField->text()); + const bool isSeparator = incr->GetIncrementType() == IncrementType::Separator; + + if (table == ui->tableWidgetIncrement) + { + ui->labelCalculated->setVisible(not isSeparator); + ui->labelCalculatedValue->setVisible(not isSeparator); + ui->labelFormula->setVisible(not isSeparator); + ui->plainTextEditFormula->setVisible(not isSeparator); + ui->pushButtonGrow->setVisible(not isSeparator); + ui->toolButtonExpr->setVisible(not isSeparator); + } + else if (table == ui->tableWidgetPC) + { + ui->labelCalculatedPC->setVisible(not isSeparator); + ui->labelCalculatedValuePC->setVisible(not isSeparator); + ui->labelFormulaPC->setVisible(not isSeparator); + ui->plainTextEditFormulaPC->setVisible(not isSeparator); + ui->pushButtonGrowPC->setVisible(not isSeparator); + ui->toolButtonExprPC->setVisible(not isSeparator); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -692,6 +722,54 @@ void DialogIncrements::ShowTableIncrementDetails(QTableWidget *table) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::InitIncrementVarTypeMenu() +{ + auto varTypeMenu = ui->toolButtonAdd->menu(); + if (varTypeMenu == nullptr) + { + varTypeMenu = new QMenu(this); + } + else + { + varTypeMenu->clear(); + } + + QAction *action = varTypeMenu->addAction(tr("Increment")); + action->setData(true); // Increments tab + connect(action, &QAction::triggered, this, &DialogIncrements::AddIncrement); + + action = varTypeMenu->addAction(tr("Separator")); + action->setData(true); // Increments tab + connect(action, &QAction::triggered, this, &DialogIncrements::AddSeparator); + + ui->toolButtonAdd->setMenu(varTypeMenu); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::InitPreviewCalculationVarTypeMenu() +{ + auto varTypeMenu = ui->toolButtonAddPC->menu(); + if (varTypeMenu == nullptr) + { + varTypeMenu = new QMenu(this); + } + else + { + varTypeMenu->clear(); + } + + QAction *action = varTypeMenu->addAction(tr("Preview calculation")); + action->setData(false); // Preview calculation tab + connect(action, &QAction::triggered, this, &DialogIncrements::AddIncrement); + + action = varTypeMenu->addAction(tr("Separator")); + action->setData(false); // Preview calculation tab + connect(action, &QAction::triggered, this, &DialogIncrements::AddSeparator); + + ui->toolButtonAddPC->setMenu(varTypeMenu); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update information in tables form file @@ -765,10 +843,10 @@ void DialogIncrements::FillIncrementsTable(QTableWidget *table, //Sorting QHash by id for (i = increments.constBegin(); i != increments.constEnd(); ++i) { - QSharedPointer incr = i.value(); + const QSharedPointer& incr = i.value(); if (takePreviewCalculations == incr->IsPreviewCalculation()) { - map.insert(incr->getIndex(), i.key()); + map.insert(incr->GetIndex(), i.key()); } } @@ -778,16 +856,30 @@ void DialogIncrements::FillIncrementsTable(QTableWidget *table, while (iMap.hasNext()) { iMap.next(); - QSharedPointer incr = increments.value(iMap.value()); - currentRow++; + const QSharedPointer &incr = increments.value(iMap.value()); + ++currentRow; - AddCell(table, incr->GetName(), currentRow, 0, Qt::AlignVCenter); // name - AddCell(table, qApp->LocaleToString(*incr->GetValue()), currentRow, 1, - Qt::AlignHCenter | Qt::AlignVCenter, incr->IsFormulaOk()); // calculated value + if (incr->GetType() == VarType::Increment) + { + AddCell(table, incr->GetName(), currentRow, 0, Qt::AlignVCenter); // name + AddCell(table, qApp->LocaleToString(*incr->GetValue()), currentRow, 1, Qt::AlignCenter, + incr->IsFormulaOk()); // calculated value - QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator()); + QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator()); - AddCell(table, formula, currentRow, 2, Qt::AlignVCenter); // formula + AddCell(table, formula, currentRow, 2, Qt::AlignVCenter); // formula + + if (table->columnSpan(currentRow, 1) > 1) + { + table->setSpan(currentRow, 1, 1, 1); + } + } + else if (incr->GetType() == VarType::IncrementSeparator) + { + AddCell(table, incr->GetName(), currentRow, 0, Qt::AlignVCenter); // name + AddCell(table, incr->GetDescription(), currentRow, 1, Qt::AlignCenter); // name + table->setSpan(currentRow, 1, 1, 2); + } } if (freshCall) @@ -807,51 +899,80 @@ void DialogIncrements::AddIncrement() { qCDebug(vDialog, "Add new increment"); - QToolButton *button = qobject_cast(sender()); - QTableWidget *table = nullptr; + auto *button = qobject_cast(sender()); + auto *action = qobject_cast(sender()); + bool incrementMode = true; - if (button == ui->toolButtonAdd) + if (button == ui->toolButtonAdd || ((action != nullptr) && action->data().toBool())) { - table = ui->tableWidgetIncrement; + incrementMode = true; } - else if (button == ui->toolButtonAddPC) + else if (button == ui->toolButtonAddPC || ((action != nullptr) && not action->data().toBool())) { - table = ui->tableWidgetPC; + incrementMode = false; } else { return; } + QTableWidget *table = incrementMode ? ui->tableWidgetIncrement : ui->tableWidgetPC; + const QString name = GetCustomName(); qint32 currentRow = -1; if (table->currentRow() == -1) { currentRow = table->rowCount(); - - if (button == ui->toolButtonAdd) - { - doc->AddEmptyIncrement(name); - } - else if (button == ui->toolButtonAddPC) - { - doc->AddEmptyPreviewCalculation(name); - } + incrementMode ? doc->AddEmptyIncrement(name) : doc->AddEmptyPreviewCalculation(name); } else { currentRow = table->currentRow()+1; const QTableWidgetItem *nameField = table->item(table->currentRow(), 0); - if (button == ui->toolButtonAdd) - { - doc->AddEmptyIncrementAfter(nameField->text(), name); - } - else if (button == ui->toolButtonAddPC) - { - doc->AddEmptyPreviewCalculationAfter(nameField->text(), name); - } + incrementMode ? doc->AddEmptyIncrementAfter(nameField->text(), name) : + doc->AddEmptyPreviewCalculationAfter(nameField->text(), name); + } + + hasChanges = true; + LocalUpdateTree(); + + table->selectRow(currentRow); + table->repaint(); // Force repain to fix paint artifacts on Mac OS X +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::AddSeparator() +{ + qCDebug(vDialog, "Add new increment"); + + auto *action = qobject_cast(sender()); + if (action == nullptr) + { + return; + } + + const bool incrementMode = action->data().toBool(); + + QTableWidget *table = incrementMode ? ui->tableWidgetIncrement : ui->tableWidgetPC; + + const QString name = GetCustomName(); + qint32 currentRow = -1; + const IncrementType type = IncrementType::Separator; + + if (table->currentRow() == -1) + { + currentRow = table->rowCount(); + incrementMode ? doc->AddEmptyIncrement(name, type) : doc->AddEmptyPreviewCalculation(name, type); + } + else + { + currentRow = table->currentRow()+1; + const QTableWidgetItem *nameField = table->item(table->currentRow(), 0); + + incrementMode ? doc->AddEmptyIncrementAfter(nameField->text(), name, type) : + doc->AddEmptyPreviewCalculationAfter(nameField->text(), name, type); } hasChanges = true; @@ -905,22 +1026,14 @@ void DialogIncrements::RemoveIncrement() hasChanges = true; LocalUpdateTree(); - if (table->rowCount() > 0) - { - table->selectRow(0); - } - else - { - EnableDetails(table, false); - } - + table->rowCount() > 0 ? table->selectRow(0) : EnableDetails(table, false); table->repaint(); // Force repain to fix paint artifacts on Mac OS X } //--------------------------------------------------------------------------------------------------------------------- void DialogIncrements::MoveUp() { - QToolButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); QTableWidget *table = nullptr; @@ -1166,6 +1279,11 @@ void DialogIncrements::SaveIncrFormula() } QSharedPointer incr = data->GetVariable(nameField->text()); + if (incr->GetIncrementType() == IncrementType::Separator) + { + return; + } + if (not EvalIncrementFormula(text, true, incr->GetData(), labelCalculatedValue)) { return; @@ -1334,6 +1452,8 @@ void DialogIncrements::changeEvent(QEvent *event) { // retranslate designer form (single inheritance approach) ui->retranslateUi(this); + InitIncrementVarTypeMenu(); + InitPreviewCalculationVarTypeMenu(); FullUpdateFromFile(); } // remember to call base class implementation diff --git a/src/app/valentina/dialogs/dialogincrements.h b/src/app/valentina/dialogs/dialogincrements.h index ec3a549f4..23e57d31c 100644 --- a/src/app/valentina/dialogs/dialogincrements.h +++ b/src/app/valentina/dialogs/dialogincrements.h @@ -69,6 +69,7 @@ protected: private slots: void ShowIncrementDetails(); void AddIncrement(); + void AddSeparator(); void RemoveIncrement(); void MoveUp(); void MoveDown(); @@ -139,6 +140,9 @@ private: void CacheRename(const QString &name, const QString &newName); void ShowTableIncrementDetails(QTableWidget *table); + + void InitIncrementVarTypeMenu(); + void InitPreviewCalculationVarTypeMenu(); }; #endif // DIALOGINCREMENTS_H diff --git a/src/app/valentina/dialogs/dialogincrements.ui b/src/app/valentina/dialogs/dialogincrements.ui index fb795ba48..2b7129469 100644 --- a/src/app/valentina/dialogs/dialogincrements.ui +++ b/src/app/valentina/dialogs/dialogincrements.ui @@ -35,9 +35,6 @@ 0 - - <html><head/><body><p>Search preview calculations by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search preview calculations by regex.</p></body></html> - QTabWidget::North @@ -278,6 +275,9 @@ .. + + QToolButton::MenuButtonPopup + @@ -511,6 +511,9 @@ + + <html><head/><body><p>Search preview calculations by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search preview calculations by regex.</p></body></html> + Search @@ -720,6 +723,9 @@ .. + + QToolButton::MenuButtonPopup + @@ -756,7 +762,7 @@ - + Calculated value: @@ -770,7 +776,7 @@ - + Formula: @@ -1202,8 +1208,8 @@ tableWidgetSplines - + diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 002d57d03..fc66310de 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1541,7 +1541,7 @@ void MainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int m const QSharedPointer incr = i.value(); if (incr->IsPreviewCalculation() == save) { - map.insert(incr->getIndex(), i.key()); + map.insert(incr->GetIndex(), i.key()); } } diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index cdb73f75f..2b6ecad33 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -436,7 +436,10 @@ void VPattern::LiteParseIncrements() emit SetEnabledGUI(true); data->ClearUniqueIncrementNames(); + + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 9, "Check that you used all types"); data->ClearVariables(VarType::Increment); + data->ClearVariables(VarType::IncrementSeparator); QDomNodeList tags = elementsByTagName(TagIncrements); if (not tags.isEmpty()) @@ -3294,12 +3297,14 @@ qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPattern::MakeEmptyIncrement(const QString &name) +QDomElement VPattern::MakeEmptyIncrement(const QString &name, IncrementType type) { QDomElement element = createElement(TagIncrement); SetAttribute(element, AttrName, name); - SetAttribute(element, AttrFormula, QChar('0')); - SetAttribute(element, AttrDescription, QString()); + if (type != IncrementType::Increment) + { + SetAttribute(element, AttrType, IncrementTypeToString(type)); + } return element; } @@ -3311,7 +3316,7 @@ QDomElement VPattern::FindIncrement(const QString &name) const for (int i=0; i < list.size(); ++i) { const QDomElement domElement = list.at(i).toElement(); - if (domElement.isNull() == false) + if (not domElement.isNull()) { const QString parameter = domElement.attribute(AttrName); if (parameter == name) @@ -3374,9 +3379,9 @@ void VPattern::GarbageCollector(bool commit) } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::NewEmptyIncrement(const QString &type, const QString &name) +void VPattern::NewEmptyIncrement(const QString &type, const QString &name, IncrementType varType) { - const QDomElement element = MakeEmptyIncrement(name); + const QDomElement element = MakeEmptyIncrement(name, varType); const QDomNodeList list = elementsByTagName(type); list.at(0).appendChild(element); @@ -3384,9 +3389,10 @@ void VPattern::NewEmptyIncrement(const QString &type, const QString &name) } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::NewEmptyIncrementAfter(const QString &type, const QString &after, const QString &name) +void VPattern::NewEmptyIncrementAfter(const QString &type, const QString &after, const QString &name, + IncrementType varType) { - const QDomElement element = MakeEmptyIncrement(name); + const QDomElement element = MakeEmptyIncrement(name, varType); const QDomElement sibling = FindIncrement(after); const QDomNodeList list = elementsByTagName(type); @@ -3763,26 +3769,31 @@ void VPattern::ParseIncrementsElement(const QDomNode &node, const Document &pars { int index = 0; QDomNode domNode = node.firstChild(); - while (domNode.isNull() == false) + while (not domNode.isNull()) { if (domNode.isElement()) { const QDomElement domElement = domNode.toElement(); - if (domElement.isNull() == false) + if (not domElement.isNull()) { if (domElement.tagName() == TagIncrement) { const QString name = GetParametrString(domElement, AttrName, QString()); const QString desc = GetParametrEmptyString(domElement, AttrDescription); - const QString formula = GetParametrString(domElement, AttrFormula, QChar('0')); + const IncrementType type = StringToIncrementType(GetParametrString(domElement, AttrType, + strTypeIncrement)); + const QString formula = (type == IncrementType::Separator) ? + QChar('0') : GetParametrString(domElement, AttrFormula, QChar('0')); + bool ok = false; const qreal value = EvalFormula(data, formula, &ok); - VIncrement *increment = new VIncrement(data, name, static_cast(index), value, formula, ok, - desc); + VIncrement *increment = new VIncrement(data, name, type); + increment->SetIndex(static_cast(index++)); + increment->SetFormula(value, formula, ok); + increment->SetDescription(desc); increment->SetPreviewCalculation(node.toElement().tagName() == TagPreviewCalculations); data->AddVariable(name, increment); - ++index; } } } @@ -3796,27 +3807,27 @@ void VPattern::ParseIncrementsElement(const QDomNode &node, const Document &pars } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::AddEmptyIncrement(const QString &name) +void VPattern::AddEmptyIncrement(const QString &name, IncrementType type) { - NewEmptyIncrement(TagIncrements, name); + NewEmptyIncrement(TagIncrements, name, type); } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::AddEmptyPreviewCalculation(const QString &name) +void VPattern::AddEmptyPreviewCalculation(const QString &name, IncrementType type) { - NewEmptyIncrement(TagPreviewCalculations, name); + NewEmptyIncrement(TagPreviewCalculations, name, type); } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::AddEmptyIncrementAfter(const QString &after, const QString &name) +void VPattern::AddEmptyIncrementAfter(const QString &after, const QString &name, IncrementType type) { - NewEmptyIncrementAfter(TagIncrements, after, name); + NewEmptyIncrementAfter(TagIncrements, after, name, type); } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::AddEmptyPreviewCalculationAfter(const QString &after, const QString &name) +void VPattern::AddEmptyPreviewCalculationAfter(const QString &after, const QString &name, IncrementType type) { - NewEmptyIncrementAfter(TagPreviewCalculations, after, name); + NewEmptyIncrementAfter(TagPreviewCalculations, after, name, type); } //--------------------------------------------------------------------------------------------------------------------- @@ -4273,7 +4284,7 @@ void VPattern::PrepareForParse(const Document &parse) } else if (parse == Document::LiteParse || parse == Document::FullLiteParse) { - Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 9, "Check that you used all types"); QVector types({VarType::LineAngle, VarType::LineLength, VarType::CurveLength, @@ -4283,6 +4294,7 @@ void VPattern::PrepareForParse(const Document &parse) if (parse == Document::FullLiteParse) { types.append(VarType::Increment); + types.append(VarType::IncrementSeparator); } data->ClearVariables(types); diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 7bfb3fa40..4c35a5707 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -72,11 +72,13 @@ public: QRectF ActiveDrawBoundingRect() const; - void AddEmptyIncrement(const QString &name); - void AddEmptyPreviewCalculation(const QString &name); + void AddEmptyIncrement(const QString &name, IncrementType type = IncrementType::Increment); + void AddEmptyPreviewCalculation(const QString &name, IncrementType type = IncrementType::Increment); - void AddEmptyIncrementAfter(const QString &after, const QString &name); - void AddEmptyPreviewCalculationAfter(const QString &after, const QString &name); + void AddEmptyIncrementAfter(const QString &after, const QString &name, + IncrementType type = IncrementType::Increment); + void AddEmptyPreviewCalculationAfter(const QString &after, const QString &name, + IncrementType type = IncrementType::Increment); void RemoveIncrement(const QString &name); void RemovePreviewCalculation(const QString &name); @@ -240,11 +242,11 @@ private: qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; - QDomElement MakeEmptyIncrement(const QString &name); + QDomElement MakeEmptyIncrement(const QString &name, IncrementType type); QDomElement FindIncrement(const QString &name) const; - void NewEmptyIncrement(const QString &type, const QString &name); - void NewEmptyIncrementAfter(const QString &type, const QString &after, const QString &name); + void NewEmptyIncrement(const QString &type, const QString &name, IncrementType varType); + void NewEmptyIncrementAfter(const QString &type, const QString &after, const QString &name, IncrementType varType); void RemoveIncrement(const QString &type, const QString &name); void MoveUpIncrement(const QString &type, const QString &name); void MoveDownIncrement(const QString &type, const QString &name); diff --git a/src/libs/ifc/schema/pattern/v0.8.0.xsd b/src/libs/ifc/schema/pattern/v0.8.0.xsd index 6f753570e..c7337ffba 100644 --- a/src/libs/ifc/schema/pattern/v0.8.0.xsd +++ b/src/libs/ifc/schema/pattern/v0.8.0.xsd @@ -140,9 +140,10 @@ - + - + + @@ -153,9 +154,10 @@ - + - + + @@ -1096,4 +1098,10 @@ + + + + + + diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 1fda7e933..2709057f8 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -541,14 +541,16 @@ PassmarkLineType StringToPassmarkLineType(const QString &value) return PassmarkLineType::OneLine; } -const QString strStraightforward = QStringLiteral("straightforward"); -const QString strBisector = QStringLiteral("bisector"); -const QString strIntersection = QStringLiteral("intersection"); -const QString strIntersectionOnlyLeft = QStringLiteral("intersectionLeft"); -const QString strIntersectionOnlyRight = QStringLiteral("intersectionRight"); +const QString strStraightforward = QStringLiteral("straightforward"); +const QString strBisector = QStringLiteral("bisector"); +const QString strIntersection = QStringLiteral("intersection"); +const QString strIntersectionOnlyLeft = QStringLiteral("intersectionLeft"); +const QString strIntersectionOnlyRight = QStringLiteral("intersectionRight"); const QString strIntersection2 = QStringLiteral("intersection2"); const QString strIntersection2OnlyLeft = QStringLiteral("intersection2Left"); const QString strIntersection2OnlyRight = QStringLiteral("intersection2Right"); +const QString strTypeIncrement = QStringLiteral("increment"); +const QString strTypeSeparator = QStringLiteral("separator"); //--------------------------------------------------------------------------------------------------------------------- QString PassmarkAngleTypeToString(PassmarkAngleType type) @@ -743,3 +745,36 @@ QDataStream &operator>>(QDataStream &in, CustomSARecord &record) in >> record.includeType; return in; } + +//--------------------------------------------------------------------------------------------------------------------- +QString IncrementTypeToString(IncrementType type) +{ + switch(type) + { + case IncrementType::Increment: + return strTypeIncrement; + case IncrementType::Separator: + return strTypeSeparator; + default: + break; + } + + return strTypeIncrement; +} + +//--------------------------------------------------------------------------------------------------------------------- +IncrementType StringToIncrementType(const QString &value) +{ + const QStringList values { strTypeIncrement, strTypeSeparator }; + + switch(values.indexOf(value)) + { + case 0: + return IncrementType::Increment; + case 1: + return IncrementType::Separator; + default: + break; + } + return IncrementType::Increment; +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index db6a8fd11..8bf56379c 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -262,8 +262,13 @@ enum class Vis : ToolVisHolderType LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; -enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle, - ArcRadius, Unknown }; +enum class VarType : char { Measurement, Increment, IncrementSeparator, LineLength, CurveLength, CurveCLength, + LineAngle, CurveAngle, ArcRadius, Unknown }; + +enum class IncrementType : char { Increment, Separator }; + +QString IncrementTypeToString(IncrementType type); +IncrementType StringToIncrementType(const QString &value); static const int heightStep = 6; enum class GHeights : unsigned char { ALL, @@ -433,6 +438,8 @@ extern const QString strIntersectionOnlyRight; extern const QString strIntersection2; extern const QString strIntersection2OnlyLeft; extern const QString strIntersection2OnlyRight; +extern const QString strTypeIncrement; +extern const QString strTypeSeparator; extern const QString unitMM; extern const QString unitCM; diff --git a/src/libs/vpatterndb/variables/vincrement.cpp b/src/libs/vpatterndb/variables/vincrement.cpp index 0f1cae2f2..7ddd68a97 100644 --- a/src/libs/vpatterndb/variables/vincrement.cpp +++ b/src/libs/vpatterndb/variables/vincrement.cpp @@ -46,15 +46,11 @@ VIncrement::VIncrement() /** * @brief VIncrementTableRow create increment * @param name increment's name - * @param base value - * @param description description of increment */ -VIncrement::VIncrement(VContainer *data, const QString &name, quint32 index, qreal base, const QString &formula, - bool ok, const QString &description) - :VVariable(name, description), d(new VIncrementData(data, index, formula, ok)) +VIncrement::VIncrement(VContainer *data, const QString &name, IncrementType incrType) + :VVariable(name, QString()), d(new VIncrementData(data, incrType)) { - SetType(VarType::Increment); - VInternalVariable::SetValue(base); + incrType == IncrementType::Separator ? SetType(VarType::IncrementSeparator) : SetType(VarType::Increment); } //--------------------------------------------------------------------------------------------------------------------- @@ -84,11 +80,19 @@ VIncrement::~VIncrement() * using. * @return index */ -quint32 VIncrement::getIndex() const +quint32 VIncrement::GetIndex() const { return d->index; } +//--------------------------------------------------------------------------------------------------------------------- +void VIncrement::SetFormula(qreal base, const QString &formula, bool ok) +{ + VInternalVariable::SetValue(base); + d->formula = formula; + d->formulaOk = ok; +} + //--------------------------------------------------------------------------------------------------------------------- QString VIncrement::GetFormula() const { @@ -101,12 +105,24 @@ bool VIncrement::IsFormulaOk() const return d->formulaOk; } +//--------------------------------------------------------------------------------------------------------------------- +void VIncrement::SetIndex(quint32 index) +{ + d->index = index; +} + //--------------------------------------------------------------------------------------------------------------------- VContainer *VIncrement::GetData() { return d->data.data(); } +//--------------------------------------------------------------------------------------------------------------------- +IncrementType VIncrement::GetIncrementType() const +{ + return d->incrType; +} + //--------------------------------------------------------------------------------------------------------------------- bool VIncrement::IsPreviewCalculation() const { diff --git a/src/libs/vpatterndb/variables/vincrement.h b/src/libs/vpatterndb/variables/vincrement.h index dc430d3b3..10c5fcd6a 100644 --- a/src/libs/vpatterndb/variables/vincrement.h +++ b/src/libs/vpatterndb/variables/vincrement.h @@ -47,8 +47,7 @@ class VIncrement :public VVariable { public: VIncrement(); - VIncrement(VContainer *data, const QString &name, quint32 index, qreal base, const QString &formula, bool ok, - const QString &description = QString()); + VIncrement(VContainer *data, const QString &name, IncrementType incrType = IncrementType::Increment); VIncrement(const VIncrement &incr); virtual ~VIncrement() override; @@ -61,10 +60,15 @@ public: inline void Swap(VIncrement &incr) Q_DECL_NOTHROW { VVariable::Swap(incr); std::swap(d, incr.d); } - quint32 getIndex() const; - QString GetFormula() const; - bool IsFormulaOk() const; - VContainer *GetData(); + void SetFormula(qreal base, const QString &formula, bool ok); + QString GetFormula() const; + bool IsFormulaOk() const; + + void SetIndex(quint32 index); + quint32 GetIndex() const; + + VContainer *GetData(); + IncrementType GetIncrementType() const; bool IsPreviewCalculation() const; void SetPreviewCalculation(bool value); diff --git a/src/libs/vpatterndb/variables/vincrement_p.h b/src/libs/vpatterndb/variables/vincrement_p.h index 4a8c9daf3..de96bc9a7 100644 --- a/src/libs/vpatterndb/variables/vincrement_p.h +++ b/src/libs/vpatterndb/variables/vincrement_p.h @@ -44,29 +44,24 @@ class VIncrementData : public QSharedData public: VIncrementData() - : index(NULL_ID), - formula(QString()), - formulaOk(false), - previewCalculation(false), - data() + : index(NULL_ID) {} - VIncrementData(VContainer *data, quint32 index, const QString &formula, bool ok) - : index(index), - formula(formula), - formulaOk(ok), - previewCalculation(false), - data(QSharedPointer(new VContainer(*data))) + VIncrementData(VContainer *data, IncrementType incrType) + : data(QSharedPointer(new VContainer(*data))), + incrType(incrType) { // 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"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 9, "Check that you used all types"); this->data->ClearVariables(QVector({VarType::LineAngle, VarType::LineLength, VarType::CurveLength, VarType::CurveCLength, VarType::ArcRadius, - VarType::CurveAngle})); + VarType::CurveAngle, + VarType::IncrementSeparator + })); } VIncrementData(const VIncrementData &incr) @@ -75,7 +70,8 @@ public: formula(incr.formula), formulaOk(incr.formulaOk), previewCalculation(incr.previewCalculation), - data(incr.data) + data(incr.data), + incrType(incr.incrType) {} virtual ~VIncrementData(); @@ -83,9 +79,10 @@ public: /** @brief id each increment have unique identificator */ quint32 index; QString formula; - bool formulaOk; - bool previewCalculation; + bool formulaOk{false}; + bool previewCalculation{false}; QSharedPointer data; + IncrementType incrType{IncrementType::Increment}; private: VIncrementData &operator=(const VIncrementData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index e91e73ead..d39477386 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -371,8 +371,9 @@ void VContainer::ClearForFullParse() d->pieces->clear(); d->piecePaths->clear(); - Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 9, "Check that you used all types"); ClearVariables(QVector({VarType::Increment, + VarType::IncrementSeparator, VarType::LineAngle, VarType::LineLength, VarType::CurveLength, @@ -590,6 +591,22 @@ const QMap > VContainer::DataIncrements() co return DataVar(VarType::Increment); } +//--------------------------------------------------------------------------------------------------------------------- +const QMap > VContainer::DataIncrementsWithSeparators() const +{ + QMap > increments = DataVar(VarType::Increment); + QMap > separators = DataVar(VarType::IncrementSeparator); + + QMap>::const_iterator i = separators.constBegin(); + while (i != separators.constEnd()) + { + increments.insert(i.key(), i.value()); + ++i; + } + + return increments; +} + //--------------------------------------------------------------------------------------------------------------------- const QMap > VContainer::DataLengthLines() const { diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index e50961d7d..40ce97d79 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -202,6 +202,7 @@ public: const QMap > DataMeasurements() const; const QMap > DataIncrements() const; + const QMap > DataIncrementsWithSeparators() const; const QMap > DataLengthLines() const; const QMap > DataLengthCurves() const; const QMap > DataCurvesCLength() const; diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp index e3d922297..80646002c 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp @@ -735,9 +735,12 @@ void DialogPiecePath::EvalWidth() if (m_saWidth >= 0) { VContainer *locData = const_cast (data); - locData->AddVariable(currentSeamAllowance, new VIncrement(locData, currentSeamAllowance, 0, m_saWidth, - QString().setNum(m_saWidth), true, - tr("Current seam aloowance"))); + + auto currentSA = new VIncrement(locData, currentSeamAllowance); + currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true); + currentSA->SetDescription(tr("Current seam allowance")); + + locData->AddVariable(currentSeamAllowance, currentSA); EvalWidthBefore(); EvalWidthAfter(); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index e5f00b155..575eb416f 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -2064,9 +2064,12 @@ void DialogSeamAllowance::EvalWidth() if (m_saWidth >= 0) { VContainer *locData = const_cast (data); - locData->AddVariable(currentSeamAllowance, new VIncrement(locData, currentSeamAllowance, 0, m_saWidth, - QString().setNum(m_saWidth), true, - tr("Current seam allowance"))); + + auto currentSA = new VIncrement(locData, currentSeamAllowance); + currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true); + currentSA->SetDescription(tr("Current seam allowance")); + + locData->AddVariable(currentSeamAllowance, currentSA); EvalWidthBefore(); EvalWidthAfter(); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index b92d4a731..d18921bc5 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -116,10 +116,11 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD { if (initData.typeCreation == Source::FromGui || initData.typeCreation == Source::FromTool) { - initData.data->AddVariable(currentSeamAllowance, new VIncrement(initData.data, currentSeamAllowance, 0, - initData.detail.GetSAWidth(), - initData.width, true, - tr("Current seam allowance"))); + auto currentSA = new VIncrement(initData.data, currentSeamAllowance); + currentSA->SetFormula(initData.detail.GetSAWidth(), initData.width, true); + currentSA->SetDescription(tr("Current seam allowance")); + + initData.data->AddVariable(currentSeamAllowance, currentSA); initData.id = initData.data->AddPiece(initData.detail); } else @@ -127,9 +128,11 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD const qreal calcWidth = CheckFormula(initData.id, initData.width, initData.data); initData.detail.SetFormulaSAWidth(initData.width, calcWidth); - initData.data->AddVariable(currentSeamAllowance, new VIncrement(initData.data, currentSeamAllowance, 0, - calcWidth, initData.width, true, - tr("Current seam allowance"))); + auto currentSA = new VIncrement(initData.data, currentSeamAllowance); + currentSA->SetFormula(calcWidth, initData.width, true); + currentSA->SetDescription(tr("Current seam allowance")); + + initData.data->AddVariable(currentSeamAllowance, currentSA); initData.data->UpdatePiece(initData.id, initData.detail); if (initData.parse != Document::FullParse)