From d315e012184a2b71b7b5e41869d166c05093d13d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 23 Nov 2012 15:24:48 +0100 Subject: Add the Qt::ItemNeverHasChildren flag and use it in QTreeView. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can be used to determine whether expand() should really expand. Change-Id: If79d8c295a4ca1356e60051682b227524a065126 Reviewed-by: David Faure (KDE) Reviewed-by: Olivier Goffart Reviewed-by: Thorbjørn Lund Martsum --- src/corelib/global/qnamespace.h | 3 ++- src/corelib/global/qnamespace.qdoc | 1 + src/corelib/itemmodels/qabstractitemmodel.cpp | 22 ++++++++++++++++++++++ src/corelib/itemmodels/qabstractitemmodel.h | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index ebbfc9ca83..a60743d3df 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1395,7 +1395,8 @@ public: ItemIsDropEnabled = 8, ItemIsUserCheckable = 16, ItemIsEnabled = 32, - ItemIsTristate = 64 + ItemIsTristate = 64, + ItemNeverHasChildren = 128 }; Q_DECLARE_FLAGS(ItemFlags, ItemFlag) diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index f157190591..b271620ee0 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2441,6 +2441,7 @@ \value ItemIsUserCheckable It can be checked or unchecked by the user. \value ItemIsEnabled The user can interact with the item. \value ItemIsTristate The item is checkable with three separate states. + \value ItemNeverHasChildren The item never has child items. Note that checkable items need to be given both a suitable set of flags and an initial state, indicating whether the item is checked or not. diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index ebe38a97cd..ad9be5419b 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -3271,6 +3271,17 @@ bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const return false; } +/*! + \reimp + */ +Qt::ItemFlags QAbstractTableModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags f = QAbstractItemModel::flags(index); + if (index.isValid()) + f |= Qt::ItemNeverHasChildren; + return f; +} + /*! \class QAbstractListModel \inmodule QtCore @@ -3391,6 +3402,17 @@ QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const return QModelIndex(); } +/*! + \reimp + */ +Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags f = QAbstractItemModel::flags(index); + if (index.isValid()) + f |= Qt::ItemNeverHasChildren; + return f; +} + /*! \internal diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index f138f53487..8e4f12e9ea 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -419,6 +419,7 @@ public: bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; protected: QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent); @@ -439,6 +440,8 @@ public: QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; protected: QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent); -- cgit v1.2.3