QmlDesigner: Do not show icons for the itemlibrary in resources

Everything that is in or below a designer folder with a *.metainfo file
is not supposed to show up in the resource browser.
The code is written very defensive way and we check a maximum
of 3 directories above the current file.

Change-Id: I14b3ae8a7e47208e15e9adfc1696c531a8589231
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2018-03-15 12:38:33 +01:00
parent 12398a4abe
commit aa75c6ebed

View File

@@ -88,6 +88,33 @@ void CustomFileSystemModel::setFilter(QDir::Filters)
}
QString filterMetaIcons(const QString fileName)
{
QFileInfo info(fileName);
if (info.dir().path().split("/").contains("designer")) {
QDir currentDir = info.dir();
int i = 0;
while (!currentDir.isRoot() && i < 3) {
if (currentDir.dirName() == "designer") {
if (!currentDir.entryList({"*.metainfo"}).isEmpty())
return {};
}
currentDir.cdUp();
++i;
}
if (info.dir().dirName() == "designer")
return {};
}
return fileName;
}
QModelIndex CustomFileSystemModel::setRootPath(const QString &newPath)
{
beginResetModel();
@@ -114,7 +141,7 @@ QModelIndex CustomFileSystemModel::setRootPath(const QString &newPath)
QDirIterator fileIterator(newPath, nameFilterList, QDir::Files, QDirIterator::Subdirectories);
while (fileIterator.hasNext())
m_files.append(fileIterator.next());
m_files.append(filterMetaIcons(fileIterator.next()));
QDirIterator dirIterator(newPath, {}, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (dirIterator.hasNext())