Better way to check suffix.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-05-18 16:44:23 +03:00
parent 702245f9fb
commit 0052a883a4
3 changed files with 7 additions and 54 deletions

View File

@ -682,19 +682,19 @@ void VToolOptionsPropertyBrowser::SetOperationSuffix(const QString &suffix)
} }
QRegularExpression rx(NameRegExp()); QRegularExpression rx(NameRegExp());
const QVector<QString> names = item->GetNames(suffix); const QStringList uniqueNames = VContainer::AllUniqueNames();
for (int i=0; i < names.size(); ++i) for (int i=0; i < uniqueNames.size(); ++i)
{ {
if (not rx.match(names.at(i)).hasMatch() || not VContainer::IsUnique(names.at(i))) const QString name = uniqueNames.at(i) + suffix;
if (not rx.match(name).hasMatch() || not VContainer::IsUnique(name))
{ {
idToProperty[AttrSuffix]->setValue(item->Suffix()); idToProperty[AttrSuffix]->setValue(item->Suffix());
return;
} }
else }
{
item->SetSuffix(suffix); item->SetSuffix(suffix);
} }
}
}
else else
{ {
qWarning()<<"Can't cast item"; qWarning()<<"Can't cast item";

View File

@ -351,52 +351,6 @@ void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domEle
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QString> VToolRotation::GetNames(const QString &suffix) const
{
QVector<QString> names;
for (int i = 0; i < source.size(); ++i)
{
const QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(source.at(i));
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
#if defined(Q_CC_GNU)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#endif
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(source.at(i));
names.append(point->name() + suffix);
break;
}
case GOType::Arc:
case GOType::EllipticalArc:
case GOType::Spline:
case GOType::SplinePath:
case GOType::CubicBezier:
case GOType::CubicBezierPath:
{
const QSharedPointer<VAbstractCurve> curve =
VAbstractTool::data.GeometricObject<VAbstractCurve>(source.at(i));
names.append(curve->name() + suffix);
break;
}
case GOType::Unknown:
break;
}
#if defined(Q_CC_GNU)
#pragma GCC diagnostic pop
#endif
}
return names;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolRotation::getTagName() const QString VToolRotation::getTagName() const
{ {

View File

@ -59,7 +59,6 @@ public:
const Document &parse, const Source &typeCreation); const Document &parse, const Source &typeCreation);
static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector<quint32> &source, static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector<quint32> &source,
QVector<DestinationItem> &destination); QVector<DestinationItem> &destination);
QVector<QString> GetNames(const QString &suffix) const;
static const QString ToolType; static const QString ToolType;
static const QString TagItem; static const QString TagItem;
static const QString TagSource; static const QString TagSource;