forked from qt-creator/qt-creator
QmlDesigner: Show placeholder text when content lib user is empty
Fixes: QDS-12910 Change-Id: I3f490bfa14c1479ea7541bb0298670da5db37edc Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -158,6 +158,8 @@ HelperWidgets.ScrollView {
|
|||||||
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.")
|
||||||
else if (!ContentLibraryBackend.rootView.hasMaterialLibrary)
|
else if (!ContentLibraryBackend.rootView.hasMaterialLibrary)
|
||||||
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
|
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
|
||||||
|
else if (ContentLibraryBackend.userModel.isEmpty)
|
||||||
|
qsTr("There are no user assets in the <b>Content Library</b>.")
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,6 @@ ContentLibraryUserModel::ContentLibraryUserModel(ContentLibraryWidget *parent)
|
|||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_widget(parent)
|
, m_widget(parent)
|
||||||
{
|
{
|
||||||
m_userCategories = {tr("Materials"), tr("Textures"), tr("3D"), /*tr("Effects"), tr("2D components")*/}; // TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ContentLibraryUserModel::rowCount(const QModelIndex &) const
|
int ContentLibraryUserModel::rowCount(const QModelIndex &) const
|
||||||
@@ -113,6 +112,8 @@ void ContentLibraryUserModel::addMaterial(const QString &name, const QString &qm
|
|||||||
m_userMaterials.append(libMat);
|
m_userMaterials.append(libMat);
|
||||||
|
|
||||||
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
|
|
||||||
|
updateIsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::add3DItem(const QString &name, const QString &qml,
|
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)
|
void ContentLibraryUserModel::refreshSection(SectionIndex sectionIndex)
|
||||||
{
|
{
|
||||||
emit dataChanged(index(sectionIndex), index(sectionIndex));
|
emit dataChanged(index(sectionIndex), index(sectionIndex));
|
||||||
|
updateIsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::addTextures(const QStringList &paths)
|
void ContentLibraryUserModel::addTextures(const QStringList &paths)
|
||||||
@@ -177,6 +179,7 @@ void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex)
|
|||||||
|
|
||||||
// update model
|
// update model
|
||||||
emit dataChanged(index(TexturesSectionIdx), index(TexturesSectionIdx));
|
emit dataChanged(index(TexturesSectionIdx), index(TexturesSectionIdx));
|
||||||
|
updateIsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::removeFromContentLib(QObject *item)
|
void ContentLibraryUserModel::removeFromContentLib(QObject *item)
|
||||||
@@ -228,6 +231,7 @@ void ContentLibraryUserModel::removeMaterialFromContentLib(ContentLibraryItem *i
|
|||||||
|
|
||||||
// update model
|
// update model
|
||||||
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
|
updateIsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::remove3DFromContentLibByName(const QString &qmlFileName)
|
void ContentLibraryUserModel::remove3DFromContentLibByName(const QString &qmlFileName)
|
||||||
@@ -291,6 +295,7 @@ void ContentLibraryUserModel::remove3DFromContentLib(ContentLibraryItem *item)
|
|||||||
|
|
||||||
// update model
|
// update model
|
||||||
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
|
updateIsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -378,13 +383,13 @@ 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_matBundleLoaded && m_bundleIdMaterial == compUtils.userMaterialsBundleId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
qDeleteAll(m_userMaterials);
|
qDeleteAll(m_userMaterials);
|
||||||
m_userMaterials.clear();
|
m_userMaterials.clear();
|
||||||
m_matBundleExists = false;
|
m_matBundleLoaded = false;
|
||||||
m_noMatchMaterials = true;
|
m_noMatchMaterials = true;
|
||||||
m_bundleObjMaterial = {};
|
m_bundleObjMaterial = {};
|
||||||
m_bundleIdMaterial.clear();
|
m_bundleIdMaterial.clear();
|
||||||
@@ -445,8 +450,9 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
for (const QJsonValueConstRef &file : sharedFilesArr)
|
for (const QJsonValueConstRef &file : sharedFilesArr)
|
||||||
m_bundleMaterialSharedFiles.append(file.toString());
|
m_bundleMaterialSharedFiles.append(file.toString());
|
||||||
|
|
||||||
m_matBundleExists = true;
|
m_matBundleLoaded = true;
|
||||||
updateNoMatchMaterials();
|
updateNoMatchMaterials();
|
||||||
|
updateIsEmpty();
|
||||||
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
emit dataChanged(index(MaterialsSectionIdx), index(MaterialsSectionIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,13 +460,13 @@ void ContentLibraryUserModel::load3DBundle()
|
|||||||
{
|
{
|
||||||
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
||||||
|
|
||||||
if (m_bundle3DExists && m_bundleId3D == compUtils.user3DBundleId())
|
if (m_bundle3DLoaded && m_bundleId3D == compUtils.user3DBundleId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
qDeleteAll(m_user3DItems);
|
qDeleteAll(m_user3DItems);
|
||||||
m_user3DItems.clear();
|
m_user3DItems.clear();
|
||||||
m_bundle3DExists = false;
|
m_bundle3DLoaded = false;
|
||||||
m_noMatch3D = true;
|
m_noMatch3D = true;
|
||||||
m_bundleObj3D = {};
|
m_bundleObj3D = {};
|
||||||
m_bundleId3D.clear();
|
m_bundleId3D.clear();
|
||||||
@@ -521,8 +527,9 @@ void ContentLibraryUserModel::load3DBundle()
|
|||||||
for (const QJsonValueConstRef &file : sharedFilesArr)
|
for (const QJsonValueConstRef &file : sharedFilesArr)
|
||||||
m_bundle3DSharedFiles.append(file.toString());
|
m_bundle3DSharedFiles.append(file.toString());
|
||||||
|
|
||||||
m_bundle3DExists = true;
|
m_bundle3DLoaded = true;
|
||||||
updateNoMatch3D();
|
updateNoMatch3D();
|
||||||
|
updateIsEmpty();
|
||||||
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
emit dataChanged(index(Items3DSectionIdx), index(Items3DSectionIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,9 +564,15 @@ bool ContentLibraryUserModel::hasRequiredQuick3DImport() const
|
|||||||
return m_widget->hasQuick3DImport() && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
|
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)
|
void ContentLibraryUserModel::setSearchText(const QString &searchText)
|
||||||
|
@@ -21,9 +21,8 @@ class ContentLibraryUserModel : public QAbstractListModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
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 hasRequiredQuick3DImport READ hasRequiredQuick3DImport NOTIFY hasRequiredQuick3DImportChanged)
|
||||||
|
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
|
||||||
Q_PROPERTY(QList<ContentLibraryItem *> userMaterials MEMBER m_userMaterials NOTIFY userMaterialsChanged)
|
Q_PROPERTY(QList<ContentLibraryItem *> 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)
|
||||||
Q_PROPERTY(QList<ContentLibraryItem *> user3DItems MEMBER m_user3DItems NOTIFY user3DItemsChanged)
|
Q_PROPERTY(QList<ContentLibraryItem *> user3DItems MEMBER m_user3DItems NOTIFY user3DItemsChanged)
|
||||||
@@ -54,7 +53,7 @@ public:
|
|||||||
|
|
||||||
bool hasRequiredQuick3DImport() const;
|
bool hasRequiredQuick3DImport() const;
|
||||||
|
|
||||||
bool matBundleExists() const;
|
void updateIsEmpty();
|
||||||
|
|
||||||
void resetModel();
|
void resetModel();
|
||||||
void updateNoMatchMaterials();
|
void updateNoMatchMaterials();
|
||||||
@@ -85,13 +84,12 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void hasRequiredQuick3DImportChanged();
|
void hasRequiredQuick3DImportChanged();
|
||||||
|
void isEmptyChanged();
|
||||||
void userMaterialsChanged();
|
void userMaterialsChanged();
|
||||||
void userTexturesChanged();
|
void userTexturesChanged();
|
||||||
void user3DItemsChanged();
|
void user3DItemsChanged();
|
||||||
void userEffectsChanged();
|
void userEffectsChanged();
|
||||||
void applyToSelectedTriggered(QmlDesigner::ContentLibraryItem *mat, bool add = false);
|
void applyToSelectedTriggered(QmlDesigner::ContentLibraryItem *mat, bool add = false);
|
||||||
void matBundleExistsChanged();
|
|
||||||
void bundle3DExistsChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadMaterialBundle();
|
void loadMaterialBundle();
|
||||||
@@ -113,7 +111,8 @@ private:
|
|||||||
QList<ContentLibraryTexture *> m_userTextures;
|
QList<ContentLibraryTexture *> m_userTextures;
|
||||||
QList<ContentLibraryItem *> m_userEffects;
|
QList<ContentLibraryItem *> m_userEffects;
|
||||||
QList<ContentLibraryItem *> m_user3DItems;
|
QList<ContentLibraryItem *> 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_bundleObjMaterial;
|
||||||
QJsonObject m_bundleObj3D;
|
QJsonObject m_bundleObj3D;
|
||||||
@@ -122,8 +121,9 @@ private:
|
|||||||
bool m_noMatchTextures = true;
|
bool m_noMatchTextures = true;
|
||||||
bool m_noMatch3D = true;
|
bool m_noMatch3D = true;
|
||||||
bool m_noMatchEffects = true;
|
bool m_noMatchEffects = true;
|
||||||
bool m_matBundleExists = false;
|
bool m_matBundleLoaded = false;
|
||||||
bool m_bundle3DExists = false;
|
bool m_bundle3DLoaded = false;
|
||||||
|
bool m_isEmpty = true;
|
||||||
|
|
||||||
int m_quick3dMajorVersion = -1;
|
int m_quick3dMajorVersion = -1;
|
||||||
int m_quick3dMinorVersion = -1;
|
int m_quick3dMinorVersion = -1;
|
||||||
|
Reference in New Issue
Block a user