Resolved issue #929. New variable type: Separator.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-01-16 16:24:41 +02:00
parent 194aac3813
commit e91c92d4a9
18 changed files with 379 additions and 140 deletions

View File

@ -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.

View File

@ -44,6 +44,7 @@
#include <QSettings>
#include <QTableWidgetItem>
#include <QtNumeric>
#include <QMenu>
#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<VIncrement> incr = data->GetVariable<VIncrement>(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<VIncrement> incr = i.value();
const QSharedPointer<VIncrement>& 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<VIncrement> incr = increments.value(iMap.value());
currentRow++;
const QSharedPointer<VIncrement> &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<QToolButton *>(sender());
QTableWidget *table = nullptr;
auto *button = qobject_cast<QToolButton *>(sender());
auto *action = qobject_cast<QAction *>(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<QAction *>(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<QToolButton *>(sender());
auto *button = qobject_cast<QToolButton *>(sender());
QTableWidget *table = nullptr;
@ -1166,6 +1279,11 @@ void DialogIncrements::SaveIncrFormula()
}
QSharedPointer<VIncrement> incr = data->GetVariable<VIncrement>(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

View File

@ -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

View File

@ -35,9 +35,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Search preview calculations by term. &lt;/p&gt;&lt;p&gt;Prepend &amp;quot;/r/&amp;quot; to the front of the search string to search preview calculations by regex.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
@ -278,6 +275,9 @@
<iconset theme="list-add">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
@ -511,6 +511,9 @@
</item>
<item>
<widget class="QLineEdit" name="lineEditFindPC">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Search preview calculations by term. &lt;/p&gt;&lt;p&gt;Prepend &amp;quot;/r/&amp;quot; to the front of the search string to search preview calculations by regex.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="placeholderText">
<string>Search</string>
</property>
@ -720,6 +723,9 @@
<iconset theme="list-add">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
@ -756,7 +762,7 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelCalculated_2">
<widget class="QLabel" name="labelCalculatedPC">
<property name="text">
<string>Calculated value:</string>
</property>
@ -770,7 +776,7 @@
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelFormula_2">
<widget class="QLabel" name="labelFormulaPC">
<property name="text">
<string>Formula:</string>
</property>
@ -1202,8 +1208,8 @@
<tabstop>tableWidgetSplines</tabstop>
</tabstops>
<resources>
<include location="../../../libs/vmisc/share/resources/icon.qrc"/>
<include location="../../../libs/vmisc/share/resources/theme.qrc"/>
<include location="../../../libs/vmisc/share/resources/icon.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -1541,7 +1541,7 @@ void MainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int m
const QSharedPointer<VIncrement> incr = i.value();
if (incr->IsPreviewCalculation() == save)
{
map.insert(incr->getIndex(), i.key());
map.insert(incr->GetIndex(), i.key());
}
}

View File

@ -436,7 +436,10 @@ void VPattern::LiteParseIncrements()
emit SetEnabledGUI(true);
data->ClearUniqueIncrementNames();
Q_STATIC_ASSERT_X(static_cast<int>(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<quint32>(index), value, formula, ok,
desc);
VIncrement *increment = new VIncrement(data, name, type);
increment->SetIndex(static_cast<quint32>(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<int>(VarType::Unknown) == 8, "Check that you used all types");
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 9, "Check that you used all types");
QVector<VarType> 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);

View File

@ -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);

View File

@ -140,9 +140,10 @@
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="increment" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="description" type="xs:string"/>
<xs:attribute name="name" type="shortName" use="required"/>
<xs:attribute name="formula" type="xs:string" use="required"/>
<xs:attribute name="formula" type="xs:string"/>
<xs:attribute name="type" type="incrementType"/>
</xs:complexType>
</xs:element>
</xs:sequence>
@ -153,9 +154,10 @@
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="increment" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="description" type="xs:string"/>
<xs:attribute name="name" type="shortName" use="required"/>
<xs:attribute name="formula" type="xs:string" use="required"/>
<xs:attribute name="formula" type="xs:string"/>
<xs:attribute name="type" type="incrementType"/>
</xs:complexType>
</xs:element>
</xs:sequence>
@ -1096,4 +1098,10 @@
<xs:enumeration value="bs"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="incrementType">
<xs:restriction base="xs:string">
<xs:enumeration value="increment"/>
<xs:enumeration value="separator"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -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;
}

View File

@ -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;

View File

@ -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
{

View File

@ -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);

View File

@ -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<VContainer>(new VContainer(*data)))
VIncrementData(VContainer *data, IncrementType incrType)
: data(QSharedPointer<VContainer>(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<int>(VarType::Unknown) == 8, "Check that you used all types");
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 9, "Check that you used all types");
this->data->ClearVariables(QVector<VarType>({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<VContainer> data;
IncrementType incrType{IncrementType::Increment};
private:
VIncrementData &operator=(const VIncrementData &) Q_DECL_EQ_DELETE;

View File

@ -371,8 +371,9 @@ void VContainer::ClearForFullParse()
d->pieces->clear();
d->piecePaths->clear();
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 8, "Check that you used all types");
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 9, "Check that you used all types");
ClearVariables(QVector<VarType>({VarType::Increment,
VarType::IncrementSeparator,
VarType::LineAngle,
VarType::LineLength,
VarType::CurveLength,
@ -590,6 +591,22 @@ const QMap<QString, QSharedPointer<VIncrement> > VContainer::DataIncrements() co
return DataVar<VIncrement>(VarType::Increment);
}
//---------------------------------------------------------------------------------------------------------------------
const QMap<QString, QSharedPointer<VIncrement> > VContainer::DataIncrementsWithSeparators() const
{
QMap<QString, QSharedPointer<VIncrement> > increments = DataVar<VIncrement>(VarType::Increment);
QMap<QString, QSharedPointer<VIncrement> > separators = DataVar<VIncrement>(VarType::IncrementSeparator);
QMap<QString, QSharedPointer<VIncrement>>::const_iterator i = separators.constBegin();
while (i != separators.constEnd())
{
increments.insert(i.key(), i.value());
++i;
}
return increments;
}
//---------------------------------------------------------------------------------------------------------------------
const QMap<QString, QSharedPointer<VLengthLine> > VContainer::DataLengthLines() const
{

View File

@ -202,6 +202,7 @@ public:
const QMap<QString, QSharedPointer<VMeasurement> > DataMeasurements() const;
const QMap<QString, QSharedPointer<VIncrement> > DataIncrements() const;
const QMap<QString, QSharedPointer<VIncrement> > DataIncrementsWithSeparators() const;
const QMap<QString, QSharedPointer<VLengthLine> > DataLengthLines() const;
const QMap<QString, QSharedPointer<VCurveLength> > DataLengthCurves() const;
const QMap<QString, QSharedPointer<VCurveCLength> > DataCurvesCLength() const;

View File

@ -735,9 +735,12 @@ void DialogPiecePath::EvalWidth()
if (m_saWidth >= 0)
{
VContainer *locData = const_cast<VContainer *> (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();

View File

@ -2064,9 +2064,12 @@ void DialogSeamAllowance::EvalWidth()
if (m_saWidth >= 0)
{
VContainer *locData = const_cast<VContainer *> (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();

View File

@ -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)