QmlDesigner: Hide material bundle if QtQuick3D version too low

Most materials in the material bundle require at least QtQuick3D 6.3,
so we hide the bundle materials from material browser when the detected
module version is less than 6.3.

Fixes: QDS-8100
Change-Id: I9f50b507c3c3c50f821fa6a902995b999da24464
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-10-27 16:40:52 +03:00
parent d72f5674b5
commit bc370aecfd
6 changed files with 91 additions and 22 deletions

View File

@@ -94,7 +94,7 @@ QHash<int, QByteArray> MaterialBrowserBundleModel::roleNames() const
void MaterialBrowserBundleModel::loadMaterialBundle()
{
if (m_matBundleExists || m_probeMatBundleDir)
if (m_matBundleLoaded || m_probeMatBundleDir)
return;
QDir matBundleDir(qEnvironmentVariable("MATERIAL_BUNDLE_PATH"));
@@ -130,7 +130,7 @@ void MaterialBrowserBundleModel::loadMaterialBundle()
}
}
m_matBundleExists = true;
m_matBundleLoaded = true;
QString bundleId = m_matBundleObj.value("id").toString();
@@ -184,20 +184,6 @@ void MaterialBrowserBundleModel::loadMaterialBundle()
});
}
bool MaterialBrowserBundleModel::hasQuick3DImport() const
{
return m_hasQuick3DImport;
}
void MaterialBrowserBundleModel::setHasQuick3DImport(bool b)
{
if (b == m_hasQuick3DImport)
return;
m_hasQuick3DImport = b;
emit hasQuick3DImportChanged();
}
bool MaterialBrowserBundleModel::hasMaterialRoot() const
{
return m_hasMaterialRoot;
@@ -212,6 +198,11 @@ void MaterialBrowserBundleModel::setHasMaterialRoot(bool b)
emit hasMaterialRootChanged();
}
bool MaterialBrowserBundleModel::matBundleExists() const
{
return m_matBundleLoaded && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
}
Internal::BundleImporter *MaterialBrowserBundleModel::bundleImporter() const
{
return m_importer;
@@ -253,6 +244,17 @@ void MaterialBrowserBundleModel::updateImportedState(const QStringList &imported
resetModel();
}
void MaterialBrowserBundleModel::setQuick3DImportVersion(int major, int minor)
{
bool bundleExisted = matBundleExists();
m_quick3dMajorVersion = major;
m_quick3dMinorVersion = minor;
if (bundleExisted != matBundleExists())
emit matBundleExistsChanged();
}
void MaterialBrowserBundleModel::resetModel()
{
beginResetModel();

View File

@@ -46,9 +46,8 @@ class MaterialBrowserBundleModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(bool matBundleExists MEMBER m_matBundleExists CONSTANT)
Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged)
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)
Q_PROPERTY(bool importerRunning MEMBER m_importerRunning NOTIFY importerRunningChanged)
@@ -63,12 +62,13 @@ public:
void setSearchText(const QString &searchText);
void updateImportedState(const QStringList &importedMats);
bool hasQuick3DImport() const;
void setHasQuick3DImport(bool b);
void setQuick3DImportVersion(int major, int minor);
bool hasMaterialRoot() const;
void setHasMaterialRoot(bool b);
bool matBundleExists() const;
Internal::BundleImporter *bundleImporter() const;
void resetModel();
@@ -87,6 +87,7 @@ signals:
void bundleMaterialAboutToUnimport(const QmlDesigner::TypeName &type);
void bundleMaterialUnimported(const QmlDesigner::NodeMetaInfo &metaInfo);
void importerRunningChanged();
void matBundleExistsChanged();
private:
void loadMaterialBundle();
@@ -98,11 +99,13 @@ private:
Internal::BundleImporter *m_importer = nullptr;
bool m_isEmpty = true;
bool m_hasQuick3DImport = false;
bool m_hasMaterialRoot = false;
bool m_matBundleExists = false;
bool m_matBundleLoaded = false;
bool m_probeMatBundleDir = false;
bool m_importerRunning = false;
int m_quick3dMajorVersion = -1;
int m_quick3dMinorVersion = -1;
};
} // namespace QmlDesigner

View File

@@ -43,6 +43,14 @@
#include <qmldesignerconstants.h>
#include <utils/algorithm.h>
#ifndef QMLDESIGNER_TEST
#include <projectexplorer/kit.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#endif
#include <QQuickItem>
#include <QRegularExpression>
#include <QTimer>
@@ -289,6 +297,7 @@ void MaterialBrowserView::modelAttached(Model *model)
m_widget->materialBrowserModel()->setHasMaterialRoot(rootModelNode().isSubclassOf("QtQuick3D.Material"));
m_hasQuick3DImport = model->hasImport("QtQuick3D");
updateBundleMaterialsQuick3DVersion();
updateBundleMaterialsImportedState();
// Project load is already very busy and may even trigger puppet reset, so let's wait a moment
@@ -482,6 +491,41 @@ void MaterialBrowserView::updateBundleMaterialsImportedState()
m_widget->materialBrowserBundleModel()->updateImportedState(importedBundleMats);
}
void MaterialBrowserView::updateBundleMaterialsQuick3DVersion()
{
bool hasImport = false;
int major = -1;
int minor = -1;
const QString url {"QtQuick3D"};
const auto imports = model()->imports();
for (const auto &import : imports) {
if (import.url() == url) {
hasImport = true;
const int importMajor = import.majorVersion();
if (major < importMajor) {
minor = -1;
major = importMajor;
}
if (major == importMajor)
minor = qMax(minor, import.minorVersion());
}
}
#ifndef QMLDESIGNER_TEST
if (hasImport && major == -1) {
// Import without specifying version, so we take the kit version
auto target = ProjectExplorer::SessionManager::startupTarget();
if (target) {
QtSupport::QtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(target->kit());
if (qtVersion) {
major = qtVersion->qtVersion().majorVersion;
minor = qtVersion->qtVersion().minorVersion;
}
}
}
#endif
m_widget->materialBrowserBundleModel()->setQuick3DImportVersion(major, minor);
}
ModelNode MaterialBrowserView::getBundleMaterialDefaultInstance(const TypeName &type)
{
const QList<ModelNode> materials = m_widget->materialBrowserModel()->materials();
@@ -511,6 +555,8 @@ void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, cons
bool hasQuick3DImport = model()->hasImport("QtQuick3D");
updateBundleMaterialsQuick3DVersion();
if (hasQuick3DImport == m_hasQuick3DImport)
return;

View File

@@ -69,6 +69,7 @@ private:
bool isMaterial(const ModelNode &node) const;
void loadPropertyGroups();
void updateBundleMaterialsImportedState();
void updateBundleMaterialsQuick3DVersion();
void applyBundleMaterialToDropTarget(const ModelNode &bundleMat, const NodeMetaInfo &metaInfo = {});
ModelNode getBundleMaterialDefaultInstance(const TypeName &type);

View File

@@ -63,7 +63,9 @@ public:
bool isSameModule(const Import &other) const;
int majorVersion() const;
int minorVersion() const;
static int majorFromVersion(const QString &version);
static int minorFromVersion(const QString &version);
private:
Import(const QString &url, const QString &file, const QString &version, const QString &alias, const QStringList &importPaths);

View File

@@ -102,6 +102,11 @@ int Import::majorVersion() const
return majorFromVersion(m_version);
}
int Import::minorVersion() const
{
return minorFromVersion(m_version);
}
int Import::majorFromVersion(const QString &version)
{
if (version.isEmpty())
@@ -109,6 +114,16 @@ int Import::majorFromVersion(const QString &version)
return version.split('.').first().toInt();
}
int Import::minorFromVersion(const QString &version)
{
if (version.isEmpty())
return -1;
const QStringList parts = version.split('.');
if (parts.size() < 2)
return -1;
return parts[1].toInt();
}
Utils::QHashValueType qHash(const Import &import)
{
return ::qHash(import.url()) ^ ::qHash(import.file()) ^ ::qHash(import.version()) ^ ::qHash(import.alias());