forked from qt-creator/qt-creator
QmlDesigner: Add directory imports item library entries getter
Move the code from itemLibraryEntries getter to directoryImportsItemLibraryEntries. Task-number: QDS-15144 Change-Id: Ibb078c2a0fc711f8843ac3a27b959726ad777baa Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -209,6 +209,7 @@ public:
|
||||
#endif
|
||||
|
||||
QList<ItemLibraryEntry> itemLibraryEntries() const;
|
||||
QList<ItemLibraryEntry> directoryImportsItemLibraryEntries() const;
|
||||
|
||||
void attachView(AbstractView *view);
|
||||
void detachView(AbstractView *view, ViewNotification emitDetachNotify = NotifyView);
|
||||
|
@@ -2819,6 +2819,17 @@ QList<ItemLibraryEntry> Model::itemLibraryEntries() const
|
||||
#endif
|
||||
}
|
||||
|
||||
QList<ItemLibraryEntry> Model::directoryImportsItemLibraryEntries() const
|
||||
{
|
||||
#ifdef QDS_USE_PROJECTSTORAGE
|
||||
using namespace Storage::Info;
|
||||
return toItemLibraryEntries(*d->pathCache,
|
||||
d->projectStorage->directoryImportsItemLibraryEntries(d->m_sourceId));
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
NodeMetaInfo Model::qtQuickTimelineKeyframeGroupMetaInfo() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
|
@@ -870,7 +870,7 @@ struct ProjectStorage::Statements
|
||||
" USING(moduleId) "
|
||||
" WHERE di.sourceId=?)",
|
||||
database};
|
||||
mutable Sqlite::ReadStatement<4, 2> selectLocalFileItemLibraryEntriesBySourceIdStatement{
|
||||
mutable Sqlite::ReadStatement<4, 2> selectDirectoryImportsItemLibraryEntriesBySourceIdStatement{
|
||||
"SELECT typeId, etn.name, m.name, t.sourceId "
|
||||
"FROM documentImports AS di "
|
||||
" JOIN exportedTypeNames AS etn USING(moduleId) "
|
||||
@@ -1877,16 +1877,16 @@ Storage::Info::ItemLibraryEntries ProjectStorage::itemLibraryEntries(SourceId so
|
||||
using Storage::Info::ItemLibraryProperties;
|
||||
Storage::Info::ItemLibraryEntries entries;
|
||||
|
||||
auto typeAnnotationCallback = [&](TypeId typeId,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView name,
|
||||
Utils::SmallStringView iconPath,
|
||||
Utils::SmallStringView category,
|
||||
Utils::SmallStringView import,
|
||||
Utils::SmallStringView toolTip,
|
||||
Utils::SmallStringView properties,
|
||||
Utils::SmallStringView extraFilePaths,
|
||||
Utils::SmallStringView templatePath) {
|
||||
auto callback = [&](TypeId typeId,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView name,
|
||||
Utils::SmallStringView iconPath,
|
||||
Utils::SmallStringView category,
|
||||
Utils::SmallStringView import,
|
||||
Utils::SmallStringView toolTip,
|
||||
Utils::SmallStringView properties,
|
||||
Utils::SmallStringView extraFilePaths,
|
||||
Utils::SmallStringView templatePath) {
|
||||
auto &last = entries.emplace_back(
|
||||
typeId, typeName, name, iconPath, category, import, toolTip, templatePath);
|
||||
if (properties.size())
|
||||
@@ -1895,23 +1895,7 @@ Storage::Info::ItemLibraryEntries ProjectStorage::itemLibraryEntries(SourceId so
|
||||
s->selectItemLibraryExtraFilePathsStatement.readTo(last.extraFilePaths, extraFilePaths);
|
||||
};
|
||||
|
||||
s->selectItemLibraryEntriesBySourceIdStatement.readCallbackWithTransaction(typeAnnotationCallback,
|
||||
sourceId);
|
||||
|
||||
auto fileComponentCallback = [&](TypeId typeId,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView import,
|
||||
SourceId componentSourceId) {
|
||||
if (!isCapitalLetter(typeName.front()))
|
||||
return;
|
||||
|
||||
auto &last = entries.emplace_back(typeId, typeName, typeName, "My Components", import);
|
||||
last.moduleKind = Storage::ModuleKind::PathLibrary;
|
||||
last.componentSourceId = componentSourceId;
|
||||
};
|
||||
|
||||
s->selectLocalFileItemLibraryEntriesBySourceIdStatement.readCallbackWithTransaction(
|
||||
fileComponentCallback, sourceId, Storage::ModuleKind::PathLibrary);
|
||||
s->selectItemLibraryEntriesBySourceIdStatement.readCallbackWithTransaction(callback, sourceId);
|
||||
|
||||
tracer.end(keyValue("item library entries", entries));
|
||||
|
||||
@@ -1951,6 +1935,36 @@ Storage::Info::ItemLibraryEntries ProjectStorage::allItemLibraryEntries() const
|
||||
return entries;
|
||||
}
|
||||
|
||||
Storage::Info::ItemLibraryEntries ProjectStorage::directoryImportsItemLibraryEntries(SourceId sourceId) const
|
||||
{
|
||||
using NanotraceHR::keyValue;
|
||||
NanotraceHR::Tracer tracer{"get directory import item library entries",
|
||||
projectStorageCategory(),
|
||||
keyValue("source id", sourceId)};
|
||||
|
||||
using Storage::Info::ItemLibraryProperties;
|
||||
Storage::Info::ItemLibraryEntries entries;
|
||||
|
||||
auto callback = [&](TypeId typeId,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView import,
|
||||
SourceId componentSourceId) {
|
||||
if (!isCapitalLetter(typeName.front()))
|
||||
return;
|
||||
|
||||
auto &last = entries.emplace_back(typeId, typeName, typeName, "My Components", import);
|
||||
last.moduleKind = Storage::ModuleKind::PathLibrary;
|
||||
last.componentSourceId = componentSourceId;
|
||||
};
|
||||
|
||||
s->selectDirectoryImportsItemLibraryEntriesBySourceIdStatement
|
||||
.readCallbackWithTransaction(callback, sourceId, Storage::ModuleKind::PathLibrary);
|
||||
|
||||
tracer.end(keyValue("item library entries", entries));
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
std::vector<Utils::SmallString> ProjectStorage::signalDeclarationNames(TypeId typeId) const
|
||||
{
|
||||
using NanotraceHR::keyValue;
|
||||
|
@@ -110,12 +110,10 @@ public:
|
||||
SmallSourceContextIds<64> typeAnnotationDirectoryIds() const override;
|
||||
|
||||
Storage::Info::ItemLibraryEntries itemLibraryEntries(TypeId typeId) const override;
|
||||
|
||||
Storage::Info::ItemLibraryEntries itemLibraryEntries(ImportId importId) const;
|
||||
|
||||
Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const override;
|
||||
|
||||
Storage::Info::ItemLibraryEntries allItemLibraryEntries() const override;
|
||||
Storage::Info::ItemLibraryEntries directoryImportsItemLibraryEntries(SourceId sourceId) const override;
|
||||
|
||||
std::vector<Utils::SmallString> signalDeclarationNames(TypeId typeId) const override;
|
||||
|
||||
|
@@ -65,6 +65,7 @@ public:
|
||||
virtual Storage::Info::ItemLibraryEntries itemLibraryEntries(TypeId typeId) const = 0;
|
||||
virtual Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const = 0;
|
||||
virtual Storage::Info::ItemLibraryEntries allItemLibraryEntries() const = 0;
|
||||
virtual Storage::Info::ItemLibraryEntries directoryImportsItemLibraryEntries(SourceId sourceId) const = 0;
|
||||
virtual std::vector<::Utils::SmallString> signalDeclarationNames(TypeId typeId) const = 0;
|
||||
virtual std::vector<::Utils::SmallString> functionDeclarationNames(TypeId typeId) const = 0;
|
||||
virtual std::optional<::Utils::SmallString>
|
||||
|
@@ -243,6 +243,13 @@ void ProjectStorageMock::setItemLibraryEntries(
|
||||
ON_CALL(*this, itemLibraryEntries(TypedEq<SourceId>(sourceId))).WillByDefault(Return(entries));
|
||||
}
|
||||
|
||||
void ProjectStorageMock::setDirectoryImportsItemLibraryEntries(
|
||||
QmlDesigner::SourceId sourceId, const QmlDesigner::Storage::Info::ItemLibraryEntries &entries)
|
||||
{
|
||||
ON_CALL(*this, directoryImportsItemLibraryEntries(TypedEq<SourceId>(sourceId)))
|
||||
.WillByDefault(Return(entries));
|
||||
}
|
||||
|
||||
namespace {
|
||||
void addBaseProperties(TypeId typeId,
|
||||
const QmlDesigner::SmallTypeIds<16> &baseTypeIds,
|
||||
|
@@ -114,6 +114,8 @@ public:
|
||||
const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
||||
void setItemLibraryEntries(QmlDesigner::SourceId sourceId,
|
||||
const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
||||
void setDirectoryImportsItemLibraryEntries(
|
||||
QmlDesigner::SourceId sourceId, const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
||||
|
||||
MOCK_METHOD(void,
|
||||
synchronize,
|
||||
@@ -228,6 +230,10 @@ public:
|
||||
allItemLibraryEntries,
|
||||
(),
|
||||
(const, override));
|
||||
MOCK_METHOD(QmlDesigner::Storage::Info::ItemLibraryEntries,
|
||||
directoryImportsItemLibraryEntries,
|
||||
(QmlDesigner::SourceId sourceId),
|
||||
(const, override));
|
||||
MOCK_METHOD(std::vector<::Utils::SmallString>,
|
||||
signalDeclarationNames,
|
||||
(QmlDesigner::TypeId typeId),
|
||||
|
@@ -1333,6 +1333,37 @@ TEST_F(Model_TypeAnnotation, item_library_entries)
|
||||
ElementsAre(u"/extra/file/path"))));
|
||||
}
|
||||
|
||||
TEST_F(Model_TypeAnnotation, directory_imports_item_library_entries)
|
||||
{
|
||||
using namespace Qt::StringLiterals;
|
||||
QmlDesigner::Storage::Info::ItemLibraryEntries storageEntries{{itemTypeId,
|
||||
"Item",
|
||||
"Item",
|
||||
"/path/to/icon",
|
||||
"basic category",
|
||||
"QtQuick",
|
||||
"It's a item",
|
||||
"/path/to/template"}};
|
||||
storageEntries.front().properties.emplace_back("x", "double", Sqlite::ValueView::create(1));
|
||||
storageEntries.front().extraFilePaths.emplace_back("/extra/file/path");
|
||||
projectStorageMock.setDirectoryImportsItemLibraryEntries(pathCacheMock.sourceId, storageEntries);
|
||||
|
||||
auto entries = model.directoryImportsItemLibraryEntries();
|
||||
|
||||
ASSERT_THAT(entries,
|
||||
ElementsAre(
|
||||
IsItemLibraryEntry(itemTypeId,
|
||||
"Item",
|
||||
u"Item",
|
||||
u"/path/to/icon",
|
||||
u"basic category",
|
||||
u"QtQuick",
|
||||
u"It's a item",
|
||||
u"/path/to/template",
|
||||
ElementsAre(IsItemLibraryProperty("x", "double"_L1, QVariant{1})),
|
||||
ElementsAre(u"/extra/file/path"))));
|
||||
}
|
||||
|
||||
class Model_ViewManagement : public Model
|
||||
{
|
||||
protected:
|
||||
|
@@ -8890,14 +8890,14 @@ TEST_F(ProjectStorage, get_item_library_entries_by_source_id)
|
||||
IsEmpty())));
|
||||
}
|
||||
|
||||
TEST_F(ProjectStorage, get_local_file_item_library_entries_by_source_id)
|
||||
TEST_F(ProjectStorage, get_directory_imports_item_library_entries_by_source_id)
|
||||
{
|
||||
auto package{createSimpleSynchronizationPackage()};
|
||||
package.imports.emplace_back(pathToModuleId, Storage::Version{}, sourceId2);
|
||||
package.types[1].exportedTypes.emplace_back(pathToModuleId, "Object");
|
||||
storage.synchronize(package);
|
||||
|
||||
auto entries = storage.itemLibraryEntries(sourceId2);
|
||||
auto entries = storage.directoryImportsItemLibraryEntries(sourceId2);
|
||||
|
||||
ASSERT_THAT(entries,
|
||||
UnorderedElementsAre(IsItemLibraryEntry(fetchTypeId(sourceId2, "QObject"),
|
||||
|
Reference in New Issue
Block a user