modify entity brower
This commit is contained in:
parent
e153ea5e8f
commit
53b8bb5099
@ -56,22 +56,13 @@ bool EntitiesManager::Parse(const tinyxml2::XMLElement* element, WorkSpace* work
|
||||
Entity* parent = nullptr;
|
||||
while (nullptr != xmlElement) {
|
||||
const char* name = xmlElement->Name();
|
||||
Entity* entity = Create(name);
|
||||
Entity* entity = Create(xmlElement, parent, workspce);
|
||||
if (nullptr == entity) {
|
||||
xmlElement = xmlElement->NextSiblingElement();
|
||||
LOG_WARN("Create entity failed {}", name);
|
||||
continue;
|
||||
}
|
||||
|
||||
entity->Serialize(xmlElement);
|
||||
AddEntity(entity);
|
||||
|
||||
entity->SetParent(parent);
|
||||
if (nullptr == parent) {
|
||||
workspce->AddEntity(entity);
|
||||
}
|
||||
//parent = entity;
|
||||
|
||||
xmlElement = xmlElement->NextSiblingElement();
|
||||
}
|
||||
|
||||
@ -85,6 +76,28 @@ Entity* EntitiesManager::Create(const QString& name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Entity* EntitiesManager::Create(const tinyxml2::XMLElement* element, Entity* parent, WorkSpace* workspce) {
|
||||
const char* name = element->Name();
|
||||
if (strcmp(name, "Entity") != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Entity* entity = new Entity(this);
|
||||
if (nullptr == entity) {
|
||||
LOG_WARN("create entity failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
entity->Serialize(element);
|
||||
AddEntity(entity);
|
||||
|
||||
entity->SetParent(parent);
|
||||
if (nullptr == parent) {
|
||||
workspce->AddEntity(entity);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
Entity* EntitiesManager::CreateMesh(const QString& mesh) {
|
||||
Entity* entity = Create("Entity");
|
||||
AddEntity(entity);
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
|
||||
Entity* GetEntity(const QString& uuid);
|
||||
|
||||
Entity* Create(const tinyxml2::XMLElement* element, Entity* parent, WorkSpace* workspce);
|
||||
|
||||
protected:
|
||||
void AddEntity(Entity* entity);
|
||||
void RemoveEntity(Entity* entity);
|
||||
|
@ -45,6 +45,8 @@ void Entity::Serialize(const tinyxml2::XMLElement* element) {
|
||||
const char* name = xmlElement->Name();
|
||||
SceneComponent* conponent = ComponentFactory::Create(name, rootComponet_);
|
||||
if (nullptr == conponent) {
|
||||
EntitiesManager::Get().Create(xmlElement, this, workspace_);
|
||||
|
||||
xmlElement = xmlElement->NextSiblingElement();
|
||||
continue;
|
||||
}
|
||||
|
@ -64,6 +64,10 @@ public:
|
||||
return rootComponet_;
|
||||
}
|
||||
|
||||
const std::vector<Entity*> GetChilder() const {
|
||||
return childer_;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void NameChanged(const QString& name);
|
||||
|
||||
|
@ -401,57 +401,57 @@
|
||||
<context>
|
||||
<name>ModelTreeWidget</name>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="110"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="96"/>
|
||||
<source>Release Track</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="127"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="113"/>
|
||||
<source>Add boke Entity</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="134"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="120"/>
|
||||
<source>Add lsjhqt Entity</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="141"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="127"/>
|
||||
<source>Add nimizi Entity</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="148"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="134"/>
|
||||
<source>Add tkdlj Entity</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="155"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="141"/>
|
||||
<source>Add jiaofan Entity</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="162"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="148"/>
|
||||
<source>Add satellite Entity</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="264"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="250"/>
|
||||
<source>Track</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="272"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="258"/>
|
||||
<source>Add Mesh Component</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="276"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="262"/>
|
||||
<source>Add Path Component</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="283"/>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="269"/>
|
||||
<source>Delete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -61,19 +61,32 @@ void EntityListDialog::InitEintities() {
|
||||
|
||||
const std::vector<class Entity*>& entities = workSpace->GetEntities();
|
||||
for (const auto& entity : entities) {
|
||||
const QString& entityName = entity->GetName();
|
||||
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem;
|
||||
connect(entity, &Entity::NameChanged, [item](const QString& name) {
|
||||
LOG_WARN("entity name changed: {}", name.toStdString());
|
||||
item->setText(0, name);
|
||||
}
|
||||
);
|
||||
item->setText(0, entityName);
|
||||
QVariant root;
|
||||
root.setValue(entity);
|
||||
item->setData(0, E_Entity, root);
|
||||
item->setData(0, E_UUid, entity->GetUUid());
|
||||
ui->modelTreeWidget->addTopLevelItem(item);
|
||||
AddEntity(nullptr, entity);
|
||||
}
|
||||
}
|
||||
|
||||
void EntityListDialog::AddEntity(class QTreeWidgetItem* parent, Entity* entity) {
|
||||
const QString& entityName = entity->GetName();
|
||||
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem;
|
||||
connect(entity, &Entity::NameChanged, [item](const QString& name) {
|
||||
LOG_WARN("entity name changed: {}", name.toStdString());
|
||||
item->setText(0, name);
|
||||
}
|
||||
);
|
||||
item->setText(0, entityName);
|
||||
QVariant root;
|
||||
root.setValue(entity);
|
||||
item->setData(0, E_Entity, root);
|
||||
item->setData(0, E_UUid, entity->GetUUid());
|
||||
if (nullptr == parent) {
|
||||
ui->modelTreeWidget->addTopLevelItem(item);
|
||||
} else {
|
||||
parent->addChild(item);
|
||||
}
|
||||
|
||||
const std::vector<Entity*>& children = entity->GetChilder();
|
||||
for (const auto& child : children) {
|
||||
AddEntity(item, child);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ private:
|
||||
void initUI();
|
||||
void InitEintities();
|
||||
|
||||
void AddEntity(class QTreeWidgetItem* parent, Entity* entity);
|
||||
|
||||
private:
|
||||
Ui::EntityListDialog* ui;
|
||||
|
||||
|
@ -53,21 +53,7 @@ void ModelTreeWidget::OnWorkspaceChange(WorkSpace* workSpace) {
|
||||
|
||||
const std::vector<Entity*>& entities = currentWorkSpace_->GetEntities();
|
||||
for (const auto& entity : entities) {
|
||||
const QString& entityName = entity->GetName();
|
||||
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem;
|
||||
connect(entity, &Entity::NameChanged, [item](const QString& name) {
|
||||
LOG_WARN("entity name changed: {}", name.toStdString());
|
||||
item->setText(0, name);
|
||||
}
|
||||
);
|
||||
item->setText(0, entityName);
|
||||
QVariant root;
|
||||
root.setValue(entity);
|
||||
item->setData(0, E_Entity, root);
|
||||
item->setData(0, E_UUid, entity->GetUUid());
|
||||
root_->addChild(item);
|
||||
//addTopLevelItem(root_);
|
||||
AddEntity(root_, entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,3 +343,25 @@ void ModelTreeWidget::OnTrackEntity(Entity* entity) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModelTreeWidget::AddEntity(class QTreeWidgetItem* parent, Entity* entity) {
|
||||
const QString& entityName = entity->GetName();
|
||||
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem;
|
||||
connect(entity, &Entity::NameChanged, [item](const QString& name) {
|
||||
LOG_WARN("entity name changed: {}", name.toStdString());
|
||||
item->setText(0, name);
|
||||
}
|
||||
);
|
||||
item->setText(0, entityName);
|
||||
QVariant root;
|
||||
root.setValue(entity);
|
||||
item->setData(0, E_Entity, root);
|
||||
item->setData(0, E_UUid, entity->GetUUid());
|
||||
parent->addChild(item);
|
||||
|
||||
const std::vector<Entity*>& childer = entity->GetChilder();
|
||||
for (const auto& child : childer) {
|
||||
AddEntity(item, child);
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ protected:
|
||||
|
||||
private:
|
||||
//void initUI();
|
||||
void AddEntity(class QTreeWidgetItem* parent, Entity* entity);
|
||||
|
||||
private:
|
||||
WorkSpace* currentWorkSpace_{ nullptr };
|
||||
|
@ -21,6 +21,11 @@
|
||||
<MeshComponent mesh="boke/boke.ive" location="90.000000,30.000000,0.000000" rotation="0.000000,0.000000,0.000000" scale="5.000000,5.000000,5.000000">
|
||||
<PathComponent path="workspace/chuan3.txt" location="0.000000,0.000000,0.000000" rotation="0.000000,0.000000,0.000000" scale="1.000000,1.000000,1.000000"/>
|
||||
</MeshComponent>
|
||||
<Entity uuid="{3c48c04e-a1ac-485d-9ab8-4436b9851a4d}" name="船5">
|
||||
<MeshComponent mesh="boke/boke.ive" location="10.000000,30.000000,0.000000" rotation="0.000000,0.000000,0.000000" scale="1.000000,1.000000,1.000000">
|
||||
<PathComponent path="workspace/chuan2.txt" location="0.000000,0.000000,0.000000" rotation="0.000000,0.000000,0.000000" scale="1.000000,1.000000,1.000000"/>
|
||||
</MeshComponent>
|
||||
</Entity>
|
||||
</Entity>
|
||||
<Entity uuid="{b99a4401-9cc6-493e-a42e-655b81997eb3}" name="卫星">
|
||||
<MeshComponent mesh="satellite/satellite.ive" location="0.000000,0.000000,100.000000" rotation="0.000000,0.000000,0.000000" scale="1.000000,1.000000,1.000000" uuid="{5b764fc4-89ad-4bac-b961-abf310a552fd}">
|
||||
|
Loading…
Reference in New Issue
Block a user