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>
This commit is contained in:
Miikka Heikkinen
2022-11-29 16:56:08 +02:00
parent 44cfc4a8cd
commit 57448021b8
13 changed files with 207 additions and 208 deletions

View File

@@ -35,7 +35,15 @@ Item {
id: searchBox id: searchBox
width: root.width 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) => { onSearchChanged: (searchText) => {
rootView.handleSearchFilterChanged(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 { UnimportBundleMaterialDialog {
id: confirmUnimportDialog id: confirmUnimportDialog
} }
ContentLibraryTabBar { ContentLibraryTabBar {
id: tabBar id: tabBar
visible: materialsModel.hasQuick3DImport
// TODO: update icons // TODO: update icons
tabsModel: [{name: qsTr("Materials"), icon: StudioTheme.Constants.gradient}, tabsModel: [{name: qsTr("Materials"), icon: StudioTheme.Constants.gradient},
{name: qsTr("Textures"), icon: StudioTheme.Constants.materialPreviewEnvironment}, {name: qsTr("Textures"), icon: StudioTheme.Constants.materialPreviewEnvironment},
@@ -86,7 +71,6 @@ Item {
width: root.width width: root.width
height: root.height - y height: root.height - y
currentIndex: tabBar.currIndex currentIndex: tabBar.currIndex
visible: materialsModel.hasQuick3DImport
ContentLibraryMaterialsView { ContentLibraryMaterialsView {
id: materialsView id: materialsView

View File

@@ -10,7 +10,13 @@ StudioControls.Menu {
id: root id: root
property var targetMaterial: null property var targetMaterial: null
property bool hasModelSelection: false
property bool importerRunning: false
readonly property bool targetAvailable: targetMaterial && !importerRunning
signal unimport(var bundleMat); signal unimport(var bundleMat);
signal addToProject(var bundleMat)
function popupMenu(targetMaterial = null) function popupMenu(targetMaterial = null)
{ {
@@ -22,31 +28,31 @@ StudioControls.Menu {
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Apply to selected (replace)") text: qsTr("Apply to selected (replace)")
enabled: root.targetMaterial && materialsModel.hasModelSelection enabled: root.targetAvailable && root.hasModelSelection
onTriggered: materialsModel.applyToSelected(root.targetMaterial, false) onTriggered: root.applyToSelected(root.targetMaterial, false)
} }
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Apply to selected (add)") text: qsTr("Apply to selected (add)")
enabled: root.targetMaterial && materialsModel.hasModelSelection enabled: root.targetAvailable && root.hasModelSelection
onTriggered: materialsModel.applyToSelected(root.targetMaterial, true) onTriggered: root.applyToSelected(root.targetMaterial, true)
} }
StudioControls.MenuSeparator {} StudioControls.MenuSeparator {}
StudioControls.MenuItem { StudioControls.MenuItem {
enabled: !materialsModel.importerRunning enabled: root.targetAvailable
text: qsTr("Add an instance to project") text: qsTr("Add an instance to project")
onTriggered: { onTriggered: {
materialsModel.addToProject(root.targetMaterial) root.addToProject(root.targetMaterial)
} }
} }
StudioControls.MenuItem { StudioControls.MenuItem {
enabled: !materialsModel.importerRunning && root.targetMaterial && root.targetMaterial.bundleMaterialImported enabled: root.targetAvailable && root.targetMaterial.bundleMaterialImported
text: qsTr("Remove from project") text: qsTr("Remove from project")
onTriggered: root.unimport(root.targetMaterial); onTriggered: root.unimport(root.targetMaterial)
} }
} }

View File

@@ -40,7 +40,11 @@ HelperWidgets.ScrollView {
ContentLibraryMaterialContextMenu { ContentLibraryMaterialContextMenu {
id: ctxMenu id: ctxMenu
hasModelSelection: materialsModel.hasModelSelection
importerRunning: materialsModel.importerRunning
onUnimport: (bundleMat) => root.unimport(bundleMat) onUnimport: (bundleMat) => root.unimport(bundleMat)
onAddToProject: (bundleMat) => materialsModel.addToProject(bundleMat)
} }
Repeater { Repeater {
@@ -53,7 +57,7 @@ HelperWidgets.ScrollView {
caption: bundleCategoryName caption: bundleCategoryName
addTopPadding: false addTopPadding: false
sectionBackgroundColor: "transparent" sectionBackgroundColor: "transparent"
visible: bundleCategoryVisible visible: bundleCategoryVisible && !materialsModel.isEmpty
expanded: bundleCategoryExpanded expanded: bundleCategoryExpanded
expandOnClick: false expandOnClick: false
onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded
@@ -84,13 +88,26 @@ HelperWidgets.ScrollView {
} }
Text { Text {
id: noMatchText id: infoText
text: qsTr("No match found."); 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 color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFontSize font.pixelSize: StudioTheme.Values.baseFontSize
topPadding: 10 topPadding: 10
leftPadding: 10 leftPadding: 10
visible: materialsModel.isEmpty && !searchBox.isEmpty() && !materialsModel.hasMaterialRoot visible: materialsModel.isEmpty
} }
} }
} }

View File

@@ -12,6 +12,8 @@ StudioControls.Menu {
property var targetTexture: null property var targetTexture: null
property bool hasSceneEnv: false property bool hasSceneEnv: false
property bool canUse3D: targetTexture && rootView.hasQuick3DImport && rootView.hasMaterialLibrary
function popupMenu(targetTexture = null) function popupMenu(targetTexture = null)
{ {
this.targetTexture = targetTexture this.targetTexture = targetTexture
@@ -29,13 +31,13 @@ StudioControls.Menu {
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Add texture") text: qsTr("Add texture")
enabled: root.targetTexture enabled: canUse3D
onTriggered: rootView.addTexture(root.targetTexture) onTriggered: rootView.addTexture(root.targetTexture)
} }
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Add light probe") text: qsTr("Add light probe")
enabled: root.hasSceneEnv && root.targetTexture enabled: root.hasSceneEnv && canUse3D
onTriggered: rootView.addLightProbe(root.targetTexture) onTriggered: rootView.addLightProbe(root.targetTexture)
} }
} }

View File

@@ -53,7 +53,7 @@ HelperWidgets.ScrollView {
caption: bundleCategoryName caption: bundleCategoryName
addTopPadding: false addTopPadding: false
sectionBackgroundColor: "transparent" sectionBackgroundColor: "transparent"
visible: bundleCategoryVisible visible: bundleCategoryVisible && !root.model.isEmpty
expanded: bundleCategoryExpanded expanded: bundleCategoryExpanded
expandOnClick: false expandOnClick: false
onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded
@@ -87,10 +87,12 @@ HelperWidgets.ScrollView {
Text { Text {
id: infoText id: infoText
text: { 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.") qsTr("No match found.")
else else
qsTr("Texture library is not installed.") ""
} }
color: StudioTheme.Values.themeTextColor color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFontSize font.pixelSize: StudioTheme.Values.baseFontSize

View File

@@ -6,7 +6,10 @@
#include "contentlibrarybundleimporter.h" #include "contentlibrarybundleimporter.h"
#include "contentlibrarymaterial.h" #include "contentlibrarymaterial.h"
#include "contentlibrarymaterialscategory.h" #include "contentlibrarymaterialscategory.h"
#include "contentlibrarywidget.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "utils/algorithm.h"
#include "utils/qtcassert.h" #include "utils/qtcassert.h"
#include <QCoreApplication> #include <QCoreApplication>
@@ -16,8 +19,9 @@
namespace QmlDesigner { namespace QmlDesigner {
ContentLibraryMaterialsModel::ContentLibraryMaterialsModel(QObject *parent) ContentLibraryMaterialsModel::ContentLibraryMaterialsModel(ContentLibraryWidget *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
, m_widget(parent)
{ {
loadMaterialBundle(); loadMaterialBundle();
} }
@@ -59,6 +63,22 @@ bool ContentLibraryMaterialsModel::isValidIndex(int idx) const
return idx > -1 && idx < rowCount(); 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 QHash<int, QByteArray> ContentLibraryMaterialsModel::roleNames() const
{ {
static const QHash<int, QByteArray> roles { static const QHash<int, QByteArray> roles {
@@ -72,7 +92,7 @@ QHash<int, QByteArray> ContentLibraryMaterialsModel::roleNames() const
void ContentLibraryMaterialsModel::loadMaterialBundle() void ContentLibraryMaterialsModel::loadMaterialBundle()
{ {
if (m_matBundleLoaded || m_probeMatBundleDir) if (m_matBundleExists || m_probeMatBundleDir)
return; return;
QDir matBundleDir(qEnvironmentVariable("MATERIAL_BUNDLE_PATH")); 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(); QString bundleId = m_matBundleObj.value("id").toString();
@@ -163,43 +183,17 @@ void ContentLibraryMaterialsModel::loadMaterialBundle()
emit bundleMaterialUnimported(metaInfo); emit bundleMaterialUnimported(metaInfo);
}); });
if (m_bundleCategories.isEmpty() != m_isEmpty) { updateIsEmpty();
m_isEmpty = m_bundleCategories.isEmpty();
emit isEmptyChanged();
}
} }
bool ContentLibraryMaterialsModel::hasQuick3DImport() const bool ContentLibraryMaterialsModel::hasRequiredQuick3DImport() const
{ {
return m_hasQuick3DImport; return m_widget->hasQuick3DImport() && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
}
void ContentLibraryMaterialsModel::setHasQuick3DImport(bool b)
{
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();
} }
bool ContentLibraryMaterialsModel::matBundleExists() const bool ContentLibraryMaterialsModel::matBundleExists() const
{ {
return m_matBundleLoaded && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3; return m_matBundleExists;
} }
Internal::ContentLibraryBundleImporter *ContentLibraryMaterialsModel::bundleImporter() const Internal::ContentLibraryBundleImporter *ContentLibraryMaterialsModel::bundleImporter() const
@@ -216,18 +210,11 @@ void ContentLibraryMaterialsModel::setSearchText(const QString &searchText)
m_searchText = lowerSearchText; m_searchText = lowerSearchText;
bool anyCatVisible = false;
bool catVisibilityChanged = 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); catVisibilityChanged |= cat->filter(m_searchText);
anyCatVisible |= cat->visible();
}
if (anyCatVisible == m_isEmpty) { updateIsEmpty();
m_isEmpty = !anyCatVisible;
emit isEmptyChanged();
}
if (catVisibilityChanged) if (catVisibilityChanged)
resetModel(); resetModel();
@@ -245,13 +232,19 @@ void ContentLibraryMaterialsModel::updateImportedState(const QStringList &import
void ContentLibraryMaterialsModel::setQuick3DImportVersion(int major, int minor) void ContentLibraryMaterialsModel::setQuick3DImportVersion(int major, int minor)
{ {
bool bundleExisted = matBundleExists(); bool oldRequiredImport = hasRequiredQuick3DImport();
m_quick3dMajorVersion = major; m_quick3dMajorVersion = major;
m_quick3dMinorVersion = minor; m_quick3dMinorVersion = minor;
if (bundleExisted != matBundleExists()) bool newRequiredImport = hasRequiredQuick3DImport();
emit matBundleExistsChanged();
if (oldRequiredImport == newRequiredImport)
return;
emit hasRequiredQuick3DImportChanged();
updateIsEmpty();
} }
void ContentLibraryMaterialsModel::resetModel() void ContentLibraryMaterialsModel::resetModel()

View File

@@ -12,6 +12,7 @@ namespace QmlDesigner {
class ContentLibraryMaterial; class ContentLibraryMaterial;
class ContentLibraryMaterialsCategory; class ContentLibraryMaterialsCategory;
class ContentLibraryWidget;
namespace Internal { namespace Internal {
class ContentLibraryBundleImporter; class ContentLibraryBundleImporter;
@@ -23,13 +24,12 @@ class ContentLibraryMaterialsModel : public QAbstractListModel
Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged) Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged)
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged) Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged) Q_PROPERTY(bool hasRequiredQuick3DImport READ hasRequiredQuick3DImport NOTIFY hasRequiredQuick3DImportChanged)
Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged) Q_PROPERTY(bool hasModelSelection READ hasModelSelection NOTIFY hasModelSelectionChanged)
Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)
Q_PROPERTY(bool importerRunning MEMBER m_importerRunning NOTIFY importerRunningChanged) Q_PROPERTY(bool importerRunning MEMBER m_importerRunning NOTIFY importerRunningChanged)
public: public:
ContentLibraryMaterialsModel(QObject *parent = nullptr); ContentLibraryMaterialsModel(ContentLibraryWidget *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
@@ -41,11 +41,7 @@ public:
void setQuick3DImportVersion(int major, int minor); void setQuick3DImportVersion(int major, int minor);
bool hasQuick3DImport() const; bool hasRequiredQuick3DImport() const;
void setHasQuick3DImport(bool b);
bool hasMaterialRoot() const;
void setHasMaterialRoot(bool b);
bool matBundleExists() const; bool matBundleExists() const;
@@ -53,6 +49,7 @@ public:
void setHasModelSelection(bool b); void setHasModelSelection(bool b);
void resetModel(); void resetModel();
void updateIsEmpty();
Internal::ContentLibraryBundleImporter *bundleImporter() const; Internal::ContentLibraryBundleImporter *bundleImporter() const;
@@ -62,9 +59,8 @@ public:
signals: signals:
void isEmptyChanged(); void isEmptyChanged();
void hasQuick3DImportChanged(); void hasRequiredQuick3DImportChanged();
void hasModelSelectionChanged(); void hasModelSelectionChanged();
void hasMaterialRootChanged();
void materialVisibleChanged(); void materialVisibleChanged();
void applyToSelectedTriggered(QmlDesigner::ContentLibraryMaterial *mat, bool add = false); void applyToSelectedTriggered(QmlDesigner::ContentLibraryMaterial *mat, bool add = false);
void bundleMaterialImported(const QmlDesigner::NodeMetaInfo &metaInfo); void bundleMaterialImported(const QmlDesigner::NodeMetaInfo &metaInfo);
@@ -77,15 +73,14 @@ private:
void loadMaterialBundle(); void loadMaterialBundle();
bool isValidIndex(int idx) const; bool isValidIndex(int idx) const;
ContentLibraryWidget *m_widget = nullptr;
QString m_searchText; QString m_searchText;
QList<ContentLibraryMaterialsCategory *> m_bundleCategories; QList<ContentLibraryMaterialsCategory *> m_bundleCategories;
QJsonObject m_matBundleObj; QJsonObject m_matBundleObj;
Internal::ContentLibraryBundleImporter *m_importer = nullptr; Internal::ContentLibraryBundleImporter *m_importer = nullptr;
bool m_isEmpty = true; bool m_isEmpty = true;
bool m_hasMaterialRoot = false; bool m_matBundleExists = false;
bool m_hasQuick3DImport = false;
bool m_matBundleLoaded = false;
bool m_hasModelSelection = false; bool m_hasModelSelection = false;
bool m_probeMatBundleDir = false; bool m_probeMatBundleDir = false;
bool m_importerRunning = false; bool m_importerRunning = false;

View File

@@ -4,6 +4,8 @@
#include "contentlibrarytexturesmodel.h" #include "contentlibrarytexturesmodel.h"
#include "contentlibrarytexturescategory.h" #include "contentlibrarytexturescategory.h"
#include "utils/algorithm.h"
#include "utils/qtcassert.h" #include "utils/qtcassert.h"
#include <QCoreApplication> #include <QCoreApplication>
@@ -55,6 +57,21 @@ bool ContentLibraryTexturesModel::isValidIndex(int idx) const
return idx > -1 && idx < rowCount(); 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 QHash<int, QByteArray> ContentLibraryTexturesModel::roleNames() const
{ {
static const QHash<int, QByteArray> roles { static const QHash<int, QByteArray> roles {
@@ -74,7 +91,7 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &bundlePath)
return; return;
} }
if (m_texBundleLoaded) if (!m_bundleCategories.isEmpty())
return; return;
const QFileInfoList dirs = bundleDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); const QFileInfoList dirs = bundleDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
@@ -86,38 +103,12 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &bundlePath)
m_bundleCategories.append(category); m_bundleCategories.append(category);
} }
if (m_bundleCategories.isEmpty() != m_isEmpty) { updateIsEmpty();
m_isEmpty = m_bundleCategories.isEmpty();
emit isEmptyChanged();
}
} }
bool ContentLibraryTexturesModel::hasQuick3DImport() const bool ContentLibraryTexturesModel::texBundleExists() const
{ {
return m_hasQuick3DImport; return !m_bundleCategories.isEmpty();
}
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();
} }
bool ContentLibraryTexturesModel::hasSceneEnv() const bool ContentLibraryTexturesModel::hasSceneEnv() const
@@ -134,11 +125,6 @@ void ContentLibraryTexturesModel::setHasSceneEnv(bool b)
emit hasSceneEnvChanged(); emit hasSceneEnvChanged();
} }
bool ContentLibraryTexturesModel::matBundleExists() const
{
return m_texBundleLoaded && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
}
void ContentLibraryTexturesModel::setSearchText(const QString &searchText) void ContentLibraryTexturesModel::setSearchText(const QString &searchText)
{ {
QString lowerSearchText = searchText.toLower(); QString lowerSearchText = searchText.toLower();
@@ -148,57 +134,21 @@ void ContentLibraryTexturesModel::setSearchText(const QString &searchText)
m_searchText = lowerSearchText; m_searchText = lowerSearchText;
bool anyCatVisible = false;
bool catVisibilityChanged = 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); catVisibilityChanged |= cat->filter(m_searchText);
anyCatVisible |= cat->visible();
}
if (anyCatVisible == m_isEmpty) { updateIsEmpty();
m_isEmpty = !anyCatVisible;
emit isEmptyChanged();
}
if (catVisibilityChanged) if (catVisibilityChanged)
resetModel(); 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() void ContentLibraryTexturesModel::resetModel()
{ {
beginResetModel(); beginResetModel();
endResetModel(); 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 } // namespace QmlDesigner

View File

@@ -13,12 +13,9 @@ class ContentLibraryTexturesModel : public QAbstractListModel
{ {
Q_OBJECT 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 isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged) Q_PROPERTY(bool hasSceneEnv READ hasSceneEnv NOTIFY hasSceneEnvChanged)
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)
public: public:
ContentLibraryTexturesModel(QObject *parent = nullptr); ContentLibraryTexturesModel(QObject *parent = nullptr);
@@ -30,18 +27,7 @@ public:
void setSearchText(const QString &searchText); void setSearchText(const QString &searchText);
void setQuick3DImportVersion(int major, int minor); bool texBundleExists() const;
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 hasSceneEnv() const; bool hasSceneEnv() const;
void setHasSceneEnv(bool b); void setHasSceneEnv(bool b);
@@ -49,32 +35,21 @@ public:
void resetModel(); void resetModel();
void loadTextureBundle(const QString &bundlePath); void loadTextureBundle(const QString &bundlePath);
Q_INVOKABLE void addToProject(const QString &mat);
signals: signals:
void isEmptyChanged(); void isEmptyChanged();
void hasQuick3DImportChanged();
void hasModelSelectionChanged();
void hasMaterialRootChanged();
void materialVisibleChanged(); void materialVisibleChanged();
void matBundleExistsChanged();
void hasSceneEnvChanged(); void hasSceneEnvChanged();
private: private:
bool isValidIndex(int idx) const; bool isValidIndex(int idx) const;
void updateIsEmpty();
QString m_searchText; QString m_searchText;
QList<ContentLibraryTexturesCategory *> m_bundleCategories; QList<ContentLibraryTexturesCategory *> m_bundleCategories;
bool m_isEmpty = true; bool m_isEmpty = true;
bool m_hasMaterialRoot = false;
bool m_hasQuick3DImport = false;
bool m_texBundleLoaded = false;
bool m_hasModelSelection = false;
bool m_hasSceneEnv = false; bool m_hasSceneEnv = false;
bool m_hasModelSelection = false;
int m_quick3dMajorVersion = -1;
int m_quick3dMinorVersion = -1;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -11,6 +11,7 @@
#include "contentlibrarytexturesmodel.h" #include "contentlibrarytexturesmodel.h"
#include "modelnodeoperations.h" #include "modelnodeoperations.h"
#include "nodelistproperty.h" #include "nodelistproperty.h"
#include "qmldesignerconstants.h"
#include "qmlobjectnode.h" #include "qmlobjectnode.h"
#include "variantproperty.h" #include "variantproperty.h"
@@ -161,15 +162,18 @@ void ContentLibraryView::modelAttached(Model *model)
m_hasQuick3DImport = model->hasImport("QtQuick3D"); m_hasQuick3DImport = model->hasImport("QtQuick3D");
m_widget->materialsModel()->setHasMaterialRoot(rootModelNode().metaInfo().isQtQuick3DMaterial());
m_widget->materialsModel()->setHasQuick3DImport(m_hasQuick3DImport);
updateBundleMaterialsQuick3DVersion(); updateBundleMaterialsQuick3DVersion();
updateBundleMaterialsImportedState(); updateBundleMaterialsImportedState();
const bool hasLibrary = materialLibraryNode().isValid();
m_widget->setHasMaterialLibrary(hasLibrary);
m_widget->setHasQuick3DImport(m_hasQuick3DImport);
} }
void ContentLibraryView::modelAboutToBeDetached(Model *model) void ContentLibraryView::modelAboutToBeDetached(Model *model)
{ {
m_widget->setHasMaterialLibrary(false);
m_widget->setHasQuick3DImport(false);
AbstractView::modelAboutToBeDetached(model); AbstractView::modelAboutToBeDetached(model);
} }
@@ -187,7 +191,7 @@ void ContentLibraryView::importsChanged(const QList<Import> &addedImports, const
return; return;
m_hasQuick3DImport = hasQuick3DImport; m_hasQuick3DImport = hasQuick3DImport;
m_widget->materialsModel()->setHasQuick3DImport(m_hasQuick3DImport); m_widget->setHasQuick3DImport(m_hasQuick3DImport);
} }
void ContentLibraryView::active3DSceneChanged(qint32 sceneId) 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, void ContentLibraryView::applyBundleMaterialToDropTarget(const ModelNode &bundleMat,
const NodeMetaInfo &metaInfo) const NodeMetaInfo &metaInfo)
{ {

View File

@@ -36,6 +36,10 @@ public:
const QList<ModelNode> &lastSelectedNodeList) override; const QList<ModelNode> &lastSelectedNodeList) override;
void customNotification(const AbstractView *view, const QString &identifier, void customNotification(const AbstractView *view, const QString &identifier,
const QList<ModelNode> &nodeList, const QList<QVariant> &data) override; 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: private:
void updateBundleMaterialsImportedState(); void updateBundleMaterialsImportedState();

View File

@@ -157,6 +157,44 @@ void ContentLibraryWidget::clearSearchFilter()
QMetaObject::invokeMethod(m_quickWidget->rootObject(), "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() void ContentLibraryWidget::reloadQmlSource()
{ {
const QString materialBrowserQmlPath = qmlSourcesPath() + "/ContentLibrary.qml"; const QString materialBrowserQmlPath = qmlSourcesPath() + "/ContentLibrary.qml";

View File

@@ -23,6 +23,9 @@ class ContentLibraryWidget : public QFrame
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport NOTIFY hasQuick3DImportChanged)
Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
public: public:
ContentLibraryWidget(); ContentLibraryWidget();
@@ -31,6 +34,12 @@ public:
static QString qmlSourcesPath(); static QString qmlSourcesPath();
void clearSearchFilter(); void clearSearchFilter();
bool hasQuick3DImport() const;
void setHasQuick3DImport(bool b);
bool hasMaterialLibrary() const;
void setHasMaterialLibrary(bool b);
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText); Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
void setMaterialsModel(QPointer<ContentLibraryMaterialsModel> newMaterialsModel); void setMaterialsModel(QPointer<ContentLibraryMaterialsModel> newMaterialsModel);
@@ -53,6 +62,8 @@ signals:
void bundleTextureDragStarted(QmlDesigner::ContentLibraryTexture *bundleTex); void bundleTextureDragStarted(QmlDesigner::ContentLibraryTexture *bundleTex);
void addTextureRequested(const QString texPath, QmlDesigner::ContentLibraryWidget::AddTextureMode mode); void addTextureRequested(const QString texPath, QmlDesigner::ContentLibraryWidget::AddTextureMode mode);
void updateSceneEnvStateRequested(); void updateSceneEnvStateRequested();
void hasQuick3DImportChanged();
void hasMaterialLibraryChanged();
protected: protected:
bool eventFilter(QObject *obj, QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override;
@@ -74,6 +85,9 @@ private:
ContentLibraryMaterial *m_materialToDrag = nullptr; ContentLibraryMaterial *m_materialToDrag = nullptr;
ContentLibraryTexture *m_textureToDrag = nullptr; ContentLibraryTexture *m_textureToDrag = nullptr;
QPoint m_dragStartPoint; QPoint m_dragStartPoint;
bool m_hasMaterialLibrary = false;
bool m_hasQuick3DImport = false;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner