leocad/common/group.cpp

61 lines
1.1 KiB
C++
Raw Normal View History

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