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 <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2024-05-02 14:03:50 +03:00
parent 88141c7ef5
commit e0942ce2fb
3 changed files with 15 additions and 77 deletions

View File

@@ -214,6 +214,7 @@ Column {
model: possibleTypes model: possibleTypes
showExtendedFunctionButton: false showExtendedFunctionButton: false
implicitWidth: StudioTheme.Values.singleControlColumnWidth implicitWidth: StudioTheme.Values.singleControlColumnWidth
enabled: possibleTypes.length > 1
onActivated: changeTypeName(currentValue) onActivated: changeTypeName(currentValue)
} }

View File

@@ -24,7 +24,6 @@
#include "qmldesignerplugin.h" #include "qmldesignerplugin.h"
#include "qmltimeline.h" #include "qmltimeline.h"
#include "variantproperty.h" #include "variantproperty.h"
#include <itemlibraryentry.h>
#include <utils3d.h> #include <utils3d.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -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); QmlDesignerPlugin::trackWidgetFocusTime(m_stackedWidget, Constants::EVENT_MATERIALEDITOR_TIME);
MaterialEditorDynamicPropertiesProxyModel::registerDeclarativeType(); MaterialEditorDynamicPropertiesProxyModel::registerDeclarativeType();
@@ -333,8 +328,10 @@ void MaterialEditorView::resetView()
setupQmlBackend(); setupQmlBackend();
if (m_qmlBackEnd) if (m_qmlBackEnd) {
m_qmlBackEnd->emitSelectionChanged(); m_qmlBackEnd->emitSelectionChanged();
updatePossibleTypes();
}
QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender); QTimer::singleShot(0, this, &MaterialEditorView::requestPreviewRender);
@@ -605,7 +602,6 @@ void MaterialEditorView::setupQmlBackend()
else else
m_dynamicPropertiesModel->reset(); m_dynamicPropertiesModel->reset();
delayedTypeUpdate();
initPreviewData(); initPreviewData();
m_stackedWidget->setCurrentWidget(m_qmlBackEnd->widget()); 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() void MaterialEditorView::updatePossibleTypes()
{ {
QTC_ASSERT(model(), return); QTC_ASSERT(model(), return);
@@ -712,49 +693,21 @@ void MaterialEditorView::updatePossibleTypes()
if (!m_qmlBackEnd) if (!m_qmlBackEnd)
return; return;
#ifdef QDS_USE_PROJECTSTORAGE static const QStringList basicTypes {
auto heirs = model()->qtQuick3DMaterialMetaInfo().heirs(); "CustomMaterial",
heirs.push_back(model()->qtQuick3DMaterialMetaInfo()); "DefaultMaterial",
auto entries = Utils::transform<ItemLibraryEntries>(heirs, [&](const auto &heir) { "PrincipledMaterial",
return toItemLibraryEntries(heir.itemLibrariesEntries(), *model()->projectStorage()); "SpecularGlossyMaterial"
}); };
// I am unsure about the code intention here const QString matType = m_selectedMaterial.simplifiedTypeName();
#else // Ensure basic types are always first
QStringList nonQuick3dTypes;
QStringList allTypes;
const QList<ItemLibraryEntry> itemLibEntries = m_itemLibraryInfo->entries(); if (basicTypes.contains(matType)) {
for (const ItemLibraryEntry &entry : itemLibEntries) { m_qmlBackEnd->contextObject()->setPossibleTypes(basicTypes);
NodeMetaInfo metaInfo = model()->metaInfo(entry.typeName()); return;
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<QByteArray> 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);
}
}
}
} }
allTypes.sort(); m_qmlBackEnd->contextObject()->setPossibleTypes({matType});
nonQuick3dTypes.sort();
allTypes.append(nonQuick3dTypes);
m_qmlBackEnd->contextObject()->setPossibleTypes(allTypes);
#endif
} }
void MaterialEditorView::modelAttached(Model *model) void MaterialEditorView::modelAttached(Model *model)
@@ -774,20 +727,6 @@ void MaterialEditorView::modelAttached(Model *model)
m_ensureMatLibTimer.start(500); 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) { if (!m_setupCompleted) {
reloadQml(); reloadQml();
m_setupCompleted = true; m_setupCompleted = true;

View File

@@ -109,12 +109,10 @@ private:
bool noValidSelection() const; bool noValidSelection() const;
void initPreviewData(); void initPreviewData();
void delayedTypeUpdate();
void updatePossibleTypes(); void updatePossibleTypes();
ModelNode m_selectedMaterial; ModelNode m_selectedMaterial;
QTimer m_ensureMatLibTimer; QTimer m_ensureMatLibTimer;
QTimer m_typeUpdateTimer;
QShortcut *m_updateShortcut = nullptr; QShortcut *m_updateShortcut = nullptr;
int m_timerId = 0; int m_timerId = 0;
QStackedWidget *m_stackedWidget = nullptr; QStackedWidget *m_stackedWidget = nullptr;