Utils: Fix treemodel's hasChildren

Basically this reverts 08e73d1a93, 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 <hjk@qt.io>
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Christian Stenger
2018-05-02 09:15:49 +02:00
parent 147e6078ad
commit c46b6dbb56
2 changed files with 9 additions and 0 deletions

View File

@@ -1028,6 +1028,14 @@ QVariant BaseTreeModel::headerData(int section, Qt::Orientation orientation,
return QVariant(); 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 Qt::ItemFlags BaseTreeModel::flags(const QModelIndex &idx) const
{ {
if (!idx.isValid()) if (!idx.isValid())

View File

@@ -193,6 +193,7 @@ protected:
QModelIndex sibling(int row, int column, const QModelIndex &idx) const override; QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
Qt::ItemFlags flags(const QModelIndex &idx) const override; Qt::ItemFlags flags(const QModelIndex &idx) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) 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; bool canFetchMore(const QModelIndex &idx) const override;
void fetchMore(const QModelIndex &idx) override; void fetchMore(const QModelIndex &idx) override;