QmlDesigner: Improve exported type name table

Previously, the table used SQLite's default rowid, which introduces an
additional lookup overhead during queries. By switching to a WITHOUT
ROWID table structure, SQLite can optimize lookups more efficiently,
especially when using primary keys. (See: SQLite WITHOUT ROWID)

Since primary keys in SQLite cannot contain NULL values, we now encode
the major and minor version information using the maximum integer value
to represent the absence of a version. This ensures that version-less
types are always preferred in comparisons and sorting, aligning with our
intended behavior.

Change-Id: I8f851d17a8c7d38c6d0928ee84a6cc7b4953e7e9
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-06-16 18:03:32 +02:00
parent e7cf02adbe
commit 097a72c7da
10 changed files with 383 additions and 341 deletions

View File

@@ -649,6 +649,11 @@ private:
operator long() const { return statement.fetchLongValue(column); } operator long() const { return statement.fetchLongValue(column); }
operator unsigned int() const
{
return static_cast<unsigned int>(statement.fetchLongLongValue(column));
}
operator long long() const { return statement.fetchLongLongValue(column); } operator long long() const { return statement.fetchLongLongValue(column); }
operator double() const { return statement.fetchDoubleValue(column); } operator double() const { return statement.fetchDoubleValue(column); }

View File

@@ -387,8 +387,8 @@ ImportedTypeNameId ModelPrivate::importedTypeNameId(Utils::SmallStringView typeN
: ModuleKind::PathLibrary; : ModuleKind::PathLibrary;
ModuleId moduleId = projectStorage->moduleId(Utils::PathString{found->url()}, ModuleId moduleId = projectStorage->moduleId(Utils::PathString{found->url()},
moduleKind); moduleKind);
ImportId importId = projectStorage->importId( ImportId importId = projectStorage->importId(Storage::Import::fromSignedInteger(
Storage::Import{moduleId, found->majorVersion(), found->minorVersion(), m_sourceId}); moduleId, found->majorVersion(), found->minorVersion(), m_sourceId));
return projectStorage->importedTypeNameId(importId, shortTypeName); return projectStorage->importedTypeNameId(importId, shortTypeName);
} }
} }

View File

@@ -130,7 +130,7 @@ struct ProjectStorage::Statements
"WHERE t.typeId=?", "WHERE t.typeId=?",
database}; database};
mutable Sqlite::ReadStatement<5, 1> selectExportedTypesByTypeIdStatement{ mutable Sqlite::ReadStatement<5, 1> selectExportedTypesByTypeIdStatement{
"SELECT moduleId, typeId, name, ifnull(majorVersion, -1), ifnull(minorVersion, -1) " "SELECT moduleId, typeId, name, majorVersion, minorVersion "
"FROM exportedTypeNames " "FROM exportedTypeNames "
"WHERE typeId=?", "WHERE typeId=?",
database}; database};
@@ -138,8 +138,8 @@ struct ProjectStorage::Statements
"SELECT etn.moduleId, " "SELECT etn.moduleId, "
" typeId, " " typeId, "
" name, " " name, "
" ifnull(etn.majorVersion, -1), " " etn.majorVersion, "
" ifnull(etn.minorVersion, -1) " " etn.minorVersion "
"FROM exportedTypeNames AS etn " "FROM exportedTypeNames AS etn "
"JOIN documentImports USING(moduleId) " "JOIN documentImports USING(moduleId) "
"WHERE typeId=?1 AND sourceId=?2", "WHERE typeId=?1 AND sourceId=?2",
@@ -186,7 +186,7 @@ struct ProjectStorage::Statements
"SELECT DISTINCT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN " "SELECT DISTINCT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN "
"carray(?2))", "carray(?2))",
database}; database};
Sqlite::WriteStatement<1> deleteTypeNamesByTypeIdStatement{ Sqlite::WriteStatement<1> deleteExportedTypeNamesByTypeIdStatement{
"DELETE FROM exportedTypeNames WHERE typeId=?", database}; "DELETE FROM exportedTypeNames WHERE typeId=?", database};
Sqlite::WriteStatement<1> deleteEnumerationDeclarationByTypeIdStatement{ Sqlite::WriteStatement<1> deleteEnumerationDeclarationByTypeIdStatement{
"DELETE FROM enumerationDeclarations WHERE typeId=?", database}; "DELETE FROM enumerationDeclarations WHERE typeId=?", database};
@@ -630,13 +630,16 @@ struct ProjectStorage::Statements
"RETURNING importedTypeNameId", "RETURNING importedTypeNameId",
database}; database};
mutable Sqlite::ReadStatement<1, 2> selectImportIdBySourceIdAndModuleIdStatement{ mutable Sqlite::ReadStatement<1, 2> selectImportIdBySourceIdAndModuleIdStatement{
"SELECT importId FROM documentImports WHERE sourceId=?1 AND moduleId=?2 AND " "SELECT importId "
"majorVersion " "FROM documentImports "
"IS NULL AND minorVersion IS NULL LIMIT 1", "WHERE sourceId=?1 AND moduleId=?2 AND majorVersion=0xFFFFFFFF AND minorVersion=0xFFFFFFFF "
"LIMIT 1",
database}; database};
mutable Sqlite::ReadStatement<1, 3> selectImportIdBySourceIdAndModuleIdAndMajorVersionStatement{ mutable Sqlite::ReadStatement<1, 3> selectImportIdBySourceIdAndModuleIdAndMajorVersionStatement{
"SELECT importId FROM documentImports WHERE sourceId=?1 AND moduleId=?2 AND " "SELECT importId "
"majorVersion=?3 AND minorVersion IS NULL LIMIT 1", "FROM documentImports "
"WHERE sourceId=?1 AND moduleId=?2 AND majorVersion=?3 AND minorVersion=0xFFFFFFFF "
"LIMIT 1",
database}; database};
mutable Sqlite::ReadStatement<1, 4> selectImportIdBySourceIdAndModuleIdAndVersionStatement{ mutable Sqlite::ReadStatement<1, 4> selectImportIdBySourceIdAndModuleIdAndVersionStatement{
"SELECT importId FROM documentImports WHERE sourceId=?1 AND moduleId=?2 AND " "SELECT importId FROM documentImports WHERE sourceId=?1 AND moduleId=?2 AND "
@@ -647,53 +650,57 @@ struct ProjectStorage::Statements
mutable Sqlite::ReadStatement<1, 1> selectNameFromImportedTypeNamesStatement{ mutable Sqlite::ReadStatement<1, 1> selectNameFromImportedTypeNamesStatement{
"SELECT name FROM importedTypeNames WHERE importedTypeNameId=?1", database}; "SELECT name FROM importedTypeNames WHERE importedTypeNameId=?1", database};
mutable Sqlite::ReadStatement<1, 1> selectTypeIdForQualifiedImportedTypeNameNamesStatement{ mutable Sqlite::ReadStatement<1, 1> selectTypeIdForQualifiedImportedTypeNameNamesStatement{
"SELECT typeId FROM importedTypeNames AS itn JOIN documentImports AS di ON " "SELECT typeId "
"importOrSourceId=di.importId JOIN documentImports AS di2 ON di.sourceId=di2.sourceId " "FROM importedTypeNames AS itn "
"AND " " JOIN documentImports AS di ON importOrSourceId=di.importId "
"di.moduleId=di2.sourceModuleId " " JOIN documentImports AS di2 ON di.sourceId=di2.sourceId "
"JOIN exportedTypeNames AS etn ON di2.moduleId=etn.moduleId WHERE " " AND di.moduleId=di2.sourceModuleId "
"itn.kind=2 AND importedTypeNameId=?1 AND itn.name=etn.name AND " " JOIN exportedTypeNames AS etn ON di2.moduleId=etn.moduleId "
"(di.majorVersion IS NULL OR (di.majorVersion=etn.majorVersion AND (di.minorVersion IS " "WHERE itn.kind=2 "
"NULL OR di.minorVersion>=etn.minorVersion))) ORDER BY etn.majorVersion DESC NULLS " " AND importedTypeNameId=?1 "
"FIRST, " " AND itn.name=etn.name "
"etn.minorVersion DESC NULLS FIRST LIMIT 1", " AND (di.majorVersion=0xFFFFFFFF "
database}; " OR (di.majorVersion=etn.majorVersion "
mutable Sqlite::ReadStatement<1, 1> selectTypeIdForImportedTypeNameNamesStatement{ " AND (di.minorVersion=0xFFFFFFFF OR di.minorVersion>=etn.minorVersion))) "
"WITH " "ORDER BY etn.majorVersion DESC, etn.minorVersion DESC "
" importTypeNames(moduleId, name, kind, majorVersion, minorVersion) AS ( "
" SELECT moduleId, name, di.kind, majorVersion, minorVersion "
" FROM importedTypeNames AS itn JOIN documentImports AS di ON "
" importOrSourceId=sourceId "
" WHERE "
" importedTypeNameId=?1 AND itn.kind=1) "
"SELECT typeId FROM importTypeNames AS itn "
" JOIN exportedTypeNames AS etn USING(moduleId, name) "
"WHERE (itn.majorVersion IS NULL OR (itn.majorVersion=etn.majorVersion "
" AND (itn.minorVersion IS NULL OR itn.minorVersion>=etn.minorVersion))) "
"ORDER BY itn.kind, etn.majorVersion DESC NULLS FIRST, etn.minorVersion DESC NULLS "
"FIRST "
"LIMIT 1", "LIMIT 1",
database}; database};
mutable Sqlite::ReadStatement<6, 1> selectExportedTypesForSourceIdsStatement{ mutable Sqlite::ReadStatement<1, 1> selectTypeIdForImportedTypeNameNamesStatement{
"SELECT moduleId, name, ifnull(majorVersion, -1), ifnull(minorVersion, -1), typeId, " "SELECT typeId FROM importedTypeNames AS itn "
"exportedTypeNameId FROM exportedTypeNames WHERE typeId in carray(?1) ORDER BY " " JOIN exportedTypeNames AS etn USING(name) "
"moduleId, " " JOIN documentImports AS di ON importOrSourceId=sourceId "
"name, majorVersion, minorVersion", "WHERE importedTypeNameId=?1 "
" AND itn.kind=1 "
" AND etn.moduleId=di.moduleId "
" AND (di.majorVersion=0xFFFFFFFF "
" OR (di.majorVersion=etn.majorVersion "
" AND (di.minorVersion=0xFFFFFFFF OR di.minorVersion>=etn.minorVersion))) "
"ORDER BY di.kind, etn.majorVersion DESC, etn.minorVersion DESC "
"LIMIT 1",
database}; database};
Sqlite::WriteStatement<5> insertExportedTypeNamesWithVersionStatement{ mutable Sqlite::ReadStatement<5, 1> selectExportedTypesForSourceIdsStatement{
"SELECT moduleId, "
" name, "
" majorVersion, "
" minorVersion, "
" typeId "
"FROM exportedTypeNames "
"WHERE typeId in carray(?1) "
"ORDER BY name, moduleId, majorVersion, minorVersion",
database};
Sqlite::WriteStatement<5> insertExportedTypeNamesStatement{
"INSERT INTO exportedTypeNames(moduleId, name, majorVersion, minorVersion, typeId) " "INSERT INTO exportedTypeNames(moduleId, name, majorVersion, minorVersion, typeId) "
"VALUES(?1, ?2, ?3, ?4, ?5)", "VALUES(?1, ?2, ?3, ?4, ?5)",
database}; database};
Sqlite::WriteStatement<4> insertExportedTypeNamesWithMajorVersionStatement{ Sqlite::WriteStatement<4> deleteExportedTypeNameStatement{
"INSERT INTO exportedTypeNames(moduleId, name, majorVersion, typeId) " "DELETE FROM exportedTypeNames "
"VALUES(?1, ?2, ?3, ?4)", "WHERE name=?2 AND moduleId=?1 AND majorVersion=?3 AND minorVersion=?4",
database};
Sqlite::WriteStatement<5> updateExportedTypeNameTypeIdStatement{
"UPDATE exportedTypeNames "
"SET typeId=?5 "
"WHERE name=?2 AND moduleId=?1 AND majorVersion=?3 AND minorVersion=?4",
database}; database};
Sqlite::WriteStatement<3> insertExportedTypeNamesWithoutVersionStatement{
"INSERT INTO exportedTypeNames(moduleId, name, typeId) VALUES(?1, ?2, ?3)", database};
Sqlite::WriteStatement<1> deleteExportedTypeNameStatement{
"DELETE FROM exportedTypeNames WHERE exportedTypeNameId=?", database};
Sqlite::WriteStatement<2> updateExportedTypeNameTypeIdStatement{
"UPDATE exportedTypeNames SET typeId=?2 WHERE exportedTypeNameId=?1", database};
mutable Sqlite::ReadStatement<4, 1> selectDirectoryInfosForDirectoryIdsStatement{ mutable Sqlite::ReadStatement<4, 1> selectDirectoryInfosForDirectoryIdsStatement{
"SELECT directoryId, sourceId, moduleId, fileType FROM directoryInfos WHERE " "SELECT directoryId, sourceId, moduleId, fileType FROM directoryInfos WHERE "
"directoryId IN carray(?1) ORDER BY directoryId, sourceId", "directoryId IN carray(?1) ORDER BY directoryId, sourceId",
@@ -725,17 +732,15 @@ struct ProjectStorage::Statements
mutable Sqlite::ReadStatement<1, 1> selectTypeIdsForSourceIdsStatement{ mutable Sqlite::ReadStatement<1, 1> selectTypeIdsForSourceIdsStatement{
"SELECT typeId FROM types WHERE sourceId IN carray(?1)", database}; "SELECT typeId FROM types WHERE sourceId IN carray(?1)", database};
mutable Sqlite::ReadStatement<6, 1> selectModuleExportedImportsForSourceIdStatement{ mutable Sqlite::ReadStatement<6, 1> selectModuleExportedImportsForSourceIdStatement{
"SELECT moduleExportedImportId, moduleId, exportedModuleId, ifnull(majorVersion, -1), " "SELECT moduleExportedImportId, "
"ifnull(minorVersion, -1), isAutoVersion FROM moduleExportedImports WHERE moduleId IN " " moduleId, "
"carray(?1) ORDER BY moduleId, exportedModuleId", " exportedModuleId, "
database}; " majorVersion, "
Sqlite::WriteStatement<3> insertModuleExportedImportWithoutVersionStatement{ " minorVersion, "
"INSERT INTO moduleExportedImports(moduleId, exportedModuleId, isAutoVersion) " " isAutoVersion "
"VALUES (?1, ?2, ?3)", "FROM moduleExportedImports "
database}; "WHERE moduleId IN carray(?1) "
Sqlite::WriteStatement<4> insertModuleExportedImportWithMajorVersionStatement{ "ORDER BY moduleId, exportedModuleId",
"INSERT INTO moduleExportedImports(moduleId, exportedModuleId, isAutoVersion, "
"majorVersion) VALUES (?1, ?2, ?3, ?4)",
database}; database};
Sqlite::WriteStatement<5> insertModuleExportedImportWithVersionStatement{ Sqlite::WriteStatement<5> insertModuleExportedImportWithVersionStatement{
"INSERT INTO moduleExportedImports(moduleId, exportedModuleId, isAutoVersion, " "INSERT INTO moduleExportedImports(moduleId, exportedModuleId, isAutoVersion, "
@@ -757,7 +762,7 @@ struct ProjectStorage::Statements
" iif(mei.isAutoVersion=1, i.minorVersion, mei.minorVersion), " " iif(mei.isAutoVersion=1, i.minorVersion, mei.minorVersion), "
" mei.moduleExportedImportId " " mei.moduleExportedImportId "
" FROM moduleExportedImports AS mei JOIN imports AS i USING(moduleId)) " " FROM moduleExportedImports AS mei JOIN imports AS i USING(moduleId)) "
"SELECT DISTINCT moduleId, ifnull(majorVersion, -1), ifnull(minorVersion, -1) " "SELECT DISTINCT moduleId, majorVersion, minorVersion "
"FROM imports", "FROM imports",
database}; database};
mutable Sqlite::ReadStatement<1, 1> selectLocalPropertyDeclarationIdsForTypeStatement{ mutable Sqlite::ReadStatement<1, 1> selectLocalPropertyDeclarationIdsForTypeStatement{
@@ -1072,28 +1077,21 @@ public:
{ {
Sqlite::StrictTable table; Sqlite::StrictTable table;
table.setUseIfNotExists(true); table.setUseIfNotExists(true);
table.setUseWithoutRowId(true);
table.setName("exportedTypeNames"); table.setName("exportedTypeNames");
table.addColumn("exportedTypeNameId", auto &nameColumn = table.addColumn("name", Sqlite::StrictColumnType::Text);
Sqlite::StrictColumnType::Integer,
{Sqlite::PrimaryKey{}});
auto &moduleIdColumn = table.addForeignKeyColumn("moduleId", auto &moduleIdColumn = table.addForeignKeyColumn("moduleId",
foreignModuleIdColumn, foreignModuleIdColumn,
Sqlite::ForeignKeyAction::NoAction, Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::NoAction); Sqlite::ForeignKeyAction::NoAction);
auto &nameColumn = table.addColumn("name", Sqlite::StrictColumnType::Text);
auto &typeIdColumn = table.addColumn("typeId", Sqlite::StrictColumnType::Integer); auto &typeIdColumn = table.addColumn("typeId", Sqlite::StrictColumnType::Integer);
auto &majorVersionColumn = table.addColumn("majorVersion", Sqlite::StrictColumnType::Integer); auto &majorVersionColumn = table.addColumn("majorVersion", Sqlite::StrictColumnType::Integer);
auto &minorVersionColumn = table.addColumn("minorVersion", Sqlite::StrictColumnType::Integer); auto &minorVersionColumn = table.addColumn("minorVersion", Sqlite::StrictColumnType::Integer);
table.addUniqueIndex({nameColumn, moduleIdColumn}, table.addPrimaryKeyContraint(
"majorVersion IS NULL AND minorVersion IS NULL"); {nameColumn, moduleIdColumn, majorVersionColumn, minorVersionColumn});
table.addUniqueIndex({nameColumn, moduleIdColumn, majorVersionColumn},
"majorVersion IS NOT NULL AND minorVersion IS NULL");
table.addUniqueIndex({nameColumn, moduleIdColumn, majorVersionColumn, minorVersionColumn},
"majorVersion IS NOT NULL AND minorVersion IS NOT NULL");
table.addIndex({typeIdColumn}); table.addIndex({typeIdColumn});
table.addIndex({nameColumn, moduleIdColumn});
table.addIndex({moduleIdColumn}); table.addIndex({moduleIdColumn});
table.initialize(database); table.initialize(database);
@@ -1236,24 +1234,13 @@ public:
auto &parentImportIdColumn = table.addColumn("parentImportId", auto &parentImportIdColumn = table.addColumn("parentImportId",
Sqlite::StrictColumnType::Integer); Sqlite::StrictColumnType::Integer);
table.addUniqueIndex(
{sourceIdColumn, moduleIdColumn, kindColumn, sourceModuleIdColumn, parentImportIdColumn},
"majorVersion IS NULL AND minorVersion IS NULL");
table.addUniqueIndex({sourceIdColumn,
moduleIdColumn,
kindColumn,
sourceModuleIdColumn,
majorVersionColumn,
parentImportIdColumn},
"majorVersion IS NOT NULL AND minorVersion IS NULL");
table.addUniqueIndex({sourceIdColumn, table.addUniqueIndex({sourceIdColumn,
moduleIdColumn, moduleIdColumn,
kindColumn, kindColumn,
sourceModuleIdColumn, sourceModuleIdColumn,
majorVersionColumn, majorVersionColumn,
minorVersionColumn, minorVersionColumn,
parentImportIdColumn}, parentImportIdColumn});
"majorVersion IS NOT NULL AND minorVersion IS NOT NULL");
table.addIndex({sourceIdColumn, kindColumn}); table.addIndex({sourceIdColumn, kindColumn});
@@ -2891,22 +2878,11 @@ void ProjectStorage::synchromizeModuleExportedImports(
keyValue("module id", import.moduleId)}; keyValue("module id", import.moduleId)};
tracer.tick("exported module", keyValue("module id", import.exportedModuleId)); tracer.tick("exported module", keyValue("module id", import.exportedModuleId));
if (import.version.minor) {
s->insertModuleExportedImportWithVersionStatement.write(import.moduleId, s->insertModuleExportedImportWithVersionStatement.write(import.moduleId,
import.exportedModuleId, import.exportedModuleId,
import.isAutoVersion, import.isAutoVersion,
import.version.major.value, import.version.major.value,
import.version.minor.value); import.version.minor.value);
} else if (import.version.major) {
s->insertModuleExportedImportWithMajorVersionStatement.write(import.moduleId,
import.exportedModuleId,
import.isAutoVersion,
import.version.major.value);
} else {
s->insertModuleExportedImportWithoutVersionStatement.write(import.moduleId,
import.exportedModuleId,
import.isAutoVersion);
}
}; };
auto update = [](const Storage::Synchronization::ModuleExportedImportView &, auto update = [](const Storage::Synchronization::ModuleExportedImportView &,
@@ -3125,7 +3101,7 @@ void ProjectStorage::deleteType(TypeId typeId,
handlePropertyDeclarationWithPropertyType(typeId, relinkablePropertyDeclarations); handlePropertyDeclarationWithPropertyType(typeId, relinkablePropertyDeclarations);
handleAliasPropertyDeclarationsWithPropertyType(typeId, relinkableAliasPropertyDeclarations); handleAliasPropertyDeclarationsWithPropertyType(typeId, relinkableAliasPropertyDeclarations);
handleBases(typeId, relinkableBases); handleBases(typeId, relinkableBases);
s->deleteTypeNamesByTypeIdStatement.write(typeId); s->deleteExportedTypeNamesByTypeIdStatement.write(typeId);
s->deleteEnumerationDeclarationByTypeIdStatement.write(typeId); s->deleteEnumerationDeclarationByTypeIdStatement.write(typeId);
s->deletePropertyDeclarationByTypeIdStatement.write(typeId); s->deletePropertyDeclarationByTypeIdStatement.write(typeId);
s->deleteFunctionDeclarationByTypeIdStatement.write(typeId); s->deleteFunctionDeclarationByTypeIdStatement.write(typeId);
@@ -3418,19 +3394,8 @@ void ProjectStorage::synchronizeExportedTypes(
addedExportedTypeNames.reserve(exportedTypes.size()); addedExportedTypeNames.reserve(exportedTypes.size());
std::ranges::sort(exportedTypes, [](auto &&first, auto &&second) { std::ranges::sort(exportedTypes, [](auto &&first, auto &&second) {
if (first.moduleId < second.moduleId) return std::tie(first.name, first.moduleId, first.version.major, first.version.minor)
return true; < std::tie(second.name, second.moduleId, second.version.major, second.version.minor);
else if (first.moduleId > second.moduleId)
return false;
auto nameCompare = Sqlite::compare(first.name, second.name);
if (nameCompare < 0)
return true;
else if (nameCompare > 0)
return false;
return first.version < second.version;
}); });
auto range = s->selectExportedTypesForSourceIdsStatement auto range = s->selectExportedTypesForSourceIdsStatement
@@ -3439,8 +3404,8 @@ void ProjectStorage::synchronizeExportedTypes(
auto compareKey = [](const Storage::Synchronization::ExportedTypeView &view, auto compareKey = [](const Storage::Synchronization::ExportedTypeView &view,
const Storage::Synchronization::ExportedType &type) { const Storage::Synchronization::ExportedType &type) {
return std::tie(view.moduleId, view.name, view.version.major.value, view.version.minor.value) return std::tie(view.name, view.moduleId, view.version.major.value, view.version.minor.value)
<=> std::tie(type.moduleId, type.name, type.version.major.value, type.version.minor.value); <=> std::tie(type.name, type.moduleId, type.version.major.value, type.version.minor.value);
}; };
auto insert = [&](const Storage::Synchronization::ExportedType &type) { auto insert = [&](const Storage::Synchronization::ExportedType &type) {
@@ -3453,23 +3418,12 @@ void ProjectStorage::synchronizeExportedTypes(
throw QmlDesigner::ModuleDoesNotExists{}; throw QmlDesigner::ModuleDoesNotExists{};
try { try {
if (type.version) { s->insertExportedTypeNamesStatement.write(type.moduleId,
s->insertExportedTypeNamesWithVersionStatement.write(type.moduleId,
type.name, type.name,
type.version.major.value, type.version.major.value,
type.version.minor.value, type.version.minor.value,
type.typeId); type.typeId);
} else if (type.version.major) {
s->insertExportedTypeNamesWithMajorVersionStatement.write(type.moduleId,
type.name,
type.version.major.value,
type.typeId);
} else {
s->insertExportedTypeNamesWithoutVersionStatement.write(type.moduleId,
type.name,
type.typeId);
}
} catch (const Sqlite::ConstraintPreventsModification &) { } catch (const Sqlite::ConstraintPreventsModification &) {
throw QmlDesigner::ExportedTypeCannotBeInserted{type.name}; throw QmlDesigner::ExportedTypeCannotBeInserted{type.name};
} }
@@ -3501,7 +3455,11 @@ void ProjectStorage::synchronizeExportedTypes(
handleAliasPropertyDeclarationsWithPropertyType(view.typeId, handleAliasPropertyDeclarationsWithPropertyType(view.typeId,
relinkableAliasPropertyDeclarations); relinkableAliasPropertyDeclarations);
handleBases(view.typeId, relinkableBases); handleBases(view.typeId, relinkableBases);
s->updateExportedTypeNameTypeIdStatement.write(view.exportedTypeNameId, type.typeId); s->updateExportedTypeNameTypeIdStatement.write(view.moduleId,
view.name,
view.version.major.value,
view.version.minor.value,
type.typeId);
exportedTypesChanged = ExportedTypesChanged::Yes; exportedTypesChanged = ExportedTypesChanged::Yes;
addedExportedTypeNames.emplace_back(type.moduleId, type.typeId, type.name, type.version); addedExportedTypeNames.emplace_back(type.moduleId, type.typeId, type.name, type.version);
@@ -3524,7 +3482,10 @@ void ProjectStorage::synchronizeExportedTypes(
relinkableAliasPropertyDeclarations); relinkableAliasPropertyDeclarations);
handleBases(view.typeId, relinkableBases); handleBases(view.typeId, relinkableBases);
s->deleteExportedTypeNameStatement.write(view.exportedTypeNameId); s->deleteExportedTypeNameStatement.write(view.moduleId,
view.name,
view.version.major.value,
view.version.minor.value);
removedExportedTypeNames.emplace_back(view.moduleId, view.typeId, view.name, view.version); removedExportedTypeNames.emplace_back(view.moduleId, view.typeId, view.name, view.version);
@@ -3901,7 +3862,6 @@ ImportId ProjectStorage::insertDocumentImport(const Storage::Import &import,
handleBasesWithSourceId(import.sourceId, relinkableBases); handleBasesWithSourceId(import.sourceId, relinkableBases);
} }
if (import.version.minor) {
return s->insertDocumentImportWithVersionStatement.value<ImportId>(import.sourceId, return s->insertDocumentImportWithVersionStatement.value<ImportId>(import.sourceId,
import.moduleId, import.moduleId,
sourceModuleId, sourceModuleId,
@@ -3909,20 +3869,6 @@ ImportId ProjectStorage::insertDocumentImport(const Storage::Import &import,
import.version.major.value, import.version.major.value,
import.version.minor.value, import.version.minor.value,
parentImportId); parentImportId);
} else if (import.version.major) {
return s->insertDocumentImportWithMajorVersionStatement.value<ImportId>(import.sourceId,
import.moduleId,
sourceModuleId,
importKind,
import.version.major.value,
parentImportId);
} else {
return s->insertDocumentImportWithoutVersionStatement.value<ImportId>(import.sourceId,
import.moduleId,
sourceModuleId,
importKind,
parentImportId);
}
} }
void ProjectStorage::synchronizeDocumentImports(Storage::Imports &imports, void ProjectStorage::synchronizeDocumentImports(Storage::Imports &imports,
@@ -3959,7 +3905,9 @@ void ProjectStorage::synchronizeDocumentImports(Storage::Imports &imports,
auto importId = insertDocumentImport( auto importId = insertDocumentImport(
import, importKind, import.moduleId, ImportId{}, relink, relinkableBases); import, importKind, import.moduleId, ImportId{}, relink, relinkableBases);
auto callback = [&](ModuleId exportedModuleId, int majorVersion, int minorVersion) { auto callback = [&](ModuleId exportedModuleId,
unsigned int majorVersion,
unsigned int minorVersion) {
Storage::Import additionImport{exportedModuleId, Storage::Import additionImport{exportedModuleId,
Storage::Version{majorVersion, minorVersion}, Storage::Version{majorVersion, minorVersion},
import.sourceId}; import.sourceId};

View File

@@ -250,40 +250,60 @@ using TypeNameString = ::Utils::BasicSmallString<64>;
class VersionNumber class VersionNumber
{ {
public: public:
explicit VersionNumber() = default; constexpr VersionNumber() = default;
explicit VersionNumber(int value)
explicit constexpr VersionNumber(unsigned int value)
: value{value} : value{value}
{} {}
explicit operator bool() const { return value >= 0; } explicit constexpr operator bool() const
{
return value != std::numeric_limits<unsigned int>::max();
}
auto operator<=>(const VersionNumber &first) const noexcept = default; constexpr auto operator<=>(const VersionNumber &first) const noexcept = default;
static constexpr VersionNumber noVersionNumber() { return VersionNumber{noVersion}; }
static constexpr VersionNumber convertFromSignedInteger(int number)
{
return VersionNumber{number < 0 ? noVersion : static_cast<unsigned int>(number)};
}
inline static constexpr unsigned int noVersion = std::numeric_limits<unsigned int>::max();
public: public:
int value = -1; unsigned int value = noVersion;
}; };
class Version class Version
{ {
public: public:
explicit Version() = default; constexpr Version() = default;
explicit Version(VersionNumber major, VersionNumber minor = VersionNumber{})
explicit constexpr Version(VersionNumber major, VersionNumber minor = VersionNumber{})
: major{major} : major{major}
, minor{minor} , minor{minor}
{} {}
explicit Version(int major, int minor) constexpr Version(unsigned int major, unsigned int minor)
: major{major} : major{major}
, minor{minor} , minor{minor}
{} {}
explicit Version(int major) explicit constexpr Version(unsigned int major)
: major{major} : major{major}
{} {}
auto operator<=>(const Version &first) const noexcept = default; constexpr auto operator<=>(const Version &first) const noexcept = default;
explicit operator bool() const { return major && minor; } explicit constexpr operator bool() const { return major && minor; }
static constexpr Version convertFromSignedInteger(int majorVersion, int minorVersion)
{
return Version{VersionNumber::convertFromSignedInteger(majorVersion),
VersionNumber::convertFromSignedInteger(minorVersion)};
}
template<typename String> template<typename String>
friend void convertToString(String &string, const Version &version) friend void convertToString(String &string, const Version &version)
@@ -465,8 +485,8 @@ public:
ExportedTypeName(ModuleId moduleId, ExportedTypeName(ModuleId moduleId,
TypeId typeId, TypeId typeId,
::Utils::SmallStringView name, ::Utils::SmallStringView name,
int majorVersion, unsigned int majorVersion,
int minorVersion) unsigned int minorVersion)
: name{name} : name{name}
, version{majorVersion, minorVersion} , version{majorVersion, minorVersion}
, moduleId{moduleId} , moduleId{moduleId}

View File

@@ -21,20 +21,25 @@ namespace QmlDesigner::Storage {
class Import class Import
{ {
public: public:
explicit Import() = default; Import() = default;
explicit Import(ModuleId moduleId, Storage::Version version, SourceId sourceId) Import(ModuleId moduleId, Storage::Version version, SourceId sourceId)
: version{version} : version{version}
, moduleId{moduleId} , moduleId{moduleId}
, sourceId{sourceId} , sourceId{sourceId}
{} {}
explicit Import(ModuleId moduleId, int majorVersion, int minorVersion, SourceId sourceId) Import(ModuleId moduleId, unsigned int majorVersion, unsigned int minorVersion, SourceId sourceId)
: version{majorVersion, minorVersion} : version{majorVersion, minorVersion}
, moduleId{moduleId} , moduleId{moduleId}
, sourceId{sourceId} , sourceId{sourceId}
{} {}
static Import fromSignedInteger(ModuleId moduleId, int majorVersion, int minorVersion, SourceId sourceId)
{
return {moduleId, Version::convertFromSignedInteger(majorVersion, minorVersion), sourceId};
}
friend bool operator==(const Import &first, const Import &second) friend bool operator==(const Import &first, const Import &second)
{ {
return first.moduleId == second.moduleId && first.version == second.version return first.moduleId == second.moduleId && first.version == second.version
@@ -157,8 +162,11 @@ class ImportView
public: public:
explicit ImportView() = default; explicit ImportView() = default;
explicit ImportView( explicit ImportView(ImportId importId,
ImportId importId, SourceId sourceId, ModuleId moduleId, int majorVersion, int minorVersion) SourceId sourceId,
ModuleId moduleId,
unsigned int majorVersion,
unsigned int minorVersion)
: importId{importId} : importId{importId}
, sourceId{sourceId} , sourceId{sourceId}
, moduleId{moduleId} , moduleId{moduleId}
@@ -267,8 +275,8 @@ public:
explicit ModuleExportedImportView(ModuleExportedImportId moduleExportedImportId, explicit ModuleExportedImportView(ModuleExportedImportId moduleExportedImportId,
ModuleId moduleId, ModuleId moduleId,
ModuleId exportedModuleId, ModuleId exportedModuleId,
int majorVersion, unsigned int majorVersion,
int minorVersion, unsigned int minorVersion,
IsAutoVersion isAutoVersion) IsAutoVersion isAutoVersion)
: moduleExportedImportId{moduleExportedImportId} : moduleExportedImportId{moduleExportedImportId}
, version{majorVersion, minorVersion} , version{majorVersion, minorVersion}
@@ -395,8 +403,8 @@ public:
explicit ExportedType(ModuleId moduleId, explicit ExportedType(ModuleId moduleId,
TypeId typeId, TypeId typeId,
::Utils::SmallStringView name, ::Utils::SmallStringView name,
int majorVersion, unsigned int majorVersion,
int minorVersion) unsigned int minorVersion)
: name{name} : name{name}
, version{majorVersion, minorVersion} , version{majorVersion, minorVersion}
, typeId{typeId} , typeId{typeId}
@@ -445,17 +453,16 @@ public:
, version{version} , version{version}
, moduleId{moduleId} , moduleId{moduleId}
{} {}
explicit ExportedTypeView(ModuleId moduleId, explicit ExportedTypeView(ModuleId moduleId,
::Utils::SmallStringView name, ::Utils::SmallStringView name,
int majorVersion, unsigned int majorVersion,
int minorVersion, unsigned int minorVersion,
TypeId typeId, TypeId typeId)
ExportedTypeNameId exportedTypeNameId)
: name{name} : name{name}
, version{majorVersion, minorVersion} , version{majorVersion, minorVersion}
, typeId{typeId} , typeId{typeId}
, moduleId{moduleId} , moduleId{moduleId}
, exportedTypeNameId{exportedTypeNameId}
{} {}
template<typename String> template<typename String>
@@ -466,8 +473,7 @@ public:
auto dict = dictonary(keyValue("name", exportedType.name), auto dict = dictonary(keyValue("name", exportedType.name),
keyValue("module id", exportedType.moduleId), keyValue("module id", exportedType.moduleId),
keyValue("type id", exportedType.typeId), keyValue("type id", exportedType.typeId),
keyValue("version", exportedType.version), keyValue("version", exportedType.version));
keyValue("version", exportedType.exportedTypeNameId));
convertToString(string, dict); convertToString(string, dict);
} }
@@ -477,7 +483,6 @@ public:
Storage::Version version; Storage::Version version;
TypeId typeId; TypeId typeId;
ModuleId moduleId; ModuleId moduleId;
ExportedTypeNameId exportedTypeNameId;
}; };
using ImportedTypeName = std::variant<ImportedType, QualifiedImportedType>; using ImportedTypeName = std::variant<ImportedType, QualifiedImportedType>;

View File

@@ -158,8 +158,15 @@ void addSourceIds(SourceIds &sourceIds,
Storage::Version convertVersion(QTypeRevision version) Storage::Version convertVersion(QTypeRevision version)
{ {
return Storage::Version{version.hasMajorVersion() ? version.majorVersion() : -1, using Storage::Version;
version.hasMinorVersion() ? version.minorVersion() : -1}; using Storage::VersionNumber;
return Version{version.hasMajorVersion()
? VersionNumber::convertFromSignedInteger(version.majorVersion())
: VersionNumber::noVersionNumber(),
version.hasMinorVersion()
? VersionNumber::convertFromSignedInteger(version.minorVersion())
: VersionNumber::noVersionNumber()};
} }
Storage::Synchronization::IsAutoVersion convertToIsAutoVersion(QQmlDirParser::Import::Flags flags, Storage::Synchronization::IsAutoVersion convertToIsAutoVersion(QQmlDirParser::Import::Flags flags,
@@ -1431,7 +1438,8 @@ Storage::Synchronization::ExportedTypes createExportedTypes(ProjectStorageUpdate
for (const ProjectStorageUpdater::Component &component : components) { for (const ProjectStorageUpdater::Component &component : components) {
exportedTypes.emplace_back(component.moduleId, exportedTypes.emplace_back(component.moduleId,
Utils::SmallString{component.typeName}, Utils::SmallString{component.typeName},
Storage::Version{component.majorVersion, component.minorVersion}); Storage::Version::convertFromSignedInteger(component.majorVersion,
component.minorVersion));
} }
removeDuplicates(exportedTypes); removeDuplicates(exportedTypes);

View File

@@ -37,15 +37,9 @@ namespace {
using QualifiedImports = std::map<QString, Storage::Import>; using QualifiedImports = std::map<QString, Storage::Import>;
int convertVersionNumber(qint32 versionNumber)
{
return versionNumber < 0 ? -1 : versionNumber;
}
Storage::Version convertVersion(QmlDom::Version version) Storage::Version convertVersion(QmlDom::Version version)
{ {
return Storage::Version{convertVersionNumber(version.majorVersion), return Storage::Version::convertFromSignedInteger(version.majorVersion, version.minorVersion);
convertVersionNumber(version.minorVersion)};
} }
Utils::PathString createNormalizedPath(Utils::SmallStringView directoryPath, Utils::PathString createNormalizedPath(Utils::SmallStringView directoryPath,

View File

@@ -21,6 +21,7 @@ using QmlDesigner::ModelNodes;
using QmlDesigner::Storage::ModuleKind; using QmlDesigner::Storage::ModuleKind;
using QmlDesigner::Storage::TypeTraits; using QmlDesigner::Storage::TypeTraits;
using QmlDesigner::Storage::TypeTraitsKind; using QmlDesigner::Storage::TypeTraitsKind;
using QmlDesigner::Storage::VersionNumber;
template<typename Matcher> template<typename Matcher>
auto PropertyId(const Matcher &matcher) auto PropertyId(const Matcher &matcher)
@@ -2487,21 +2488,27 @@ TEST_F(NodeMetaInfo, default_is_not_enumeration)
TEST_F(NodeMetaInfo, all_external_type_names) TEST_F(NodeMetaInfo, all_external_type_names)
{ {
auto metaInfo = createMetaInfo("QML", ModuleKind::QmlLibrary, "Foo"); auto metaInfo = createMetaInfo("QML", ModuleKind::QmlLibrary, "Foo");
QmlDesigner::Storage::Info::ExportedTypeNames names{{qmlModuleId, metaInfo.id(), "Object", 2, -1}, QmlDesigner::Storage::Info::ExportedTypeNames names{
{qmlModuleId, metaInfo.id(), "Object", 2, VersionNumber::noVersion},
{qmlModuleId, metaInfo.id(), "Obj", 2, 1}}; {qmlModuleId, metaInfo.id(), "Obj", 2, 1}};
ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id())).WillByDefault(Return(names)); ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id())).WillByDefault(Return(names));
auto exportedTypeNames = metaInfo.allExportedTypeNames(); auto exportedTypeNames = metaInfo.allExportedTypeNames();
ASSERT_THAT(exportedTypeNames, ASSERT_THAT(exportedTypeNames,
UnorderedElementsAre(IsInfoExportTypeName(qmlModuleId, metaInfo.id(), "Object", 2, -1), UnorderedElementsAre(IsInfoExportTypeName(qmlModuleId,
metaInfo.id(),
"Object",
2,
VersionNumber::noVersion),
IsInfoExportTypeName(qmlModuleId, metaInfo.id(), "Obj", 2, 1))); IsInfoExportTypeName(qmlModuleId, metaInfo.id(), "Obj", 2, 1)));
} }
TEST_F(NodeMetaInfo, default_has_no_external_type_names) TEST_F(NodeMetaInfo, default_has_no_external_type_names)
{ {
QmlDesigner::NodeMetaInfo metaInfo; QmlDesigner::NodeMetaInfo metaInfo;
QmlDesigner::Storage::Info::ExportedTypeNames names{{qmlModuleId, metaInfo.id(), "Object", 2, -1}, QmlDesigner::Storage::Info::ExportedTypeNames names{
{qmlModuleId, metaInfo.id(), "Object", 2, VersionNumber::noVersion},
{qmlModuleId, metaInfo.id(), "Obj", 2, 1}}; {qmlModuleId, metaInfo.id(), "Obj", 2, 1}};
ON_CALL(projectStorageMock, exportedTypeNames(_)).WillByDefault(Return(names)); ON_CALL(projectStorageMock, exportedTypeNames(_)).WillByDefault(Return(names));
@@ -2513,7 +2520,8 @@ TEST_F(NodeMetaInfo, default_has_no_external_type_names)
TEST_F(NodeMetaInfo, external_type_names_for_source_id) TEST_F(NodeMetaInfo, external_type_names_for_source_id)
{ {
auto metaInfo = createMetaInfo("QML", ModuleKind::QmlLibrary, "Foo"); auto metaInfo = createMetaInfo("QML", ModuleKind::QmlLibrary, "Foo");
QmlDesigner::Storage::Info::ExportedTypeNames names{{qmlModuleId, metaInfo.id(), "Object", 2, -1}, QmlDesigner::Storage::Info::ExportedTypeNames names{
{qmlModuleId, metaInfo.id(), "Object", 2, VersionNumber::noVersion},
{qmlModuleId, metaInfo.id(), "Obj", 2, 1}}; {qmlModuleId, metaInfo.id(), "Obj", 2, 1}};
ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id(), model.fileUrlSourceId())) ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id(), model.fileUrlSourceId()))
.WillByDefault(Return(names)); .WillByDefault(Return(names));
@@ -2521,14 +2529,19 @@ TEST_F(NodeMetaInfo, external_type_names_for_source_id)
auto exportedTypeNames = metaInfo.exportedTypeNamesForSourceId(model.fileUrlSourceId()); auto exportedTypeNames = metaInfo.exportedTypeNamesForSourceId(model.fileUrlSourceId());
ASSERT_THAT(exportedTypeNames, ASSERT_THAT(exportedTypeNames,
UnorderedElementsAre(IsInfoExportTypeName(qmlModuleId, metaInfo.id(), "Object", 2, -1), UnorderedElementsAre(IsInfoExportTypeName(qmlModuleId,
metaInfo.id(),
"Object",
2,
VersionNumber::noVersion),
IsInfoExportTypeName(qmlModuleId, metaInfo.id(), "Obj", 2, 1))); IsInfoExportTypeName(qmlModuleId, metaInfo.id(), "Obj", 2, 1)));
} }
TEST_F(NodeMetaInfo, default_has_no_external_type_names_for_source_id) TEST_F(NodeMetaInfo, default_has_no_external_type_names_for_source_id)
{ {
QmlDesigner::NodeMetaInfo metaInfo; QmlDesigner::NodeMetaInfo metaInfo;
QmlDesigner::Storage::Info::ExportedTypeNames names{{qmlModuleId, metaInfo.id(), "Object", 2, -1}, QmlDesigner::Storage::Info::ExportedTypeNames names{
{qmlModuleId, metaInfo.id(), "Object", 2, VersionNumber::noVersion},
{qmlModuleId, metaInfo.id(), "Obj", 2, 1}}; {qmlModuleId, metaInfo.id(), "Obj", 2, 1}};
ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id(), model.fileUrlSourceId())) ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id(), model.fileUrlSourceId()))
.WillByDefault(Return(names)); .WillByDefault(Return(names));
@@ -2541,7 +2554,8 @@ TEST_F(NodeMetaInfo, default_has_no_external_type_names_for_source_id)
TEST_F(NodeMetaInfo, invalid_source_id_has_no_external_type_names_for_source_id) TEST_F(NodeMetaInfo, invalid_source_id_has_no_external_type_names_for_source_id)
{ {
auto metaInfo = createMetaInfo("QML", ModuleKind::QmlLibrary, "Foo"); auto metaInfo = createMetaInfo("QML", ModuleKind::QmlLibrary, "Foo");
QmlDesigner::Storage::Info::ExportedTypeNames names{{qmlModuleId, metaInfo.id(), "Object", 2, -1}, QmlDesigner::Storage::Info::ExportedTypeNames names{
{qmlModuleId, metaInfo.id(), "Object", 2, VersionNumber::noVersion},
{qmlModuleId, metaInfo.id(), "Obj", 2, 1}}; {qmlModuleId, metaInfo.id(), "Obj", 2, 1}};
ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id(), model.fileUrlSourceId())) ON_CALL(projectStorageMock, exportedTypeNames(metaInfo.id(), model.fileUrlSourceId()))
.WillByDefault(Return(names)); .WillByDefault(Return(names));

View File

@@ -19,21 +19,22 @@
namespace { namespace {
using QmlDesigner::DirectoryPathId;
using QmlDesigner::DirectoryPathIds;
using QmlDesigner::FileNameId;
using QmlDesigner::FileStatus; using QmlDesigner::FileStatus;
using QmlDesigner::FileStatuses; using QmlDesigner::FileStatuses;
using QmlDesigner::FlagIs; using QmlDesigner::FlagIs;
using QmlDesigner::ModuleId; using QmlDesigner::ModuleId;
using QmlDesigner::PropertyDeclarationId; using QmlDesigner::PropertyDeclarationId;
using QmlDesigner::DirectoryPathId;
using QmlDesigner::DirectoryPathIds;
using QmlDesigner::SourceId; using QmlDesigner::SourceId;
using QmlDesigner::SourceIds; using QmlDesigner::SourceIds;
using QmlDesigner::FileNameId;
using QmlDesigner::Storage::ModuleKind; using QmlDesigner::Storage::ModuleKind;
using QmlDesigner::Storage::Synchronization::SynchronizationPackage; using QmlDesigner::Storage::Synchronization::SynchronizationPackage;
using QmlDesigner::Storage::Synchronization::TypeAnnotations; using QmlDesigner::Storage::Synchronization::TypeAnnotations;
using QmlDesigner::Storage::TypeTraits; using QmlDesigner::Storage::TypeTraits;
using QmlDesigner::Storage::TypeTraitsKind; using QmlDesigner::Storage::TypeTraitsKind;
using QmlDesigner::Storage::VersionNumber;
using QmlDesigner::TypeId; using QmlDesigner::TypeId;
namespace Storage = QmlDesigner::Storage; namespace Storage = QmlDesigner::Storage;
@@ -5772,7 +5773,7 @@ TEST_F(ProjectStorage, minimal_updates)
TypeTraitsKind::Reference), TypeTraitsKind::Reference),
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Storage::Synchronization::Type::exportedTypes, &Storage::Synchronization::Type::exportedTypes,
UnorderedElementsAre(IsExportedType(qtQuickModuleId, "Item", 2, 0), UnorderedElementsAre(IsExportedType(qtQuickModuleId, "Item", 2U, 0U),
IsExportedType(qtQuickNativeModuleId, IsExportedType(qtQuickNativeModuleId,
"QQuickItem"))), "QQuickItem"))),
Field("Type::propertyDeclarations", Field("Type::propertyDeclarations",
@@ -8224,9 +8225,14 @@ TEST_F(ProjectStorage, get_exported_type_names)
auto exportedTypeNames = storage.exportedTypeNames(typeId); auto exportedTypeNames = storage.exportedTypeNames(typeId);
ASSERT_THAT(exportedTypeNames, ASSERT_THAT(exportedTypeNames,
UnorderedElementsAre(IsInfoExportTypeName(qmlModuleId, typeId, "Object", 2, -1), UnorderedElementsAre(
IsInfoExportTypeName(qmlModuleId, typeId, "Obj", 2, -1), IsInfoExportTypeName(qmlModuleId, typeId, "Object", 2U, VersionNumber::noVersion),
IsInfoExportTypeName(qmlNativeModuleId, typeId, "QObject", -1, -1))); IsInfoExportTypeName(qmlModuleId, typeId, "Obj", 2U, VersionNumber::noVersion),
IsInfoExportTypeName(qmlNativeModuleId,
typeId,
"QObject",
VersionNumber::noVersion,
VersionNumber::noVersion)));
} }
TEST_F(ProjectStorage, get_no_exported_type_names_if_type_id_is_invalid) TEST_F(ProjectStorage, get_no_exported_type_names_if_type_id_is_invalid)
@@ -8250,8 +8256,9 @@ TEST_F(ProjectStorage, get_exported_type_names_for_source_id)
auto exportedTypeNames = storage.exportedTypeNames(typeId, sourceId3); auto exportedTypeNames = storage.exportedTypeNames(typeId, sourceId3);
ASSERT_THAT(exportedTypeNames, ASSERT_THAT(exportedTypeNames,
UnorderedElementsAre(IsInfoExportTypeName(qmlModuleId, typeId, "Object", 2, -1), UnorderedElementsAre(
IsInfoExportTypeName(qmlModuleId, typeId, "Obj", 2, -1))); IsInfoExportTypeName(qmlModuleId, typeId, "Object", 2U, VersionNumber::noVersion),
IsInfoExportTypeName(qmlModuleId, typeId, "Obj", 2U, VersionNumber::noVersion)));
} }
TEST_F(ProjectStorage, get_no_exported_type_names_for_source_id_for_invalid_type_id) TEST_F(ProjectStorage, get_no_exported_type_names_for_source_id_for_invalid_type_id)

View File

@@ -89,6 +89,7 @@ using Storage::Synchronization::Type;
using Storage::TypeTraits; using Storage::TypeTraits;
using Storage::TypeTraitsKind; using Storage::TypeTraitsKind;
using Storage::Version; using Storage::Version;
using Storage::VersionNumber;
using FileState = QmlDesigner::ProjectStorageUpdater::FileState; using FileState = QmlDesigner::ProjectStorageUpdater::FileState;
using Update = QmlDesigner::ProjectStorageUpdater::Update; using Update = QmlDesigner::ProjectStorageUpdater::Update;
using IsInsideProject = QmlDesigner::QmlDocumentParserInterface::IsInsideProject; using IsInsideProject = QmlDesigner::QmlDocumentParserInterface::IsInsideProject;
@@ -1806,8 +1807,7 @@ TEST_P(synchronize_changed_qml_documents, types)
EXPECT_CALL( EXPECT_CALL(
projectStorageMock, projectStorageMock,
synchronize(AllOf( synchronize(AllOf(
Field( Field(&SynchronizationPackage::types,
&SynchronizationPackage::types,
UnorderedElementsAre( UnorderedElementsAre(
AllOf(IsStorageType("First.qml", AllOf(IsStorageType("First.qml",
ImportedType{"Object"}, ImportedType{"Object"},
@@ -1816,8 +1816,11 @@ TEST_P(synchronize_changed_qml_documents, types)
ChangeLevel::Full), ChangeLevel::Full),
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1U, 0U),
IsExportedType(pathModuleId, "First", -1, -1)))), IsExportedType(pathModuleId,
"First",
VersionNumber::noVersion,
VersionNumber::noVersion)))),
AllOf(IsStorageType("First2.qml", AllOf(IsStorageType("First2.qml",
ImportedType{"Object2"}, ImportedType{"Object2"},
TypeTraitsKind::Reference, TypeTraitsKind::Reference,
@@ -1825,8 +1828,11 @@ TEST_P(synchronize_changed_qml_documents, types)
ChangeLevel::Full), ChangeLevel::Full),
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 2U, 2U),
IsExportedType(pathModuleId, "First2", -1, -1)))), IsExportedType(pathModuleId,
"First2",
VersionNumber::noVersion,
VersionNumber::noVersion)))),
AllOf(IsStorageType("Second.qml", AllOf(IsStorageType("Second.qml",
ImportedType{"Object3"}, ImportedType{"Object3"},
TypeTraitsKind::Reference, TypeTraitsKind::Reference,
@@ -1834,8 +1840,11 @@ TEST_P(synchronize_changed_qml_documents, types)
ChangeLevel::Full), ChangeLevel::Full),
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType(exampleModuleId, "SecondType", 2, 2), UnorderedElementsAre(IsExportedType(exampleModuleId, "SecondType", 2U, 2U),
IsExportedType(pathModuleId, "Second", -1, -1)))))), IsExportedType(pathModuleId,
"Second",
VersionNumber::noVersion,
VersionNumber::noVersion)))))),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,
IsSupersetOf({qmlDocument1SourceId, qmlDocument1_2SourceId, qmlDocument2SourceId}))))); IsSupersetOf({qmlDocument1SourceId, qmlDocument1_2SourceId, qmlDocument2SourceId})))));
@@ -2091,12 +2100,13 @@ TEST_P(synchronize_changed_qml_documents, types_in_qmldir_only)
} }
setQmlFileNames(u"/path", {"First.qml"}); setQmlFileNames(u"/path", {"First.qml"});
EXPECT_CALL(projectStorageMock, EXPECT_CALL(
projectStorageMock,
synchronize( synchronize(
AllOf(Field("SynchronizationPackage::types", AllOf(Field("SynchronizationPackage::types",
&SynchronizationPackage::types, &SynchronizationPackage::types,
AllOf(Contains(AllOf( AllOf(Contains(
IsStorageType("First.qml", AllOf(IsStorageType("First.qml",
ImportedType{}, ImportedType{},
TypeTraitsKind::None, TypeTraitsKind::None,
qmlDocument1SourceId, qmlDocument1SourceId,
@@ -2104,8 +2114,11 @@ TEST_P(synchronize_changed_qml_documents, types_in_qmldir_only)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(pathModuleId, "First", -1, -1), IsExportedType(pathModuleId,
IsExportedType(exampleModuleId, "FirstType", 1, 0))))))), "First",
VersionNumber::noVersion,
VersionNumber::noVersion),
IsExportedType(exampleModuleId, "FirstType", 1U, 0U))))))),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,
Contains(qmlDocument1SourceId))))); Contains(qmlDocument1SourceId)))));
@@ -2196,8 +2209,8 @@ TEST_P(synchronize_changed_qml_documents, types_without_qmldir)
EXPECT_CALL( EXPECT_CALL(
projectStorageMock, projectStorageMock,
synchronize( synchronize(AllOf(
AllOf(Field("SynchronizationPackage::types", Field("SynchronizationPackage::types",
&SynchronizationPackage::types, &SynchronizationPackage::types,
AllOf(Not(Contains(Field("Type::typeName", &Type::typeName, "First.qml"))), AllOf(Not(Contains(Field("Type::typeName", &Type::typeName, "First.qml"))),
Contains(AllOf(IsStorageType("First2.qml", Contains(AllOf(IsStorageType("First2.qml",
@@ -2208,8 +2221,11 @@ TEST_P(synchronize_changed_qml_documents, types_without_qmldir)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
Conditional(isAdded, Conditional(isAdded,
UnorderedElementsAre(IsExportedType( UnorderedElementsAre(
pathModuleId, "First2", -1, -1)), IsExportedType(pathModuleId,
"First2",
VersionNumber::noVersion,
VersionNumber::noVersion)),
IsEmpty())))))), IsEmpty())))))),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,
@@ -2480,8 +2496,8 @@ TEST_P(synchronize_not_existing_qml_documents, types_in_qmldir_only)
EXPECT_CALL( EXPECT_CALL(
projectStorageMock, projectStorageMock,
synchronize(AllOf( synchronize(
Field("SynchronizationPackage::types", AllOf(Field("SynchronizationPackage::types",
&SynchronizationPackage::types, &SynchronizationPackage::types,
Conditional(isRemoved, Conditional(isRemoved,
UnorderedElementsAre( UnorderedElementsAre(
@@ -2493,7 +2509,10 @@ TEST_P(synchronize_not_existing_qml_documents, types_in_qmldir_only)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(pathModuleId, "First", -1, -1)))), IsExportedType(pathModuleId,
"First",
VersionNumber::noVersion,
VersionNumber::noVersion)))),
AllOf(IsStorageType("First2.qml", AllOf(IsStorageType("First2.qml",
ImportedType{}, ImportedType{},
TypeTraits{}, TypeTraits{},
@@ -2502,7 +2521,10 @@ TEST_P(synchronize_not_existing_qml_documents, types_in_qmldir_only)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(pathModuleId, "First2", -1, -1)))), IsExportedType(pathModuleId,
"First2",
VersionNumber::noVersion,
VersionNumber::noVersion)))),
AllOf(IsStorageType("Second.qml", AllOf(IsStorageType("Second.qml",
ImportedType{}, ImportedType{},
TypeTraits{}, TypeTraits{},
@@ -2511,13 +2533,17 @@ TEST_P(synchronize_not_existing_qml_documents, types_in_qmldir_only)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(pathModuleId, "Second", -1, -1))))), IsExportedType(pathModuleId,
"Second",
VersionNumber::noVersion,
VersionNumber::noVersion))))),
IsEmpty())), IsEmpty())),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,
Conditional(isRemoved, Conditional(isRemoved,
IsSupersetOf( IsSupersetOf({qmlDocument1SourceId,
{qmlDocument1SourceId, qmlDocument1_2SourceId, qmlDocument2SourceId}), qmlDocument1_2SourceId,
qmlDocument2SourceId}),
IsEmpty()))))); IsEmpty())))));
updater.update(update); updater.update(update);
@@ -2683,7 +2709,7 @@ TEST_P(synchronize_not_existing_qml_documents, without_parsed_type_if_qml_docume
Contains(Field("Type::exportedTypes", Contains(Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType( UnorderedElementsAre(IsExportedType(
exampleModuleId, "FirstType", 1, 0)))), exampleModuleId, "FirstType", 1U, 0U)))),
IsEmpty())), IsEmpty())),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,
@@ -2759,10 +2785,13 @@ TEST_F(ProjectStorageUpdater_synchronize_qml_documents,
UnorderedElementsAre( UnorderedElementsAre(
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1U, 0U),
IsExportedType(exampleModuleId, "FirstType", 1, 1), IsExportedType(exampleModuleId, "FirstType", 1U, 1U),
IsExportedType(exampleModuleId, "FirstType", 6, 0), IsExportedType(exampleModuleId, "FirstType", 6U, 0U),
IsExportedType(pathModuleId, "First", -1, -1)))))))); IsExportedType(pathModuleId,
"First",
VersionNumber::noVersion,
VersionNumber::noVersion))))))));
updater.update({.projectDirectory = "/path"}); updater.update({.projectDirectory = "/path"});
} }
@@ -2785,9 +2814,12 @@ TEST_F(ProjectStorageUpdater_synchronize_qml_documents,
UnorderedElementsAre( UnorderedElementsAre(
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1U, 0U),
IsExportedType(exampleModuleId, "FirstType2", 1, 0), IsExportedType(exampleModuleId, "FirstType2", 1U, 0U),
IsExportedType(pathModuleId, "First", -1, -1)))))))); IsExportedType(pathModuleId,
"First",
VersionNumber::noVersion,
VersionNumber::noVersion))))))));
updater.update({.projectDirectory = "/path"}); updater.update({.projectDirectory = "/path"});
} }
@@ -2806,7 +2838,7 @@ TEST_F(ProjectStorageUpdater_synchronize_qml_documents, dont_synchronize_selecto
&SynchronizationPackage::types, &SynchronizationPackage::types,
Contains(Field("Type::exportedTypes", Contains(Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
Contains(IsExportedType(exampleModuleId, "FirstType", 1, 0)))))))); Contains(IsExportedType(exampleModuleId, "FirstType", 1U, 0U))))))));
updater.update({.qtDirectories = {"/path"}}); updater.update({.qtDirectories = {"/path"}});
} }
@@ -3499,8 +3531,11 @@ TEST_P(watcher_document_changes, types)
Conditional(isDirectorAndQmldirUnchanged, Conditional(isDirectorAndQmldirUnchanged,
IsEmpty(), IsEmpty(),
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(exampleModuleId, "FirstType", 1, 0), IsExportedType(exampleModuleId, "FirstType", 1U, 0U),
IsExportedType(pathModuleId, "First", -1, -1))))), IsExportedType(pathModuleId,
"First",
VersionNumber::noVersion,
VersionNumber::noVersion))))),
AllOf(Conditional(isDocumentUnchanged, AllOf(Conditional(isDocumentUnchanged,
IsStorageType("Second.qml", IsStorageType("Second.qml",
ImportedType{}, ImportedType{},
@@ -3520,10 +3555,16 @@ TEST_P(watcher_document_changes, types)
Conditional( Conditional(
noSecondTypeInQmldir, noSecondTypeInQmldir,
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(pathModuleId, "Second", -1, -1)), IsExportedType(pathModuleId,
"Second",
VersionNumber::noVersion,
VersionNumber::noVersion)),
UnorderedElementsAre( UnorderedElementsAre(
IsExportedType(exampleModuleId, "SecondType", 2, 2), IsExportedType(exampleModuleId, "SecondType", 2U, 2U),
IsExportedType(pathModuleId, "Second", -1, -1))))))))), IsExportedType(pathModuleId,
"Second",
VersionNumber::noVersion,
VersionNumber::noVersion))))))))),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,
Conditional(isIgnoredPartId, Conditional(isIgnoredPartId,
@@ -3786,7 +3827,7 @@ TEST_P(watcher_document_not_existing, types)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType( UnorderedElementsAre(IsExportedType(
exampleModuleId, "FirstType", 1, 0))))), exampleModuleId, "FirstType", 1U, 0U))))),
Contains(AllOf(IsStorageType("Second.qml", Contains(AllOf(IsStorageType("Second.qml",
ImportedType{}, ImportedType{},
TypeTraitsKind::None, TypeTraitsKind::None,
@@ -3795,7 +3836,7 @@ TEST_P(watcher_document_not_existing, types)
Field("Type::exportedTypes", Field("Type::exportedTypes",
&Type::exportedTypes, &Type::exportedTypes,
UnorderedElementsAre(IsExportedType( UnorderedElementsAre(IsExportedType(
exampleModuleId, "SecondType", 2, 2))))) exampleModuleId, "SecondType", 2U, 2U)))))
.Times(noSecondTypeInQmldir ? 0 : 1)))), .Times(noSecondTypeInQmldir ? 0 : 1)))),
Field("SynchronizationPackage::updatedSourceIds", Field("SynchronizationPackage::updatedSourceIds",
&SynchronizationPackage::updatedSourceIds, &SynchronizationPackage::updatedSourceIds,