- TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
- TreeItem(TreeItem *parent = 0);
- virtual ~TreeItem();
-
- void appendChild(TreeItem *child);
- void removeChild(int row);
-
- virtual uint id() const;
- TreeItem *child(int row) const;
- TreeItem *childById(const uint &) const;
- int childCount() const;
- int columnCount() const;
- virtual QVariant data(int column, int role) const;
- int row() const;
- TreeItem *parent();
-
+ enum TreeItemFlag
+ {
+ NoTreeItemFlag = 0x00,
+ DeleteOnLastChildRemoved = 0x01
+ };
+ Q_DECLARE_FLAGS(TreeItemFlags, TreeItemFlag)
+
+ AbstractTreeItem(AbstractTreeItem* parent = nullptr);
+
+ bool newChild(AbstractTreeItem* child);
+ bool newChilds(const QList<AbstractTreeItem*>& items);
+
+ bool removeChild(int row);
+ inline bool removeChild(AbstractTreeItem* child) { return removeChild(child->row()); }
+ void removeAllChilds();
+
+ bool reParent(AbstractTreeItem* newParent);
+
+ AbstractTreeItem* child(int row) const;
+
+ int childCount(int column = 0) const;
+
+ virtual int columnCount() const = 0;
+
+ virtual QVariant data(int column, int role) const = 0;
+ virtual bool setData(int column, const QVariant& value, int role) = 0;
+
+ virtual inline Qt::ItemFlags flags() const { return _flags; }
+ virtual inline void setFlags(Qt::ItemFlags flags) { _flags = flags; }
+
+ inline AbstractTreeItem::TreeItemFlags treeItemFlags() const { return _treeItemFlags; }
+ inline void setTreeItemFlags(AbstractTreeItem::TreeItemFlags flags) { _treeItemFlags = flags; }
+ int row() const;
+ inline AbstractTreeItem* parent() const { return qobject_cast<AbstractTreeItem*>(QObject::parent()); }
+
+ void dumpChildList();
+
+signals:
+ void dataChanged(int column = -1);
+
+ void beginAppendChilds(int firstRow, int lastRow);
+ void endAppendChilds();
+
+ void beginRemoveChilds(int firstRow, int lastRow);
+ void endRemoveChilds();
+