Automatically generate suffix.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-05-18 15:35:07 +03:00
parent 291c19d5a2
commit 180903b807
9 changed files with 80 additions and 24 deletions

View File

@ -59,6 +59,12 @@ QString VLitePattern::GenerateLabel(const LabelType &type, const QString &reserv
return QString();
}
//---------------------------------------------------------------------------------------------------------------------
QString VLitePattern::GenerateSuffix() const
{
return QString();
}
//---------------------------------------------------------------------------------------------------------------------
void VLitePattern::UpdateToolData(const quint32 &id, VContainer *data)
{

View File

@ -43,6 +43,7 @@ public:
virtual void DecrementReferens(quint32 id) 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 void UpdateToolData(const quint32 &id, VContainer *data) Q_DECL_OVERRIDE;

View File

@ -2880,10 +2880,9 @@ void VPattern::SetIncrementDescription(const QString &name, const QString &text)
*/
QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedName) const
{
QDomNodeList drawList = elementsByTagName(TagDraw);
if (type == LabelType::NewPatternPiece)
{
const QDomNodeList drawList = elementsByTagName(TagDraw);
QString name;
int i = 0;
for (;;)
@ -2904,25 +2903,7 @@ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedNa
}
else if (type == LabelType::NewLabel)
{
if (drawList.isEmpty())
{
const QString label = GetLabelBase(0);
qCDebug(vXML, "Point label: %s", qUtf8Printable(label));
return label;
}
int index = 0;
for (int i = 0; i < drawList.size(); ++i)
{
QDomElement node = drawList.at(i).toElement();
if (node.attribute(AttrName) == nameActivPP)
{
index = i;
break;
}
}
QString labelBase = GetLabelBase(static_cast<quint32>(index));
const QString labelBase = GetLabelBase(static_cast<quint32>(GetIndexActivPP()));
qint32 num = 1;
QString name;
@ -2942,6 +2923,40 @@ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedNa
return QString();
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GenerateSuffix() const
{
const QString suffixBase = GetLabelBase(static_cast<quint32>(GetIndexActivPP())).toLower();
const QStringList uniqueNames = data->AllUniqueNames();
qint32 num = 1;
QString suffix;
for (;;)
{
suffix = QString("%1%2").arg(suffixBase).arg(num);
for (int i=0; i < uniqueNames.size(); ++i)
{
if (not data->IsUnique(uniqueNames.at(i) + suffix))
{
break;
}
if (i == uniqueNames.size()-1)
{
qCDebug(vXML, "Suffix is: %s", qUtf8Printable(suffix));
return suffix;
}
}
if (num == INT_MAX)
{
break;
}
++num;
}
return QString();
}
//---------------------------------------------------------------------------------------------------------------------
bool VPattern::IsDefCustom() const
{

View File

@ -77,6 +77,7 @@ public:
void SetIncrementDescription(const QString &name, const QString &text);
virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const Q_DECL_OVERRIDE;
virtual QString GenerateSuffix() const Q_DECL_OVERRIDE;
bool IsDefCustom() const;
void SetDefCustom(bool value);

View File

@ -1172,6 +1172,28 @@ void VAbstractPattern::InsertTag(const QStringList &tags, const QDomElement &ele
SetVersion();
}
//---------------------------------------------------------------------------------------------------------------------
int VAbstractPattern::GetIndexActivPP() const
{
const QDomNodeList drawList = elementsByTagName(TagDraw);
int index = 0;
if (not drawList.isEmpty())
{
for (int i = 0; i < drawList.size(); ++i)
{
QDomElement node = drawList.at(i).toElement();
if (node.attribute(AttrName) == nameActivPP)
{
index = i;
break;
}
}
}
return index;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListIncrements() const
{

View File

@ -74,6 +74,7 @@ public:
virtual void DecrementReferens(quint32 id) const=0;
virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const=0;
virtual QString GenerateSuffix() const=0;
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0;
@ -284,6 +285,7 @@ protected:
QDomElement CheckTagExists(const QString &tag);
void InsertTag(const QStringList &tags, const QDomElement &element);
int GetIndexActivPP() const;
private:
Q_DISABLE_COPY(VAbstractPattern)

View File

@ -56,7 +56,7 @@ Q_LOGGING_CATEGORY(vCon, "v.container")
quint32 VContainer::_id = NULL_ID;
qreal VContainer::_size = 50;
qreal VContainer::_height = 176;
QSet<const QString> VContainer::uniqueNames = QSet<const QString>();
QSet<QString> VContainer::uniqueNames = QSet<QString>();
//---------------------------------------------------------------------------------------------------------------------
/**
@ -557,6 +557,14 @@ bool VContainer::IsUnique(const QString &name)
return (!uniqueNames.contains(name) && !builInFunctions.contains(name));
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VContainer::AllUniqueNames()
{
QStringList names = builInFunctions;
names.append(uniqueNames.toList());
return names;
}
//---------------------------------------------------------------------------------------------------------------------
const Unit *VContainer::GetPatternUnit() const
{

View File

@ -167,6 +167,7 @@ public:
const QHash<QString, qreal *> PlainVariables() const;
static bool IsUnique(const QString &name);
static QStringList AllUniqueNames();
const Unit *GetPatternUnit() const;
const VTranslateVars *GetTrVars() const;
@ -178,7 +179,7 @@ private:
static quint32 _id;
static qreal _size;
static qreal _height;
static QSet<const QString> uniqueNames;
static QSet<QString> uniqueNames;
QSharedDataPointer<VContainerData> d;

View File

@ -54,7 +54,7 @@ DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QW
this->formulaBaseHeightAngle = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
// ui->lineEditSuffix->setText(/*qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)*/);
ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix());
timerAngle = new QTimer(this);
connect(timerAngle, &QTimer::timeout, this, &DialogRotation::EvalAngle);