File: group.cpp

package info (click to toggle)
leocad 18.02-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,772 kB
  • sloc: cpp: 46,325; xml: 2,856; sh: 33; makefile: 14
file content (64 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "lc_global.h"
#include <stdlib.h>
#include "group.h"
#include "lc_file.h"

lcGroup::lcGroup()
{
	mGroup = nullptr;
}

lcGroup::~lcGroup()
{
}

void lcGroup::FileLoad(lcFile* File)
{
	qint32 GroupIndex;
	char Name[LC_MAX_GROUP_NAME + 1];

	File->ReadU8();
	File->ReadBuffer(Name, sizeof(Name));
	mName = QString::fromUtf8(Name);
	File->ReadVector3();
	File->ReadS32(&GroupIndex, 1);
	mGroup = (lcGroup*)(quintptr)GroupIndex;
}

void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
{
	if (!mName.isEmpty())
	{
		bool Found = false;
		for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
		{
			if (Groups[GroupIdx]->mName == mName)
			{
				Found = true;
				break;
			}
		}

		if (!Found)
			return;
	}

	int Max = 0;
	QString Prefix = QApplication::tr("Group #");
	int Length = Prefix.length();

	for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
	{
		const QString& Name = Groups[GroupIdx]->mName;

		if (Name.startsWith(Prefix))
		{
			bool Ok = false;
			int GroupNumber = Name.mid(Length).toInt(&Ok);
			if (Ok && GroupNumber > Max)
				Max = GroupNumber;
		}
	}

	mName = Prefix + QString::number(Max + 1);
}