QmlDesigner: Add ProjectStorage::functionDeclarationNames

As we changed the MetaInfo interface we can return ids too but as an
intermediate step we return the sorted function names. Beware that the
sort is not matching the normal SmallString "<" operator because it is
not using size.

Task-number: QDS-7284
Change-Id: I96c6494d7c36f37d451d439be8aee35e0221f20b
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2022-07-13 17:40:50 +02:00
parent 63243aabc1
commit 4ca769afb1
2 changed files with 63 additions and 3 deletions

View File

@@ -190,6 +190,12 @@ public:
.template valuesWithTransaction<Utils::SmallString>(32, &typeId); .template valuesWithTransaction<Utils::SmallString>(32, &typeId);
} }
std::vector<Utils::SmallString> functionDeclarationNames(TypeId typeId) const
{
return selectFuncionDeclarationNamesForTypeStatement
.template valuesWithTransaction<Utils::SmallString>(32, &typeId);
}
Utils::optional<Utils::SmallString> propertyName(PropertyDeclarationId propertyDeclarationId) const Utils::optional<Utils::SmallString> propertyName(PropertyDeclarationId propertyDeclarationId) const
{ {
return selectPropertyNameStatement.template optionalValueWithTransaction<Utils::SmallString>( return selectPropertyNameStatement.template optionalValueWithTransaction<Utils::SmallString>(
@@ -2955,6 +2961,16 @@ public:
"SELECT name FROM typeChain JOIN signalDeclarations " "SELECT name FROM typeChain JOIN signalDeclarations "
" USING(typeId) ORDER BY name", " USING(typeId) ORDER BY name",
database}; database};
mutable ReadStatement<1, 1> selectFuncionDeclarationNamesForTypeStatement{
"WITH RECURSIVE "
" typeChain(typeId) AS ("
" VALUES(?1)"
" UNION ALL "
" SELECT prototypeId FROM types JOIN typeChain "
" USING(typeId) WHERE prototypeId IS NOT NULL)"
"SELECT name FROM typeChain JOIN functionDeclarations "
" USING(typeId) ORDER BY name",
database};
}; };
extern template class ProjectStorage<Sqlite::Database>; extern template class ProjectStorage<Sqlite::Database>;
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -787,7 +787,7 @@ protected:
Storage::Synchronization::ImportedType{"Object"}, Storage::Synchronization::ImportedType{"Object"},
Storage::PropertyDeclarationTraits::IsList Storage::PropertyDeclarationTraits::IsList
| Storage::PropertyDeclarationTraits::IsReadOnly}}, | Storage::PropertyDeclarationTraits::IsReadOnly}},
{}, {Storage::Synchronization::FunctionDeclaration{"values", {}, {}}},
{Storage::Synchronization::SignalDeclaration{"valuesChanged", {}}}}); {Storage::Synchronization::SignalDeclaration{"valuesChanged", {}}}});
package.types.push_back(Storage::Synchronization::Type{ package.types.push_back(Storage::Synchronization::Type{
"QObject2", "QObject2",
@@ -806,7 +806,7 @@ protected:
Storage::Synchronization::ImportedType{"Object3"}, Storage::Synchronization::ImportedType{"Object3"},
Storage::PropertyDeclarationTraits::IsList Storage::PropertyDeclarationTraits::IsList
| Storage::PropertyDeclarationTraits::IsReadOnly}}, | Storage::PropertyDeclarationTraits::IsReadOnly}},
{}, {Storage::Synchronization::FunctionDeclaration{"items", {}, {}}},
{Storage::Synchronization::SignalDeclaration{"itemsChanged", {}}}}); {Storage::Synchronization::SignalDeclaration{"itemsChanged", {}}}});
package.types.push_back(Storage::Synchronization::Type{ package.types.push_back(Storage::Synchronization::Type{
"QObject3", "QObject3",
@@ -825,7 +825,7 @@ protected:
Storage::Synchronization::ImportedType{"Object2"}, Storage::Synchronization::ImportedType{"Object2"},
Storage::PropertyDeclarationTraits::IsList Storage::PropertyDeclarationTraits::IsList
| Storage::PropertyDeclarationTraits::IsReadOnly}}, | Storage::PropertyDeclarationTraits::IsReadOnly}},
{}, {Storage::Synchronization::FunctionDeclaration{"objects", {}, {}}},
{Storage::Synchronization::SignalDeclaration{"objectsChanged", {}}}}); {Storage::Synchronization::SignalDeclaration{"objectsChanged", {}}}});
package.updatedSourceIds.push_back(sourceId1); package.updatedSourceIds.push_back(sourceId1);
@@ -5741,4 +5741,48 @@ TEST_F(ProjectStorage, GetOnlySignalDeclarationNamesFromUpIntoThePrototypeChain)
ASSERT_THAT(signalNames, ElementsAre("itemsChanged", "valuesChanged")); ASSERT_THAT(signalNames, ElementsAre("itemsChanged", "valuesChanged"));
} }
TEST_F(ProjectStorage, GetFunctionDeclarationNames)
{
auto package{createPackageWithProperties()};
storage.synchronize(package);
auto typeId = fetchTypeId(sourceId1, "QObject3");
auto functionNames = storage.functionDeclarationNames(typeId);
ASSERT_THAT(functionNames, ElementsAre("items", "objects", "values"));
}
TEST_F(ProjectStorage, GetFunctionDeclarationNamesAreOrdered)
{
auto package{createPackageWithProperties()};
storage.synchronize(package);
auto typeId = fetchTypeId(sourceId1, "QObject3");
auto functionNames = storage.functionDeclarationNames(typeId);
ASSERT_THAT(functionNames, StringsAreSorted());
}
TEST_F(ProjectStorage, GetNoFunctionDeclarationNamesForInvalidTypeId)
{
auto package{createPackageWithProperties()};
storage.synchronize(package);
auto typeId = fetchTypeId(sourceId1, "WrongObject");
auto functionNames = storage.functionDeclarationNames(typeId);
ASSERT_THAT(functionNames, IsEmpty());
}
TEST_F(ProjectStorage, GetOnlyFunctionDeclarationNamesFromUpIntoThePrototypeChain)
{
auto package{createPackageWithProperties()};
storage.synchronize(package);
auto typeId = fetchTypeId(sourceId1, "QObject2");
auto functionNames = storage.functionDeclarationNames(typeId);
ASSERT_THAT(functionNames, ElementsAre("items", "values"));
}
} // namespace } // namespace