diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2021-03-11 22:49:39 +0200 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2021-03-12 17:00:22 +0000 |
commit | 5fbef6c060bd437f2e749f240031576aafdbd942 (patch) | |
tree | c880fe87cde5b23aa68487848015fddbd1c30e1b | |
parent | ac24d4357c077b4ff1bcefc0d9b1c196d5afe4c3 (diff) |
QmlDesigner: Add all Quick3DAssets under 1 import section
Fixes: QDS-3866
Change-Id: I3aad4aee0d6c388446b459e558d87f68b204de59
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
3 files changed, 37 insertions, 7 deletions
diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.cpp index d0a87013dd..a2b1073594 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.cpp @@ -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::Quick3DAssets) + return "__"; // Quick3DAssets come second + if (m_sectionType == SectionType::Unimported) - return "zzzzzz"; // Unimported components always come last + return "zzzzzz"; // Unimported components come last - if (!hasCategories()) // imports with no categories are at the bottom of the list + 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"); diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.h index ed60c1cffe..982e47df70 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimport.h @@ -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; diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp index e727675038..6648393901 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp @@ -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; |