-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjecttreewidget.cpp
39 lines (33 loc) · 1.3 KB
/
objecttreewidget.cpp
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
#include "objecttreewidget.h"
#include <QDropEvent>
#include <QDebug>
#include "mainwindow.h"
#include "world.h"
ObjectTreeWidget::ObjectTreeWidget(QWidget* parent) : QTreeWidget(parent)
{
}
void ObjectTreeWidget::dropEvent(QDropEvent* event)
{
auto currentEntity = mMainWindow->getEntityAt(currentItem());
auto destinationEntity = mMainWindow->getEntityAt(itemAt(event->pos()));
auto parentEntity = mMainWindow->getEntityAt(currentItem()->parent());
if(currentEntity)
{
if(parentEntity)
{
if(auto transform = World::getWorld().getEntityManager()->getComponent<TransformComponent>(parentEntity->entityId))
{
transform->children.erase(std::remove(transform->children.begin(), transform->children.end(), currentEntity->entityId), transform->children.end());
}
}
if(destinationEntity)
{
if(auto transform = World::getWorld().getEntityManager()->getComponent<TransformComponent>(destinationEntity->entityId))
{
if (std::find(transform->children.begin(), transform->children.end(), currentEntity->entityId) == transform->children.end())
transform->children.push_back(currentEntity->entityId);
}
}
}
QTreeWidget::dropEvent(event);
}