ProjectExplorer: Guard against misuse of Node API

in QtC the only direct subclasses of Node are FileNode and FolderNode,
so that ensures that we always either have asFileNode() or
asFolderNode(), but custom subclasses could do that wrong. Warn instead
of crash in the FlatModel in that case (though there is no guarantee
that there are other places that make that assumption).

Change-Id: I29bc02116c775bc1b1068e791e08b2a7fa767917
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2025-03-17 09:36:41 +01:00
parent a106c7cc02
commit a2f4a45a1e

View File

@@ -223,8 +223,9 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
return tooltip; return tooltip;
} }
case Qt::DecorationRole: { case Qt::DecorationRole: {
QTC_ASSERT(fileNode || folderNode, return {});
if (!folderNode) if (!folderNode)
return node->asFileNode()->icon(); return fileNode->icon();
if (!project) if (!project)
return folderNode->icon(); return folderNode->icon();
static QIcon warnIcon = Utils::Icons::WARNING.icon(); static QIcon warnIcon = Utils::Icons::WARNING.icon();