mapHandler.cpp 1.42 KB
Newer Older
1
#include "mapHandler.h"
2

3 4
#include "system.h"
#include "Utils/vbo.h"
5

6 7
MapHandler::MapHandler(const QString& name, CGoGN::GenericMap *map) :
	m_name(name),
8 9 10 11 12
	m_map(map)
{}

MapHandler::~MapHandler()
{
13 14
	foreach(CGoGN::Utils::VBO* vbo, h_vbo)
		delete vbo;
15 16 17 18 19

	if (m_map)
		delete m_map;
}

20
CGoGN::Utils::VBO* MapHandler::addVBO(const QString& name)
21
{
22
	if (h_vbo.contains(name))
23
	{
24 25
		System::Error::code = System::Error::VBO_EXISTS;
		return NULL;
26 27
	}

28 29 30
	CGoGN::Utils::VBO* vbo = new CGoGN::Utils::VBO();
	h_vbo.insert(name, vbo);
	return vbo;
31 32
}

33
void MapHandler::removeVBO(const QString& name)
34
{
35
	if (h_vbo.contains(name))
36
	{
37 38 39
		CGoGN::Utils::VBO* vbo = h_vbo[name];
		h_vbo.remove(name);
		delete vbo;
40 41 42
	}
}

43
CGoGN::Utils::VBO* MapHandler::getVBO(const QString& name)
44
{
45 46 47
	if (h_vbo.contains(name))
		return h_vbo[name];
	else
48
	{
49 50
		System::Error::code = System::Error::VBO_DOES_NOT_EXIST;
		return NULL;
51 52 53
	}
}

54
CGoGN::Utils::VBO* MapHandler::findFirstVBOMatching(const QRegExp& regexp)
55
{
56 57
	QHash<QString, CGoGN::Utils::VBO*>::iterator it;
	for (it = h_vbo.begin(); it != h_vbo.end(); ++it)
58
	{
59 60
		if (it.key().contains(regexp))
			return it.value();
61 62 63 64
	}
	return NULL;
}

65
QList<CGoGN::Utils::VBO*> MapHandler::findVBOsMatching(const QRegExp& regexp)
66
{
67 68 69
	QList<CGoGN::Utils::VBO*> rlist;
	QHash<QString, CGoGN::Utils::VBO*>::iterator it;
	for (it = h_vbo.begin(); it != h_vbo.end(); ++it)
70
	{
71 72
		if (it.key().contains(regexp))
			rlist.push_back(it.value());
73 74 75
	}
	return rlist;
}