leocad/common/group.cpp

61 lines
1 KiB
C++
Raw Normal View History

#include "lc_global.h"
2011-09-07 21:06:51 +00:00
#include <stdlib.h>
#include "group.h"
#include "lc_file.h"
2011-09-07 21:06:51 +00:00
2014-05-25 01:45:19 +00:00
lcGroup::lcGroup()
2011-09-07 21:06:51 +00:00
{
mGroup = nullptr;
2011-09-07 21:06:51 +00:00
}
2014-05-25 18:23:09 +00:00
void lcGroup::FileLoad(lcFile* File)
2011-09-07 21:06:51 +00:00
{
2017-12-02 12:22:04 -08:00
qint32 GroupIndex;
2015-10-21 15:03:45 +00:00
char Name[LC_MAX_GROUP_NAME + 1];
2014-05-25 18:23:09 +00:00
File->ReadU8();
2015-10-21 15:03:45 +00:00
File->ReadBuffer(Name, sizeof(Name));
mName = QString::fromUtf8(Name);
2014-05-25 18:23:09 +00:00
File->ReadVector3();
File->ReadS32(&GroupIndex, 1);
2016-02-19 17:53:54 +00:00
mGroup = (lcGroup*)(quintptr)GroupIndex;
2011-09-07 21:06:51 +00:00
}
2014-12-15 23:55:17 +00:00
void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
{
2015-10-21 15:03:45 +00:00
if (!mName.isEmpty())
2014-12-15 23:55:17 +00:00
{
bool Found = false;
2020-03-22 20:18:52 -07:00
for (const lcGroup* const Group : Groups)
2014-12-15 23:55:17 +00:00
{
2019-03-28 17:59:58 -07:00
if (Group->mName == mName)
2014-12-15 23:55:17 +00:00
{
Found = true;
break;
}
}
if (!Found)
return;
}
2015-10-21 15:03:45 +00:00
int Max = 0;
QString Prefix = QApplication::tr("Group #");
2020-03-22 20:18:52 -07:00
const int Length = Prefix.length();
2014-12-15 23:55:17 +00:00
2020-03-22 20:18:52 -07:00
for (const lcGroup* const Group : Groups)
2015-10-21 15:03:45 +00:00
{
2019-03-28 17:59:58 -07:00
const QString& Name = Group->mName;
2015-10-21 15:03:45 +00:00
if (Name.startsWith(Prefix))
{
bool Ok = false;
2017-04-20 18:56:35 -07:00
int GroupNumber = Name.mid(Length).toInt(&Ok);
2015-10-21 15:03:45 +00:00
if (Ok && GroupNumber > Max)
Max = GroupNumber;
}
}
2014-12-15 23:55:17 +00:00
2015-10-21 15:03:45 +00:00
mName = Prefix + QString::number(Max + 1);
2014-12-15 23:55:17 +00:00
}