diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-01-18 10:45:43 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-01-21 14:20:17 +0000 |
commit | 73f5afb75fa211a6c5a4ca189b5f4a15c87c9d73 (patch) | |
tree | 6aa5842c0ab6ee456b64bca50fc83f0ef3834069 | |
parent | 3efcc9bd53c65844397fa81c96c2a86e71ac8ec4 (diff) |
Qt: Implement ProtoTreeModel::flags.
QTreeView checks to see if Qt::ItemNeverHasChildren is set in various
places, particularly when updating its set of expanded items. Implement
ProtoTreeModel::flags and set Qt::ItemNeverHasChildren when needed so
that QTreeView won't mark a leaf node expanded. Otherwise
ProtoTree::isExpanded will return true when it shouldn't and break the
iterator in ProtoTree::toString.
Bug: 14355
Change-Id: Id89be9911aa14dbbb52725f7203ac26a747c42fc
Reviewed-on: https://code.wireshark.org/review/25376
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | ui/qt/models/proto_tree_model.cpp | 9 | ||||
-rw-r--r-- | ui/qt/models/proto_tree_model.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/ui/qt/models/proto_tree_model.cpp b/ui/qt/models/proto_tree_model.cpp index 45e1d6b056..b782c7a449 100644 --- a/ui/qt/models/proto_tree_model.cpp +++ b/ui/qt/models/proto_tree_model.cpp @@ -25,6 +25,15 @@ ProtoTreeModel::ProtoTreeModel(QObject * parent) : root_node_(0) {} +Qt::ItemFlags ProtoTreeModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags item_flags = QAbstractItemModel::flags(index); + if (rowCount(index) < 1) { + item_flags |= Qt::ItemNeverHasChildren; + } + return item_flags; +} + QModelIndex ProtoTreeModel::index(int row, int, const QModelIndex &parent) const { ProtoNode parent_node(root_node_); diff --git a/ui/qt/models/proto_tree_model.h b/ui/qt/models/proto_tree_model.h index e0e815cf4b..dce8060b9d 100644 --- a/ui/qt/models/proto_tree_model.h +++ b/ui/qt/models/proto_tree_model.h @@ -22,6 +22,7 @@ class ProtoTreeModel : public QAbstractItemModel public: explicit ProtoTreeModel(QObject * parent = 0); + virtual Qt::ItemFlags flags(const QModelIndex &index) const; QModelIndex index(int row, int, const QModelIndex &parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex &index) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; |