!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Sandbox / Plugins / SchematycEditor / GenericWidgetModel.cpp
blobd5aa7b84c31df99093a6e66af6f229eeda8190c8
1 // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "StdAfx.h"
4 #include "GenericWidgetModel.h"
6 #include <Controls/DictionaryWidget.h>
8 #include <ProxyModels/MergingProxyModel.h>
9 #include <ProxyModels/ItemModelAttribute.h>
11 #include <CrySchematyc2/IFramework.h>
12 #include <CrySchematyc2/Script/IScriptGraph.h>
13 #include <CrySchematyc2/Script/IScriptRegistry.h>
15 #include "Util.h"
17 namespace Cry {
18 namespace SchematycEd {
20 //////////////////////////////////////////////////////////////////////////
21 CGenericWidgetDictionaryEntry::CGenericWidgetDictionaryEntry(CGenericWidgetDictionaryModel& dictionaryModel)
22 : m_node(Type_Undefined)
23 , m_dictionaryModel(dictionaryModel)
27 //////////////////////////////////////////////////////////////////////////
28 uint32 CGenericWidgetDictionaryEntry::GetType() const
30 return m_node;
33 //////////////////////////////////////////////////////////////////////////
34 int32 CGenericWidgetDictionaryEntry::GetNumChildEntries() const
36 return m_childs.size();
39 //////////////////////////////////////////////////////////////////////////
40 const CAbstractDictionaryEntry* CGenericWidgetDictionaryEntry::GetChildEntry(int32 index) const
42 if ((index >= 0) && (index < m_childs.size()))
43 return m_dictionaryModel.GetEntryByGUID(m_childs[index]);
45 return nullptr;
48 //////////////////////////////////////////////////////////////////////////
49 const CAbstractDictionaryEntry* CGenericWidgetDictionaryEntry::GetParentEntry() const
51 return m_dictionaryModel.GetEntryByGUID(m_parent);
54 //////////////////////////////////////////////////////////////////////////
55 QString CGenericWidgetDictionaryEntry::GetToolTip() const
57 return m_description;
60 //////////////////////////////////////////////////////////////////////////
61 QString CGenericWidgetDictionaryEntry::GetName() const
63 return m_name;
66 //////////////////////////////////////////////////////////////////////////
67 QString CGenericWidgetDictionaryEntry::GetFullName() const
69 return m_fullName;
72 //////////////////////////////////////////////////////////////////////////
73 SGUID CGenericWidgetDictionaryEntry::GetTypeGUID()
75 return m_guid;
78 //////////////////////////////////////////////////////////////////////////
79 QVariant CGenericWidgetDictionaryEntry::GetColumnValue(int32 columnIndex) const
81 switch (columnIndex)
83 case CGenericWidgetDictionaryModel::Column_Name:
85 return QVariant::fromValue(m_name);
87 case CGenericWidgetDictionaryModel::Column_Type:
89 return QVariant::fromValue(m_type);
91 default:
93 break;
97 return QVariant();
100 //////////////////////////////////////////////////////////////////////////
101 void CGenericWidgetDictionaryModel::ClearScriptElementModel()
103 m_entryGuid.clear();
104 m_entryPool.clear();
105 m_entryDict.clear();
107 m_entryPool.reserve(128);
110 //////////////////////////////////////////////////////////////////////////
111 CGenericWidgetDictionaryEntry* CGenericWidgetDictionaryModel::BuildScriptElementEntry(const IScriptElement& element, const char* typeName)
113 m_entryPool.emplace_back(*this);
114 CGenericWidgetDictionaryEntry& entry = m_entryPool.back();
116 entry.m_name = element.GetName();
117 entry.m_guid = element.GetGUID();
118 entry.m_node = CAbstractDictionaryEntry::Type_Entry;
119 entry.m_type = typeName;
121 m_entryDict.insert(std::make_pair(entry.m_guid, &entry));
122 return &entry;
125 void CGenericWidgetDictionaryModel::BuildScriptElementParent(const IScriptElement& element, CGenericWidgetDictionaryEntry* childEntry, const std::vector<EScriptElementType>& parentType)
127 const IScriptElement* parent = element.GetParent();
128 for (auto& type : parentType)
130 if (parent && (parent->GetElementType() == type))
132 CGenericWidgetDictionaryEntry* parentEntry = GetEntryByGUID(parent->GetGUID());
133 if (!parentEntry)
134 break;
136 parentEntry->m_childs.emplace_back(childEntry->m_guid);
137 parentEntry->m_node = CAbstractDictionaryEntry::Type_Folder;
139 childEntry->m_parent = parent->GetGUID();
140 return;
144 m_entryGuid.push_back(childEntry->m_guid);
145 return;
148 //////////////////////////////////////////////////////////////////////////
149 int32 CGenericWidgetDictionaryModel::GetNumEntries() const
151 return m_entryGuid.size();
154 //////////////////////////////////////////////////////////////////////////
155 const CAbstractDictionaryEntry* CGenericWidgetDictionaryModel::GetEntry(int32 index) const
157 if (index < m_entryGuid.size())
159 return GetEntryByGUID(m_entryGuid[index]);
162 return nullptr;
165 //////////////////////////////////////////////////////////////////////////
166 int32 CGenericWidgetDictionaryModel::GetNumColumns() const
168 return Column_Count;
171 //////////////////////////////////////////////////////////////////////////
172 QString CGenericWidgetDictionaryModel::GetColumnName(int32 index) const
174 auto pAttribute = CGenericWidgetDictionaryModel::GetColumnAttributeInternal(index);
175 if (pAttribute)
177 return QString(pAttribute->GetName());
180 return QString();
183 //////////////////////////////////////////////////////////////////////////
184 int32 CGenericWidgetDictionaryModel::GetDefaultFilterColumn() const
186 return Column_Type;
189 //////////////////////////////////////////////////////////////////////////
190 int32 CGenericWidgetDictionaryModel::GetDefaultSortColumn() const
192 return Column_Name;
195 //////////////////////////////////////////////////////////////////////////
196 const CItemModelAttribute* CGenericWidgetDictionaryModel::GetColumnAttribute(int32 index) const
198 return GetColumnAttributeInternal(index);
201 //////////////////////////////////////////////////////////////////////////
202 CGenericWidgetDictionaryEntry* CGenericWidgetDictionaryModel::GetEntryByGUID(const Schematyc2::SGUID& guid) const
204 auto it = m_entryDict.find(guid);
205 if (it != m_entryDict.end())
207 return it->second;
210 return nullptr;
213 const CItemModelAttribute* CGenericWidgetDictionaryModel::GetColumnAttributeInternal(int column)
215 static CItemModelAttribute Name("Name", eAttributeType_String);
216 static CItemModelAttribute Type("Type", eAttributeType_String);
217 static CItemModelAttribute None(" ", eAttributeType_String);
219 switch (column)
221 case Column_Name: return &Name;
222 case Column_Type: return &Type;
225 return &None;
228 } //namespace SchematycEd
229 } //namespace Cry