forked from qt-creator/qt-creator
TreeModel: Add an optional ParentType parameter for TypedTreeItem
... and use it to add a ParentType *parent() function. Also, de-virtualize the TreeModel::parent(), this flexibility has not been needed so far. Change-Id: I0bcf930a0d6b05d5621753a5a8a1f8c3e5017386 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -41,7 +41,7 @@ public:
|
|||||||
TreeItem();
|
TreeItem();
|
||||||
virtual ~TreeItem();
|
virtual ~TreeItem();
|
||||||
|
|
||||||
virtual TreeItem *parent() const { return m_parent; }
|
TreeItem *parent() const { return m_parent; }
|
||||||
virtual TreeItem *child(int pos) const;
|
virtual TreeItem *child(int pos) const;
|
||||||
virtual int rowCount() const;
|
virtual int rowCount() const;
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// A TreeItem with children all of the same type.
|
// A TreeItem with children all of the same type.
|
||||||
template <class ChildType>
|
template <class ChildType, class ParentType = TreeItem>
|
||||||
class TypedTreeItem : public TreeItem
|
class TypedTreeItem : public TreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -175,6 +175,10 @@ public:
|
|||||||
ChildType *findFirstLevelChild(Predicate pred) const {
|
ChildType *findFirstLevelChild(Predicate pred) const {
|
||||||
return TreeItem::findFirstLevelChild<ChildType *, Predicate>(pred);
|
return TreeItem::findFirstLevelChild<ChildType *, Predicate>(pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParentType *parent() const {
|
||||||
|
return static_cast<ParentType *>(TreeItem::parent());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT StaticTreeItem : public TreeItem
|
class QTCREATOR_UTILS_EXPORT StaticTreeItem : public TreeItem
|
||||||
|
Reference in New Issue
Block a user