From 645e479a1a426f0d3c3e9938ef6807633bc9e446 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Thu, 13 Jun 2024 16:03:32 +0300 Subject: [PATCH] QmlDesigner: Show placeholder text when content lib user is empty Fixes: QDS-12910 Change-Id: I3f490bfa14c1479ea7541bb0298670da5db37edc Reviewed-by: Miikka Heikkinen --- .../ContentLibraryUserView.qml | 2 ++ .../contentlibraryusermodel.cpp | 31 +++++++++++++------ .../contentlibrary/contentlibraryusermodel.h | 16 +++++----- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml index 518409ba76e..d93895ec554 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml @@ -158,6 +158,8 @@ HelperWidgets.ScrollView { qsTr("To use Content Library, first add the QtQuick3D module in the Components view.") else if (!ContentLibraryBackend.rootView.hasMaterialLibrary) qsTr("Content Library is disabled inside a non-visual component.") + else if (ContentLibraryBackend.userModel.isEmpty) + qsTr("There are no user assets in the Content Library.") else "" } diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp index 4249428a0ae..53b0cea71de 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp @@ -28,7 +28,6 @@ ContentLibraryUserModel::ContentLibraryUserModel(ContentLibraryWidget *parent) : QAbstractListModel(parent) , m_widget(parent) { - m_userCategories = {tr("Materials"), tr("Textures"), tr("3D"), /*tr("Effects"), tr("2D components")*/}; // TODO } int ContentLibraryUserModel::rowCount(const QModelIndex &) const @@ -113,6 +112,8 @@ void ContentLibraryUserModel::addMaterial(const QString &name, const QString &qm m_userMaterials.append(libMat); emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx)); + + updateIsEmpty(); } void ContentLibraryUserModel::add3DItem(const QString &name, const QString &qml, @@ -129,6 +130,7 @@ void ContentLibraryUserModel::add3DItem(const QString &name, const QString &qml, void ContentLibraryUserModel::refreshSection(SectionIndex sectionIndex) { emit dataChanged(index(sectionIndex), index(sectionIndex)); + updateIsEmpty(); } void ContentLibraryUserModel::addTextures(const QStringList &paths) @@ -177,6 +179,7 @@ void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex) // update model emit dataChanged(index(TexturesSectionIdx), index(TexturesSectionIdx)); + updateIsEmpty(); } void ContentLibraryUserModel::removeFromContentLib(QObject *item) @@ -228,6 +231,7 @@ void ContentLibraryUserModel::removeMaterialFromContentLib(ContentLibraryItem *i // update model emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx)); + updateIsEmpty(); } void ContentLibraryUserModel::remove3DFromContentLibByName(const QString &qmlFileName) @@ -291,6 +295,7 @@ void ContentLibraryUserModel::remove3DFromContentLib(ContentLibraryItem *item) // update model emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx)); + updateIsEmpty(); } /** @@ -378,13 +383,13 @@ void ContentLibraryUserModel::loadBundles() void ContentLibraryUserModel::loadMaterialBundle() { auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); - if (m_matBundleExists && m_bundleIdMaterial == compUtils.userMaterialsBundleId()) + if (m_matBundleLoaded && m_bundleIdMaterial == compUtils.userMaterialsBundleId()) return; // clean up qDeleteAll(m_userMaterials); m_userMaterials.clear(); - m_matBundleExists = false; + m_matBundleLoaded = false; m_noMatchMaterials = true; m_bundleObjMaterial = {}; m_bundleIdMaterial.clear(); @@ -445,8 +450,9 @@ void ContentLibraryUserModel::loadMaterialBundle() for (const QJsonValueConstRef &file : sharedFilesArr) m_bundleMaterialSharedFiles.append(file.toString()); - m_matBundleExists = true; + m_matBundleLoaded = true; updateNoMatchMaterials(); + updateIsEmpty(); emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx)); } @@ -454,13 +460,13 @@ void ContentLibraryUserModel::load3DBundle() { auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); - if (m_bundle3DExists && m_bundleId3D == compUtils.user3DBundleId()) + if (m_bundle3DLoaded && m_bundleId3D == compUtils.user3DBundleId()) return; // clean up qDeleteAll(m_user3DItems); m_user3DItems.clear(); - m_bundle3DExists = false; + m_bundle3DLoaded = false; m_noMatch3D = true; m_bundleObj3D = {}; m_bundleId3D.clear(); @@ -521,8 +527,9 @@ void ContentLibraryUserModel::load3DBundle() for (const QJsonValueConstRef &file : sharedFilesArr) m_bundle3DSharedFiles.append(file.toString()); - m_bundle3DExists = true; + m_bundle3DLoaded = true; updateNoMatch3D(); + updateIsEmpty(); emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx)); } @@ -557,9 +564,15 @@ bool ContentLibraryUserModel::hasRequiredQuick3DImport() const return m_widget->hasQuick3DImport() && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3; } -bool ContentLibraryUserModel::matBundleExists() const +void ContentLibraryUserModel::updateIsEmpty() { - return m_matBundleExists; + bool newIsEmpty = m_user3DItems.isEmpty() && m_userMaterials.isEmpty() && m_userTextures.isEmpty() + && m_userEffects.isEmpty(); + if (m_isEmpty == newIsEmpty) + return; + + m_isEmpty = newIsEmpty; + emit isEmptyChanged(); } void ContentLibraryUserModel::setSearchText(const QString &searchText) diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h index 9e63f37a490..e5c9adc2216 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h @@ -21,9 +21,8 @@ class ContentLibraryUserModel : public QAbstractListModel { Q_OBJECT - Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged) - Q_PROPERTY(bool bundle3DExists MEMBER m_bundle3DExists NOTIFY bundle3DExistsChanged) Q_PROPERTY(bool hasRequiredQuick3DImport READ hasRequiredQuick3DImport NOTIFY hasRequiredQuick3DImportChanged) + Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged) Q_PROPERTY(QList userMaterials MEMBER m_userMaterials NOTIFY userMaterialsChanged) Q_PROPERTY(QList userTextures MEMBER m_userTextures NOTIFY userTexturesChanged) Q_PROPERTY(QList user3DItems MEMBER m_user3DItems NOTIFY user3DItemsChanged) @@ -54,7 +53,7 @@ public: bool hasRequiredQuick3DImport() const; - bool matBundleExists() const; + void updateIsEmpty(); void resetModel(); void updateNoMatchMaterials(); @@ -85,13 +84,12 @@ public: signals: void hasRequiredQuick3DImportChanged(); + void isEmptyChanged(); void userMaterialsChanged(); void userTexturesChanged(); void user3DItemsChanged(); void userEffectsChanged(); void applyToSelectedTriggered(QmlDesigner::ContentLibraryItem *mat, bool add = false); - void matBundleExistsChanged(); - void bundle3DExistsChanged(); private: void loadMaterialBundle(); @@ -113,7 +111,8 @@ private: QList m_userTextures; QList m_userEffects; QList m_user3DItems; - QStringList m_userCategories; + const QStringList m_userCategories = {tr("Materials"), tr("Textures"), tr("3D"), + /*tr("Effects"), tr("2D components")*/}; // TODO; QJsonObject m_bundleObjMaterial; QJsonObject m_bundleObj3D; @@ -122,8 +121,9 @@ private: bool m_noMatchTextures = true; bool m_noMatch3D = true; bool m_noMatchEffects = true; - bool m_matBundleExists = false; - bool m_bundle3DExists = false; + bool m_matBundleLoaded = false; + bool m_bundle3DLoaded = false; + bool m_isEmpty = true; int m_quick3dMajorVersion = -1; int m_quick3dMinorVersion = -1;