oops... that were 2 files too much...
[quassel.git] / src / client / treemodel.cpp
index f40fa7d..0d35ef6 100644 (file)
@@ -57,6 +57,9 @@ bool AbstractTreeItem::newChild(int column, AbstractTreeItem *item) {
     _childItems[column] = QList<AbstractTreeItem *>();
   }
 
+  // check if a child with that ID is already known
+  Q_ASSERT(childById(item->id()) == 0);
+    
   int newRow = _childItems[column].count();
   emit beginAppendChilds(column, newRow, newRow);
   _childItems[column].append(item);
@@ -191,6 +194,25 @@ void AbstractTreeItem::setFlags(Qt::ItemFlags flags) {
   _flags = flags;
 }
 
+void AbstractTreeItem::dumpChildList() {
+  AbstractTreeItem *child;
+
+  qDebug() << "==== Childlist for Item:" << this << id() << "====";
+  QHash<int, QList<AbstractTreeItem *> >::iterator columnIter = _childItems.begin();
+  while(columnIter != _childItems.end()) {
+    if(columnIter->count() > 0) {
+      QList<AbstractTreeItem *>::const_iterator childIter = columnIter->constBegin();
+      while(childIter != columnIter->constEnd()) {
+       child = *childIter;
+       qDebug() << "Column:" << columnIter.key() << "Row:" << child->row() << child << child->id() << child->data(0, Qt::DisplayRole);
+       childIter++;
+      }
+    }
+    columnIter++;
+  }
+  qDebug() << "==== End Of Childlist ====";  
+}
+
 /*****************************************
  * SimpleTreeItem
  *****************************************/
@@ -289,6 +311,17 @@ TreeModel::TreeModel(const QList<QVariant> &data, QObject *parent)
 {
   rootItem = new SimpleTreeItem(data, 0);
   connectItem(rootItem);
+
+  /*
+  connect(this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
+         this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int)));
+  connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
+         this, SLOT(debug_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
+  connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+         this, SLOT(debug_rowsInserted(const QModelIndex &, int, int)));
+  connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+         this, SLOT(debug_rowsRemoved(const QModelIndex &, int, int)));
+  */
 }
 
 TreeModel::~TreeModel() {
@@ -519,3 +552,29 @@ void TreeModel::endRemoveChilds() {
 void TreeModel::clear() {
   rootItem->removeAllChilds();
 }
+
+void TreeModel::debug_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) {
+  qDebug() << "debug_rowsAboutToBeInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
+}
+
+void TreeModel::debug_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
+  qDebug() << "debug_rowsAboutToBeRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
+  QModelIndex child;
+  for(int i = start; i <= end; i++) {
+    child = parent.child(i, 0);
+    qDebug() << "    " << child << child.data().toString(); // << static_cast<AbstractTreeItem *>(parent.child(i, 0).internalPointer())->id();
+  }
+}
+
+void TreeModel::debug_rowsInserted(const QModelIndex &parent, int start, int end) {
+  qDebug() << "debug_rowsInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
+  QModelIndex child;
+  for(int i = start; i <= end; i++) {
+    child = parent.child(i, 0);
+    qDebug() << "    " << child << child.data().toString(); // << static_cast<AbstractTreeItem *>(parent.child(i, 0).internalPointer())->id();
+  }
+}
+
+void TreeModel::debug_rowsRemoved(const QModelIndex &parent, int start, int end) {
+  qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
+}