1 /* 2 SPDX-FileCopyrightText: 2008 Vladimir Prus <ghost@cs.msu.su> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef KDEVPLATFORM_TREEITEM_H 8 #define KDEVPLATFORM_TREEITEM_H 9 10 #include <QVariant> 11 #include <QVector> 12 #include <QIcon> 13 14 #include <iostream> 15 16 #include <debugger/debuggerexport.h> 17 18 namespace KDevelop { 19 20 class TreeModel; 21 22 class KDEVPLATFORMDEBUGGER_EXPORT TreeItem: public QObject 23 { 24 Q_OBJECT 25 public: 26 ~TreeItem() override; 27 28 // FIXME: should be protected 29 public: // Methods that the derived classes should implement 30 31 /** Fetches more children, and adds them by calling appendChild. 32 The amount of children to fetch is up to the implementation. 33 After fetching, should call setHasMore. */ 34 virtual void fetchMoreChildren()=0; 35 setColumn(int index,const QVariant & data)36 virtual void setColumn(int index, const QVariant& data) { Q_UNUSED(index); Q_UNUSED(data); } 37 void emitAllChildrenFetched(); 38 39 protected: // Interface for derived classes 40 41 /** Creates a tree item with the specified data. 42 FIXME: do we actually have to have the model 43 pointer. 44 */ 45 explicit TreeItem(TreeModel* model, TreeItem *parent = nullptr); 46 47 /** Set the data to be shown for the item itself. */ 48 void setData(const QVector<QVariant> &data); 49 50 /** Adds a new child and notifies the interested parties. 51 Clears the "hasMore" flag. */ 52 void appendChild(TreeItem *child, bool initial = false); 53 54 void insertChild(int position, TreeItem *child, bool initial = false); 55 56 void removeChild(int index); 57 58 void removeSelf(); 59 60 void deleteChildren(); 61 62 /** Report change in data of this item. */ 63 void reportChange(); 64 void reportChange(int column); 65 66 /** Clears all children. */ 67 void clear(); 68 69 /** Sets a flag that tells if we have some more children that are 70 not fetched yet. */ 71 void setHasMore(bool more); 72 73 void setHasMoreInitial(bool more); 74 model()75 TreeModel* model() { return model_; } 76 isExpanded()77 bool isExpanded() const { return expanded_; } 78 79 Q_SIGNALS: 80 void expanded(); 81 void collapsed(); 82 void allChildrenFetched(); 83 84 protected: // Backend implementation of Model/View 85 friend class TreeModel; 86 87 TreeItem *child(int row); 88 int childCount() const; 89 int columnCount() const; 90 virtual QVariant data(int column, int role) const; 91 int row() const; 92 TreeItem *parent(); hasMore()93 bool hasMore() const { return more_; } 94 void setExpanded(bool b); 95 clicked()96 virtual void clicked() {} 97 virtual QVariant icon(int column) const; 98 99 protected: 100 QVector<TreeItem*> childItems; 101 QVector<QVariant> itemData; 102 TreeItem *parentItem; 103 TreeModel *model_; 104 bool more_; 105 TreeItem *ellipsis_; 106 bool expanded_; 107 }; 108 109 } 110 111 #endif 112