ProjectExplorer: Overlay the original icon for missing files

QmlProject could be edited manually to add files into the project.
In case of the files are mising in the file system (or if there's
a typo in the file path) file names still shown in the project
explorer without any information. This patch brings a small overlay
on top of the original icon to notify the users that the file doesn't
exist.

Task-number: QDS-10344
Change-Id: Ia73699b048725bcc70a1ee0f52c34b55b081a779
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Burak Hancerli
2023-10-16 14:22:53 +02:00
parent c524cf62e1
commit d92043e69c
5 changed files with 31 additions and 3 deletions

View File

@@ -49,7 +49,8 @@ public:
enum ModelRoles {
// Absolute file path
FilePathRole = QFileSystemModel::FilePathRole,
isParsingRole
isParsingRole,
UseUnavailableMarkerRole,
};
Project(const QString &mimeType, const Utils::FilePath &fileName);

View File

@@ -193,6 +193,7 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
return {};
const FolderNode * const folderNode = node->asFolderNode();
const FileNode * const fileNode = node->asFileNode();
const ContainerNode * const containerNode = node->asContainerNode();
const Project * const project = containerNode ? containerNode->project() : nullptr;
const Target * const target = project ? project->activeTarget() : nullptr;
@@ -246,6 +247,8 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
return node->filePath().toString();
case Project::isParsingRole:
return project && bs ? bs->isParsing() && !project->needsConfiguration() : false;
case Project::UseUnavailableMarkerRole:
return fileNode ? fileNode->useUnavailableMarker() : false;
}
return {};
}
@@ -923,4 +926,3 @@ const QLoggingCategory &FlatModel::logger()
} // namespace Internal
} // namespace ProjectExplorer

View File

@@ -260,6 +260,16 @@ void FileNode::setHasError(bool error) const
m_hasError = error;
}
bool FileNode::useUnavailableMarker() const
{
return m_useUnavailableMarker;
}
void FileNode::setUseUnavailableMarker(bool useUnavailableMarker)
{
m_useUnavailableMarker = useUnavailableMarker;
}
/*!
Returns \c true if the file is automatically generated by a compile step.
*/
@@ -382,6 +392,7 @@ FileNode::FileNode(const Utils::FilePath &filePath, const FileType fileType) :
m_fileType(fileType)
{
setFilePath(filePath);
setUseUnavailableMarker(!filePath.needsDevice() && !filePath.exists());
setListInProject(true);
if (fileType == FileType::Project)
setPriority(DefaultProjectFilePriority);

View File

@@ -204,10 +204,14 @@ public:
QIcon icon() const;
void setIcon(const QIcon icon);
bool useUnavailableMarker() const;
void setUseUnavailableMarker(bool useUnavailableMarker);
private:
FileType m_fileType;
mutable QIcon m_icon;
mutable bool m_hasError = false;
bool m_useUnavailableMarker = false;
};
// Documentation inside.

View File

@@ -72,8 +72,18 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
QStyledItemDelegate::paint(painter, option, index);
const bool useUnavailableMarker = index.data(Project::UseUnavailableMarkerRole).toBool();
if (useUnavailableMarker) {
QStyleOptionViewItem opt = option;
opt.palette.setColor(QPalette::Text, creatorTheme()->color(Theme::TextColorDisabled));
QStyledItemDelegate::paint(painter, opt, index);
static const QPixmap pixmap
= QApplication::style()->standardIcon(QStyle::SP_BrowserStop).pixmap(10);
painter->drawPixmap(option.rect.topLeft(), pixmap);
return;
}
QStyledItemDelegate::paint(painter, option, index);
if (index.data(Project::isParsingRole).toBool()) {
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);