From c46b6dbb5661e9f3d16310da381909376e8e9a6b Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 2 May 2018 09:15:49 +0200 Subject: [PATCH] Utils: Fix treemodel's hasChildren Basically this reverts 08e73d1a9336, but adds an additional check for the column as the BaseTreeModel implementation just allows children at the first column. Main reason for this revert is that the variable choosers used across Qt Creator did no more populate their respective macro lists automatically. Change-Id: I172506a9dbe18f20b152ec797f35feff717dc3cf Reviewed-by: hjk Reviewed-by: Ivan Donchevskii --- src/libs/utils/treemodel.cpp | 8 ++++++++ src/libs/utils/treemodel.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/libs/utils/treemodel.cpp b/src/libs/utils/treemodel.cpp index 0493a67a4a8..d17174a0246 100644 --- a/src/libs/utils/treemodel.cpp +++ b/src/libs/utils/treemodel.cpp @@ -1028,6 +1028,14 @@ QVariant BaseTreeModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } +bool BaseTreeModel::hasChildren(const QModelIndex &idx) const +{ + if (idx.column() > 0) + return false; + TreeItem *item = itemForIndex(idx); + return !item || item->hasChildren(); +} + Qt::ItemFlags BaseTreeModel::flags(const QModelIndex &idx) const { if (!idx.isValid()) diff --git a/src/libs/utils/treemodel.h b/src/libs/utils/treemodel.h index fd299bd9455..930f6f5e2ec 100644 --- a/src/libs/utils/treemodel.h +++ b/src/libs/utils/treemodel.h @@ -193,6 +193,7 @@ protected: QModelIndex sibling(int row, int column, const QModelIndex &idx) const override; Qt::ItemFlags flags(const QModelIndex &idx) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + bool hasChildren(const QModelIndex &idx) const override; bool canFetchMore(const QModelIndex &idx) const override; void fetchMore(const QModelIndex &idx) override;