From e2d4843586d84da62e325d1cb0025a795b162c1c Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 6 Oct 2012 11:02:42 +0200 Subject: More fixes to MappingTreeModel Fix move, addChild and such. Rename Fields and Roles to more speaking names, but that revealed a much deeper bug: the ParentID isn't really the parent_id, but the mapping_id. That could explain a lot. Nevertheless, it's still faster to repopulate the model after moving oder adding children instead of calling removeRows and insertRows. Another non-working commit... :( --- smtreemodel.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'smtreemodel.cpp') diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 4596a5b..71c815e 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -143,7 +143,7 @@ QModelIndex SmTreeModel::find(const QVariant &value, int column, const QModelInd for(int i = 0; i < parentItem->childCount(); ++i){ SmTreeItem *child = parentItem->child(i); if(child->data(column) == value){ - return index(i, column, parent); + return index(i, column, parent); } } return QModelIndex(); @@ -200,11 +200,11 @@ void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent, if(!idx.isValid()){ return; } - SmTreeItem *item = static_cast(idx.internalPointer()); - QList data; - for(int i = 0; i < item->columnCount(); ++i){ - data << item->data(i); - } + SmTreeItem *item = static_cast(idx.internalPointer()); + QList data; + for(int i = 0; i < item->columnCount(); ++i){ + data << item->data(i); + } QPersistentModelIndex pNewParent = newParent; removeRows(idx.row(), 1, idx.parent()); addRow(data, pNewParent, sorted); @@ -218,7 +218,7 @@ bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){ return false; } - beginInsertRows(parent, row, row + count - 1); + beginInsertRows(parent, row, row + count - 1); for(int i = row; i < row + count; ++i){ SmTreeItem *newItem = new SmTreeItem(mRootItem->columnCount(), parentItem); retval = parentItem->insertChild(i, newItem); @@ -264,8 +264,8 @@ bool SmTreeModel::addRow(const QList &data, const QModelIndex &parent, for(int i = 0; i < data.count(); ++i){ child->setData(i, data.at(i)); } - QModelIndex start = index(parentItem->childCount() - 1, 0, parent); - QModelIndex end = index(parentItem->childCount() - 1, parentItem->columnCount() - 1, parent); + QModelIndex start = index(parentItem->childCount() - 1, 0, parent); + QModelIndex end = index(parentItem->childCount() - 1, parentItem->columnCount() - 1, parent); emit dataChanged(start, end); return true; } -- cgit v1.2.3-70-g09d2