User should be able to rename increments.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-08-08 17:43:41 +03:00
parent 6b29b8c528
commit 16ec3a3ea8
8 changed files with 267 additions and 305 deletions

View File

@ -61,7 +61,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
doc(doc), doc(doc),
formulaBaseHeight(0), formulaBaseHeight(0),
search(), search(),
hasChanges(false) hasChanges(false),
renameList()
{ {
ui->setupUi(this); ui->setupUi(this);
@ -466,6 +467,64 @@ void DialogIncrements::LocalUpdateTree()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::UpdateTree() void DialogIncrements::UpdateTree()
{ {
FillIncrements();
search->RefreshList(ui->lineEditFind->text());
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogIncrements::IncrementUsed(const QString &name) const
{
const QVector<VFormulaField> expressions = doc->ListExpressions();
for(int i = 0; i < expressions.size(); ++i)
{
if (expressions.at(i).expression.indexOf(name) != -1)
{
// Eval formula
try
{
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i).expression, false,
false));
// Tokens (variables, measurements)
if (cal->GetTokens().values().contains(name))
{
return true;
}
}
catch (const qmu::QmuParserError &)
{
// Do nothing. Because we not sure if used. A formula is broken.
}
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::CacheRename(const QString &name, const QString &newName)
{
for (int i = 0; i < renameList.size(); ++i)
{
if (renameList.at(i).second == name)
{
renameList[i].second = newName;
return;
}
}
renameList.append(qMakePair(name, newName));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FullUpdateFromFile update information in tables form file
*/
void DialogIncrements::FullUpdateFromFile()
{
hasChanges = false;
ui->tableWidgetLines->clearContents(); ui->tableWidgetLines->clearContents();
ui->tableWidgetSplines->clearContents(); ui->tableWidgetSplines->clearContents();
ui->tableWidgetAnglesCurves->clearContents(); ui->tableWidgetAnglesCurves->clearContents();
@ -483,51 +542,18 @@ void DialogIncrements::UpdateTree()
search->RefreshList(ui->lineEditFind->text()); search->RefreshList(ui->lineEditFind->text());
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogIncrements::IncrementUsed(const QString &name) const
{
const QStringList expressions = doc->ListExpressions();
for(int i = 0; i < expressions.size(); ++i)
{
if (expressions.at(i).indexOf(name) != -1)
{
// Eval formula
try
{
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i), false, false));
// Tokens (variables, measurements)
if (cal->GetTokens().values().contains(name))
{
return true;
}
}
catch (const qmu::QmuParserError &)
{
// Do nothing. Because we not sure if used. A formula is broken.
}
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FullUpdateFromFile update information in tables form file
*/
void DialogIncrements::FullUpdateFromFile()
{
hasChanges = false;
UpdateTree();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::RefreshPattern() void DialogIncrements::RefreshPattern()
{ {
if (hasChanges) if (hasChanges)
{ {
QVector<VFormulaField> expressions = doc->ListExpressions();
for (int i = 0; i < renameList.size(); ++i)
{
doc->ReplaceNameInFormula(expressions, renameList.at(i).first, renameList.at(i).second);
}
renameList.clear();
const int row = ui->tableWidgetIncrement->currentRow(); const int row = ui->tableWidgetIncrement->currentRow();
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
@ -663,6 +689,9 @@ void DialogIncrements::SaveIncrName(const QString &text)
} }
doc->SetIncrementName(nameField->text(), newName); doc->SetIncrementName(nameField->text(), newName);
QVector<VFormulaField> expressions = doc->ListIncrementExpressions();
doc->ReplaceNameInFormula(expressions, nameField->text(), newName);
CacheRename(nameField->text(), newName);
hasChanges = true; hasChanges = true;
LocalUpdateTree(); LocalUpdateTree();
@ -832,6 +861,7 @@ void DialogIncrements::closeEvent(QCloseEvent *event)
ui->lineEditName->blockSignals(true); ui->lineEditName->blockSignals(true);
ui->plainTextEditDescription->blockSignals(true); ui->plainTextEditDescription->blockSignals(true);
emit UpdateProperties();
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
event->accept(); event->accept();
} }
@ -942,7 +972,6 @@ void DialogIncrements::ShowIncrementDetails()
ui->lineEditName->blockSignals(true); ui->lineEditName->blockSignals(true);
ui->lineEditName->setText(ClearIncrementName(incr->GetName())); ui->lineEditName->setText(ClearIncrementName(incr->GetName()));
ui->lineEditName->blockSignals(false); ui->lineEditName->blockSignals(false);
ui->lineEditName->setReadOnly(IncrementUsed(incr->GetName()));
ui->plainTextEditDescription->blockSignals(true); ui->plainTextEditDescription->blockSignals(true);
ui->plainTextEditDescription->setPlainText(incr->GetDescription()); ui->plainTextEditDescription->setPlainText(incr->GetDescription());

View File

@ -33,6 +33,8 @@
#include "../xml/vpattern.h" #include "../xml/vpattern.h"
#include "../vmisc/vtablesearch.h" #include "../vmisc/vtablesearch.h"
#include <QPair>
class VIndividualMeasurements; class VIndividualMeasurements;
namespace Ui namespace Ui
@ -50,6 +52,9 @@ public:
DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr); DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr);
virtual ~DialogIncrements() Q_DECL_OVERRIDE; virtual ~DialogIncrements() Q_DECL_OVERRIDE;
signals:
void UpdateProperties();
protected: protected:
virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE; virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE;
virtual void changeEvent ( QEvent * event) Q_DECL_OVERRIDE; virtual void changeEvent ( QEvent * event) Q_DECL_OVERRIDE;
@ -88,6 +93,8 @@ private:
bool hasChanges; bool hasChanges;
QVector<QPair<QString, QString>> renameList;
template <typename T> template <typename T>
void FillTable(const QMap<QString, T> &varTable, QTableWidget *table); void FillTable(const QMap<QString, T> &varTable, QTableWidget *table);
@ -115,6 +122,8 @@ private:
void UpdateTree(); void UpdateTree();
bool IncrementUsed(const QString &name) const; bool IncrementUsed(const QString &name) const;
void CacheRename(const QString &name, const QString &newName);
}; };
#endif // DIALOGINCREMENTS_H #endif // DIALOGINCREMENTS_H

View File

@ -3919,6 +3919,8 @@ void MainWindow::CreateActions()
if (checked) if (checked)
{ {
dialogTable = new DialogIncrements(pattern, doc, this); dialogTable = new DialogIncrements(pattern, doc, this);
connect(dialogTable.data(), &DialogIncrements::UpdateProperties, toolOptions,
&VToolOptionsPropertyBrowser::RefreshOptions);
connect(dialogTable.data(), &DialogIncrements::DialogClosed, this, [this]() connect(dialogTable.data(), &DialogIncrements::DialogClosed, this, [this]()
{ {
ui->actionTable->setChecked(false); ui->actionTable->setChecked(false);

View File

@ -44,6 +44,7 @@
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
#include "../vmisc/projectversion.h" #include "../vmisc/projectversion.h"
#include "../qmuparser/qmuparsererror.h" #include "../qmuparser/qmuparsererror.h"
#include "../qmuparser/qmutokenparser.h"
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
#include "../vgeometry/vellipticalarc.h" #include "../vgeometry/vellipticalarc.h"
#include "../vgeometry/vsplinepath.h" #include "../vgeometry/vsplinepath.h"
@ -3509,6 +3510,63 @@ void VPattern::SetIncrementDescription(const QString &name, const QString &text)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ReplaceNameInFormula(QVector<VFormulaField> &expressions, const QString &name, const QString &newName)
{
const int bias = name.length() - newName.length();
for(int i = 0; i < expressions.size(); ++i)
{
if (expressions.at(i).expression.indexOf(name) != -1)
{
QMap<int, QString> tokens;
// Eval formula
try
{
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i).expression, false,
false));
tokens = cal->GetTokens();// Tokens (variables, measurements)
}
catch (const qmu::QmuParserError &)
{
continue;// Because we not sure if used. A formula is broken.
}
QList<QString> tValues = tokens.values();
if (not tValues.contains(name))
{
continue;
}
QList<int> tKeys = tokens.keys();// Take all tokens positions
QString newFormula = expressions.at(i).expression;
for (int i = 0; i < tKeys.size(); ++i)
{
if (tValues.at(i) != name)
{
continue;
}
newFormula.replace(tKeys.at(i), name.length(), newName);
if (bias != 0)
{// Translated token has different length than original. Position next tokens need to be corrected.
VTranslateVars::BiasTokens(tKeys.at(i), bias, tokens);
tKeys = tokens.keys();
tValues = tokens.values();
}
}
expressions[i].expression = newFormula;
expressions[i].element.setAttribute(expressions.at(i).attribute, newFormula);
emit patternChanged(false);
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GenerateLabel create label for pattern piece of point. * @brief GenerateLabel create label for pattern piece of point.

View File

@ -79,6 +79,8 @@ public:
void SetIncrementFormula(const QString &name, const QString &text); void SetIncrementFormula(const QString &name, const QString &text);
void SetIncrementDescription(const QString &name, const QString &text); void SetIncrementDescription(const QString &name, const QString &text);
void ReplaceNameInFormula(QVector<VFormulaField> &expressions, const QString &name, const QString &newName);
virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const Q_DECL_OVERRIDE; virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const Q_DECL_OVERRIDE;
virtual QString GenerateSuffix() const Q_DECL_OVERRIDE; virtual QString GenerateSuffix() const Q_DECL_OVERRIDE;

View File

@ -194,6 +194,28 @@ const QString VAbstractPattern::NodeSplinePath = QStringLiteral("NodeSplinePath"
QHash<quint32, VDataTool*> VAbstractPattern::tools = QHash<quint32, VDataTool*>(); QHash<quint32, VDataTool*> VAbstractPattern::tools = QHash<quint32, VDataTool*>();
namespace
{
void ReadExpressionAttribute(QVector<VFormulaField> &expressions, const QDomElement &element, const QString &attribute)
{
VFormulaField formula;
try
{
formula.expression = VDomDocument::GetParametrString(element, attribute);
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
return;
}
formula.element = element;
formula.attribute = attribute;
expressions.append(formula);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractPattern::VAbstractPattern(QObject *parent) VAbstractPattern::VAbstractPattern(QObject *parent)
: QObject(parent), : QObject(parent),
@ -218,17 +240,18 @@ QStringList VAbstractPattern::ListMeasurements() const
others.insert(increments.at(i)); others.insert(increments.at(i));
} }
const QStringList expressions = ListExpressions(); const QVector<VFormulaField> expressions = ListExpressions();
for (int i=0; i < expressions.size(); ++i) for (int i=0; i < expressions.size(); ++i)
{ {
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i), false, false));// Eval formula // Eval formula
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i).expression, false, false));
const QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements) const QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
delete cal.take(); delete cal.take();
const QList<QString> tValues = tokens.values(); const QList<QString> tValues = tokens.values();
for (int j = 0; j < tValues.size(); ++j) for (int j = 0; j < tValues.size(); ++j)
{ {
if (tValues.at(j) == QLatin1String("-")) if (tValues.at(j) == QChar('-'))
{ {
continue; continue;
} }
@ -1613,9 +1636,9 @@ QStringList VAbstractPattern::ListIncrements() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListExpressions() const QVector<VFormulaField> VAbstractPattern::ListExpressions() const
{ {
QStringList list; QVector<VFormulaField> list;
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
// Note. Tool Union Details also contains formulas, but we don't use them for union and keep only to simplifying // Note. Tool Union Details also contains formulas, but we don't use them for union and keep only to simplifying
@ -1633,333 +1656,180 @@ QStringList VAbstractPattern::ListExpressions() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListPointExpressions() const QVector<VFormulaField> VAbstractPattern::ListPointExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment a number. // If no just increment a number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagPoint); const QDomNodeList list = elementsByTagName(TagPoint);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QDomElement dom = list.at(i).toElement();
// Each tag can contains several attributes. // Each tag can contains several attributes.
try ReadExpressionAttribute(expressions, dom, AttrLength);
{ ReadExpressionAttribute(expressions, dom, AttrAngle);
expressions.append(GetParametrString(dom, AttrLength)); ReadExpressionAttribute(expressions, dom, AttrC1Radius);
} ReadExpressionAttribute(expressions, dom, AttrC2Radius);
catch (VExceptionEmptyParameter &e) ReadExpressionAttribute(expressions, dom, AttrCRadius);
{ ReadExpressionAttribute(expressions, dom, AttrRadius);
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrAngle));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrC1Radius));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrC2Radius));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrCRadius));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrRadius));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListArcExpressions() const QVector<VFormulaField> VAbstractPattern::ListArcExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment number. // If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagArc); const QDomNodeList list = elementsByTagName(TagArc);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QDomElement dom = list.at(i).toElement();
try // Each tag can contains several attributes.
{ ReadExpressionAttribute(expressions, dom, AttrAngle1);
expressions.append(GetParametrString(dom, AttrAngle1)); ReadExpressionAttribute(expressions, dom, AttrAngle2);
} ReadExpressionAttribute(expressions, dom, AttrRadius);
catch (VExceptionEmptyParameter &e) ReadExpressionAttribute(expressions, dom, AttrLength);
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrAngle2));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrRadius));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrLength));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListElArcExpressions() const QVector<VFormulaField> VAbstractPattern::ListElArcExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment number. // If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagElArc); const QDomNodeList list = elementsByTagName(TagElArc);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QDomElement dom = list.at(i).toElement();
try // Each tag can contains several attributes.
{ ReadExpressionAttribute(expressions, dom, AttrRadius1);
expressions.append(GetParametrString(dom, AttrRadius1)); ReadExpressionAttribute(expressions, dom, AttrRadius2);
} ReadExpressionAttribute(expressions, dom, AttrAngle1);
catch (VExceptionEmptyParameter &e) ReadExpressionAttribute(expressions, dom, AttrAngle2);
{ ReadExpressionAttribute(expressions, dom, AttrRotationAngle);
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrRadius2));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrAngle1));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrAngle2));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrRotationAngle));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListSplineExpressions() const QVector<VFormulaField> VAbstractPattern::ListSplineExpressions() const
{ {
QStringList expressions; QVector<VFormulaField> expressions;
expressions << ListPathPointExpressions(); expressions << ListPathPointExpressions();
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListPathPointExpressions() const QVector<VFormulaField> VAbstractPattern::ListPathPointExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment number. // If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(AttrPathPoint); const QDomNodeList list = elementsByTagName(AttrPathPoint);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QDomElement dom = list.at(i).toElement();
try // Each tag can contains several attributes.
{ ReadExpressionAttribute(expressions, dom, AttrKAsm1);
expressions.append(GetParametrString(dom, AttrKAsm1)); ReadExpressionAttribute(expressions, dom, AttrKAsm2);
} ReadExpressionAttribute(expressions, dom, AttrAngle);
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrKAsm2));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrAngle));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListIncrementExpressions() const QVector<VFormulaField> VAbstractPattern::ListIncrementExpressions() const
{ {
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagIncrement); const QDomNodeList list = elementsByTagName(TagIncrement);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QDomElement dom = list.at(i).toElement();
try ReadExpressionAttribute(expressions, dom, IncrementFormula);
{
expressions.append(GetParametrString(dom, IncrementFormula));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListOperationExpressions() const QVector<VFormulaField> VAbstractPattern::ListOperationExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment number. // If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagOperation); const QDomNodeList list = elementsByTagName(TagOperation);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QDomElement dom = list.at(i).toElement();
// Each tag can contains several attributes. // Each tag can contains several attributes.
try ReadExpressionAttribute(expressions, dom, AttrAngle);
{ ReadExpressionAttribute(expressions, dom, AttrLength);
expressions.append(GetParametrString(dom, AttrAngle));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(dom, AttrLength));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListNodesExpressions(const QDomElement &nodes) const QVector<VFormulaField> VAbstractPattern::ListNodesExpressions(const QDomElement &nodes) const
{
QStringList expressions;
VPiecePath path;
if (not nodes.isNull())
{
path = ParsePathNodes(nodes);
}
for(int i = 0; i < path.CountNodes(); ++i)
{
expressions.append(path.at(i).GetFormulaSABefore());
expressions.append(path.at(i).GetFormulaSAAfter());
}
return expressions;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListPathExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment number. // If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList nodeList = nodes.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
{
const QDomElement element = nodeList.at(i).toElement();
if (not element.isNull() && element.tagName() == VAbstractPattern::TagNode)
{
ReadExpressionAttribute(expressions, element, VAbstractPattern::AttrSABefore);
ReadExpressionAttribute(expressions, element, VAbstractPattern::AttrSAAfter);
}
}
return expressions;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VFormulaField> VAbstractPattern::ListPathExpressions() const
{
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagPath); const QDomNodeList list = elementsByTagName(TagPath);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
@ -1976,43 +1846,28 @@ QStringList VAbstractPattern::ListPathExpressions() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListGrainlineExpressions(const QDomElement &element) const QVector<VFormulaField> VAbstractPattern::ListGrainlineExpressions(const QDomElement &element) const
{ {
QStringList expressions; QVector<VFormulaField> expressions;
if (not element.isNull()) if (not element.isNull())
{ {
// Each tag can contains several attributes. // Each tag can contains several attributes.
try ReadExpressionAttribute(expressions, element, AttrRotation);
{ ReadExpressionAttribute(expressions, element, AttrLength);
expressions.append(GetParametrString(element, AttrRotation));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(element, AttrLength));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
} }
return expressions; return expressions;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListPieceExpressions() const QVector<VFormulaField> VAbstractPattern::ListPieceExpressions() const
{ {
// Check if new tool doesn't bring new attribute with a formula. // Check if new tool doesn't bring new attribute with a formula.
// If no just increment number. // If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53); Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
QStringList expressions; QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagDetail); const QDomNodeList list = elementsByTagName(TagDetail);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
@ -2023,14 +1878,7 @@ QStringList VAbstractPattern::ListPieceExpressions() const
} }
// Each tag can contains several attributes. // Each tag can contains several attributes.
try ReadExpressionAttribute(expressions, dom, AttrWidth);
{
expressions.append(GetParametrString(dom, AttrWidth));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
expressions << ListNodesExpressions(dom.firstChildElement(TagNodes)); expressions << ListNodesExpressions(dom.firstChildElement(TagNodes));
expressions << ListGrainlineExpressions(dom.firstChildElement(TagGrainline)); expressions << ListGrainlineExpressions(dom.firstChildElement(TagGrainline));

View File

@ -60,6 +60,18 @@ enum class AxisType : char {VerticalAxis = 1, HorizontalAxis = 2};
class VContainer; class VContainer;
class VDataTool; class VDataTool;
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
struct VFormulaField
{
QString expression;
QDomElement element;
QString attribute;
};
QT_WARNING_POP
class VAbstractPattern : public QObject, public VDomDocument class VAbstractPattern : public QObject, public VDomDocument
{ {
Q_OBJECT Q_OBJECT
@ -68,7 +80,8 @@ public:
virtual ~VAbstractPattern() Q_DECL_EQ_DEFAULT; virtual ~VAbstractPattern() Q_DECL_EQ_DEFAULT;
QStringList ListMeasurements() const; QStringList ListMeasurements() const;
QStringList ListExpressions() const; QVector<VFormulaField> ListExpressions() const;
QVector<VFormulaField> ListIncrementExpressions() const;
virtual void CreateEmptyFile()=0; virtual void CreateEmptyFile()=0;
@ -388,17 +401,16 @@ private:
Q_DISABLE_COPY(VAbstractPattern) Q_DISABLE_COPY(VAbstractPattern)
QStringList ListIncrements() const; QStringList ListIncrements() const;
QStringList ListPointExpressions() const; QVector<VFormulaField> ListPointExpressions() const;
QStringList ListArcExpressions() const; QVector<VFormulaField> ListArcExpressions() const;
QStringList ListElArcExpressions() const; QVector<VFormulaField> ListElArcExpressions() const;
QStringList ListSplineExpressions() const; QVector<VFormulaField> ListSplineExpressions() const;
QStringList ListPathPointExpressions() const; QVector<VFormulaField> ListPathPointExpressions() const;
QStringList ListIncrementExpressions() const; QVector<VFormulaField> ListOperationExpressions() const;
QStringList ListOperationExpressions() const; QVector<VFormulaField> ListNodesExpressions(const QDomElement &nodes) const;
QStringList ListNodesExpressions(const QDomElement &nodes) const; QVector<VFormulaField> ListPathExpressions() const;
QStringList ListPathExpressions() const; QVector<VFormulaField> ListGrainlineExpressions(const QDomElement &element) const;
QStringList ListGrainlineExpressions(const QDomElement &element) const; QVector<VFormulaField> ListPieceExpressions() const;
QStringList ListPieceExpressions() const;
bool IsVariable(const QString& token) const; bool IsVariable(const QString& token) const;
bool IsPostfixOperator(const QString& token) const; bool IsPostfixOperator(const QString& token) const;

View File

@ -65,6 +65,8 @@ public:
QMap<QString, qmu::QmuTranslation> GetFunctions() const; QMap<QString, qmu::QmuTranslation> GetFunctions() const;
static void BiasTokens(int position, int bias, QMap<int, QString> &tokens);
private: private:
Q_DISABLE_COPY(VTranslateVars) Q_DISABLE_COPY(VTranslateVars)
QMap<QString, qmu::QmuTranslation> PMSystemNames; QMap<QString, qmu::QmuTranslation> PMSystemNames;
@ -86,7 +88,7 @@ private:
const qmu::QmuTranslation &book); const qmu::QmuTranslation &book);
void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens, QMap<int, QString> &numbers) const; void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens, QMap<int, QString> &numbers) const;
static void BiasTokens(int position, int bias, QMap<int, QString> &tokens);
}; };
#endif // VTRANSLATEVARS_H #endif // VTRANSLATEVARS_H