From 53e1a67785c97daa8d7ef0ea7694ac3a230a1a2e Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Fri, 8 Feb 2008 19:16:34 +0000 Subject: [PATCH] just a minor update before I get my hands dirty with the TreeModel... --- src/client/networkmodel.cpp | 6 ++-- src/client/treemodel.cpp | 61 ++++++++++++++++++++++++++++++------- src/client/treemodel.h | 3 ++ version.inc | 2 +- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 992f52f2..71b586e7 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -251,7 +251,7 @@ void BufferItem::removeUserFromCategory(IrcUser *ircUser) { } if(!success) { - qDebug() << "didn't find User:" << ircUser << (quint64)ircUser; + qDebug() << "didn't find User:" << ircUser << qHash(ircUser); qDebug() << "==== Childlist for Item:" << this << id() << bufferName() << "===="; for(int i = 0; i < childCount(); i++) { categoryItem = qobject_cast(child(i)); @@ -272,7 +272,7 @@ void BufferItem::userModeChanged(IrcUser *ircUser) { UserCategoryItem *categoryItem; int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser)); - if((categoryItem = qobject_cast(childById(qHash(categoryId)))) && categoryItem->childById((quint64)(ircUser))) + if((categoryItem = qobject_cast(childById(qHash(categoryId)))) && categoryItem->childById(qHash(ircUser))) return; // already in the right category; removeUserFromCategory(ircUser); @@ -439,7 +439,7 @@ void UserCategoryItem::addUser(IrcUser *ircUser) { } bool UserCategoryItem::removeUser(IrcUser *ircUser) { - return removeChildById((quint64)ircUser); + return removeChildById(qHash(ircUser)); } int UserCategoryItem::categoryFromModes(const QString &modes) { diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 0d35ef64..949dba19 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -61,6 +61,7 @@ bool AbstractTreeItem::newChild(int column, AbstractTreeItem *item) { Q_ASSERT(childById(item->id()) == 0); int newRow = _childItems[column].count(); + qDebug() << "# new Child:" << this << newRow << item << item->id() << item->data(0, Qt::DisplayRole); emit beginAppendChilds(column, newRow, newRow); _childItems[column].append(item); emit endAppendChilds(); @@ -76,6 +77,8 @@ bool AbstractTreeItem::removeChild(int column, int row) { if(!_childItems.contains(column) || row >= childCount(column)) return false; + AbstractTreeItem *item = _childItems[column][row]; + qDebug() << "# Remove Child:" << this << row << item << item->id() << item->data(0, Qt::DisplayRole); emit beginRemoveChilds(column, row, row); AbstractTreeItem *treeitem = _childItems[column].takeAt(row); treeitem->deleteLater(); @@ -92,6 +95,7 @@ bool AbstractTreeItem::removeChildById(int column, const quint64 &id) { if(!_childItems.contains(column)) return false; + qDebug() << "removeChildyById" << id; for(int i = 0; i < _childItems[column].count(); i++) { if(_childItems[column][i]->id() == id) return removeChild(column, i); @@ -310,9 +314,9 @@ TreeModel::TreeModel(const QList &data, QObject *parent) _aboutToRemoveOrInsert(false) { rootItem = new SimpleTreeItem(data, 0); + rootItem->setObjectName("rootItem"); 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)), @@ -321,7 +325,6 @@ TreeModel::TreeModel(const QList &data, QObject *parent) 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() { @@ -554,27 +557,63 @@ void TreeModel::clear() { } void TreeModel::debug_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) { - qDebug() << "debug_rowsAboutToBeInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << 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; + AbstractTreeItem *parentItem; + parentItem = static_cast(parent.internalPointer()); + if(!parentItem) + parentItem = rootItem; + qDebug() << "#" << parent << parentItem << parent.data().toString() << rowCount(parent) << start << end; + + if(!_childLists.contains(parentItem)) + _childLists[parentItem] = QList(); + + QList &childList = _childLists[parentItem]; QModelIndex child; - for(int i = start; i <= end; i++) { - child = parent.child(i, 0); - qDebug() << " " << child << child.data().toString(); // << static_cast(parent.child(i, 0).internalPointer())->id(); + AbstractTreeItem *childItem; + for(int i = end; i >= start; i--) { + if(childList.count() <= i) { + qDebug() << "#! not removing existing item! lastItem:" << childList.count() - 1 << "Delpos:" << i; + Q_ASSERT(false); + } else { + child = parent.child(i, 0); + childItem = parentItem->child(i); + Q_ASSERT(childItem); + childList.removeAt(i); + qDebug() << ">>>" << i << child << childItem->id() << child.data().toString(); + } } } void TreeModel::debug_rowsInserted(const QModelIndex &parent, int start, int end) { - qDebug() << "debug_rowsInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; + AbstractTreeItem *parentItem; + parentItem = static_cast(parent.internalPointer()); + if(!parentItem) + parentItem = rootItem; + qDebug() << "#" << parent << parentItem << parent.data().toString() << rowCount(parent) << start << end; + + if(!_childLists.contains(parentItem)) + _childLists[parentItem] = QList(); + + QList &childList = _childLists[parentItem]; QModelIndex child; + AbstractTreeItem *childItem; for(int i = start; i <= end; i++) { - child = parent.child(i, 0); - qDebug() << " " << child << child.data().toString(); // << static_cast(parent.child(i, 0).internalPointer())->id(); + if(childList.count() != i) { + qDebug() << "#! not appending at the End! End:" << childList.count() << "Insertpos:" << i; + Q_ASSERT(false); + } else { + child = parent.child(i, 0); + childItem = parentItem->child(i); + Q_ASSERT(childItem); + childList.append(childItem); + qDebug() << "<<<" << i << child << childItem->id() << child.data().toString(); + } } } void TreeModel::debug_rowsRemoved(const QModelIndex &parent, int start, int end) { - qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; + // qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; } diff --git a/src/client/treemodel.h b/src/client/treemodel.h index 6f2575c0..2ce2befe 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -194,6 +194,9 @@ private slots: void debug_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); void debug_rowsInserted(const QModelIndex &parent, int start, int end); void debug_rowsRemoved(const QModelIndex &parent, int start, int end); + +private: + QHash > _childLists; }; #endif diff --git a/version.inc b/version.inc index 0aa8dbea..d15b87de 100644 --- a/version.inc +++ b/version.inc @@ -5,7 +5,7 @@ quasselVersion = "0.2.0-pre"; quasselDate = "2008-02-08"; - quasselBuild = 483; + quasselBuild = 486; //! Minimum client build number the core needs clientBuildNeeded = 480; -- 2.20.1