forked from qt-creator/qt-creator
QmlDesigner: Handle content library user items empty state
- Make sure search is working - Hide sections with no items - Other tweaks Fixes: QDS-12682 Fixes: QDS-12625 Change-Id: Ia304743323c0459dd314752dba0cf1dc5e4c4889 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -92,8 +92,6 @@ HelperWidgets.ScrollView {
|
|||||||
|
|
||||||
onCountChanged: root.assignMaxCount()
|
onCountChanged: root.assignMaxCount()
|
||||||
|
|
||||||
property int numVisibleItem: 1 // initially, the tab is invisible so this will be 0
|
|
||||||
|
|
||||||
Grid {
|
Grid {
|
||||||
width: section.width - section.leftPadding - section.rightPadding
|
width: section.width - section.leftPadding - section.rightPadding
|
||||||
spacing: StudioTheme.Values.sectionGridSpacing
|
spacing: StudioTheme.Values.sectionGridSpacing
|
||||||
@@ -114,10 +112,6 @@ HelperWidgets.ScrollView {
|
|||||||
|
|
||||||
onShowContextMenu: ctxMenuItem.popupMenu(modelData)
|
onShowContextMenu: ctxMenuItem.popupMenu(modelData)
|
||||||
onAddToProject: ContentLibraryBackend.userModel.addToProject(modelData)
|
onAddToProject: ContentLibraryBackend.userModel.addToProject(modelData)
|
||||||
|
|
||||||
onVisibleChanged: {
|
|
||||||
section.numVisibleItem += visible ? 1 : -1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
@@ -149,7 +143,7 @@ HelperWidgets.ScrollView {
|
|||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
font.pixelSize: StudioTheme.Values.baseFontSize
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
||||||
leftPadding: 10
|
leftPadding: 10
|
||||||
visible: !searchBox.isEmpty() && section.numVisibleItem === 0
|
visible: infoText.text === "" && !searchBox.isEmpty() && categoryNoMatch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,9 +151,7 @@ HelperWidgets.ScrollView {
|
|||||||
Text {
|
Text {
|
||||||
id: infoText
|
id: infoText
|
||||||
text: {
|
text: {
|
||||||
if (!ContentLibraryBackend.effectsModel.bundleExists)
|
if (!ContentLibraryBackend.rootView.isQt6Project)
|
||||||
qsTr("User bundle couldn't be found.")
|
|
||||||
else if (!ContentLibraryBackend.rootView.isQt6Project)
|
|
||||||
qsTr("<b>Content Library</b> is not supported in Qt5 projects.")
|
qsTr("<b>Content Library</b> is not supported in Qt5 projects.")
|
||||||
else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
|
else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
|
||||||
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
|
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
|
||||||
@@ -172,7 +164,7 @@ HelperWidgets.ScrollView {
|
|||||||
font.pixelSize: StudioTheme.Values.baseFontSize
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
||||||
topPadding: 10
|
topPadding: 10
|
||||||
leftPadding: 10
|
leftPadding: 10
|
||||||
visible: ContentLibraryBackend.effectsModel.isEmpty
|
visible: infoText.text !== ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -120,6 +120,11 @@ void ContentLibraryTexture::doSetDownloaded()
|
|||||||
m_toolTip = resolveToolTipText();
|
m_toolTip = resolveToolTipText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ContentLibraryTexture::visible() const
|
||||||
|
{
|
||||||
|
return m_visible;
|
||||||
|
}
|
||||||
|
|
||||||
QString ContentLibraryTexture::parentDirPath() const
|
QString ContentLibraryTexture::parentDirPath() const
|
||||||
{
|
{
|
||||||
return m_dirPath;
|
return m_dirPath;
|
||||||
|
@@ -46,6 +46,8 @@ public:
|
|||||||
void setHasUpdate(bool value);
|
void setHasUpdate(bool value);
|
||||||
bool hasUpdate() const;
|
bool hasUpdate() const;
|
||||||
|
|
||||||
|
bool visible() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void textureVisibleChanged();
|
void textureVisibleChanged();
|
||||||
void textureToolTipChanged();
|
void textureToolTipChanged();
|
||||||
|
@@ -46,18 +46,37 @@ QVariant ContentLibraryUserModel::data(const QModelIndex &index, int role) const
|
|||||||
return m_userCategories.at(index.row());
|
return m_userCategories.at(index.row());
|
||||||
|
|
||||||
if (role == ItemsRole) {
|
if (role == ItemsRole) {
|
||||||
if (index.row() == 0)
|
if (index.row() == MaterialsSectionIdx)
|
||||||
return QVariant::fromValue(m_userMaterials);
|
return QVariant::fromValue(m_userMaterials);
|
||||||
if (index.row() == 1)
|
if (index.row() == TexturesSectionIdx)
|
||||||
return QVariant::fromValue(m_userTextures);
|
return QVariant::fromValue(m_userTextures);
|
||||||
if (index.row() == 2)
|
if (index.row() == Items3DSectionIdx)
|
||||||
return QVariant::fromValue(m_user3DItems);
|
return QVariant::fromValue(m_user3DItems);
|
||||||
if (index.row() == 3)
|
if (index.row() == EffectsSectionIdx)
|
||||||
return QVariant::fromValue(m_userEffects);
|
return QVariant::fromValue(m_userEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == VisibleRole)
|
if (role == NoMatchRole) {
|
||||||
return true; // TODO
|
if (index.row() == MaterialsSectionIdx)
|
||||||
|
return m_noMatchMaterials;
|
||||||
|
if (index.row() == TexturesSectionIdx)
|
||||||
|
return m_noMatchTextures;
|
||||||
|
if (index.row() == Items3DSectionIdx)
|
||||||
|
return m_noMatch3D;
|
||||||
|
if (index.row() == EffectsSectionIdx)
|
||||||
|
return m_noMatchEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == VisibleRole) {
|
||||||
|
if (index.row() == MaterialsSectionIdx)
|
||||||
|
return !m_userMaterials.isEmpty();
|
||||||
|
if (index.row() == TexturesSectionIdx)
|
||||||
|
return !m_userTextures.isEmpty();
|
||||||
|
if (index.row() == Items3DSectionIdx)
|
||||||
|
return !m_user3DItems.isEmpty();
|
||||||
|
if (index.row() == EffectsSectionIdx)
|
||||||
|
return !m_userEffects.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -67,32 +86,25 @@ bool ContentLibraryUserModel::isValidIndex(int idx) const
|
|||||||
return idx > -1 && idx < rowCount();
|
return idx > -1 && idx < rowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::updateIsEmptyMaterials()
|
void ContentLibraryUserModel::updateNoMatchMaterials()
|
||||||
{
|
{
|
||||||
bool anyMatVisible = Utils::anyOf(m_userMaterials, [&](ContentLibraryMaterial *mat) {
|
m_noMatchMaterials = Utils::allOf(m_userMaterials, [&](ContentLibraryMaterial *item) {
|
||||||
return mat->visible();
|
return !item->visible();
|
||||||
});
|
});
|
||||||
|
|
||||||
bool newEmpty = !anyMatVisible || !m_widget->hasMaterialLibrary() || !hasRequiredQuick3DImport();
|
|
||||||
|
|
||||||
if (newEmpty != m_isEmptyMaterials) {
|
|
||||||
m_isEmptyMaterials = newEmpty;
|
|
||||||
emit isEmptyMaterialsChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::updateIsEmpty3D()
|
void ContentLibraryUserModel::updateNoMatchTextures()
|
||||||
{
|
{
|
||||||
bool anyItemVisible = Utils::anyOf(m_user3DItems, [&](ContentLibraryItem *item) {
|
m_noMatchTextures = Utils::allOf(m_userTextures, [&](ContentLibraryTexture *item) {
|
||||||
return item->visible();
|
return !item->visible();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool newEmpty = !anyItemVisible || !m_widget->hasMaterialLibrary() || !hasRequiredQuick3DImport();
|
void ContentLibraryUserModel::updateNoMatch3D()
|
||||||
|
{
|
||||||
if (newEmpty != m_isEmpty3D) {
|
m_noMatch3D = Utils::allOf(m_user3DItems, [&](ContentLibraryItem *item) {
|
||||||
m_isEmpty3D = newEmpty;
|
return !item->visible();
|
||||||
emit isEmpty3DChanged();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::addMaterial(const QString &name, const QString &qml,
|
void ContentLibraryUserModel::addMaterial(const QString &name, const QString &qml,
|
||||||
@@ -107,8 +119,7 @@ void ContentLibraryUserModel::addMaterial(const QString &name, const QString &qm
|
|||||||
Paths::bundlesPathSetting().append("/User/materials"));
|
Paths::bundlesPathSetting().append("/User/materials"));
|
||||||
m_userMaterials.append(libMat);
|
m_userMaterials.append(libMat);
|
||||||
|
|
||||||
int matSectionIdx = 0;
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
emit dataChanged(index(matSectionIdx), index(matSectionIdx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::add3DItem(const QString &name, const QString &qml,
|
void ContentLibraryUserModel::add3DItem(const QString &name, const QString &qml,
|
||||||
@@ -124,8 +135,7 @@ void ContentLibraryUserModel::add3DItem(const QString &name, const QString &qml,
|
|||||||
|
|
||||||
void ContentLibraryUserModel::refresh3DSection()
|
void ContentLibraryUserModel::refresh3DSection()
|
||||||
{
|
{
|
||||||
int sectionIdx = 2;
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::addTextures(const QStringList &paths)
|
void ContentLibraryUserModel::addTextures(const QStringList &paths)
|
||||||
@@ -147,20 +157,19 @@ void ContentLibraryUserModel::addTextures(const QStringList &paths)
|
|||||||
m_userTextures.append(tex);
|
m_userTextures.append(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int texSectionIdx = 1;
|
emit dataChanged(index(TexturesSectionIdx), index(TexturesSectionIdx));
|
||||||
emit dataChanged(index(texSectionIdx), index(texSectionIdx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::add3DInstance(ContentLibraryItem *bundleItem)
|
void ContentLibraryUserModel::add3DInstance(ContentLibraryItem *bundleItem)
|
||||||
{
|
{
|
||||||
QString err = m_widget->importer()->importComponent(m_bundlePath3D.path(), bundleItem->type(),
|
QString err = m_widget->importer()->importComponent(m_bundlePath3D.path(), bundleItem->type(),
|
||||||
bundleItem->qml(),
|
bundleItem->qml(),
|
||||||
bundleItem->files() + m_bundle3DSharedFiles);
|
bundleItem->files() + m_bundle3DSharedFiles);
|
||||||
|
|
||||||
if (err.isEmpty())
|
if (err.isEmpty())
|
||||||
m_widget->setImporterRunning(true);
|
m_widget->setImporterRunning(true);
|
||||||
else
|
else
|
||||||
qWarning() << __FUNCTION__ << err;
|
qWarning() << __FUNCTION__ << err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex)
|
void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex)
|
||||||
@@ -174,8 +183,7 @@ void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex)
|
|||||||
tex->deleteLater();
|
tex->deleteLater();
|
||||||
|
|
||||||
// update model
|
// update model
|
||||||
int texSectionIdx = 1;
|
emit dataChanged(index(TexturesSectionIdx), index(TexturesSectionIdx));
|
||||||
emit dataChanged(index(texSectionIdx), index(texSectionIdx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::removeFromContentLib(QObject *item)
|
void ContentLibraryUserModel::removeFromContentLib(QObject *item)
|
||||||
@@ -226,8 +234,7 @@ void ContentLibraryUserModel::removeMaterialFromContentLib(ContentLibraryMateria
|
|||||||
item->deleteLater();
|
item->deleteLater();
|
||||||
|
|
||||||
// update model
|
// update model
|
||||||
int sectionIdx = 0;
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::remove3DFromContentLib(ContentLibraryItem *item)
|
void ContentLibraryUserModel::remove3DFromContentLib(ContentLibraryItem *item)
|
||||||
@@ -268,8 +275,7 @@ void ContentLibraryUserModel::remove3DFromContentLib(ContentLibraryItem *item)
|
|||||||
item->deleteLater();
|
item->deleteLater();
|
||||||
|
|
||||||
// update model
|
// update model
|
||||||
int sectionIdx = 2;
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,7 +333,8 @@ QHash<int, QByteArray> ContentLibraryUserModel::roleNames() const
|
|||||||
static const QHash<int, QByteArray> roles {
|
static const QHash<int, QByteArray> roles {
|
||||||
{NameRole, "categoryName"},
|
{NameRole, "categoryName"},
|
||||||
{VisibleRole, "categoryVisible"},
|
{VisibleRole, "categoryVisible"},
|
||||||
{ItemsRole, "categoryItems"}
|
{ItemsRole, "categoryItems"},
|
||||||
|
{NoMatchRole, "categoryNoMatch"}
|
||||||
};
|
};
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
@@ -352,7 +359,6 @@ void ContentLibraryUserModel::loadBundles()
|
|||||||
void ContentLibraryUserModel::loadMaterialBundle()
|
void ContentLibraryUserModel::loadMaterialBundle()
|
||||||
{
|
{
|
||||||
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
||||||
|
|
||||||
if (m_matBundleExists && m_bundleIdMaterial == compUtils.userMaterialsBundleId())
|
if (m_matBundleExists && m_bundleIdMaterial == compUtils.userMaterialsBundleId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -360,12 +366,10 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
qDeleteAll(m_userMaterials);
|
qDeleteAll(m_userMaterials);
|
||||||
m_userMaterials.clear();
|
m_userMaterials.clear();
|
||||||
m_matBundleExists = false;
|
m_matBundleExists = false;
|
||||||
m_isEmptyMaterials = true;
|
m_noMatchMaterials = true;
|
||||||
m_bundleObjMaterial = {};
|
m_bundleObjMaterial = {};
|
||||||
m_bundleIdMaterial.clear();
|
m_bundleIdMaterial.clear();
|
||||||
|
|
||||||
int sectionIdx = 0;
|
|
||||||
|
|
||||||
m_bundlePathMaterial = Utils::FilePath::fromString(Paths::bundlesPathSetting() + "/User/materials");
|
m_bundlePathMaterial = Utils::FilePath::fromString(Paths::bundlesPathSetting() + "/User/materials");
|
||||||
m_bundlePathMaterial.ensureWritableDir();
|
m_bundlePathMaterial.ensureWritableDir();
|
||||||
m_bundlePathMaterial.pathAppended("icons").ensureWritableDir();
|
m_bundlePathMaterial.pathAppended("icons").ensureWritableDir();
|
||||||
@@ -379,7 +383,7 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
Utils::expected_str<qint64> res = jsonFilePath.writeFileContents(jsonContent.toLatin1());
|
Utils::expected_str<qint64> res = jsonFilePath.writeFileContents(jsonContent.toLatin1());
|
||||||
if (!res.has_value()) {
|
if (!res.has_value()) {
|
||||||
qWarning() << __FUNCTION__ << res.error();
|
qWarning() << __FUNCTION__ << res.error();
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,14 +391,14 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
Utils::expected_str<QByteArray> jsonContents = jsonFilePath.fileContents();
|
Utils::expected_str<QByteArray> jsonContents = jsonFilePath.fileContents();
|
||||||
if (!jsonContents.has_value()) {
|
if (!jsonContents.has_value()) {
|
||||||
qWarning() << __FUNCTION__ << jsonContents.error();
|
qWarning() << __FUNCTION__ << jsonContents.error();
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(jsonContents.value());
|
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(jsonContents.value());
|
||||||
if (bundleJsonDoc.isNull()) {
|
if (bundleJsonDoc.isNull()) {
|
||||||
qWarning() << __FUNCTION__ << "Invalid user_materials_bundle.json file";
|
qWarning() << __FUNCTION__ << "Invalid user_materials_bundle.json file";
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +408,7 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
|
|
||||||
// parse items
|
// parse items
|
||||||
QString typePrefix = compUtils.userMaterialsBundleType();
|
QString typePrefix = compUtils.userMaterialsBundleType();
|
||||||
const QJsonArray itemsArr = m_bundleObj3D.value("items").toArray();
|
const QJsonArray itemsArr = m_bundleObjMaterial.value("items").toArray();
|
||||||
for (const QJsonValueConstRef &itemRef : itemsArr) {
|
for (const QJsonValueConstRef &itemRef : itemsArr) {
|
||||||
const QJsonObject itemObj = itemRef.toObject();
|
const QJsonObject itemObj = itemRef.toObject();
|
||||||
|
|
||||||
@@ -427,8 +431,8 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
m_bundleMaterialSharedFiles.append(file.toString());
|
m_bundleMaterialSharedFiles.append(file.toString());
|
||||||
|
|
||||||
m_matBundleExists = true;
|
m_matBundleExists = true;
|
||||||
updateIsEmptyMaterials();
|
updateNoMatchMaterials();
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::load3DBundle()
|
void ContentLibraryUserModel::load3DBundle()
|
||||||
@@ -442,12 +446,10 @@ void ContentLibraryUserModel::load3DBundle()
|
|||||||
qDeleteAll(m_user3DItems);
|
qDeleteAll(m_user3DItems);
|
||||||
m_user3DItems.clear();
|
m_user3DItems.clear();
|
||||||
m_bundle3DExists = false;
|
m_bundle3DExists = false;
|
||||||
m_isEmpty3D = true;
|
m_noMatch3D = true;
|
||||||
m_bundleObj3D = {};
|
m_bundleObj3D = {};
|
||||||
m_bundleId3D.clear();
|
m_bundleId3D.clear();
|
||||||
|
|
||||||
int sectionIdx = 2;
|
|
||||||
|
|
||||||
m_bundlePath3D = Utils::FilePath::fromString(Paths::bundlesPathSetting() + "/User/3d");
|
m_bundlePath3D = Utils::FilePath::fromString(Paths::bundlesPathSetting() + "/User/3d");
|
||||||
m_bundlePath3D.ensureWritableDir();
|
m_bundlePath3D.ensureWritableDir();
|
||||||
m_bundlePath3D.pathAppended("icons").ensureWritableDir();
|
m_bundlePath3D.pathAppended("icons").ensureWritableDir();
|
||||||
@@ -461,7 +463,7 @@ void ContentLibraryUserModel::load3DBundle()
|
|||||||
Utils::expected_str<qint64> res = jsonFilePath.writeFileContents(jsonContent);
|
Utils::expected_str<qint64> res = jsonFilePath.writeFileContents(jsonContent);
|
||||||
if (!res.has_value()) {
|
if (!res.has_value()) {
|
||||||
qWarning() << __FUNCTION__ << res.error();
|
qWarning() << __FUNCTION__ << res.error();
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,14 +471,14 @@ void ContentLibraryUserModel::load3DBundle()
|
|||||||
Utils::expected_str<QByteArray> jsonContents = jsonFilePath.fileContents();
|
Utils::expected_str<QByteArray> jsonContents = jsonFilePath.fileContents();
|
||||||
if (!jsonContents.has_value()) {
|
if (!jsonContents.has_value()) {
|
||||||
qWarning() << __FUNCTION__ << jsonContents.error();
|
qWarning() << __FUNCTION__ << jsonContents.error();
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(jsonContents.value());
|
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(jsonContents.value());
|
||||||
if (bundleJsonDoc.isNull()) {
|
if (bundleJsonDoc.isNull()) {
|
||||||
qWarning() << __FUNCTION__ << "Invalid user_3d_bundle.json file";
|
qWarning() << __FUNCTION__ << "Invalid user_3d_bundle.json file";
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,8 +510,8 @@ void ContentLibraryUserModel::load3DBundle()
|
|||||||
m_bundle3DSharedFiles.append(file.toString());
|
m_bundle3DSharedFiles.append(file.toString());
|
||||||
|
|
||||||
m_bundle3DExists = true;
|
m_bundle3DExists = true;
|
||||||
updateIsEmpty3D();
|
updateNoMatch3D();
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::loadTextureBundle()
|
void ContentLibraryUserModel::loadTextureBundle()
|
||||||
@@ -534,8 +536,8 @@ void ContentLibraryUserModel::loadTextureBundle()
|
|||||||
m_userTextures.append(tex);
|
m_userTextures.append(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int texSectionIdx = 1;
|
updateNoMatchTextures();
|
||||||
emit dataChanged(index(texSectionIdx), index(texSectionIdx));
|
emit dataChanged(index(TexturesSectionIdx), index(TexturesSectionIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentLibraryUserModel::hasRequiredQuick3DImport() const
|
bool ContentLibraryUserModel::hasRequiredQuick3DImport() const
|
||||||
@@ -557,11 +559,19 @@ void ContentLibraryUserModel::setSearchText(const QString &searchText)
|
|||||||
|
|
||||||
m_searchText = lowerSearchText;
|
m_searchText = lowerSearchText;
|
||||||
|
|
||||||
for (ContentLibraryMaterial *mat : std::as_const(m_userMaterials))
|
for (ContentLibraryMaterial *item : std::as_const(m_userMaterials))
|
||||||
mat->filter(m_searchText);
|
item->filter(m_searchText);
|
||||||
|
|
||||||
updateIsEmptyMaterials();
|
for (ContentLibraryTexture *item : std::as_const(m_userTextures))
|
||||||
updateIsEmpty3D();
|
item->filter(m_searchText);
|
||||||
|
|
||||||
|
for (ContentLibraryItem *item : std::as_const(m_user3DItems))
|
||||||
|
item->filter(m_searchText);
|
||||||
|
|
||||||
|
updateNoMatchMaterials();
|
||||||
|
updateNoMatchTextures();
|
||||||
|
updateNoMatch3D();
|
||||||
|
resetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::updateMaterialsImportedState(const QStringList &importedItems)
|
void ContentLibraryUserModel::updateMaterialsImportedState(const QStringList &importedItems)
|
||||||
@@ -570,10 +580,8 @@ void ContentLibraryUserModel::updateMaterialsImportedState(const QStringList &im
|
|||||||
for (ContentLibraryMaterial *mat : std::as_const(m_userMaterials))
|
for (ContentLibraryMaterial *mat : std::as_const(m_userMaterials))
|
||||||
changed |= mat->setImported(importedItems.contains(mat->qml().chopped(4)));
|
changed |= mat->setImported(importedItems.contains(mat->qml().chopped(4)));
|
||||||
|
|
||||||
if (changed) {
|
if (changed)
|
||||||
int matSectionIdx = 0;
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
emit dataChanged(index(matSectionIdx), index(matSectionIdx));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::update3DImportedState(const QStringList &importedItems)
|
void ContentLibraryUserModel::update3DImportedState(const QStringList &importedItems)
|
||||||
@@ -582,10 +590,8 @@ void ContentLibraryUserModel::update3DImportedState(const QStringList &importedI
|
|||||||
for (ContentLibraryItem *item : std::as_const(m_user3DItems))
|
for (ContentLibraryItem *item : std::as_const(m_user3DItems))
|
||||||
changed |= item->setImported(importedItems.contains(item->qml().chopped(4)));
|
changed |= item->setImported(importedItems.contains(item->qml().chopped(4)));
|
||||||
|
|
||||||
if (changed) {
|
if (changed)
|
||||||
int sectionIdx = 2;
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
emit dataChanged(index(sectionIdx), index(sectionIdx));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::setQuick3DImportVersion(int major, int minor)
|
void ContentLibraryUserModel::setQuick3DImportVersion(int major, int minor)
|
||||||
@@ -601,9 +607,6 @@ void ContentLibraryUserModel::setQuick3DImportVersion(int major, int minor)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
emit hasRequiredQuick3DImportChanged();
|
emit hasRequiredQuick3DImportChanged();
|
||||||
|
|
||||||
updateIsEmptyMaterials();
|
|
||||||
updateIsEmpty3D();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::resetModel()
|
void ContentLibraryUserModel::resetModel()
|
||||||
|
@@ -24,8 +24,6 @@ class ContentLibraryUserModel : public QAbstractListModel
|
|||||||
|
|
||||||
Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged)
|
Q_PROPERTY(bool matBundleExists READ matBundleExists NOTIFY matBundleExistsChanged)
|
||||||
Q_PROPERTY(bool bundle3DExists MEMBER m_bundle3DExists NOTIFY bundle3DExistsChanged)
|
Q_PROPERTY(bool bundle3DExists MEMBER m_bundle3DExists NOTIFY bundle3DExistsChanged)
|
||||||
Q_PROPERTY(bool isEmptyMaterials MEMBER m_isEmptyMaterials NOTIFY isEmptyMaterialsChanged)
|
|
||||||
Q_PROPERTY(bool isEmpty3D MEMBER m_isEmpty3D NOTIFY isEmpty3DChanged)
|
|
||||||
Q_PROPERTY(bool hasRequiredQuick3DImport READ hasRequiredQuick3DImport NOTIFY hasRequiredQuick3DImportChanged)
|
Q_PROPERTY(bool hasRequiredQuick3DImport READ hasRequiredQuick3DImport NOTIFY hasRequiredQuick3DImportChanged)
|
||||||
Q_PROPERTY(QList<ContentLibraryMaterial *> userMaterials MEMBER m_userMaterials NOTIFY userMaterialsChanged)
|
Q_PROPERTY(QList<ContentLibraryMaterial *> userMaterials MEMBER m_userMaterials NOTIFY userMaterialsChanged)
|
||||||
Q_PROPERTY(QList<ContentLibraryTexture *> userTextures MEMBER m_userTextures NOTIFY userTexturesChanged)
|
Q_PROPERTY(QList<ContentLibraryTexture *> userTextures MEMBER m_userTextures NOTIFY userTexturesChanged)
|
||||||
@@ -53,8 +51,9 @@ public:
|
|||||||
bool matBundleExists() const;
|
bool matBundleExists() const;
|
||||||
|
|
||||||
void resetModel();
|
void resetModel();
|
||||||
void updateIsEmptyMaterials();
|
void updateNoMatchMaterials();
|
||||||
void updateIsEmpty3D();
|
void updateNoMatchTextures();
|
||||||
|
void updateNoMatch3D();
|
||||||
|
|
||||||
void addMaterial(const QString &name, const QString &qml, const QUrl &icon, const QStringList &files);
|
void addMaterial(const QString &name, const QString &qml, const QUrl &icon, const QStringList &files);
|
||||||
void add3DItem(const QString &name, const QString &qml, const QUrl &icon, const QStringList &files);
|
void add3DItem(const QString &name, const QString &qml, const QUrl &icon, const QStringList &files);
|
||||||
@@ -76,8 +75,6 @@ public:
|
|||||||
Q_INVOKABLE void removeFromContentLib(QObject *item);
|
Q_INVOKABLE void removeFromContentLib(QObject *item);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void isEmptyMaterialsChanged();
|
|
||||||
void isEmpty3DChanged();
|
|
||||||
void hasRequiredQuick3DImportChanged();
|
void hasRequiredQuick3DImportChanged();
|
||||||
void userMaterialsChanged();
|
void userMaterialsChanged();
|
||||||
void userTexturesChanged();
|
void userTexturesChanged();
|
||||||
@@ -88,6 +85,11 @@ signals:
|
|||||||
void bundle3DExistsChanged();
|
void bundle3DExistsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum SectionIndex { MaterialsSectionIdx = 0,
|
||||||
|
TexturesSectionIdx,
|
||||||
|
Items3DSectionIdx,
|
||||||
|
EffectsSectionIdx };
|
||||||
|
|
||||||
void loadMaterialBundle();
|
void loadMaterialBundle();
|
||||||
void load3DBundle();
|
void load3DBundle();
|
||||||
void loadTextureBundle();
|
void loadTextureBundle();
|
||||||
@@ -115,15 +117,17 @@ private:
|
|||||||
QJsonObject m_bundleObjMaterial;
|
QJsonObject m_bundleObjMaterial;
|
||||||
QJsonObject m_bundleObj3D;
|
QJsonObject m_bundleObj3D;
|
||||||
|
|
||||||
bool m_isEmptyMaterials = true;
|
bool m_noMatchMaterials = true;
|
||||||
bool m_isEmpty3D = true;
|
bool m_noMatchTextures = true;
|
||||||
|
bool m_noMatch3D = true;
|
||||||
|
bool m_noMatchEffects = true;
|
||||||
bool m_matBundleExists = false;
|
bool m_matBundleExists = false;
|
||||||
bool m_bundle3DExists = false;
|
bool m_bundle3DExists = false;
|
||||||
|
|
||||||
int m_quick3dMajorVersion = -1;
|
int m_quick3dMajorVersion = -1;
|
||||||
int m_quick3dMinorVersion = -1;
|
int m_quick3dMinorVersion = -1;
|
||||||
|
|
||||||
enum Roles { NameRole = Qt::UserRole + 1, VisibleRole, ItemsRole };
|
enum Roles { NameRole = Qt::UserRole + 1, VisibleRole, ItemsRole, NoMatchRole };
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -699,8 +699,6 @@ void ContentLibraryWidget::setHasQuick3DImport(bool b)
|
|||||||
|
|
||||||
m_materialsModel->updateIsEmpty();
|
m_materialsModel->updateIsEmpty();
|
||||||
m_effectsModel->updateIsEmpty();
|
m_effectsModel->updateIsEmpty();
|
||||||
m_userModel->updateIsEmptyMaterials();
|
|
||||||
m_userModel->updateIsEmpty3D();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentLibraryWidget::hasMaterialLibrary() const
|
bool ContentLibraryWidget::hasMaterialLibrary() const
|
||||||
@@ -717,8 +715,6 @@ void ContentLibraryWidget::setHasMaterialLibrary(bool b)
|
|||||||
emit hasMaterialLibraryChanged();
|
emit hasMaterialLibraryChanged();
|
||||||
|
|
||||||
m_materialsModel->updateIsEmpty();
|
m_materialsModel->updateIsEmpty();
|
||||||
m_userModel->updateIsEmptyMaterials();
|
|
||||||
m_userModel->updateIsEmpty3D();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentLibraryWidget::hasActive3DScene() const
|
bool ContentLibraryWidget::hasActive3DScene() const
|
||||||
|
Reference in New Issue
Block a user