paysages3d/src/definition/BaseDefinition.cpp

79 lines
1.4 KiB
C++
Raw Normal View History

#include "BaseDefinition.h"
BaseDefinition::BaseDefinition(BaseDefinition* parent):
parent(parent)
{
2013-10-30 14:39:56 +00:00
if (parent)
{
root = parent->root;
}
else
{
root = this;
}
}
BaseDefinition::~BaseDefinition()
{
QListIterator<BaseDefinition*> it(children);
while (it.hasNext())
{
delete it.next();
}
}
2013-10-31 16:59:18 +00:00
void BaseDefinition::setName(QString name)
2013-10-30 14:39:56 +00:00
{
2013-10-31 16:59:18 +00:00
this->name = name;
2013-10-30 14:39:56 +00:00
}
void BaseDefinition::save(PackStream* pack)
{
2013-10-31 16:59:18 +00:00
pack->write(name);
2013-10-30 14:39:56 +00:00
QListIterator<BaseDefinition*> it(children);
while (it.hasNext())
{
it.next()->save(pack);
}
}
void BaseDefinition::load(PackStream* pack)
{
2013-10-31 16:59:18 +00:00
name = pack->readString();
2013-10-30 14:39:56 +00:00
QListIterator<BaseDefinition*> it(children);
while (it.hasNext())
{
it.next()->load(pack);
}
}
2013-10-31 16:59:18 +00:00
void BaseDefinition::copy(BaseDefinition* destination)
{
2013-10-31 23:09:51 +00:00
destination->setName(name);
// can't copy children as we don't know their types...
2013-10-31 16:59:18 +00:00
}
void BaseDefinition::validate()
{
QListIterator<BaseDefinition*> it(children);
while (it.hasNext())
{
it.next()->validate();
}
}
void BaseDefinition::addChild(BaseDefinition* child)
{
if (not children.contains(child))
{
children.append(child);
child->parent = this;
child->root = this->root;
}
}
void BaseDefinition::removeChild(BaseDefinition* child)
{
children.removeOne(child);
}