forked from qt-creator/qt-creator
QmlDesigner: Add Model::allItemLibraryEntries and use it in item lib
Item library now allows searching for non-imported items also in project storage builds. Fixes: QDS-14849 Change-Id: I6eb5de7d55b8d07c2406242a3ec4c259b1e16302 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
committed by
Marco Bubke
parent
5ca2f1d612
commit
92e969361a
@@ -358,15 +358,14 @@ void ItemLibraryModel::update(Model *model)
|
|||||||
itemLibImport->setImportExpanded(loadExpandedState(itemLibImport->importUrl()));
|
itemLibImport->setImportExpanded(loadExpandedState(itemLibImport->importUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QDS_USE_PROJECTSTORAGE
|
|
||||||
DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||||
const bool blockNewImports = document->inFileComponentModelActive();
|
const bool blockNewImports = document->inFileComponentModelActive();
|
||||||
#endif
|
|
||||||
|
|
||||||
TypeName currentFileType = QFileInfo(model->fileUrl().toLocalFile()).baseName().toUtf8();
|
TypeName currentFileType = QFileInfo(model->fileUrl().toLocalFile()).baseName().toUtf8();
|
||||||
|
|
||||||
const QList<ItemLibraryEntry> itemLibEntries = model->itemLibraryEntries();
|
QList<ItemLibraryEntry> itemLibEntries = model->allItemLibraryEntries();
|
||||||
for (const ItemLibraryEntry &entry : itemLibEntries) {
|
itemLibEntries.append(model->directoryImportsItemLibraryEntries());
|
||||||
|
for (const ItemLibraryEntry &entry : std::as_const(itemLibEntries)) {
|
||||||
NodeMetaInfo metaInfo;
|
NodeMetaInfo metaInfo;
|
||||||
|
|
||||||
#ifdef QDS_USE_PROJECTSTORAGE
|
#ifdef QDS_USE_PROJECTSTORAGE
|
||||||
@@ -407,15 +406,14 @@ void ItemLibraryModel::update(Model *model)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QDS_USE_PROJECTSTORAGE
|
|
||||||
Import import = entryToImport(entry);
|
Import import = entryToImport(entry);
|
||||||
bool hasImport = model->hasImport(import, true, true);
|
bool hasImport = model->hasImport(import, true, true);
|
||||||
|
#ifndef QDS_USE_PROJECTSTORAGE
|
||||||
bool isImportPossible = false;
|
bool isImportPossible = false;
|
||||||
if (!hasImport)
|
if (!hasImport)
|
||||||
isImportPossible = !blockNewImports && model->isImportPossible(import, true, true);
|
isImportPossible = !blockNewImports && model->isImportPossible(import, true, true);
|
||||||
#else
|
#else
|
||||||
bool hasImport = true;
|
bool isImportPossible = !blockNewImports;
|
||||||
bool isImportPossible = false;
|
|
||||||
#endif
|
#endif
|
||||||
bool isUsable = (valid && (isItem || forceVisibility))
|
bool isUsable = (valid && (isItem || forceVisibility))
|
||||||
&& (entry.requiredImport().isEmpty() || hasImport);
|
&& (entry.requiredImport().isEmpty() || hasImport);
|
||||||
|
@@ -210,6 +210,7 @@ public:
|
|||||||
|
|
||||||
QList<ItemLibraryEntry> itemLibraryEntries() const;
|
QList<ItemLibraryEntry> itemLibraryEntries() const;
|
||||||
QList<ItemLibraryEntry> directoryImportsItemLibraryEntries() const;
|
QList<ItemLibraryEntry> directoryImportsItemLibraryEntries() const;
|
||||||
|
QList<ItemLibraryEntry> allItemLibraryEntries() const;
|
||||||
|
|
||||||
void attachView(AbstractView *view);
|
void attachView(AbstractView *view);
|
||||||
void detachView(AbstractView *view, ViewNotification emitDetachNotify = NotifyView);
|
void detachView(AbstractView *view, ViewNotification emitDetachNotify = NotifyView);
|
||||||
|
@@ -2830,6 +2830,16 @@ QList<ItemLibraryEntry> Model::directoryImportsItemLibraryEntries() const
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ItemLibraryEntry> Model::allItemLibraryEntries() const
|
||||||
|
{
|
||||||
|
#ifdef QDS_USE_PROJECTSTORAGE
|
||||||
|
using namespace Storage::Info;
|
||||||
|
return toItemLibraryEntries(*d->pathCache, d->projectStorage->allItemLibraryEntries());
|
||||||
|
#else
|
||||||
|
return d->metaInfo().itemLibraryInfo()->entries();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
NodeMetaInfo Model::qtQuickTimelineKeyframeGroupMetaInfo() const
|
NodeMetaInfo Model::qtQuickTimelineKeyframeGroupMetaInfo() const
|
||||||
{
|
{
|
||||||
if constexpr (useProjectStorage()) {
|
if constexpr (useProjectStorage()) {
|
||||||
|
@@ -1363,6 +1363,36 @@ TEST_F(Model_TypeAnnotation, directory_imports_item_library_entries)
|
|||||||
ElementsAre(IsItemLibraryProperty("x", "double"_L1, QVariant{1})),
|
ElementsAre(IsItemLibraryProperty("x", "double"_L1, QVariant{1})),
|
||||||
ElementsAre(u"/extra/file/path"))));
|
ElementsAre(u"/extra/file/path"))));
|
||||||
}
|
}
|
||||||
|
TEST_F(Model_TypeAnnotation, all_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");
|
||||||
|
ON_CALL(projectStorageMock, allItemLibraryEntries()).WillByDefault(Return(storageEntries));
|
||||||
|
|
||||||
|
auto entries = model.allItemLibraryEntries();
|
||||||
|
|
||||||
|
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
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user