QmlDesigner: Add all Quick3DAssets under 1 import section

Fixes: QDS-3866
Change-Id: I3aad4aee0d6c388446b459e558d87f68b204de59
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2021-03-11 22:49:39 +02:00
parent ac24d4357c
commit 5fbef6c060
3 changed files with 38 additions and 8 deletions

View File

@@ -41,6 +41,9 @@ QString ItemLibraryImport::importName() const
if (m_sectionType == SectionType::User)
return userComponentsTitle();
if (m_sectionType == SectionType::Quick3DAssets)
return quick3DAssetsTitle();
if (m_sectionType == SectionType::Unimported)
return unimportedComponentsTitle();
@@ -55,6 +58,9 @@ QString ItemLibraryImport::importUrl() const
if (m_sectionType == SectionType::User)
return userComponentsTitle();
if (m_sectionType == SectionType::Quick3DAssets)
return quick3DAssetsTitle();
if (m_sectionType == SectionType::Unimported)
return unimportedComponentsTitle();
@@ -71,10 +77,13 @@ QString ItemLibraryImport::sortingName() const
if (m_sectionType == SectionType::User)
return "_"; // user components always come first
if (m_sectionType == SectionType::Unimported)
return "zzzzzz"; // Unimported components always come last
if (m_sectionType == SectionType::Quick3DAssets)
return "__"; // Quick3DAssets come second
if (!hasCategories()) // imports with no categories are at the bottom of the list
if (m_sectionType == SectionType::Unimported)
return "zzzzzz"; // Unimported components come last
if (!hasCategories()) // imports with no categories come before last
return "zzzzz_" + importName();
return importName();
@@ -188,6 +197,13 @@ QString ItemLibraryImport::userComponentsTitle()
return tr("My Components");
}
// static
QString ItemLibraryImport::quick3DAssetsTitle()
{
return tr("My 3D Components");
}
// static
QString ItemLibraryImport::unimportedComponentsTitle()
{
return tr("All Other Components");

View File

@@ -48,6 +48,7 @@ public:
enum class SectionType {
Default,
User,
Quick3DAssets,
Unimported
};
@@ -75,6 +76,7 @@ public:
void expandCategories(bool expand = true);
static QString userComponentsTitle();
static QString quick3DAssetsTitle();
static QString unimportedComponentsTitle();
SectionType sectionType() const;

View File

@@ -216,24 +216,32 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
for (const Import &import : model->imports()) {
if (import.isLibraryImport() && import.url() != projectName) {
bool addNew = true;
ItemLibraryImport *oldImport = importHash.value(import.url());
if (oldImport && oldImport->importEntry().url() == import.url()) {
bool isQuick3DAsset = import.url().startsWith("Quick3DAssets.");
QString importUrl = isQuick3DAsset ? ItemLibraryImport::quick3DAssetsTitle() : import.url();
ItemLibraryImport *oldImport = importHash.value(importUrl);
if (oldImport && oldImport->sectionType() == ItemLibraryImport::SectionType::Quick3DAssets
&& isQuick3DAsset) {
addNew = false; // add only 1 Quick3DAssets import section
} else if (oldImport && oldImport->importEntry().url() == import.url()) {
// Retain the higher version if multiples exist
if (compareVersions(oldImport->importEntry().version(), import.version()))
addNew = false;
else
delete oldImport;
}
if (addNew) {
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this);
importHash.insert(import.url(), itemLibImport);
auto sectionType = isQuick3DAsset ? ItemLibraryImport::SectionType::Quick3DAssets
: ItemLibraryImport::SectionType::Default;
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this, sectionType);
importHash.insert(importUrl, itemLibImport);
}
}
}
for (const auto itemLibImport : qAsConst(importHash)) {
m_importList.append(itemLibImport);
itemLibImport->setImportExpanded(loadExpandedState(itemLibImport->importEntry().url()));
itemLibImport->setImportExpanded(loadExpandedState(itemLibImport->importUrl()));
}
const QList<ItemLibraryEntry> itemLibEntries = itemLibraryInfo->entries();
@@ -280,6 +288,8 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
m_importList.append(importSection);
importSection->setImportExpanded(loadExpandedState(catName));
}
} else if (catName == "My Quick3D Components") {
importSection = importByUrl(ItemLibraryImport::quick3DAssetsTitle());
} else {
if (catName.startsWith("Qt Quick - "))
catName = catName.mid(11); // remove "Qt Quick - "
@@ -354,6 +364,8 @@ ItemLibraryImport *ItemLibraryModel::importByUrl(const QString &importUrl) const
|| (importUrl.isEmpty() && itemLibraryImport->importUrl() == "QtQuick")
|| (importUrl == ItemLibraryImport::userComponentsTitle()
&& itemLibraryImport->sectionType() == ItemLibraryImport::SectionType::User)
|| (importUrl == ItemLibraryImport::quick3DAssetsTitle()
&& itemLibraryImport->sectionType() == ItemLibraryImport::SectionType::Quick3DAssets)
|| (importUrl == ItemLibraryImport::unimportedComponentsTitle()
&& itemLibraryImport->sectionType() == ItemLibraryImport::SectionType::Unimported)) {
return itemLibraryImport;