From d92043e69c7fd42183ba82a103e4b5eaef341667 Mon Sep 17 00:00:00 2001 From: Burak Hancerli Date: Mon, 16 Oct 2023 14:22:53 +0200 Subject: [PATCH] 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 Reviewed-by: Qt CI Patch Build Bot --- src/plugins/projectexplorer/project.h | 3 ++- src/plugins/projectexplorer/projectmodels.cpp | 4 +++- src/plugins/projectexplorer/projectnodes.cpp | 11 +++++++++++ src/plugins/projectexplorer/projectnodes.h | 4 ++++ src/plugins/projectexplorer/projecttreewidget.cpp | 12 +++++++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 40b26d6faa0..e1bf1eb7b02 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -49,7 +49,8 @@ public: enum ModelRoles { // Absolute file path FilePathRole = QFileSystemModel::FilePathRole, - isParsingRole + isParsingRole, + UseUnavailableMarkerRole, }; Project(const QString &mimeType, const Utils::FilePath &fileName); diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index 0af76f1bbef..f824a19cc91 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -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 - diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 11ab5fe0561..e1edbd7d930 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -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); diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index 5e424b62bbc..9d159aeea35 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -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. diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index cb505a43a7c..a173b77c22a 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -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);