diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-08-15 16:44:12 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-08-17 04:02:15 +0000 |
commit | 6656ec08f1b7880f171fd234a6f7afab7df1f4ef (patch) | |
tree | 3725c5fbaa8008d372d89140f20e806ad473b803 | |
parent | e53fe016e071c00967beb0b8e9b0755d78d70cb5 (diff) |
Highlight referenced presentations
Also cleaned up references handling a bit.
Task-number: QT3DS-2075
Change-Id: I4dac2b5d3ea128921dc61c59adb2072f1bbbad02
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
6 files changed, 71 insertions, 51 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.cpp b/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.cpp index 1bfc9bac..a9e5e249 100644 --- a/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.cpp +++ b/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.cpp @@ -1322,6 +1322,23 @@ std::set<Q3DStudio::CString> CClientDataModelBridge::GetDynamicObjectTextureList return theSourcePathList; } +std::set<QString> CClientDataModelBridge::getRenderableList() const +{ + std::vector<SValue> valueList + = GetValueList(m_Layer.m_Instance, m_SceneAsset.m_SourcePath, nullptr); + std::vector<SValue> imageList + = GetValueList(m_SceneImage.m_Instance, m_SceneImage.m_SubPresentation, nullptr); + valueList.insert(valueList.end(), imageList.begin(), imageList.end()); + + std::set<QString> idList; + for (auto it = valueList.begin(); it != valueList.end(); ++it) { + QString renderableId = qt3dsdm::get<TDataStrPtr>(*it)->toQString(); + if (!renderableId.isEmpty()) + idList.insert(renderableId); + } + return idList; +} + bool CClientDataModelBridge::IsLockedAtAll(qt3dsdm::Qt3DSDMInstanceHandle inInstance) { qt3dsdm::SValue theValue; diff --git a/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.h b/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.h index 4d0a85c2..4b43ef3e 100644 --- a/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.h +++ b/src/Authoring/Client/Code/Core/Doc/ClientDataModelBridge/ClientDataModelBridge.h @@ -367,6 +367,7 @@ public: std::set<Q3DStudio::CString> GetSourcePathList() const; std::set<Q3DStudio::CString> GetFontFileList() const; std::set<Q3DStudio::CString> GetDynamicObjectTextureList() const; + std::set<QString> getRenderableList() const; bool IsLockedAtAll(qt3dsdm::Qt3DSDMInstanceHandle inInstance); bool IsDuplicateable(qt3dsdm::Qt3DSDMInstanceHandle inInstance); bool IsMultiSelectable(qt3dsdm::Qt3DSDMInstanceHandle inInstance); diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMDataTypes.h b/src/Authoring/QT3DSDM/Systems/Qt3DSDMDataTypes.h index 9a0bedf7..104a4558 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMDataTypes.h +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMDataTypes.h @@ -196,6 +196,7 @@ public: const wchar_t *GetData() const { return m_Data.size() <= 1 ? L"" : &(*m_Data.begin()); } size_t GetLength() const { return m_Data.size() > 1 ? m_Data.size() - 1 : 0; } bool operator==(const CDataStr &inOther) const { return m_Data == inOther.m_Data; } + QString toQString() const { return QString::fromWCharArray(GetData()); } }; typedef std::shared_ptr<CDataStr> TDataStrPtr; diff --git a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp index 39587036..9190b9a9 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp @@ -132,7 +132,7 @@ bool ProjectFileSystemModel::isRefreshable(int row) const return path.endsWith(QLatin1String(".import")); } -void ProjectFileSystemModel::updateReferences(bool emitDataChanged) +void ProjectFileSystemModel::updateReferences() { m_references.clear(); const auto doc = g_StudioApp.GetCore()->GetDoc(); @@ -140,57 +140,45 @@ void ProjectFileSystemModel::updateReferences(bool emitDataChanged) const auto sourcePathList = bridge->GetSourcePathList(); const auto fontFileList = bridge->GetFontFileList(); const auto effectTextureList = bridge->GetDynamicObjectTextureList(); - - // Handle source and font references - QString uipPath = QDir::cleanPath(doc->GetDocumentDirectory().toQString()); - auto addFileReferencesUip = [this, doc, &uipPath](const Q3DStudio::CString &str) { - auto path = doc->GetResolvedPathToDoc(str).toQString(); - path = QDir::cleanPath(path); - m_references.append(path); - QString parentPath = QFileInfo(path).path(); - do { - if (!m_references.contains(parentPath)) - m_references.append(parentPath); - - path = parentPath; - parentPath = QFileInfo(path).path(); - } while (uipPath != path && parentPath != path); + auto renderableList = bridge->getRenderableList(); + auto subpresentationRecord = g_StudioApp.m_subpresentations; + + const QDir projectDir(doc->GetCore()->getProjectFile().getProjectPath()); + const QString projectPath = QDir::cleanPath(projectDir.absolutePath()); + const QString projectPathSlash = projectPath + QStringLiteral("/"); + + // Add current presentation to renderables list + renderableList.insert(doc->getPresentationId()); + subpresentationRecord.push_back( + SubPresentationRecord( + QString(), doc->getPresentationId(), + projectDir.relativeFilePath(doc->GetDocumentPath().GetPath().toQString()))); + + auto addReferencesPresentation = [this, doc, &projectPath](const Q3DStudio::CString &str) { + addPathsToReferences(projectPath, doc->GetResolvedPathToDoc(str).toQString()); + }; + auto addReferencesProject = [this, doc, &projectPath](const Q3DStudio::CString &str) { + addPathsToReferences( + projectPath, + doc->GetCore()->getProjectFile().getResolvedPathTo(str.toQString())); }; - std::for_each(sourcePathList.begin(), sourcePathList.end(), addFileReferencesUip); - std::for_each(fontFileList.begin(), fontFileList.end(), addFileReferencesUip); - - // Handle effect texture references - QString projectPath = QDir::cleanPath(doc->GetCore()->getProjectFile().getProjectPath()); - auto addFileReferencesUia = [this, doc, &projectPath](const Q3DStudio::CString &str) { - auto path = doc->GetCore()->getProjectFile().getResolvedPathTo(str.toQString()); - m_references.append(path); - QString parentPath = QFileInfo(path).path(); - do { - if (!m_references.contains(parentPath)) - m_references.append(parentPath); - - path = parentPath; - parentPath = QFileInfo(path).path(); - } while (projectPath != path && parentPath != path); + auto addReferencesRenderable = [this, &projectPath, &projectPathSlash, &subpresentationRecord] + (const QString &id) { + for (SubPresentationRecord r : qAsConst(subpresentationRecord)) { + if (r.m_id == id) + addPathsToReferences(projectPath, projectPathSlash + r.m_argsOrSrc); + } }; - std::for_each(effectTextureList.begin(), effectTextureList.end(), addFileReferencesUia); - // add currently open presentation references - QString path = QDir::cleanPath(doc->GetDocumentPath().GetPath().toQString()); - QString parentPath = QFileInfo(path).path(); - m_references.append(path); - do { - if (!m_references.contains(parentPath)) - m_references.append(parentPath); + std::for_each(sourcePathList.begin(), sourcePathList.end(), addReferencesPresentation); + std::for_each(fontFileList.begin(), fontFileList.end(), addReferencesPresentation); + std::for_each(effectTextureList.begin(), effectTextureList.end(), addReferencesProject); + std::for_each(renderableList.begin(), renderableList.end(), addReferencesRenderable); - path = parentPath; - parentPath = QFileInfo(path).path(); - } while (uipPath != path && parentPath != path); + m_references.insert(projectPath); - if (emitDataChanged) { - Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {IsReferencedRole, - Qt::DecorationRole}); - } + Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {IsReferencedRole, + Qt::DecorationRole}); } Q3DStudio::DocumentEditorFileType::Enum ProjectFileSystemModel::assetTypeForRow(int row) @@ -238,7 +226,6 @@ void ProjectFileSystemModel::setRootIndex(const QModelIndex &rootIndex) return; clearModelData(); - updateReferences(false); m_rootIndex = rootIndex; @@ -874,3 +861,16 @@ void ProjectFileSystemModel::updateDefaultDirMap() } } } + +void ProjectFileSystemModel::addPathsToReferences(const QString &projectPath, + const QString &origPath) +{ + m_references.insert(origPath); + QString path = origPath; + QString parentPath = QFileInfo(path).path(); + do { + m_references.insert(path); + path = parentPath; + parentPath = QFileInfo(path).path(); + } while (path != projectPath && parentPath != path); +} diff --git a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.h b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.h index 75f9e985..df104876 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.h +++ b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.h @@ -64,7 +64,7 @@ public: QString filePath(int row) const; bool isRefreshable(int row) const; - void updateReferences(bool emitDataChanged); + void updateReferences(); Q3DStudio::DocumentEditorFileType::Enum assetTypeForRow(int row); int rowForPath(const QString &path) const; @@ -99,6 +99,7 @@ private: void importQmlAssets(const QObject *qmlNode, const QDir &srcDir, const QDir &targetDir); void updateDefaultDirMap(); + void addPathsToReferences(const QString &projectPath, const QString &origPath); struct TreeItem { QPersistentModelIndex index; @@ -111,7 +112,7 @@ private: QFileSystemModel *m_model = nullptr; QPersistentModelIndex m_rootIndex; QList<TreeItem> m_items; - QStringList m_references; + QSet<QString> m_references; QHash<QString, QString> m_defaultDirToAbsPathMap; int m_importQmlOverrideChoice = QMessageBox::NoButton; }; diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp index f97c7c1a..79782df9 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp @@ -227,7 +227,7 @@ void ProjectView::OnBeginDataModelNotifications() void ProjectView::OnEndDataModelNotifications() { - m_ProjectModel->updateReferences(true); + QTimer::singleShot(0, m_ProjectModel, &ProjectFileSystemModel::updateReferences); } void ProjectView::OnImmediateRefreshInstanceSingle(qt3dsdm::Qt3DSDMInstanceHandle inInstance) |