From efbec780a5188badb9165324df2a393c3b36f27a Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Thu, 6 Jun 2019 14:21:22 +0300 Subject: Fix memory leak in inspector and other tweaks - Fix a memory leak: inspector groups are never deleted, so each change of object selection will increment memory. - Remove all dynamic casts from InspectorControlModel.cpp - Other relevant tweaks Task-number: QT3DS-3639 Change-Id: I882ba6d42870a383c20d94247e1fc8690f5026f4 Reviewed-by: Miikka Heikkinen --- src/Authoring/Qt3DStudio/Application/StudioApp.cpp | 29 --- src/Authoring/Qt3DStudio/Application/StudioApp.h | 1 - .../Palettes/Inspector/InspectorControlModel.cpp | 208 +++++++++++---------- .../Palettes/Inspector/InspectorControlModel.h | 50 +++-- .../Palettes/Inspector/InspectorControlView.cpp | 11 +- .../Palettes/Inspector/Qt3DSDMInspectable.cpp | 27 ++- .../Palettes/Inspector/Qt3DSDMInspectable.h | 3 + .../Palettes/Inspector/Qt3DSDMInspectorGroup.cpp | 8 +- .../Palettes/Inspector/Qt3DSDMInspectorGroup.h | 3 +- src/Authoring/Qt3DStudio/Qt3DStudio.pro | 1 - 10 files changed, 173 insertions(+), 168 deletions(-) diff --git a/src/Authoring/Qt3DStudio/Application/StudioApp.cpp b/src/Authoring/Qt3DStudio/Application/StudioApp.cpp index f3594c94..6e2ca19a 100644 --- a/src/Authoring/Qt3DStudio/Application/StudioApp.cpp +++ b/src/Authoring/Qt3DStudio/Application/StudioApp.cpp @@ -204,7 +204,6 @@ int main(int argc, char *argv[]) #include "Qt3DSDMStudioSystem.h" #include "Qt3DSDMInspectable.h" #include "Qt3DSDMSlides.h" -#include "Qt3DSDMMaterialInspectable.h" #include "Qt3DSDMAnimation.h" #include "Qt3DSDMDataCore.h" #include "IDirectoryWatchingSystem.h" @@ -1408,34 +1407,6 @@ void CStudioApp::PlaybackToggle() PlaybackPlay(); } -// TODO: move to more appropriate place (InspectorControlModel.cpp) -CInspectableBase *CStudioApp::getInspectableFromInstance(qt3dsdm::Qt3DSDMInstanceHandle inInstance) -{ - CInspectableBase *inspectableBase = nullptr; - CDoc *doc = m_core->GetDoc(); - - if (doc->GetDocumentReader().IsInstance(inInstance)) { - CClientDataModelBridge *theBridge = doc->GetStudioSystem()->GetClientDataModelBridge(); - qt3dsdm::Qt3DSDMSlideHandle activeSlide = doc->GetActiveSlide(); - - // Slide, scene or component - if (inInstance == theBridge->GetOwningComponentInstance(activeSlide)) { - Qt3DSDMInstanceHandle activeSlideInstance = doc->GetStudioSystem()->GetSlideSystem() - ->GetSlideInstance(activeSlide); - - inspectableBase = new Qt3DSDMInspectable(inInstance, activeSlideInstance); - } - if (!inspectableBase) { - if (theBridge->IsMaterialBaseInstance(inInstance)) - inspectableBase = new Qt3DSDMMaterialInspectable(inInstance); - else - inspectableBase = new Qt3DSDMInspectable(inInstance); - } - } - - return inspectableBase; -} - void CStudioApp::RegisterGlobalKeyboardShortcuts(CHotKeys *inShortcutHandler, QWidget *actionParent) { diff --git a/src/Authoring/Qt3DStudio/Application/StudioApp.h b/src/Authoring/Qt3DStudio/Application/StudioApp.h index 86603af0..6931efa9 100644 --- a/src/Authoring/Qt3DStudio/Application/StudioApp.h +++ b/src/Authoring/Qt3DStudio/Application/StudioApp.h @@ -199,7 +199,6 @@ public: void AdvanceUltraBigTime(); void ReduceUltraBigTime(); void PlaybackToggle(); - CInspectableBase *getInspectableFromInstance(qt3dsdm::Qt3DSDMInstanceHandle inInstance); void RegisterGlobalKeyboardShortcuts(CHotKeys *inShortcutHandler, QWidget *actionParent); bool OnSave(bool autosave = false); void onProjectSaveAs(); diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp index 53519573..f43751bc 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp @@ -44,7 +44,6 @@ #include "Qt3DSDMDataTypes.h" #include "IObjectReferenceHelper.h" #include "SlideSystem.h" -#include "Qt3DSDMMaterialInspectable.h" #include "ClientDataModelBridge.h" #include "IDocumentReader.h" #include "IStudioRenderer.h" @@ -371,9 +370,8 @@ void InspectorControlModel::updateMaterialValues(const QStringList &values, int startIndex = m_groupElements.count() - 1; // Update the last group for referenced materials for (int row = startIndex; row < m_groupElements.count(); ++row) { const CInspectorGroup *inspectorGroup = m_inspectableBase->getGroup(row); - const auto group = dynamic_cast(inspectorGroup); - const auto materialGroup = dynamic_cast(group); - if (materialGroup && (materialGroup->isMaterialGroup() || isReferenced)) { + const auto group = static_cast(inspectorGroup); + if (group->isMaterial() || isReferenced) { if (m_groupElements[row].controlElements.size()) { auto item = m_groupElements[row].controlElements[elementIndex] .value(); @@ -640,11 +638,7 @@ InspectorControlBase *InspectorControlModel::createMaterialTypeItem( item->m_propertyType = qt3dsdm::AdditionalMetaDataType::None; item->m_tooltip = tr("Type of material being used"); item->m_animatable = false; - - const QStringList values = materialTypeValues(); - item->m_values = values; - - QString sourcePath = getBridge()->GetSourcePath(item->m_instance); + item->m_values = materialTypeValues(); switch (inspectable->getObjectType()) { case OBJTYPE_MATERIAL: @@ -652,17 +646,19 @@ InspectorControlBase *InspectorControlModel::createMaterialTypeItem( item->m_value = getAnimatableMaterialString(); break; - case OBJTYPE_REFERENCEDMATERIAL: - item->m_value = getReferencedMaterialString(); - if (sourcePath == getBridge()->getDefaultMaterialName()) - item->m_value = getBasicMaterialString(); - for (int matIdx = 0, end = int(m_matDatas.size()); matIdx < end; ++matIdx) { - if (QString::compare(m_matDatas[matIdx].m_relativePath, - sourcePath, Qt::CaseInsensitive) == 0) { + case OBJTYPE_REFERENCEDMATERIAL: { + QString sourcePath = getBridge()->GetSourcePath(item->m_instance); + item->m_value = sourcePath == getBridge()->getDefaultMaterialName() + ? getBasicMaterialString() + : getReferencedMaterialString(); + + for (auto &mData : m_matDatas) { + if (QString::compare(mData.m_relativePath, sourcePath, Qt::CaseInsensitive) == 0) { item->m_value = getBasicMaterialString(); + break; } } - break; + } break; default: break; @@ -689,9 +685,11 @@ InspectorControlBase *InspectorControlModel::createShaderItem( QString sourcePath = getBridge()->GetSourcePath(item->m_instance); item->m_value = values[0]; - for (int matIdx = 0, end = int(m_materials.size()); matIdx < end; ++matIdx) { - if (m_materials[matIdx].m_relativePath == sourcePath) - item->m_value = values[matIdx + 1]; + for (int i = 0, end = int(m_materials.size()); i < end; ++i) { + if (m_materials[i].m_relativePath == sourcePath) { + item->m_value = values[i + 1]; // + 1 for Standard shader + break; + } } return item; @@ -715,10 +713,10 @@ InspectorControlBase *InspectorControlModel::createMatDataItem( QString sourcePath = getBridge()->GetSourcePath(item->m_instance); item->m_value = getDefaultMaterialString(); - for (int matIdx = 0, end = int(m_matDatas.size()); matIdx < end; ++matIdx) { - if (QString::compare(m_matDatas[matIdx].m_relativePath, - sourcePath, Qt::CaseInsensitive) == 0) { - item->m_value = values[matIdx + 1]; // + 1 for Default basic material + for (int i = 0, end = int(m_matDatas.size()); i < end; ++i) { + if (QString::compare(m_matDatas[i].m_relativePath, sourcePath, Qt::CaseInsensitive) == 0) { + item->m_value = values[i + 1]; // + 1 for Default basic material + break; } } @@ -918,29 +916,31 @@ bool InspectorControlModel::isGroupRebuildRequired(CInspectableBase *inspectable if (existingGroup.groupTitle != theInspectorGroup->GetName()) return true; - if (const auto cdmInspectable = dynamic_cast(inspectable)) { + if (inspectable->getObjectType() != OBJTYPE_GUIDE) { + const auto dmInspectable = static_cast(inspectable); + const auto group = static_cast(theInspectorGroup); int existingIndex = 0; - if (const auto group = dynamic_cast(theInspectorGroup)) { - const auto materialGroup = dynamic_cast(group); - if (materialGroup && materialGroup->isMaterialGroup()) { - auto i = existingGroup.controlElements.at(existingIndex++).value(); - if (i->m_instance != cdmInspectable->GetGroupInstance(theIndex)) - return true; - if (!isInsideMaterialContainer()) - existingIndex++; // Add material type dropdown to existing elements - } - - if ((existingGroup.controlElements.size() - existingIndex) != group->GetRows().size()) + if (group && group->isMaterial()) { + auto i = existingGroup.controlElements.at(existingIndex++) + .value(); + if (i->m_instance != dmInspectable->GetGroupInstance(theIndex)) return true; - for (const auto row : group->GetRows()) { - auto i = existingGroup.controlElements.at(existingIndex++).value(); - if (i->m_instance != cdmInspectable->GetGroupInstance(theIndex)) - return true; + if (!isInsideMaterialContainer()) + existingIndex++; // Add material type dropdown to existing elements + } - if (i->m_property != row->GetMetaDataPropertyInfo().m_Property) - return true; - } + if ((existingGroup.controlElements.size() - existingIndex) != group->GetRows().size()) + return true; + + for (const auto row : group->GetRows()) { + auto i = existingGroup.controlElements.at(existingIndex++) + .value(); + if (i->m_instance != dmInspectable->GetGroupInstance(theIndex)) + return true; + + if (i->m_property != row->GetMetaDataPropertyInfo().m_Property) + return true; } } @@ -952,17 +952,37 @@ CClientDataModelBridge *InspectorControlModel::getBridge() const return g_StudioApp.GetCore()->GetDoc()->GetStudioSystem()->GetClientDataModelBridge(); } -auto InspectorControlModel::computeTree(CInspectableBase *inspectBase) +CInspectableBase *InspectorControlModel::getInspectableFromInstance( + qt3dsdm::Qt3DSDMInstanceHandle inInstance) +{ + CDoc *doc = g_StudioApp.GetCore()->GetDoc(); + qt3dsdm::ISlideSystem *slideSystem = doc->GetStudioSystem()->GetSlideSystem(); + + if (doc->GetDocumentReader().IsInstance(inInstance)) { + qt3dsdm::Qt3DSDMSlideHandle activeSlide = doc->GetActiveSlide(); + qt3dsdm::Qt3DSDMInstanceHandle activeSlideInstance = 0; + + // Slide, scene or component + if (inInstance == getBridge()->GetOwningComponentInstance(activeSlide)) + activeSlideInstance = slideSystem->GetSlideInstance(activeSlide); + + return new Qt3DSDMInspectable(inInstance, activeSlideInstance); + } + + return nullptr; +} + +auto InspectorControlModel::computeTree(CInspectableBase *inspectableBase) -> QVector { QVector result; - if (inspectBase) { - qt3dsdm::Qt3DSDMInstanceHandle instance = inspectBase->getInstance(); + if (inspectableBase) { + qt3dsdm::Qt3DSDMInstanceHandle instance = inspectableBase->getInstance(); bool isMatFromFile = instance.Valid() && getBridge()->isInsideMaterialContainer(instance); - long groupCount = inspectBase->getGroupCount(); + long groupCount = inspectableBase->getGroupCount(); for (long idx = 0; idx < groupCount; ++idx) - result.append(computeGroup(inspectBase, idx, isMatFromFile, false)); + result.append(computeGroup(inspectableBase, idx, isMatFromFile, false)); if (isDefaultMaterial() && result.size() > 0) { result[result.size() - 1].groupInfo = tr("\nDefault material cannot be edited.\n\n" @@ -970,9 +990,9 @@ auto InspectorControlModel::computeTree(CInspectableBase *inspectBase) } //Show original material properties for referenced materials - auto refMaterial = getReferenceMaterial(inspectBase); + auto refMaterial = getReferenceMaterial(inspectableBase); if (refMaterial.Valid()) { - auto refMaterialInspectable = g_StudioApp.getInspectableFromInstance(refMaterial); + auto refMaterialInspectable = getInspectableFromInstance(refMaterial); if (refMaterialInspectable) { QString materialSrcPath; if (instance.Valid()) @@ -992,11 +1012,11 @@ auto InspectorControlModel::computeTree(CInspectableBase *inspectBase) return result; } -auto InspectorControlModel::computeGroup(CInspectableBase *inspectable, int theIndex, +auto InspectorControlModel::computeGroup(CInspectableBase *inspectable, int index, bool disableAnimation, bool isReference) -> GroupInspectorControl { - CInspectorGroup *theInspectorGroup = inspectable->getGroup(theIndex); + CInspectorGroup *theInspectorGroup = inspectable->getGroup(index); GroupInspectorControl result; result.groupTitle = theInspectorGroup->GetName(); result.groupInfo.clear(); @@ -1004,43 +1024,44 @@ auto InspectorControlModel::computeGroup(CInspectableBase *inspectable, int theI if (isReference) result.groupTitle += tr(" (Reference)"); - if (const auto cdmInspectable = dynamic_cast(inspectable)) { - if (const auto group = dynamic_cast(theInspectorGroup)) { - const auto materialGroup = dynamic_cast(group); - bool isMatData = isBasicMaterial(cdmInspectable); - if (materialGroup && materialGroup->isMaterialGroup()) { - InspectorControlBase *item = nullptr; - - if (!isInsideMaterialContainer(cdmInspectable) && !isReference) { - item = createMaterialTypeItem(cdmInspectable, theIndex); - if (item) - result.controlElements.push_back(QVariant::fromValue(item)); - } - - if (isAnimatableMaterial(cdmInspectable)) { - item = createShaderItem(cdmInspectable, theIndex); - if (item) - result.controlElements.push_back(QVariant::fromValue(item)); - } else if (isMatData) { - item = createMatDataItem(cdmInspectable, theIndex); - if (item) - result.controlElements.push_back(QVariant::fromValue(item)); - } - } + if (inspectable->getObjectType() != OBJTYPE_GUIDE) { + const auto dmInspectable = static_cast(inspectable); + const auto group = static_cast(theInspectorGroup); - for (const auto row : group->GetRows()) { - InspectorControlBase *item = createItem(cdmInspectable, row, theIndex); - if (!item) - continue; + bool isBasicMat = isBasicMaterial(dmInspectable); + if (group->isMaterial()) { + InspectorControlBase *item = nullptr; - if (disableAnimation) - item->m_animatable = false; + if (!isInsideMaterialContainer(dmInspectable) && !isReference) { + item = createMaterialTypeItem(dmInspectable, index); + if (item) + result.controlElements.push_back(QVariant::fromValue(item)); + } - if (!isMatData || item->m_title != getReferencedMaterialString()) + if (isAnimatableMaterial(dmInspectable)) { + item = createShaderItem(dmInspectable, index); + if (item) + result.controlElements.push_back(QVariant::fromValue(item)); + } else if (isBasicMat) { + item = createMatDataItem(dmInspectable, index); + if (item) result.controlElements.push_back(QVariant::fromValue(item)); } } - } else if (const auto guideInspectable = dynamic_cast(inspectable)) { + + for (const auto row : group->GetRows()) { + InspectorControlBase *item = createItem(dmInspectable, row, index); + if (!item) + continue; + + if (disableAnimation) + item->m_animatable = false; + + if (!isBasicMat || item->m_title != getReferencedMaterialString()) + result.controlElements.push_back(QVariant::fromValue(item)); + } + } else { // Guide + const auto guideInspectable = static_cast(inspectable); // Guide properties don't come from metadata as they are not actual objects m_guideInspectable = guideInspectable; const auto &properties = m_guideInspectable->properties(); @@ -1426,7 +1447,7 @@ void InspectorControlModel::saveIfMaterial(qt3dsdm::Qt3DSDMInstanceHandle instan EStudioObjectType type = getBridge()->GetObjectType(instance); auto material = instance; - if (type == EStudioObjectType::OBJTYPE_IMAGE) + if (type == OBJTYPE_IMAGE) material = sceneEditor->GetParent(instance); if (!material.Valid()) @@ -1441,8 +1462,7 @@ void InspectorControlModel::saveIfMaterial(qt3dsdm::Qt3DSDMInstanceHandle instan type = getBridge()->GetObjectType(material); - if (type == EStudioObjectType::OBJTYPE_MATERIAL - || type == EStudioObjectType::OBJTYPE_CUSTOMMATERIAL) { + if (type & (OBJTYPE_MATERIAL | OBJTYPE_CUSTOMMATERIAL)) { qt3dsdm::SValue value; studio->GetPropertySystem()->GetInstancePropertyValue( material, getBridge()->GetObjectDefinitions().m_Named.m_NameProp, value); @@ -1563,7 +1583,7 @@ void InspectorControlModel::setMatDataValue(long instance, int handle, const QVa const QString typeValue = value.toString(); QString v; QString name; - Q3DStudio::CString srcPath; + QString srcPath; QMap values; QMap> textureValues; @@ -1573,7 +1593,7 @@ void InspectorControlModel::setMatDataValue(long instance, int handle, const QVa if (typeValue == getDefaultMaterialString()) { v = QStringLiteral("Referenced Material"); name = getBridge()->getDefaultMaterialName(); - srcPath = Q3DStudio::CString::fromQString(name); + srcPath = name; changeMaterialFile = true; } else { const auto sceneEditor = doc->getSceneEditor(); @@ -1589,15 +1609,15 @@ void InspectorControlModel::setMatDataValue(long instance, int handle, const QVa v = QStringLiteral("Referenced Material"); changeMaterialFile = true; name = m_matDatas[matIdx].m_name; - srcPath = Q3DStudio::CString::fromQString(m_matDatas[matIdx].m_relativePath); - const auto material = sceneEditor->getMaterial(srcPath.toQString()); + srcPath = m_matDatas[matIdx].m_relativePath; + const auto material = sceneEditor->getMaterial(srcPath); if (material.Valid()) { // Get the correct case source path const auto absPath = sceneEditor->getFilePathFromMaterialName( sceneEditor->GetName(material).toQString()); const auto relPath = QDir(doc->GetDocumentDirectory()) .relativeFilePath(absPath); - srcPath = Q3DStudio::CString::fromQString(relPath); + srcPath = relPath; } values = m_matDatas[matIdx].m_values; textureValues = m_matDatas[matIdx].m_textureValues; @@ -1609,7 +1629,7 @@ void InspectorControlModel::setMatDataValue(long instance, int handle, const QVa if (changeMaterialFile) { { Q3DStudio::SCOPED_DOCUMENT_EDITOR(*doc, QString()) - ->setMaterialValues(srcPath.toQString(), values, textureValues); + ->setMaterialValues(srcPath, values, textureValues); } // Several aspects of the editor are not updated correctly // if the data core is changed without a transaction @@ -1624,8 +1644,8 @@ void InspectorControlModel::setMatDataValue(long instance, int handle, const QVa scopedEditor->SetMaterialType(instance, v); if (changeMaterialFile) { - scopedEditor->setMaterialSourcePath(instance, srcPath); - scopedEditor->setMaterialReferenceByPath(instance, srcPath.toQString()); + scopedEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(srcPath)); + scopedEditor->setMaterialReferenceByPath(instance, srcPath); // Select original instance again since potentially // creating a material selects the created one diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h index 3063f047..f068b875 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h @@ -160,23 +160,13 @@ public: Q_INVOKABLE void updateGroupCollapseState(int groupIdx, bool state); private: - void onSlideRearranged(const qt3dsdm::Qt3DSDMSlideHandle &inMaster, int inOldIndex, - int inNewIndex); - - - struct GroupInspectorControl { + struct GroupInspectorControl + { QString groupTitle; QVariantList controlElements; QString groupInfo; - - ~GroupInspectorControl() { - } }; - QVector m_groupElements; - CInspectableBase *m_inspectableBase = nullptr; - GuideInspectable *m_guideInspectable = nullptr; - struct MaterialEntry { QString m_name; @@ -191,20 +181,9 @@ private: QMap> m_textureValues; }; - std::vector m_materials; - std::vector m_matDatas; - std::vector m_cachedMatDatas; - qt3dsdm::Qt3DSDMInstanceHandle m_refMaterial; - - Q3DStudio::CUpdateableDocumentEditor m_UpdatableEditor; - - bool m_suspendMaterialRename = false; - - QPair m_modifiedProperty; - - qt3dsdm::SValue m_previouslyCommittedValue; + void onSlideRearranged(const qt3dsdm::Qt3DSDMSlideHandle &inMaster, int inOldIndex, + int inNewIndex); - QHash > m_collapseMap; QString getBasicMaterialString() const; QString getAnimatableMaterialString() const; @@ -247,11 +226,30 @@ private: int theIndex, bool disableAnimation = false, bool isReference = false); bool isGroupRebuildRequired(CInspectableBase *inspectable, int theIndex) const; - + CInspectableBase *getInspectableFromInstance(qt3dsdm::Qt3DSDMInstanceHandle inInstance); CClientDataModelBridge *getBridge() const; static int handleToGuidePropIndex(int handle) { return handle - 1; } + QVector m_groupElements; + CInspectableBase *m_inspectableBase = nullptr; + GuideInspectable *m_guideInspectable = nullptr; + + std::vector m_materials; + std::vector m_matDatas; + std::vector m_cachedMatDatas; + qt3dsdm::Qt3DSDMInstanceHandle m_refMaterial; + + Q3DStudio::CUpdateableDocumentEditor m_UpdatableEditor; + + bool m_suspendMaterialRename = false; + + QPair m_modifiedProperty; + + qt3dsdm::SValue m_previouslyCommittedValue; + + QHash > m_collapseMap; + VariantsGroupModel *m_variantsModel = nullptr; }; diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlView.cpp b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlView.cpp index c642d1e8..3ae6ae95 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlView.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlView.cpp @@ -65,7 +65,6 @@ #include "SelectedValue.h" #include "Qt3DSDMInspectable.h" #include "Qt3DSDMSlides.h" -#include "Qt3DSDMMaterialInspectable.h" #include "GuideInspectable.h" #include @@ -407,8 +406,10 @@ void InspectorControlView::OnSelectionSet(Q3DStudio::SSelectedValue selectable) { CInspectableBase *inspectable = createInspectableFromSelectable(selectable); - if (inspectable && !inspectable->isValid()) + if (inspectable && !inspectable->isValid()) { + delete inspectable; inspectable = nullptr; + } setInspectable(inspectable); } @@ -444,8 +445,6 @@ CInspectableBase *InspectorControlView::createInspectableFromSelectable( ->GetSlideSystem()->GetSlideInstance(activeSlide); inspectableBase = new Qt3DSDMInspectable(selectedInstance, activeSlideInstance); - } else if (bridge->IsMaterialBaseInstance(selectedInstance)) { - inspectableBase = new Qt3DSDMMaterialInspectable(selectedInstance); } else { inspectableBase = new Qt3DSDMInspectable(selectedInstance); } @@ -470,6 +469,10 @@ void InspectorControlView::setInspectable(CInspectableBase *inInspectable) { if (m_inspectableBase != inInspectable) { m_activeBrowser.clear(); + + if (m_inspectableBase) + delete m_inspectableBase; + m_inspectableBase = inInspectable; m_inspectorControlModel->setInspectable(inInspectable); diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.cpp b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.cpp index a82df79c..c42840a4 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.cpp @@ -54,6 +54,13 @@ Qt3DSDMInspectable::Qt3DSDMInspectable(qt3dsdm::Qt3DSDMInstanceHandle instance, } } +Qt3DSDMInspectable::~Qt3DSDMInspectable() +{ + for (auto g : qAsConst(m_groups)) + delete g; + m_groups.clear(); +} + // Returns the name of this inspectable Q3DStudio::CString Qt3DSDMInspectable::getName() { @@ -87,11 +94,15 @@ long Qt3DSDMInspectable::getGroupCount() const } // Return the property group for display -CInspectorGroup *Qt3DSDMInspectable::getGroup(long inIndex) +CInspectorGroup *Qt3DSDMInspectable::getGroup(long index) { - Qt3DSDMInspectorGroup *group = new Qt3DSDMInspectorGroup(GetGroupName(inIndex)); + if (m_groups.contains(index)) + return m_groups[index]; + + Qt3DSDMInspectorGroup *group = new Qt3DSDMInspectorGroup(GetGroupName(index)); + m_groups[index] = group; - TMetaDataPropertyHandleList properties = GetGroupProperties(inIndex); + TMetaDataPropertyHandleList properties = GetGroupProperties(index); for (auto &prop : properties) group->CreateRow(getDoc(), prop); @@ -100,16 +111,16 @@ CInspectorGroup *Qt3DSDMInspectable::getGroup(long inIndex) } // Return the property handles for display, given the group index -TMetaDataPropertyHandleList Qt3DSDMInspectable::GetGroupProperties(long inIndex) +TMetaDataPropertyHandleList Qt3DSDMInspectable::GetGroupProperties(long index) { - long activeGroupIdx = activeGroupIndex(inIndex); + long activeGroupIdx = activeGroupIndex(index); TMetaDataPropertyHandleList retval; IMetaData &theMetaData = *getDoc()->GetStudioSystem()->GetActionMetaData(); - theMetaData.GetMetaDataProperties(GetGroupInstance(inIndex), retval); + theMetaData.GetMetaDataProperties(GetGroupInstance(index), retval); qt3dsdm::IPropertySystem &thePropertySystem(*getDoc()->GetStudioSystem()->GetPropertySystem()); // get name of the current group for filtering Option theGroupFilterName = - theMetaData.GetGroupFilterNameForInstance(GetGroupInstance(inIndex), activeGroupIdx); + theMetaData.GetGroupFilterNameForInstance(GetGroupInstance(index), activeGroupIdx); long theGroupCount = getGroupCount(); // end is explicitly required @@ -140,7 +151,7 @@ TMetaDataPropertyHandleList Qt3DSDMInspectable::GetGroupProperties(long inIndex) SValue theValue; thePropertySystem.GetInstancePropertyValue( - GetGroupInstance(inIndex), theFilter.m_FilterProperty, theValue); + GetGroupInstance(index), theFilter.m_FilterProperty, theValue); bool resultIfTrue = theFilter.m_FilterType == PropertyFilterTypes::ShowIfEqual; if (Equals(theValue.toOldSkool(), theFilter.m_Value.toOldSkool())) { keepProperty = resultIfTrue; diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.h b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.h index 0da2916d..56529c5d 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.h +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectable.h @@ -41,6 +41,7 @@ class Qt3DSDMInspectable : public CInspectableBase public: Qt3DSDMInspectable(qt3dsdm::Qt3DSDMInstanceHandle inInstance, qt3dsdm::Qt3DSDMInstanceHandle activeSlideInstance = 0); + ~Qt3DSDMInspectable(); Q3DStudio::CString getName() override; long getGroupCount() const override; @@ -59,6 +60,8 @@ protected: virtual QString GetGroupName(long inGroupIndex); CDoc *getDoc() const; long activeGroupIndex(long groupIndex) const; + + QHash m_groups; }; #endif diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.cpp b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.cpp index f62812ac..c3f435f1 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.cpp @@ -29,7 +29,6 @@ #include "Qt3DSDMInspectorGroup.h" #include "Qt3DSDMInspectorRow.h" -#include "Qt3DSDMInspectable.h" #include "Qt3DSDMMetaData.h" Qt3DSDMInspectorGroup::Qt3DSDMInspectorGroup(const QString &inName) @@ -39,11 +38,12 @@ Qt3DSDMInspectorGroup::Qt3DSDMInspectorGroup(const QString &inName) Qt3DSDMInspectorGroup::~Qt3DSDMInspectorGroup() { - for (auto it = m_inspectorRows.begin(); it != m_inspectorRows.end(); ++it) - delete (*it); + for (auto row : m_inspectorRows) + delete row; + + m_inspectorRows.clear(); } -// Create a new InspectorRowBase. void Qt3DSDMInspectorGroup::CreateRow(CDoc *inDoc, qt3dsdm::Qt3DSDMMetaDataPropertyHandle inProperty) { diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.h b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.h index c2bbc9fc..146d6363 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.h +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/Qt3DSDMInspectorGroup.h @@ -49,8 +49,9 @@ public: void CreateRow(CDoc *inDoc, qt3dsdm::Qt3DSDMMetaDataPropertyHandle inProperty); const std::vector &GetRows() const { return m_inspectorRows; } + bool isMaterial() const { return m_name == QLatin1String("Material"); } -protected: +private: std::vector m_inspectorRows; }; diff --git a/src/Authoring/Qt3DStudio/Qt3DStudio.pro b/src/Authoring/Qt3DStudio/Qt3DStudio.pro index 5a7af2a3..e7bc3810 100644 --- a/src/Authoring/Qt3DStudio/Qt3DStudio.pro +++ b/src/Authoring/Qt3DStudio/Qt3DStudio.pro @@ -314,7 +314,6 @@ SOURCES += \ Palettes/Inspector/Qt3DSDMInspectable.cpp \ Palettes/Inspector/Qt3DSDMInspectorGroup.cpp \ Palettes/Inspector/Qt3DSDMInspectorRow.cpp \ - Palettes/Inspector/Qt3DSDMMaterialInspectable.cpp \ Palettes/Inspector/TabOrderHandler.cpp \ Palettes/Inspector/TextureChooserView.cpp \ Palettes/PaletteManager.cpp \ -- cgit v1.2.3