QmlDesigner: Fix propertyGroups.json warning for 2D projects

Load property groups file only if Quick3D import exists

Change-Id: Idf7b95cb4efa34dde6196964e5e2cbad54341193
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2022-08-22 16:09:42 +03:00
parent 3b73b27862
commit 86d1526564
4 changed files with 21 additions and 6 deletions

View File

@@ -95,8 +95,9 @@ bool MaterialBrowserModel::isValidIndex(int idx) const
* propertyGroups.json contains lists of QtQuick3D objects' properties grouped by sections * propertyGroups.json contains lists of QtQuick3D objects' properties grouped by sections
* *
* @param path path to propertyGroups.json file * @param path path to propertyGroups.json file
* @return load successful
*/ */
void MaterialBrowserModel::loadPropertyGroups(const QString &path) bool MaterialBrowserModel::loadPropertyGroups(const QString &path)
{ {
bool ok = true; bool ok = true;
@@ -131,6 +132,8 @@ void MaterialBrowserModel::loadPropertyGroups(const QString &path)
m_customMaterialSections.append(customMatSections); m_customMaterialSections.append(customMatSections);
} }
emit materialSectionsChanged(); emit materialSectionsChanged();
return ok;
} }
QHash<int, QByteArray> MaterialBrowserModel::roleNames() const QHash<int, QByteArray> MaterialBrowserModel::roleNames() const

View File

@@ -79,7 +79,7 @@ public:
void updateSelectedMaterial(); void updateSelectedMaterial();
int materialIndex(const ModelNode &material) const; int materialIndex(const ModelNode &material) const;
ModelNode materialAt(int idx) const; ModelNode materialAt(int idx) const;
void loadPropertyGroups(const QString &path); bool loadPropertyGroups(const QString &path);
void resetModel(); void resetModel();

View File

@@ -128,14 +128,12 @@ void MaterialBrowserView::modelAttached(Model *model)
{ {
AbstractView::modelAttached(model); AbstractView::modelAttached(model);
QString matPropsPath = model->metaInfo("QtQuick3D.Material").importDirectoryPath()
+ "/designer/propertyGroups.json";
m_widget->materialBrowserModel()->loadPropertyGroups(matPropsPath);
m_widget->clearSearchFilter(); m_widget->clearSearchFilter();
m_widget->materialBrowserModel()->setHasMaterialRoot(rootModelNode().isSubclassOf("QtQuick3D.Material")); m_widget->materialBrowserModel()->setHasMaterialRoot(rootModelNode().isSubclassOf("QtQuick3D.Material"));
m_hasQuick3DImport = model->hasImport("QtQuick3D"); m_hasQuick3DImport = model->hasImport("QtQuick3D");
loadPropertyGroups();
// Project load is already very busy and may even trigger puppet reset, so let's wait a moment // Project load is already very busy and may even trigger puppet reset, so let's wait a moment
// before refreshing the model // before refreshing the model
QTimer::singleShot(1000, this, [this]() { QTimer::singleShot(1000, this, [this]() {
@@ -295,6 +293,16 @@ void MaterialBrowserView::nodeRemoved(const ModelNode &removedNode,
m_widget->materialBrowserModel()->updateSelectedMaterial(); m_widget->materialBrowserModel()->updateSelectedMaterial();
} }
void QmlDesigner::MaterialBrowserView::loadPropertyGroups()
{
if (!m_hasQuick3DImport || m_propertyGroupsLoaded)
return;
QString matPropsPath = model()->metaInfo("QtQuick3D.Material").importDirectoryPath()
+ "/designer/propertyGroups.json";
m_propertyGroupsLoaded = m_widget->materialBrowserModel()->loadPropertyGroups(matPropsPath);
}
void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports) void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
{ {
Q_UNUSED(addedImports) Q_UNUSED(addedImports)
@@ -307,6 +315,8 @@ void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, cons
m_hasQuick3DImport = hasQuick3DImport; m_hasQuick3DImport = hasQuick3DImport;
loadPropertyGroups();
// Import change will trigger puppet reset, so we don't want to update previews immediately // Import change will trigger puppet reset, so we don't want to update previews immediately
refreshModel(false); refreshModel(false);
} }

View File

@@ -70,6 +70,8 @@ private:
bool m_hasQuick3DImport = false; bool m_hasQuick3DImport = false;
bool m_autoSelectModelMaterial = false; // TODO: wire this to some action bool m_autoSelectModelMaterial = false; // TODO: wire this to some action
bool m_puppetResetPending = false; bool m_puppetResetPending = false;
bool m_propertyGroupsLoaded = false;
void loadPropertyGroups();
}; };
} // namespace QmlDesigner } // namespace QmlDesigner