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
|
#endif
|
||||||
|
|
||||||
QList<ItemLibraryEntry> itemLibraryEntries() const;
|
QList<ItemLibraryEntry> itemLibraryEntries() const;
|
||||||
|
QList<ItemLibraryEntry> directoryImportsItemLibraryEntries() const;
|
||||||
|
|
||||||
void attachView(AbstractView *view);
|
void attachView(AbstractView *view);
|
||||||
void detachView(AbstractView *view, ViewNotification emitDetachNotify = NotifyView);
|
void detachView(AbstractView *view, ViewNotification emitDetachNotify = NotifyView);
|
||||||
|
@@ -2819,6 +2819,17 @@ QList<ItemLibraryEntry> Model::itemLibraryEntries() const
|
|||||||
#endif
|
#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
|
NodeMetaInfo Model::qtQuickTimelineKeyframeGroupMetaInfo() const
|
||||||
{
|
{
|
||||||
if constexpr (useProjectStorage()) {
|
if constexpr (useProjectStorage()) {
|
||||||
|
@@ -870,7 +870,7 @@ struct ProjectStorage::Statements
|
|||||||
" USING(moduleId) "
|
" USING(moduleId) "
|
||||||
" WHERE di.sourceId=?)",
|
" WHERE di.sourceId=?)",
|
||||||
database};
|
database};
|
||||||
mutable Sqlite::ReadStatement<4, 2> selectLocalFileItemLibraryEntriesBySourceIdStatement{
|
mutable Sqlite::ReadStatement<4, 2> selectDirectoryImportsItemLibraryEntriesBySourceIdStatement{
|
||||||
"SELECT typeId, etn.name, m.name, t.sourceId "
|
"SELECT typeId, etn.name, m.name, t.sourceId "
|
||||||
"FROM documentImports AS di "
|
"FROM documentImports AS di "
|
||||||
" JOIN exportedTypeNames AS etn USING(moduleId) "
|
" JOIN exportedTypeNames AS etn USING(moduleId) "
|
||||||
@@ -1877,7 +1877,7 @@ Storage::Info::ItemLibraryEntries ProjectStorage::itemLibraryEntries(SourceId so
|
|||||||
using Storage::Info::ItemLibraryProperties;
|
using Storage::Info::ItemLibraryProperties;
|
||||||
Storage::Info::ItemLibraryEntries entries;
|
Storage::Info::ItemLibraryEntries entries;
|
||||||
|
|
||||||
auto typeAnnotationCallback = [&](TypeId typeId,
|
auto callback = [&](TypeId typeId,
|
||||||
Utils::SmallStringView typeName,
|
Utils::SmallStringView typeName,
|
||||||
Utils::SmallStringView name,
|
Utils::SmallStringView name,
|
||||||
Utils::SmallStringView iconPath,
|
Utils::SmallStringView iconPath,
|
||||||
@@ -1895,23 +1895,7 @@ Storage::Info::ItemLibraryEntries ProjectStorage::itemLibraryEntries(SourceId so
|
|||||||
s->selectItemLibraryExtraFilePathsStatement.readTo(last.extraFilePaths, extraFilePaths);
|
s->selectItemLibraryExtraFilePathsStatement.readTo(last.extraFilePaths, extraFilePaths);
|
||||||
};
|
};
|
||||||
|
|
||||||
s->selectItemLibraryEntriesBySourceIdStatement.readCallbackWithTransaction(typeAnnotationCallback,
|
s->selectItemLibraryEntriesBySourceIdStatement.readCallbackWithTransaction(callback, sourceId);
|
||||||
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);
|
|
||||||
|
|
||||||
tracer.end(keyValue("item library entries", entries));
|
tracer.end(keyValue("item library entries", entries));
|
||||||
|
|
||||||
@@ -1951,6 +1935,36 @@ Storage::Info::ItemLibraryEntries ProjectStorage::allItemLibraryEntries() const
|
|||||||
return entries;
|
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
|
std::vector<Utils::SmallString> ProjectStorage::signalDeclarationNames(TypeId typeId) const
|
||||||
{
|
{
|
||||||
using NanotraceHR::keyValue;
|
using NanotraceHR::keyValue;
|
||||||
|
@@ -110,12 +110,10 @@ public:
|
|||||||
SmallSourceContextIds<64> typeAnnotationDirectoryIds() const override;
|
SmallSourceContextIds<64> typeAnnotationDirectoryIds() const override;
|
||||||
|
|
||||||
Storage::Info::ItemLibraryEntries itemLibraryEntries(TypeId typeId) const override;
|
Storage::Info::ItemLibraryEntries itemLibraryEntries(TypeId typeId) const override;
|
||||||
|
|
||||||
Storage::Info::ItemLibraryEntries itemLibraryEntries(ImportId importId) const;
|
Storage::Info::ItemLibraryEntries itemLibraryEntries(ImportId importId) const;
|
||||||
|
|
||||||
Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const override;
|
Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const override;
|
||||||
|
|
||||||
Storage::Info::ItemLibraryEntries allItemLibraryEntries() 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;
|
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(TypeId typeId) const = 0;
|
||||||
virtual Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const = 0;
|
virtual Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const = 0;
|
||||||
virtual Storage::Info::ItemLibraryEntries allItemLibraryEntries() 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> signalDeclarationNames(TypeId typeId) const = 0;
|
||||||
virtual std::vector<::Utils::SmallString> functionDeclarationNames(TypeId typeId) const = 0;
|
virtual std::vector<::Utils::SmallString> functionDeclarationNames(TypeId typeId) const = 0;
|
||||||
virtual std::optional<::Utils::SmallString>
|
virtual std::optional<::Utils::SmallString>
|
||||||
|
@@ -243,6 +243,13 @@ void ProjectStorageMock::setItemLibraryEntries(
|
|||||||
ON_CALL(*this, itemLibraryEntries(TypedEq<SourceId>(sourceId))).WillByDefault(Return(entries));
|
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 {
|
namespace {
|
||||||
void addBaseProperties(TypeId typeId,
|
void addBaseProperties(TypeId typeId,
|
||||||
const QmlDesigner::SmallTypeIds<16> &baseTypeIds,
|
const QmlDesigner::SmallTypeIds<16> &baseTypeIds,
|
||||||
|
@@ -114,6 +114,8 @@ public:
|
|||||||
const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
||||||
void setItemLibraryEntries(QmlDesigner::SourceId sourceId,
|
void setItemLibraryEntries(QmlDesigner::SourceId sourceId,
|
||||||
const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
||||||
|
void setDirectoryImportsItemLibraryEntries(
|
||||||
|
QmlDesigner::SourceId sourceId, const QmlDesigner::Storage::Info::ItemLibraryEntries &entries);
|
||||||
|
|
||||||
MOCK_METHOD(void,
|
MOCK_METHOD(void,
|
||||||
synchronize,
|
synchronize,
|
||||||
@@ -228,6 +230,10 @@ public:
|
|||||||
allItemLibraryEntries,
|
allItemLibraryEntries,
|
||||||
(),
|
(),
|
||||||
(const, override));
|
(const, override));
|
||||||
|
MOCK_METHOD(QmlDesigner::Storage::Info::ItemLibraryEntries,
|
||||||
|
directoryImportsItemLibraryEntries,
|
||||||
|
(QmlDesigner::SourceId sourceId),
|
||||||
|
(const, override));
|
||||||
MOCK_METHOD(std::vector<::Utils::SmallString>,
|
MOCK_METHOD(std::vector<::Utils::SmallString>,
|
||||||
signalDeclarationNames,
|
signalDeclarationNames,
|
||||||
(QmlDesigner::TypeId typeId),
|
(QmlDesigner::TypeId typeId),
|
||||||
|
@@ -1333,6 +1333,37 @@ TEST_F(Model_TypeAnnotation, item_library_entries)
|
|||||||
ElementsAre(u"/extra/file/path"))));
|
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
|
class Model_ViewManagement : public Model
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@@ -8890,14 +8890,14 @@ TEST_F(ProjectStorage, get_item_library_entries_by_source_id)
|
|||||||
IsEmpty())));
|
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()};
|
auto package{createSimpleSynchronizationPackage()};
|
||||||
package.imports.emplace_back(pathToModuleId, Storage::Version{}, sourceId2);
|
package.imports.emplace_back(pathToModuleId, Storage::Version{}, sourceId2);
|
||||||
package.types[1].exportedTypes.emplace_back(pathToModuleId, "Object");
|
package.types[1].exportedTypes.emplace_back(pathToModuleId, "Object");
|
||||||
storage.synchronize(package);
|
storage.synchronize(package);
|
||||||
|
|
||||||
auto entries = storage.itemLibraryEntries(sourceId2);
|
auto entries = storage.directoryImportsItemLibraryEntries(sourceId2);
|
||||||
|
|
||||||
ASSERT_THAT(entries,
|
ASSERT_THAT(entries,
|
||||||
UnorderedElementsAre(IsItemLibraryEntry(fetchTypeId(sourceId2, "QObject"),
|
UnorderedElementsAre(IsItemLibraryEntry(fetchTypeId(sourceId2, "QObject"),
|
||||||
|
Reference in New Issue
Block a user