Some more tweaking for QuasselTopia.
[quassel.git] / src / client / treemodel.h
index 1941602..f1317be 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <QList>
 #include <QVariant>
+#include <QHash>
 #include <QAbstractItemModel>
 
 /*****************************************
  *****************************************/
 class TreeItem : public QObject {
   Q_OBJECT
-  
+  Q_PROPERTY(uint id READ id)
+
 public:
   TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
   TreeItem(TreeItem *parent = 0);
   virtual ~TreeItem();
-  
+
   void appendChild(TreeItem *child);
   void removeChild(int row);
-                   
-  TreeItem *child(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;
+
+  Qt::ItemFlags flags() const;
+  void setFlags(Qt::ItemFlags);
+
   int row() const;
   TreeItem *parent();
-    
+
+
+private slots:
+  void childDestroyed();
+
+
 protected:
-  QList<TreeItem*> childItems;
-  TreeItem *parentItem;
   QList<QVariant> itemData;
+
+private:
+  QList<TreeItem *> _childItems;
+  QHash<uint, TreeItem *> _childHash; // uint to be compatible to qHash functions
+  TreeItem *_parentItem;
+  Qt::ItemFlags _flags;
 };
 
 
@@ -58,21 +78,25 @@ protected:
  *****************************************/
 class TreeModel : public QAbstractItemModel {
   Q_OBJECT
-  
+
 public:
   TreeModel(const QList<QVariant> &, QObject *parent = 0);
   virtual ~TreeModel();
-  
+
   QVariant data(const QModelIndex &index, int role) const;
   virtual Qt::ItemFlags flags(const QModelIndex &index) const;
   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+  QModelIndex indexById(uint id, const QModelIndex &parent = QModelIndex()) const;
   QModelIndex parent(const QModelIndex &index) const;
   int rowCount(const QModelIndex &parent = QModelIndex()) const;
   int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
+  virtual void clear();
+
 protected:
   bool removeRow(int row, const QModelIndex &parent = QModelIndex());
+  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
   
   TreeItem *rootItem;
 };