Refactoring.

Move GetNodeName to better place.
This commit is contained in:
Roman Telezhynskyi 2021-11-23 17:10:00 +02:00
parent b9958e9953
commit 869b9e98e1
6 changed files with 77 additions and 77 deletions

View File

@ -428,7 +428,7 @@ bool DoublePoints(QListWidget *listWidget, const VContainer *data)
}
//---------------------------------------------------------------------------------------------------------------------
bool DoubleCurves(QListWidget *listWidget)
auto DoubleCurves(QListWidget *listWidget) -> bool
{
SCASSERT(listWidget != nullptr);
for (int i=0, sz = listWidget->count()-1; i<sz; ++i)
@ -576,3 +576,60 @@ auto SegmentAliases(GOType curveType, const QString &alias1, const QString &alia
return {};
}
QT_WARNING_POP
//---------------------------------------------------------------------------------------------------------------------
QString GetNodeName(const VContainer *data, const VPieceNode &node, bool showPassmarkDetails)
{
const QSharedPointer<VGObject> obj = data->GetGObject(node.GetId());
QString name = obj->ObjectName();
if (node.GetTypeTool() != Tool::NodePoint)
{
if (node.GetReverse())
{
name = QStringLiteral("- ") + name;
}
}
else
{
if (showPassmarkDetails && node.IsPassmark())
{
switch(node.GetPassmarkLineType())
{
case PassmarkLineType::OneLine:
name += QLatin1Char('|');
break;
case PassmarkLineType::TwoLines:
name += QLatin1String("||");
break;
case PassmarkLineType::ThreeLines:
name += QLatin1String("|||");
break;
case PassmarkLineType::TMark:
name += QStringLiteral("");
break;
case PassmarkLineType::VMark:
name += QStringLiteral("");
break;
case PassmarkLineType::VMark2:
name += QStringLiteral("");
break;
case PassmarkLineType::UMark:
name += QStringLiteral("");
break;
case PassmarkLineType::BoxMark:
name += QStringLiteral("");
break;
default:
break;
}
}
if (not node.IsCheckUniqueness())
{
name = QLatin1Char('[') + name + QLatin1Char(']');
}
}
return name;
}

View File

@ -90,5 +90,6 @@ void CurrentCurveLength(vidtype curveId, VContainer *data);
void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar=4);
QIcon LineColor(int size, const QString &color);
auto SegmentAliases(GOType curveType, const QString &alias1, const QString &alias2) -> QPair<QString, QString>;
QString GetNodeName(const VContainer *data, const VPieceNode &node, bool showPassmarkDetails = false);
#endif // DIALOGTOOLBOX_H

View File

@ -391,63 +391,6 @@ quint32 DialogTool::DNumber(const QString &baseName) const
return num;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogTool::GetNodeName(const VPieceNode &node, bool showPassmarkDetails) const
{
const QSharedPointer<VGObject> obj = data->GetGObject(node.GetId());
QString name = obj->ObjectName();
if (node.GetTypeTool() != Tool::NodePoint)
{
if (node.GetReverse())
{
name = QStringLiteral("- ") + name;
}
}
else
{
if (showPassmarkDetails && node.IsPassmark())
{
switch(node.GetPassmarkLineType())
{
case PassmarkLineType::OneLine:
name += QLatin1Char('|');
break;
case PassmarkLineType::TwoLines:
name += QLatin1String("||");
break;
case PassmarkLineType::ThreeLines:
name += QLatin1String("|||");
break;
case PassmarkLineType::TMark:
name += QStringLiteral("");
break;
case PassmarkLineType::VMark:
name += QStringLiteral("");
break;
case PassmarkLineType::VMark2:
name += QStringLiteral("");
break;
case PassmarkLineType::UMark:
name += QStringLiteral("");
break;
case PassmarkLineType::BoxMark:
name += QStringLiteral("");
break;
default:
break;
}
}
if (not node.IsCheckUniqueness())
{
name = QLatin1Char('[') + name + QLatin1Char(']');
}
}
return name;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bool showPassmark, bool showExclusion)
{
@ -461,7 +404,7 @@ void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bo
case (Tool::NodeElArc):
case (Tool::NodeSpline):
case (Tool::NodeSplinePath):
name = GetNodeName(node, showPassmark);
name = GetNodeName(data, node, showPassmark);
break;
default:
qDebug()<<"Got wrong tools. Ignore.";

View File

@ -218,7 +218,6 @@ protected:
*/
virtual void SaveData() {}
quint32 DNumber(const QString &baseName) const;
QString GetNodeName(const VPieceNode &node, bool showPassmarkDetails = false) const;
void NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bool showPassmark = true,
bool showExclusion = true);

View File

@ -368,7 +368,7 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos)
{
rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, IsShowNotch()));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
else if (m_showMode && rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionPassmark
&& GetType() == PiecePathType::CustomSeamAllowance
@ -376,20 +376,20 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos)
{
rowNode.SetPassmark(not rowNode.IsPassmark());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, IsShowNotch()));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
else if (selectedAction == actionExcluded)
{
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, true));
rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
}
else if (rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionUniqueness)
{
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, IsShowNotch()));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
ValidObjects(PathIsValid());
@ -714,7 +714,7 @@ void DialogPiecePath::PassmarkLineTypeChanged(int id)
rowNode.SetPassmarkLineType(lineType);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, IsShowNotch()));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
ListChanged();
}
@ -768,7 +768,7 @@ void DialogPiecePath::PassmarkAngleTypeChanged(int id)
rowNode.SetPassmarkAngleType(angleType);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, IsShowNotch()));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
ListChanged();
}
@ -1226,7 +1226,7 @@ void DialogPiecePath::InitNodesList()
const VPieceNode node = path.at(i);
if (node.GetTypeTool() == Tool::NodePoint)
{
const QString name = GetNodeName(node);
const QString name = GetNodeName(data, node);
ui->comboBoxNodes->addItem(name, node.GetId());
}
@ -1259,7 +1259,7 @@ void DialogPiecePath::InitPassmarksList()
{
if (node.GetTypeTool() == Tool::NodePoint && node.IsPassmark())
{
const QString name = GetNodeName(node);
const QString name = GetNodeName(data, node);
ui->comboBoxPassmarks->addItem(name, node.GetId());
}

View File

@ -782,26 +782,26 @@ void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos)
{
rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, true));
rowItem->setText(GetNodeName(data, rowNode, true));
}
else if (selectedAction == actionExcluded)
{
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, true));
rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
}
else if (applyAllowed && selectedAction == actionPassmark)
{
rowNode.SetPassmark(not rowNode.IsPassmark());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, true));
rowItem->setText(GetNodeName(data, rowNode, true));
}
else if (selectedAction == actionUniqueness)
{
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, true));
rowItem->setText(GetNodeName(data, rowNode, true));
}
ValidObjects(MainPathIsValid());
@ -1618,7 +1618,7 @@ void DialogSeamAllowance::PassmarkLineTypeChanged(int id)
rowNode.SetPassmarkLineType(lineType);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode, true));
rowItem->setText(GetNodeName(data, rowNode, true));
ListChanged();
}
@ -2771,7 +2771,7 @@ void DialogSeamAllowance::InitNodesList()
{
if (node.GetTypeTool() == Tool::NodePoint && not node.IsExcluded())
{
const QString name = GetNodeName(node);
const QString name = GetNodeName(data, node);
uiTabPaths->comboBoxNodes->addItem(name, node.GetId());
}
@ -2804,7 +2804,7 @@ void DialogSeamAllowance::InitPassmarksList()
{
if (node.GetTypeTool() == Tool::NodePoint && node.IsPassmark())
{
const QString name = GetNodeName(node);
const QString name = GetNodeName(data, node);
uiTabPassmarks->comboBoxPassmarks->addItem(name, node.GetId());
}
@ -3132,11 +3132,11 @@ void DialogSeamAllowance::InitCSAPoint(QComboBox *box)
const QVector<VPieceNode> nodes = GetListInternals<VPieceNode>(uiTabPaths->listWidgetMainPath);
for (auto &node : nodes)
for (const auto &node : nodes)
{
if (node.GetTypeTool() == Tool::NodePoint && not node.IsExcluded())
{
const QString name = GetNodeName(node);
const QString name = GetNodeName(data, node);
box->addItem(name, node.GetId());
}
}