QmlDesigner: Display informative string for 3D support in Qt5 projects

Fixes: QDS-10661
Change-Id: I91ba32e478039711758e19c11d385af9fac4c99f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Mats Honkamaa <mats.honkamaa@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-09-14 17:08:56 +03:00
parent 6fbf77b027
commit ac6d875d12
19 changed files with 143 additions and 39 deletions

View File

@@ -91,6 +91,8 @@ HelperWidgets.ScrollView {
text: {
if (!ContentLibraryBackend.effectsModel.bundleExists)
qsTr("No effects available.")
else if (!ContentLibraryBackend.rootView.isQt6Project)
qsTr("<b>Content Library</b> effects are not supported in Qt5 projects.")
else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
else if (!ContentLibraryBackend.effectsModel.hasRequiredQuick3DImport)

View File

@@ -99,6 +99,8 @@ HelperWidgets.ScrollView {
text: {
if (!materialsModel.matBundleExists)
qsTr("No materials available. Make sure you have internet connection.")
else if (!ContentLibraryBackend.rootView.isQt6Project)
qsTr("<b>Content Library</b> materials are not supported in Qt5 projects.")
else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
else if (!materialsModel.hasRequiredQuick3DImport)

View File

@@ -592,7 +592,9 @@ Item {
anchors.centerIn: parent
text: {
if (!materialBrowserModel.hasQuick3DImport)
if (!materialBrowserModel.isQt6Project)
qsTr("<b>Material Browser</b> is not supported in Qt5 projects.")
else if (!materialBrowserModel.hasQuick3DImport)
qsTr("To use <b>Material Browser</b>, first add the QtQuick3D module in the <b>Components</b> view.")
else if (!materialBrowserModel.hasMaterialLibrary)
qsTr("<b>Material Browser</b> is disabled inside a non-visual component.")

View File

@@ -35,7 +35,9 @@ PropertyEditorPane {
Text {
text: {
if (!hasQuick3DImport)
if (!isQt6Project)
qsTr("<b>Material Editor</b> is not supported in Qt5 projects.")
else if (!hasQuick3DImport)
qsTr("To use <b>Material Editor</b>, first add the QtQuick3D module in the <b>Components</b> view.")
else if (!hasMaterialLibrary)
qsTr("<b>Material Editor</b> is disabled inside a non-visual component.")

View File

@@ -32,7 +32,9 @@ PropertyEditorPane {
Text {
text: {
if (!hasQuick3DImport)
if (!isQt6Project)
qsTr("<b>Texture Editor</b> is not supported in Qt5 projects.")
else if (!hasQuick3DImport)
qsTr("To use <b>Texture Editor</b>, first add the QtQuick3D module in the <b>Components</b> view.")
else if (!hasMaterialLibrary)
qsTr("<b>Texture Editor</b> is disabled inside a non-visual component.")

View File

@@ -11,6 +11,7 @@
#include "contentlibrarytexture.h"
#include "contentlibrarytexturesmodel.h"
#include "contentlibrarywidget.h"
#include "externaldependenciesinterface.h"
#include "nodelistproperty.h"
#include "qmldesignerconstants.h"
#include "qmlobjectnode.h"
@@ -223,6 +224,7 @@ void ContentLibraryView::modelAttached(Model *model)
const bool hasLibrary = materialLibraryNode().isValid();
m_widget->setHasMaterialLibrary(hasLibrary);
m_widget->setHasQuick3DImport(m_hasQuick3DImport);
m_widget->setIsQt6Project(externalDependencies().isQt6Project());
m_sceneId = model->active3DSceneId();

View File

@@ -681,6 +681,20 @@ void ContentLibraryWidget::setHasActive3DScene(bool b)
emit hasActive3DSceneChanged();
}
bool ContentLibraryWidget::isQt6Project() const
{
return m_isQt6Project;
}
void ContentLibraryWidget::setIsQt6Project(bool b)
{
if (m_isQt6Project == b)
return;
m_isQt6Project = b;
emit isQt6ProjectChanged();
}
void ContentLibraryWidget::reloadQmlSource()
{
const QString materialBrowserQmlPath = qmlSourcesPath() + "/ContentLibrary.qml";

View File

@@ -32,6 +32,7 @@ class ContentLibraryWidget : public QFrame
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport NOTIFY hasQuick3DImportChanged)
Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
Q_PROPERTY(bool hasActive3DScene READ hasActive3DScene WRITE setHasActive3DScene NOTIFY hasActive3DSceneChanged)
Q_PROPERTY(bool isQt6Project READ isQt6Project NOTIFY isQt6ProjectChanged)
// Needed for a workaround for a bug where after drag-n-dropping an item, the ScrollView scrolls to a random position
Q_PROPERTY(bool isDragging MEMBER m_isDragging NOTIFY isDraggingChanged)
@@ -53,6 +54,9 @@ public:
bool hasActive3DScene() const;
void setHasActive3DScene(bool b);
bool isQt6Project() const;
void setIsQt6Project(bool b);
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
void setMaterialsModel(QPointer<ContentLibraryMaterialsModel> newMaterialsModel);
@@ -83,6 +87,7 @@ signals:
void hasMaterialLibraryChanged();
void hasActive3DSceneChanged();
void isDraggingChanged();
void isQt6ProjectChanged();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
@@ -121,6 +126,7 @@ private:
bool m_hasActive3DScene = false;
bool m_hasQuick3DImport = false;
bool m_isDragging = false;
bool m_isQt6Project = false;
QString m_baseUrl;
QString m_texturesUrl;
QString m_textureIconsUrl;

View File

@@ -9,6 +9,7 @@
#include "edit3dtoolbarmenu.h"
#include "edit3dview.h"
#include "edit3dviewconfig.h"
#include "externaldependenciesinterface.h"
#include "materialutils.h"
#include "metainfo.h"
#include "modelnodeoperations.h"
@@ -168,28 +169,8 @@ Edit3DWidget::Edit3DWidget(Edit3DView *view)
createContextMenu();
m_mcuLabel = new QLabel(this);
m_mcuLabel->setText(tr("MCU project does not support Qt Quick 3D."));
m_mcuLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
fillLayout->addWidget(m_mcuLabel.data());
// Onboarding label contains instructions for new users how to get 3D content into the project
m_onboardingLabel = new QLabel(this);
QString labelText =
tr("Your file does not import Qt Quick 3D.<br><br>"
"To create a 3D view, add the"
" <b>QtQuick3D</b>"
" module in the"
" <b>Components</b>"
" view or click"
" <a href=\"#add_import\"><span style=\"text-decoration:none;color:%1\">here</span></a>"
".<br><br>"
"To import 3D assets, select"
" <b>+</b>"
" in the"
" <b>Assets</b>"
" view.");
m_onboardingLabel->setText(labelText.arg(Utils::creatorTheme()->color(Utils::Theme::TextColorLink).name()));
m_onboardingLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
connect(m_onboardingLabel, &QLabel::linkActivated, this, &Edit3DWidget::linkActivated);
fillLayout->addWidget(m_onboardingLabel.data());
@@ -316,6 +297,42 @@ bool Edit3DWidget::isSceneLocked() const
return false;
}
void Edit3DWidget::showOnboardingLabel()
{
QString text;
const DesignerMcuManager &mcuManager = DesignerMcuManager::instance();
if (mcuManager.isMCUProject()) {
const QStringList mcuAllowedList = mcuManager.allowedImports();
if (!mcuAllowedList.contains("QtQuick3d"))
text = tr("3D view is not supported in MCU projects.");
}
if (text.isEmpty()) {
if (m_view->externalDependencies().isQt6Project()) {
QString labelText =
tr("Your file does not import Qt Quick 3D.<br><br>"
"To create a 3D view, add the"
" <b>QtQuick3D</b>"
" module in the"
" <b>Components</b>"
" view or click"
" <a href=\"#add_import\"><span style=\"text-decoration:none;color:%1\">here</span></a>"
".<br><br>"
"To import 3D assets, select"
" <b>+</b>"
" in the"
" <b>Assets</b>"
" view.");
text = labelText.arg(Utils::creatorTheme()->color(Utils::Theme::TextColorLink).name());
} else {
text = tr("3D view is not supported in Qt5 projects.");
}
}
m_onboardingLabel->setText(text);
m_onboardingLabel->setVisible(true);
}
// Called by the view to update the "create" sub-menu when the Quick3D entries are ready.
void Edit3DWidget::updateCreateSubMenu(const QList<ItemLibraryDetails> &entriesList)
{
@@ -420,23 +437,10 @@ void Edit3DWidget::showCanvas(bool show)
}
m_canvas->setVisible(show);
if (show) {
if (show)
m_onboardingLabel->setVisible(false);
m_mcuLabel->setVisible(false);
} else {
bool quick3dAllowed = true;
const DesignerMcuManager &mcuManager = DesignerMcuManager::instance();
if (mcuManager.isMCUProject()) {
const QStringList mcuAllowedList = mcuManager.allowedImports();
if (!mcuAllowedList.contains("QtQuick3d"))
quick3dAllowed = false;
}
m_onboardingLabel->setVisible(quick3dAllowed);
m_mcuLabel->setVisible(!quick3dAllowed);
}
else
showOnboardingLabel();
}
QMenu *Edit3DWidget::visibilityTogglesMenu() const

View File

@@ -66,6 +66,8 @@ private:
bool isPasteAvailable() const;
bool isSceneLocked() const;
void showOnboardingLabel();
QPointer<Edit3DView> m_edit3DView;
QPointer<Edit3DView> m_view;
QPointer<Edit3DCanvas> m_canvas;

View File

@@ -187,6 +187,20 @@ void MaterialBrowserModel::setHasMaterialLibrary(bool b)
emit hasMaterialLibraryChanged();
}
bool MaterialBrowserModel::isQt6Project() const
{
return m_isQt6Project;
}
void MaterialBrowserModel::setIsQt6Project(bool b)
{
if (m_isQt6Project == b)
return;
m_isQt6Project = b;
emit isQt6ProjectChanged();
}
QString MaterialBrowserModel::copiedMaterialType() const
{
return m_copiedMaterialType;

View File

@@ -23,6 +23,7 @@ class MaterialBrowserModel : public QAbstractListModel
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary WRITE setHasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
Q_PROPERTY(bool isQt6Project READ isQt6Project NOTIFY isQt6ProjectChanged)
Q_PROPERTY(QString copiedMaterialType READ copiedMaterialType WRITE setCopiedMaterialType NOTIFY copiedMaterialTypeChanged)
Q_PROPERTY(QStringList defaultMaterialSections MEMBER m_defaultMaterialSections NOTIFY materialSectionsChanged)
Q_PROPERTY(QStringList principledMaterialSections MEMBER m_principledMaterialSections NOTIFY materialSectionsChanged)
@@ -49,6 +50,9 @@ public:
bool hasMaterialLibrary() const;
void setHasMaterialLibrary(bool b);
bool isQt6Project() const;
void setIsQt6Project(bool b);
bool isEmpty() const { return m_isEmpty; }
QString copiedMaterialType() const;
@@ -105,6 +109,7 @@ signals:
const QmlDesigner::ModelNode &material,
const QList<QmlDesigner::MaterialBrowserModel::PropertyCopyData> &props,
bool all);
void isQt6ProjectChanged();
private:
bool isValidIndex(int idx) const;
@@ -126,6 +131,7 @@ private:
bool m_hasModelSelection = false;
bool m_hasMaterialLibrary = false;
bool m_allPropsCopied = true;
bool m_isQt6Project = false;
QString m_copiedMaterialType;
QPointer<MaterialBrowserView> m_view;

View File

@@ -6,6 +6,7 @@
#include "bindingproperty.h"
#include "createtexture.h"
#include "designmodecontext.h"
#include "externaldependenciesinterface.h"
#include "materialbrowsermodel.h"
#include "materialbrowsertexturesmodel.h"
#include "materialbrowserwidget.h"
@@ -230,6 +231,7 @@ void MaterialBrowserView::modelAttached(Model *model)
m_widget->clearSearchFilter();
m_widget->materialBrowserModel()->setHasMaterialLibrary(false);
m_hasQuick3DImport = model->hasImport("QtQuick3D");
m_widget->materialBrowserModel()->setIsQt6Project(externalDependencies().isQt6Project());
// Project load is already very busy and may even trigger puppet reset, so let's wait a moment
// before refreshing the model

View File

@@ -331,6 +331,20 @@ void MaterialEditorContextObject::setHasMaterialLibrary(bool b)
emit hasMaterialLibraryChanged();
}
bool MaterialEditorContextObject::isQt6Project() const
{
return m_isQt6Project;
}
void MaterialEditorContextObject::setIsQt6Project(bool b)
{
if (m_isQt6Project == b)
return;
m_isQt6Project = b;
emit isQt6ProjectChanged();
}
bool MaterialEditorContextObject::hasModelSelection() const
{
return m_hasModelSelection;

View File

@@ -39,6 +39,7 @@ class MaterialEditorContextObject : public QObject
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary WRITE setHasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
Q_PROPERTY(bool isQt6Project READ isQt6Project NOTIFY isQt6ProjectChanged)
Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
@@ -96,6 +97,9 @@ public:
bool hasMaterialLibrary() const;
void setHasMaterialLibrary(bool b);
bool isQt6Project() const;
void setIsQt6Project(bool b);
bool hasModelSelection() const;
void setHasModelSelection(bool b);
@@ -134,6 +138,7 @@ signals:
void hasQuick3DImportChanged();
void hasMaterialLibraryChanged();
void hasModelSelectionChanged();
void isQt6ProjectChanged();
private:
void updatePossibleTypeIndex();
@@ -163,6 +168,7 @@ private:
bool m_hasQuick3DImport = false;
bool m_hasMaterialLibrary = false;
bool m_hasModelSelection = false;
bool m_isQt6Project = false;
ModelNode m_selectedMaterial;
};

View File

@@ -9,6 +9,7 @@
#include "designdocument.h"
#include "designmodewidget.h"
#include "dynamicpropertiesmodel.h"
#include "externaldependenciesinterface.h"
#include "itemlibraryinfo.h"
#include "materialeditorqmlbackend.h"
#include "materialeditorcontextobject.h"
@@ -598,6 +599,7 @@ void MaterialEditorView::setupQmlBackend()
currentQmlBackend->contextObject()->setHasMaterialLibrary(materialLibraryNode().isValid());
currentQmlBackend->contextObject()->setSpecificQmlData(specificQmlData);
currentQmlBackend->contextObject()->setCurrentType(currentTypeName);
currentQmlBackend->contextObject()->setIsQt6Project(externalDependencies().isQt6Project());
m_qmlBackEnd = currentQmlBackend;

View File

@@ -159,6 +159,20 @@ void TextureEditorContextObject::setHasMaterialLibrary(bool b)
emit hasMaterialLibraryChanged();
}
bool TextureEditorContextObject::isQt6Project() const
{
return m_isQt6Project;
}
void TextureEditorContextObject::setIsQt6Project(bool b)
{
if (m_isQt6Project == b)
return;
m_isQt6Project = b;
emit isQt6ProjectChanged();
}
bool TextureEditorContextObject::hasSingleModelSelection() const
{
return m_hasSingleModelSelection;

View File

@@ -39,6 +39,7 @@ class TextureEditorContextObject : public QObject
Q_PROPERTY(bool hasSingleModelSelection READ hasSingleModelSelection WRITE setHasSingleModelSelection
NOTIFY hasSingleModelSelectionChanged)
Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary WRITE setHasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
Q_PROPERTY(bool isQt6Project READ isQt6Project NOTIFY isQt6ProjectChanged)
Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
@@ -95,6 +96,9 @@ public:
bool hasMaterialLibrary() const;
void setHasMaterialLibrary(bool b);
bool isQt6Project() const;
void setIsQt6Project(bool b);
bool hasSingleModelSelection() const;
void setHasSingleModelSelection(bool b);
@@ -133,6 +137,7 @@ signals:
void hasMaterialLibraryChanged();
void hasSingleModelSelectionChanged();
void activeDragSuffixChanged();
void isQt6ProjectChanged();
private:
QUrl m_specificsUrl;
@@ -157,6 +162,7 @@ private:
bool m_hasQuick3DImport = false;
bool m_hasMaterialLibrary = false;
bool m_hasSingleModelSelection = false;
bool m_isQt6Project = false;
ModelNode m_selectedTexture;

View File

@@ -13,6 +13,7 @@
#include <auxiliarydataproperties.h>
#include <bindingproperty.h>
#include <dynamicpropertiesmodel.h>
#include <externaldependenciesinterface.h>
#include <metainfo.h>
#include <nodeinstanceview.h>
#include <nodelistproperty.h>
@@ -461,6 +462,7 @@ void TextureEditorView::setupQmlBackend()
currentQmlBackend->contextObject()->setSpecificQmlData(specificQmlData);
bool hasValidSelection = QmlObjectNode(m_selectedModel).hasBindingProperty("materials");
currentQmlBackend->contextObject()->setHasSingleModelSelection(hasValidSelection);
currentQmlBackend->contextObject()->setIsQt6Project(externalDependencies().isQt6Project());
m_qmlBackEnd = currentQmlBackend;