From 2bc0f9c2ee2e1702ca85344dca764167680e2899 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Wed, 15 Aug 2018 16:33:39 +0300 Subject: Allow editing Qml streams presentation Id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow editing a qml stream's Id from the project palette context menu. Also removed the scaling of texture upon DnD a presentation to the scene. Task-number: QT3DS-2087 Change-Id: I16e8f35094835c04bb887c99081c7055657091e0 Reviewed-by: Miikka Heikkinen Reviewed-by: Tomi Korpipää --- .../Client/Code/Core/Doc/DocumentEditor.cpp | 12 ------- src/Authoring/Studio/Application/ProjectFile.cpp | 38 ++++++++++++++++------ .../Palettes/Project/EditPresentationIdDlg.cpp | 11 +++++-- .../Studio/Palettes/Project/ProjectContextMenu.cpp | 6 ++++ .../Studio/Palettes/Project/ProjectView.cpp | 20 ++++++++++-- .../Studio/Palettes/Project/ProjectView.h | 1 + 6 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index c0157e8e..f6f64190 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -1614,18 +1614,6 @@ public: Q3DStudio::DocumentEditorInsertType::LastChild, pos, PRIMITIVETYPE_RECT, startTime); - // match rect size with the presentation - QSize size = PresentationFile::readSize(pPath); - if (!size.isNull()) { - qt3dsdm::Qt3DSDMPropertyHandle scaleHandle = - m_PropertySystem.GetAggregateInstancePropertyByName(rectInstance, L"scale"); - - SetInstancePropertyValue(rectInstance, scaleHandle, - qt3dsdm::SFloat3(size.width() * .01f, - size.height() * .01f, 1)); - // TODO: relate presentation size and rect scale in a better way? - } - // Set the subpresentation for the rect's material's diffuseMap for (long i = 0; i < m_AssetGraph.GetChildCount(rectInstance); ++i) { Qt3DSDMInstanceHandle mat(m_AssetGraph.GetChild(rectInstance, i)); diff --git a/src/Authoring/Studio/Application/ProjectFile.cpp b/src/Authoring/Studio/Application/ProjectFile.cpp index bc9c7b0d..13a797a4 100644 --- a/src/Authoring/Studio/Application/ProjectFile.cpp +++ b/src/Authoring/Studio/Application/ProjectFile.cpp @@ -106,6 +106,11 @@ void ProjectFile::addPresentationNode(const QString &pPath, const QString &pId) file.resize(0); file.write(doc.toByteArray(4)); + + // add to m_subpresentations + g_StudioApp.m_subpresentations.push_back( + SubPresentationRecord(QStringLiteral("presentation-qml"), presentationId, + relativePresentationPath)); } file.close(); @@ -143,8 +148,10 @@ QString ProjectFile::getFirstPresentationPath(const QString &uiaPath) const void ProjectFile::writePresentationId(const QString &id, const QString &src) { CDoc *doc = g_StudioApp.GetCore()->GetDoc(); + QString theSrc = src.isEmpty() ? doc->getRelativePath() : src; + QString theId = id.isEmpty() ? doc->getPresentationId() : id; - if (src.isEmpty() || src == doc->getRelativePath()) + if (theSrc == doc->getRelativePath()) doc->setPresentationId(id); QFile file(getProjectFilePath()); @@ -153,17 +160,17 @@ void ProjectFile::writePresentationId(const QString &id, const QString &src) domDoc.setContent(&file); QDomElement rootElem = domDoc.documentElement(); - QDomNodeList pNodes = rootElem.elementsByTagName(QStringLiteral("presentation")); + QDomNodeList pNodes = rootElem.firstChildElement(QStringLiteral("assets")).childNodes(); QString oldId; if (!pNodes.isEmpty()) { - QString relativePath = !src.isEmpty() ? src : doc->getRelativePath(); for (int i = 0; i < pNodes.length(); ++i) { QDomElement pElem = pNodes.at(i).toElement(); - if (pElem.attribute(QStringLiteral("src")) == relativePath) { - oldId = pElem.attribute(QStringLiteral("id")); - pElem.setAttribute(QStringLiteral("id"), !id.isEmpty() ? id - : doc->getPresentationId()); - break; + if (pElem.nodeName().startsWith(QLatin1String("presentation"))) { + if (pElem.attribute(QStringLiteral("src")) == theSrc) { + oldId = pElem.attribute(QStringLiteral("id")); + pElem.setAttribute(QStringLiteral("id"), theId); + break; + } } } } @@ -173,13 +180,22 @@ void ProjectFile::writePresentationId(const QString &id, const QString &src) file.write(domDoc.toByteArray(4)); file.close(); + // update in-memory values + auto *sp = std::find_if(g_StudioApp.m_subpresentations.begin(), + g_StudioApp.m_subpresentations.end(), + [&theSrc](const SubPresentationRecord &spr) -> bool { + return spr.m_argsOrSrc == theSrc; + }); + if (sp != g_StudioApp.m_subpresentations.end()) + sp->m_id = theId; + // update changed presentation Id in all .uip files if in-use if (!oldId.isEmpty()) { for (int i = 0; i < pNodes.length(); ++i) { QDomElement pElem = pNodes.at(i).toElement(); QString path = getProjectPath() + QStringLiteral("/") + pElem.attribute(QStringLiteral("src")); - PresentationFile::updatePresentationId(path, oldId, id); + PresentationFile::updatePresentationId(path, oldId, theId); } } } @@ -227,7 +243,9 @@ QString ProjectFile::getPresentationId(const QString &src) const reader.setNamespaceProcessing(false); while (!reader.atEnd()) { - if (reader.readNextStartElement() && reader.name() == QLatin1String("presentation")) { + if (reader.readNextStartElement() + && (reader.name() == QLatin1String("presentation") + || reader.name() == QLatin1String("presentation-qml"))) { const auto attrs = reader.attributes(); if (attrs.value(QLatin1String("src")) == src) return attrs.value(QLatin1String("id")).toString(); diff --git a/src/Authoring/Studio/Palettes/Project/EditPresentationIdDlg.cpp b/src/Authoring/Studio/Palettes/Project/EditPresentationIdDlg.cpp index dfd8bc72..18233edf 100644 --- a/src/Authoring/Studio/Palettes/Project/EditPresentationIdDlg.cpp +++ b/src/Authoring/Studio/Palettes/Project/EditPresentationIdDlg.cpp @@ -38,9 +38,16 @@ EditPresentationIdDlg::EditPresentationIdDlg(const QString &src, QWidget *parent { m_ui->setupUi(this); - m_presentationId = g_StudioApp.GetCore()->getProjectFile().getPresentationId(src); + auto *sp = std::find_if(g_StudioApp.m_subpresentations.begin(), + g_StudioApp.m_subpresentations.end(), + [&src](const SubPresentationRecord &spr) -> bool { + return spr.m_argsOrSrc == src; + }); - m_ui->lineEditPresentationId->setText(m_presentationId); + if (sp != g_StudioApp.m_subpresentations.end()) { + m_presentationId = sp->m_id; + m_ui->lineEditPresentationId->setText(m_presentationId); + } connect(m_ui->lineEditPresentationId, &QLineEdit::textEdited, this, &EditPresentationIdDlg::onChangePresentationId); diff --git a/src/Authoring/Studio/Palettes/Project/ProjectContextMenu.cpp b/src/Authoring/Studio/Palettes/Project/ProjectContextMenu.cpp index 1ff86939..74d209ce 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectContextMenu.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectContextMenu.cpp @@ -44,6 +44,12 @@ ProjectContextMenu::ProjectContextMenu(ProjectView *parent, int index) connect(action, &QAction::triggered, this, &ProjectContextMenu::handleEditPresentationId); addAction(action); + addSeparator(); + } else if (m_view->isQmlStream(m_index)) { + QAction *action = new QAction(tr("Edit Qml stream Id")); + connect(action, &QAction::triggered, this, &ProjectContextMenu::handleEditPresentationId); + addAction(action); + addSeparator(); } diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp index 79782df9..1c26a8f7 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp @@ -50,6 +50,7 @@ #include #include #include +#include ProjectView::ProjectView(const QSize &preferredSize, QWidget *parent) : QQuickWidget(parent) , m_ProjectModel(new ProjectFileSystemModel(this)) @@ -282,10 +283,10 @@ bool ProjectView::isCurrentPresentation(int row) const void ProjectView::editPresentationId(int row) { - QString relativeUipPath = QDir(g_StudioApp.GetCore()->getProjectFile().getProjectPath()) - .relativeFilePath(m_ProjectModel->filePath(row)); + QString relativePresPath = QDir(g_StudioApp.GetCore()->getProjectFile().getProjectPath()) + .relativeFilePath(m_ProjectModel->filePath(row)); - EditPresentationIdDlg dlg(relativeUipPath, this); + EditPresentationIdDlg dlg(relativePresPath, this); dlg.exec(); } @@ -343,6 +344,19 @@ bool ProjectView::isPresentation(int row) const return m_ProjectModel->filePath(row).endsWith(QLatin1String(".uip")); } +bool ProjectView::isQmlStream(int row) const +{ + const QString filePath = m_ProjectModel->filePath(row); + + if (!filePath.endsWith(QLatin1String(".qml"))) + return false; + + QQmlApplicationEngine qmlEngine(filePath); + const char *rootClassName = qmlEngine.rootObjects().at(0) + ->metaObject()->superClass()->className(); + return strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0; +} + bool ProjectView::isRefreshable(int row) const { return m_ProjectModel->isRefreshable(row); diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.h b/src/Authoring/Studio/Palettes/Project/ProjectView.h index eedd562e..b39ef832 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectView.h +++ b/src/Authoring/Studio/Palettes/Project/ProjectView.h @@ -77,6 +77,7 @@ public: Q_INVOKABLE void showContextMenu(int x, int y, int index); Q_INVOKABLE bool toolTipsEnabled(); bool isPresentation(int row) const; + bool isQmlStream(int row) const; bool isCurrentPresentation(int row) const; void openPresentation(int row); void editPresentationId(int row); -- cgit v1.2.3