From e0942ce2fb8bba0fdd1df5929d3c9592deb80032 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 2 May 2024 14:03:50 +0300 Subject: [PATCH] QmlDesigner: Handle material type without using item library entries Recent project structure changes invalidated material bundle metainfo files, as we can't support both new and old structure with them. They were only used for populating possible types in material editor, so adjusted this functionality to only allow changing the type between basic types. If the material is a custom component, then the only the current type is displayed and the type combo box is disabled. Fixes: QDS-12628 Change-Id: I07b1a482977f0ecc94c35f3d485302c85c6153f9 Reviewed-by: Thomas Hartmann --- .../MaterialEditorTopSection.qml | 1 + .../materialeditor/materialeditorview.cpp | 89 +++---------------- .../materialeditor/materialeditorview.h | 2 - 3 files changed, 15 insertions(+), 77 deletions(-) diff --git a/share/qtcreator/qmldesigner/materialEditorQmlSources/MaterialEditorTopSection.qml b/share/qtcreator/qmldesigner/materialEditorQmlSources/MaterialEditorTopSection.qml index 23311636bc2..1879ea177c6 100644 --- a/share/qtcreator/qmldesigner/materialEditorQmlSources/MaterialEditorTopSection.qml +++ b/share/qtcreator/qmldesigner/materialEditorQmlSources/MaterialEditorTopSection.qml @@ -214,6 +214,7 @@ Column { model: possibleTypes showExtendedFunctionButton: false implicitWidth: StudioTheme.Values.singleControlColumnWidth + enabled: possibleTypes.length > 1 onActivated: changeTypeName(currentValue) } diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp index e083310cdbb..d65ce800c03 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp @@ -24,7 +24,6 @@ #include "qmldesignerplugin.h" #include "qmltimeline.h" #include "variantproperty.h" -#include #include #include @@ -63,10 +62,6 @@ MaterialEditorView::MaterialEditorView(ExternalDependenciesInterface &externalDe } }); - m_typeUpdateTimer.setSingleShot(true); - m_typeUpdateTimer.setInterval(500); - connect(&m_typeUpdateTimer, &QTimer::timeout, this, &MaterialEditorView::updatePossibleTypes); - QmlDesignerPlugin::trackWidgetFocusTime(m_stackedWidget, Constants::EVENT_MATERIALEDITOR_TIME); MaterialEditorDynamicPropertiesProxyModel::registerDeclarativeType(); @@ -333,8 +328,10 @@ void MaterialEditorView::resetView() setupQmlBackend(); - if (m_qmlBackEnd) + if (m_qmlBackEnd) { m_qmlBackEnd->emitSelectionChanged(); + updatePossibleTypes(); + } QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender); @@ -605,7 +602,6 @@ void MaterialEditorView::setupQmlBackend() else m_dynamicPropertiesModel->reset(); - delayedTypeUpdate(); initPreviewData(); m_stackedWidget->setCurrentWidget(m_qmlBackEnd->widget()); @@ -690,21 +686,6 @@ void MaterialEditorView::initPreviewData() } } -void MaterialEditorView::delayedTypeUpdate() -{ - m_typeUpdateTimer.start(); -} - -[[maybe_unused]] static Import entryToImport(const ItemLibraryEntry &entry) -{ - if (entry.majorVersion() == -1 && entry.minorVersion() == -1) - return Import::createFileImport(entry.requiredImport()); - - return Import::createLibraryImport(entry.requiredImport(), - QString::number(entry.majorVersion()) + QLatin1Char('.') + - QString::number(entry.minorVersion())); -} - void MaterialEditorView::updatePossibleTypes() { QTC_ASSERT(model(), return); @@ -712,49 +693,21 @@ void MaterialEditorView::updatePossibleTypes() if (!m_qmlBackEnd) return; -#ifdef QDS_USE_PROJECTSTORAGE - auto heirs = model()->qtQuick3DMaterialMetaInfo().heirs(); - heirs.push_back(model()->qtQuick3DMaterialMetaInfo()); - auto entries = Utils::transform(heirs, [&](const auto &heir) { - return toItemLibraryEntries(heir.itemLibrariesEntries(), *model()->projectStorage()); - }); + static const QStringList basicTypes { + "CustomMaterial", + "DefaultMaterial", + "PrincipledMaterial", + "SpecularGlossyMaterial" + }; - // I am unsure about the code intention here -#else // Ensure basic types are always first - QStringList nonQuick3dTypes; - QStringList allTypes; + const QString matType = m_selectedMaterial.simplifiedTypeName(); - const QList itemLibEntries = m_itemLibraryInfo->entries(); - for (const ItemLibraryEntry &entry : itemLibEntries) { - NodeMetaInfo metaInfo = model()->metaInfo(entry.typeName()); - bool valid = metaInfo.isValid() - && (metaInfo.majorVersion() >= entry.majorVersion() - || metaInfo.majorVersion() < 0); - if (valid && metaInfo.isQtQuick3DMaterial()) { - bool addImport = entry.requiredImport().isEmpty(); - if (!addImport) { - Import import = entryToImport(entry); - addImport = model()->hasImport(import, true, true); - } - if (addImport) { - const QList typeSplit = entry.typeName().split('.'); - const QString typeName = QString::fromLatin1(typeSplit.last()); - if (typeSplit.size() == 2 && typeSplit.first() == "QtQuick3D") { - if (!allTypes.contains(typeName)) - allTypes.append(typeName); - } else if (!nonQuick3dTypes.contains(typeName)) { - nonQuick3dTypes.append(typeName); - } - } - } + if (basicTypes.contains(matType)) { + m_qmlBackEnd->contextObject()->setPossibleTypes(basicTypes); + return; } - allTypes.sort(); - nonQuick3dTypes.sort(); - allTypes.append(nonQuick3dTypes); - - m_qmlBackEnd->contextObject()->setPossibleTypes(allTypes); -#endif + m_qmlBackEnd->contextObject()->setPossibleTypes({matType}); } void MaterialEditorView::modelAttached(Model *model) @@ -774,20 +727,6 @@ void MaterialEditorView::modelAttached(Model *model) m_ensureMatLibTimer.start(500); } -#ifndef QDS_USE_PROJECTSTORAGE - if (m_itemLibraryInfo.data() != model->metaInfo().itemLibraryInfo()) { - if (m_itemLibraryInfo) { - disconnect(m_itemLibraryInfo.data(), &ItemLibraryInfo::entriesChanged, - this, &MaterialEditorView::delayedTypeUpdate); - } - m_itemLibraryInfo = model->metaInfo().itemLibraryInfo(); - if (m_itemLibraryInfo) { - connect(m_itemLibraryInfo.data(), &ItemLibraryInfo::entriesChanged, - this, &MaterialEditorView::delayedTypeUpdate); - } - } -#endif - if (!m_setupCompleted) { reloadQml(); m_setupCompleted = true; diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h index c201742bd51..11bea460638 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h @@ -109,12 +109,10 @@ private: bool noValidSelection() const; void initPreviewData(); - void delayedTypeUpdate(); void updatePossibleTypes(); ModelNode m_selectedMaterial; QTimer m_ensureMatLibTimer; - QTimer m_typeUpdateTimer; QShortcut *m_updateShortcut = nullptr; int m_timerId = 0; QStackedWidget *m_stackedWidget = nullptr;