summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2022-11-29 16:56:08 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2022-12-02 08:19:56 +0000
commit57448021b8475f622c655c0e4dde1d0a3c58329c (patch)
tree099366e054954178b2791bdb9c3098b0ef71b0ad
parent44cfc4a8cda8a39a83ebb4e0a7ea0b86b74ef8b0 (diff)
downloadqt-creator-57448021b8475f622c655c0e4dde1d0a3c58329c.tar.gz
QmlDesigner: Fix content library visibility logic
Also fix enable logic of context menus in content library. Fixes: QDS-8446 Change-Id: I82f80779f507aa5336ebafac5cffc36365238fc5 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml34
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml22
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml25
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml6
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml8
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp83
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h23
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp96
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.h35
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp27
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h4
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp38
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h14
13 files changed, 207 insertions, 208 deletions
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml
index 53fae29a53..19c1a039c1 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml
@@ -35,7 +35,15 @@ Item {
id: searchBox
width: root.width
- enabled: !materialsModel.hasMaterialRoot && materialsModel.hasQuick3DImport
+ enabled: {
+ if (tabBar.currIndex == 0) { // Materials tab
+ materialsModel.matBundleExists
+ && rootView.hasMaterialLibrary
+ && materialsModel.hasRequiredQuick3DImport
+ } else { // Textures / Environments tabs
+ texturesModel.texBundleExists
+ }
+ }
onSearchChanged: (searchText) => {
rootView.handleSearchFilterChanged(searchText)
@@ -47,35 +55,12 @@ Item {
}
}
- Text {
- // TODO: only disable the materials section, textures should be available
- text: {
- if (materialsModel.hasMaterialRoot)
- qsTr("<b>Content Library</b> is disabled inside a material component.")
- else if (!materialsModel.hasQuick3DImport)
- qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
- else
- ""
- }
-
- textFormat: Text.RichText
- color: StudioTheme.Values.themeTextColor
- font.pixelSize: StudioTheme.Values.mediumFontSize
- topPadding: 30
- horizontalAlignment: Text.AlignHCenter
- wrapMode: Text.WordWrap
- width: root.width
- visible: text !== ""
- }
-
UnimportBundleMaterialDialog {
id: confirmUnimportDialog
}
ContentLibraryTabBar {
id: tabBar
-
- visible: materialsModel.hasQuick3DImport
// TODO: update icons
tabsModel: [{name: qsTr("Materials"), icon: StudioTheme.Constants.gradient},
{name: qsTr("Textures"), icon: StudioTheme.Constants.materialPreviewEnvironment},
@@ -86,7 +71,6 @@ Item {
width: root.width
height: root.height - y
currentIndex: tabBar.currIndex
- visible: materialsModel.hasQuick3DImport
ContentLibraryMaterialsView {
id: materialsView
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml
index a85699e6dc..4d5d75b6e5 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml
@@ -10,7 +10,13 @@ StudioControls.Menu {
id: root
property var targetMaterial: null
+ property bool hasModelSelection: false
+ property bool importerRunning: false
+
+ readonly property bool targetAvailable: targetMaterial && !importerRunning
+
signal unimport(var bundleMat);
+ signal addToProject(var bundleMat)
function popupMenu(targetMaterial = null)
{
@@ -22,31 +28,31 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Apply to selected (replace)")
- enabled: root.targetMaterial && materialsModel.hasModelSelection
- onTriggered: materialsModel.applyToSelected(root.targetMaterial, false)
+ enabled: root.targetAvailable && root.hasModelSelection
+ onTriggered: root.applyToSelected(root.targetMaterial, false)
}
StudioControls.MenuItem {
text: qsTr("Apply to selected (add)")
- enabled: root.targetMaterial && materialsModel.hasModelSelection
- onTriggered: materialsModel.applyToSelected(root.targetMaterial, true)
+ enabled: root.targetAvailable && root.hasModelSelection
+ onTriggered: root.applyToSelected(root.targetMaterial, true)
}
StudioControls.MenuSeparator {}
StudioControls.MenuItem {
- enabled: !materialsModel.importerRunning
+ enabled: root.targetAvailable
text: qsTr("Add an instance to project")
onTriggered: {
- materialsModel.addToProject(root.targetMaterial)
+ root.addToProject(root.targetMaterial)
}
}
StudioControls.MenuItem {
- enabled: !materialsModel.importerRunning && root.targetMaterial && root.targetMaterial.bundleMaterialImported
+ enabled: root.targetAvailable && root.targetMaterial.bundleMaterialImported
text: qsTr("Remove from project")
- onTriggered: root.unimport(root.targetMaterial);
+ onTriggered: root.unimport(root.targetMaterial)
}
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml
index 6483ebdd6b..57c507c3ff 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml
@@ -40,7 +40,11 @@ HelperWidgets.ScrollView {
ContentLibraryMaterialContextMenu {
id: ctxMenu
+ hasModelSelection: materialsModel.hasModelSelection
+ importerRunning: materialsModel.importerRunning
+
onUnimport: (bundleMat) => root.unimport(bundleMat)
+ onAddToProject: (bundleMat) => materialsModel.addToProject(bundleMat)
}
Repeater {
@@ -53,7 +57,7 @@ HelperWidgets.ScrollView {
caption: bundleCategoryName
addTopPadding: false
sectionBackgroundColor: "transparent"
- visible: bundleCategoryVisible
+ visible: bundleCategoryVisible && !materialsModel.isEmpty
expanded: bundleCategoryExpanded
expandOnClick: false
onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded
@@ -84,13 +88,26 @@ HelperWidgets.ScrollView {
}
Text {
- id: noMatchText
- text: qsTr("No match found.");
+ id: infoText
+ text: {
+ if (!materialsModel.matBundleExists)
+ qsTr("<b>Content Library</b> materials are not installed.")
+ else if (!rootView.hasQuick3DImport)
+ qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
+ else if (!materialsModel.hasRequiredQuick3DImport)
+ qsTr("To use <b>Content Library</b>, version 6.3 or later of the QtQuick3D module is required.")
+ else if (!rootView.hasMaterialLibrary)
+ qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
+ else if (!searchBox.isEmpty())
+ qsTr("No match found.")
+ else
+ ""
+ }
color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFontSize
topPadding: 10
leftPadding: 10
- visible: materialsModel.isEmpty && !searchBox.isEmpty() && !materialsModel.hasMaterialRoot
+ visible: materialsModel.isEmpty
}
}
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml
index f9d3d88a78..b1617578ce 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml
@@ -12,6 +12,8 @@ StudioControls.Menu {
property var targetTexture: null
property bool hasSceneEnv: false
+ property bool canUse3D: targetTexture && rootView.hasQuick3DImport && rootView.hasMaterialLibrary
+
function popupMenu(targetTexture = null)
{
this.targetTexture = targetTexture
@@ -29,13 +31,13 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Add texture")
- enabled: root.targetTexture
+ enabled: canUse3D
onTriggered: rootView.addTexture(root.targetTexture)
}
StudioControls.MenuItem {
text: qsTr("Add light probe")
- enabled: root.hasSceneEnv && root.targetTexture
+ enabled: root.hasSceneEnv && canUse3D
onTriggered: rootView.addLightProbe(root.targetTexture)
}
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml
index dd6509b67e..b80ef7471a 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml
@@ -53,7 +53,7 @@ HelperWidgets.ScrollView {
caption: bundleCategoryName
addTopPadding: false
sectionBackgroundColor: "transparent"
- visible: bundleCategoryVisible
+ visible: bundleCategoryVisible && !root.model.isEmpty
expanded: bundleCategoryExpanded
expandOnClick: false
onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded
@@ -87,10 +87,12 @@ HelperWidgets.ScrollView {
Text {
id: infoText
text: {
- if (!searchBox.isEmpty())
+ if (!root.model.texBundleExists)
+ qsTr("<b>Content Library</b> textures are not installed.")
+ else if (!searchBox.isEmpty())
qsTr("No match found.")
else
- qsTr("Texture library is not installed.")
+ ""
}
color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFontSize
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp
index 55acaf1574..2acc449978 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp
@@ -6,7 +6,10 @@
#include "contentlibrarybundleimporter.h"
#include "contentlibrarymaterial.h"
#include "contentlibrarymaterialscategory.h"
+#include "contentlibrarywidget.h"
#include "qmldesignerconstants.h"
+
+#include "utils/algorithm.h"
#include "utils/qtcassert.h"
#include <QCoreApplication>
@@ -16,8 +19,9 @@
namespace QmlDesigner {
-ContentLibraryMaterialsModel::ContentLibraryMaterialsModel(QObject *parent)
+ContentLibraryMaterialsModel::ContentLibraryMaterialsModel(ContentLibraryWidget *parent)
: QAbstractListModel(parent)
+ , m_widget(parent)
{
loadMaterialBundle();
}
@@ -59,6 +63,22 @@ bool ContentLibraryMaterialsModel::isValidIndex(int idx) const
return idx > -1 && idx < rowCount();
}
+void ContentLibraryMaterialsModel::updateIsEmpty()
+{
+ const bool anyCatVisible = Utils::anyOf(m_bundleCategories,
+ [&](ContentLibraryMaterialsCategory *cat) {
+ return cat->visible();
+ });
+
+ const bool newEmpty = !anyCatVisible || m_bundleCategories.isEmpty()
+ || !m_widget->hasMaterialLibrary() || !hasRequiredQuick3DImport();
+
+ if (newEmpty != m_isEmpty) {
+ m_isEmpty = newEmpty;
+ emit isEmptyChanged();
+ }
+}
+
QHash<int, QByteArray> ContentLibraryMaterialsModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
@@ -72,7 +92,7 @@ QHash<int, QByteArray> ContentLibraryMaterialsModel::roleNames() const
void ContentLibraryMaterialsModel::loadMaterialBundle()
{
- if (m_matBundleLoaded || m_probeMatBundleDir)
+ if (m_matBundleExists || m_probeMatBundleDir)
return;
QDir matBundleDir(qEnvironmentVariable("MATERIAL_BUNDLE_PATH"));
@@ -108,7 +128,7 @@ void ContentLibraryMaterialsModel::loadMaterialBundle()
}
}
- m_matBundleLoaded = true;
+ m_matBundleExists = true;
QString bundleId = m_matBundleObj.value("id").toString();
@@ -163,43 +183,17 @@ void ContentLibraryMaterialsModel::loadMaterialBundle()
emit bundleMaterialUnimported(metaInfo);
});
- if (m_bundleCategories.isEmpty() != m_isEmpty) {
- m_isEmpty = m_bundleCategories.isEmpty();
- emit isEmptyChanged();
- }
-}
-
-bool ContentLibraryMaterialsModel::hasQuick3DImport() const
-{
- return m_hasQuick3DImport;
+ updateIsEmpty();
}
-void ContentLibraryMaterialsModel::setHasQuick3DImport(bool b)
+bool ContentLibraryMaterialsModel::hasRequiredQuick3DImport() const
{
- if (b == m_hasQuick3DImport)
- return;
-
- m_hasQuick3DImport = b;
- emit hasQuick3DImportChanged();
-}
-
-bool ContentLibraryMaterialsModel::hasMaterialRoot() const
-{
- return m_hasMaterialRoot;
-}
-
-void ContentLibraryMaterialsModel::setHasMaterialRoot(bool b)
-{
- if (m_hasMaterialRoot == b)
- return;
-
- m_hasMaterialRoot = b;
- emit hasMaterialRootChanged();
+ return m_widget->hasQuick3DImport() && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
}
bool ContentLibraryMaterialsModel::matBundleExists() const
{
- return m_matBundleLoaded && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
+ return m_matBundleExists;
}
Internal::ContentLibraryBundleImporter *ContentLibraryMaterialsModel::bundleImporter() const
@@ -216,18 +210,11 @@ void ContentLibraryMaterialsModel::setSearchText(const QString &searchText)
m_searchText = lowerSearchText;
- bool anyCatVisible = false;
bool catVisibilityChanged = false;
-
- for (ContentLibraryMaterialsCategory *cat : std::as_const(m_bundleCategories)) {
+ for (ContentLibraryMaterialsCategory *cat : std::as_const(m_bundleCategories))
catVisibilityChanged |= cat->filter(m_searchText);
- anyCatVisible |= cat->visible();
- }
- if (anyCatVisible == m_isEmpty) {
- m_isEmpty = !anyCatVisible;
- emit isEmptyChanged();
- }
+ updateIsEmpty();
if (catVisibilityChanged)
resetModel();
@@ -245,13 +232,19 @@ void ContentLibraryMaterialsModel::updateImportedState(const QStringList &import
void ContentLibraryMaterialsModel::setQuick3DImportVersion(int major, int minor)
{
- bool bundleExisted = matBundleExists();
+ bool oldRequiredImport = hasRequiredQuick3DImport();
m_quick3dMajorVersion = major;
m_quick3dMinorVersion = minor;
- if (bundleExisted != matBundleExists())
- emit matBundleExistsChanged();
+ bool newRequiredImport = hasRequiredQuick3DImport();
+
+ if (oldRequiredImport == newRequiredImport)
+ return;
+
+ emit hasRequiredQuick3DImportChanged();
+
+ updateIsEmpty();
}
void ContentLibraryMaterialsModel::resetModel()
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h
index 9fe76cd25d..91ec476c51 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h
@@ -12,6 +12,7 @@ namespace QmlDesigner {
class ContentLibraryMaterial;
class ContentLibraryMaterialsCategory;
+class ContentLibraryWidget;
namespace Internal {
class ContentLibraryBundleImporter;
@@ -23,13 +24,12 @@ class ContentLibraryMaterialsModel : public QAbstractListModel
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 hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
- Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)
+ Q_PROPERTY(bool hasRequiredQuick3DImport READ hasRequiredQuick3DImport NOTIFY hasRequiredQuick3DImportChanged)
+ Q_PROPERTY(bool hasModelSelection READ hasModelSelection NOTIFY hasModelSelectionChanged)
Q_PROPERTY(bool importerRunning MEMBER m_importerRunning NOTIFY importerRunningChanged)
public:
- ContentLibraryMaterialsModel(QObject *parent = nullptr);
+ ContentLibraryMaterialsModel(ContentLibraryWidget *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
@@ -41,11 +41,7 @@ public:
void setQuick3DImportVersion(int major, int minor);
- bool hasQuick3DImport() const;
- void setHasQuick3DImport(bool b);
-
- bool hasMaterialRoot() const;
- void setHasMaterialRoot(bool b);
+ bool hasRequiredQuick3DImport() const;
bool matBundleExists() const;
@@ -53,6 +49,7 @@ public:
void setHasModelSelection(bool b);
void resetModel();
+ void updateIsEmpty();
Internal::ContentLibraryBundleImporter *bundleImporter() const;
@@ -62,9 +59,8 @@ public:
signals:
void isEmptyChanged();
- void hasQuick3DImportChanged();
+ void hasRequiredQuick3DImportChanged();
void hasModelSelectionChanged();
- void hasMaterialRootChanged();
void materialVisibleChanged();
void applyToSelectedTriggered(QmlDesigner::ContentLibraryMaterial *mat, bool add = false);
void bundleMaterialImported(const QmlDesigner::NodeMetaInfo &metaInfo);
@@ -77,15 +73,14 @@ private:
void loadMaterialBundle();
bool isValidIndex(int idx) const;
+ ContentLibraryWidget *m_widget = nullptr;
QString m_searchText;
QList<ContentLibraryMaterialsCategory *> m_bundleCategories;
QJsonObject m_matBundleObj;
Internal::ContentLibraryBundleImporter *m_importer = nullptr;
bool m_isEmpty = true;
- bool m_hasMaterialRoot = false;
- bool m_hasQuick3DImport = false;
- bool m_matBundleLoaded = false;
+ bool m_matBundleExists = false;
bool m_hasModelSelection = false;
bool m_probeMatBundleDir = false;
bool m_importerRunning = false;
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp
index 8a0ea67c3e..b12473da61 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp
@@ -4,6 +4,8 @@
#include "contentlibrarytexturesmodel.h"
#include "contentlibrarytexturescategory.h"
+
+#include "utils/algorithm.h"
#include "utils/qtcassert.h"
#include <QCoreApplication>
@@ -55,6 +57,21 @@ bool ContentLibraryTexturesModel::isValidIndex(int idx) const
return idx > -1 && idx < rowCount();
}
+void ContentLibraryTexturesModel::updateIsEmpty()
+{
+ const bool anyCatVisible = Utils::anyOf(m_bundleCategories,
+ [&](ContentLibraryTexturesCategory *cat) {
+ return cat->visible();
+ });
+
+ const bool newEmpty = !anyCatVisible || m_bundleCategories.isEmpty();
+
+ if (newEmpty != m_isEmpty) {
+ m_isEmpty = newEmpty;
+ emit isEmptyChanged();
+ }
+}
+
QHash<int, QByteArray> ContentLibraryTexturesModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
@@ -74,7 +91,7 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &bundlePath)
return;
}
- if (m_texBundleLoaded)
+ if (!m_bundleCategories.isEmpty())
return;
const QFileInfoList dirs = bundleDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
@@ -86,38 +103,12 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &bundlePath)
m_bundleCategories.append(category);
}
- if (m_bundleCategories.isEmpty() != m_isEmpty) {
- m_isEmpty = m_bundleCategories.isEmpty();
- emit isEmptyChanged();
- }
+ updateIsEmpty();
}
-bool ContentLibraryTexturesModel::hasQuick3DImport() const
+bool ContentLibraryTexturesModel::texBundleExists() const
{
- return m_hasQuick3DImport;
-}
-
-void ContentLibraryTexturesModel::setHasQuick3DImport(bool b)
-{
- if (b == m_hasQuick3DImport)
- return;
-
- m_hasQuick3DImport = b;
- emit hasQuick3DImportChanged();
-}
-
-bool ContentLibraryTexturesModel::hasMaterialRoot() const
-{
- return m_hasMaterialRoot;
-}
-
-void ContentLibraryTexturesModel::setHasMaterialRoot(bool b)
-{
- if (m_hasMaterialRoot == b)
- return;
-
- m_hasMaterialRoot = b;
- emit hasMaterialRootChanged();
+ return !m_bundleCategories.isEmpty();
}
bool ContentLibraryTexturesModel::hasSceneEnv() const
@@ -134,11 +125,6 @@ void ContentLibraryTexturesModel::setHasSceneEnv(bool b)
emit hasSceneEnvChanged();
}
-bool ContentLibraryTexturesModel::matBundleExists() const
-{
- return m_texBundleLoaded && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
-}
-
void ContentLibraryTexturesModel::setSearchText(const QString &searchText)
{
QString lowerSearchText = searchText.toLower();
@@ -148,57 +134,21 @@ void ContentLibraryTexturesModel::setSearchText(const QString &searchText)
m_searchText = lowerSearchText;
- bool anyCatVisible = false;
bool catVisibilityChanged = false;
- for (ContentLibraryTexturesCategory *cat : std::as_const(m_bundleCategories)) {
+ for (ContentLibraryTexturesCategory *cat : std::as_const(m_bundleCategories))
catVisibilityChanged |= cat->filter(m_searchText);
- anyCatVisible |= cat->visible();
- }
- if (anyCatVisible == m_isEmpty) {
- m_isEmpty = !anyCatVisible;
- emit isEmptyChanged();
- }
+ updateIsEmpty();
if (catVisibilityChanged)
resetModel();
}
-void ContentLibraryTexturesModel::setQuick3DImportVersion(int major, int minor)
-{
- bool bundleExisted = matBundleExists();
-
- m_quick3dMajorVersion = major;
- m_quick3dMinorVersion = minor;
-
- if (bundleExisted != matBundleExists())
- emit matBundleExistsChanged();
-}
-
void ContentLibraryTexturesModel::resetModel()
{
beginResetModel();
endResetModel();
}
-void ContentLibraryTexturesModel::addToProject(const QString &mat)
-{
- // TODO: import asset
-}
-
-bool ContentLibraryTexturesModel::hasModelSelection() const
-{
- return m_hasModelSelection;
-}
-
-void ContentLibraryTexturesModel::setHasModelSelection(bool b)
-{
- if (b == m_hasModelSelection)
- return;
-
- m_hasModelSelection = b;
- emit hasModelSelectionChanged();
-}
-
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.h
index ca5e7a6963..cbbd2a364c 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.h
@@ -13,12 +13,9 @@ class ContentLibraryTexturesModel : public QAbstractListModel
{
Q_OBJECT
- Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged)
+ Q_PROPERTY(bool texBundleExists READ texBundleExists CONSTANT)
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
- Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
- Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
- Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)
- Q_PROPERTY(bool hasSceneEnv READ hasSceneEnv WRITE setHasSceneEnv NOTIFY hasSceneEnvChanged)
+ Q_PROPERTY(bool hasSceneEnv READ hasSceneEnv NOTIFY hasSceneEnvChanged)
public:
ContentLibraryTexturesModel(QObject *parent = nullptr);
@@ -30,18 +27,7 @@ public:
void setSearchText(const QString &searchText);
- void setQuick3DImportVersion(int major, int minor);
-
- bool hasQuick3DImport() const;
- void setHasQuick3DImport(bool b);
-
- bool hasMaterialRoot() const;
- void setHasMaterialRoot(bool b);
-
- bool matBundleExists() const;
-
- bool hasModelSelection() const;
- void setHasModelSelection(bool b);
+ bool texBundleExists() const;
bool hasSceneEnv() const;
void setHasSceneEnv(bool b);
@@ -49,32 +35,21 @@ public:
void resetModel();
void loadTextureBundle(const QString &bundlePath);
- Q_INVOKABLE void addToProject(const QString &mat);
-
signals:
void isEmptyChanged();
- void hasQuick3DImportChanged();
- void hasModelSelectionChanged();
- void hasMaterialRootChanged();
void materialVisibleChanged();
- void matBundleExistsChanged();
void hasSceneEnvChanged();
private:
bool isValidIndex(int idx) const;
+ void updateIsEmpty();
QString m_searchText;
QList<ContentLibraryTexturesCategory *> m_bundleCategories;
bool m_isEmpty = true;
- bool m_hasMaterialRoot = false;
- bool m_hasQuick3DImport = false;
- bool m_texBundleLoaded = false;
- bool m_hasModelSelection = false;
bool m_hasSceneEnv = false;
-
- int m_quick3dMajorVersion = -1;
- int m_quick3dMinorVersion = -1;
+ bool m_hasModelSelection = false;
};
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
index 347512a837..5e9f572c7a 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
@@ -11,6 +11,7 @@
#include "contentlibrarytexturesmodel.h"
#include "modelnodeoperations.h"
#include "nodelistproperty.h"
+#include "qmldesignerconstants.h"
#include "qmlobjectnode.h"
#include "variantproperty.h"
@@ -161,15 +162,18 @@ void ContentLibraryView::modelAttached(Model *model)
m_hasQuick3DImport = model->hasImport("QtQuick3D");
- m_widget->materialsModel()->setHasMaterialRoot(rootModelNode().metaInfo().isQtQuick3DMaterial());
- m_widget->materialsModel()->setHasQuick3DImport(m_hasQuick3DImport);
-
updateBundleMaterialsQuick3DVersion();
updateBundleMaterialsImportedState();
+
+ const bool hasLibrary = materialLibraryNode().isValid();
+ m_widget->setHasMaterialLibrary(hasLibrary);
+ m_widget->setHasQuick3DImport(m_hasQuick3DImport);
}
void ContentLibraryView::modelAboutToBeDetached(Model *model)
{
+ m_widget->setHasMaterialLibrary(false);
+ m_widget->setHasQuick3DImport(false);
AbstractView::modelAboutToBeDetached(model);
}
@@ -187,7 +191,7 @@ void ContentLibraryView::importsChanged(const QList<Import> &addedImports, const
return;
m_hasQuick3DImport = hasQuick3DImport;
- m_widget->materialsModel()->setHasQuick3DImport(m_hasQuick3DImport);
+ m_widget->setHasQuick3DImport(m_hasQuick3DImport);
}
void ContentLibraryView::active3DSceneChanged(qint32 sceneId)
@@ -244,6 +248,21 @@ void ContentLibraryView::customNotification(const AbstractView *view, const QStr
}
}
+void ContentLibraryView::nodeReparented(const ModelNode &node,
+ [[maybe_unused]] const NodeAbstractProperty &newPropertyParent,
+ [[maybe_unused]] const NodeAbstractProperty &oldPropertyParent,
+ [[maybe_unused]] PropertyChangeFlags propertyChange)
+{
+ if (node.id() == Constants::MATERIAL_LIB_ID)
+ m_widget->setHasMaterialLibrary(true);
+}
+
+void ContentLibraryView::nodeAboutToBeRemoved(const ModelNode &removedNode)
+{
+ if (removedNode.id() == Constants::MATERIAL_LIB_ID)
+ m_widget->setHasMaterialLibrary(false);
+}
+
void ContentLibraryView::applyBundleMaterialToDropTarget(const ModelNode &bundleMat,
const NodeMetaInfo &metaInfo)
{
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h
index 5b4914a50c..c54ec924d0 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h
@@ -36,6 +36,10 @@ public:
const QList<ModelNode> &lastSelectedNodeList) override;
void customNotification(const AbstractView *view, const QString &identifier,
const QList<ModelNode> &nodeList, const QList<QVariant> &data) override;
+ void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent,
+ const NodeAbstractProperty &oldPropertyParent,
+ AbstractView::PropertyChangeFlags propertyChange) override;
+ void nodeAboutToBeRemoved(const ModelNode &removedNode) override;
private:
void updateBundleMaterialsImportedState();
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp
index 75eff3af98..4f6c268b78 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp
@@ -157,6 +157,44 @@ void ContentLibraryWidget::clearSearchFilter()
QMetaObject::invokeMethod(m_quickWidget->rootObject(), "clearSearchFilter");
}
+bool ContentLibraryWidget::hasQuick3DImport() const
+{
+ return m_hasQuick3DImport;
+}
+
+void ContentLibraryWidget::setHasQuick3DImport(bool b)
+{
+ if (b == m_hasQuick3DImport)
+ return;
+
+ const bool oldRequired = m_materialsModel->hasRequiredQuick3DImport();
+ m_hasQuick3DImport = b;
+ const bool newRequired = m_materialsModel->hasRequiredQuick3DImport();
+
+ if (oldRequired != newRequired)
+ emit m_materialsModel->hasRequiredQuick3DImportChanged();
+
+ emit hasQuick3DImportChanged();
+
+ m_materialsModel->updateIsEmpty();
+}
+
+bool ContentLibraryWidget::hasMaterialLibrary() const
+{
+ return m_hasMaterialLibrary;
+}
+
+void ContentLibraryWidget::setHasMaterialLibrary(bool b)
+{
+ if (m_hasMaterialLibrary == b)
+ return;
+
+ m_hasMaterialLibrary = b;
+ emit hasMaterialLibraryChanged();
+
+ m_materialsModel->updateIsEmpty();
+}
+
void ContentLibraryWidget::reloadQmlSource()
{
const QString materialBrowserQmlPath = qmlSourcesPath() + "/ContentLibrary.qml";
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h
index 4d77068632..b6b24c4dec 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h
@@ -23,6 +23,9 @@ class ContentLibraryWidget : public QFrame
{
Q_OBJECT
+ Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport NOTIFY hasQuick3DImportChanged)
+ Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
+
public:
ContentLibraryWidget();
@@ -31,6 +34,12 @@ public:
static QString qmlSourcesPath();
void clearSearchFilter();
+ bool hasQuick3DImport() const;
+ void setHasQuick3DImport(bool b);
+
+ bool hasMaterialLibrary() const;
+ void setHasMaterialLibrary(bool b);
+
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
void setMaterialsModel(QPointer<ContentLibraryMaterialsModel> newMaterialsModel);
@@ -53,6 +62,8 @@ signals:
void bundleTextureDragStarted(QmlDesigner::ContentLibraryTexture *bundleTex);
void addTextureRequested(const QString texPath, QmlDesigner::ContentLibraryWidget::AddTextureMode mode);
void updateSceneEnvStateRequested();
+ void hasQuick3DImportChanged();
+ void hasMaterialLibraryChanged();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
@@ -74,6 +85,9 @@ private:
ContentLibraryMaterial *m_materialToDrag = nullptr;
ContentLibraryTexture *m_textureToDrag = nullptr;
QPoint m_dragStartPoint;
+
+ bool m_hasMaterialLibrary = false;
+ bool m_hasQuick3DImport = false;
};
} // namespace QmlDesigner