From 2defc44300bd18917e6e5e2327ebb72f951ff7b1 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 17 Nov 2012 05:14:56 +0100 Subject: Finally { fix MappingTreeModel }!!! I think I did it! Fixed MappingTreeModel to make it usable, avoid all the traps with the insane column and variable names! Now we can actually have the same mapping with different parents! Yay! Hope it won't come back and bite me! --- mappingtreemodel.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'mappingtreemodel.cpp') diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index ddfd5e2..cf8bfc0 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -219,7 +219,7 @@ bool MappingTreeModel::setData(const QModelIndex &index, const QVariant &value, } bool MappingTreeModel::move(const QModelIndex &source, const QModelIndex &dest){ - QVariant sourceId = source.data(DescIdRole); + QVariant sourceId = source.data(MappingIdRole); QVariant destId = dest.data(MappingIdRole); mDb.transaction(); mUpdateParentQ->bindValue(":id", destId); @@ -295,7 +295,7 @@ bool MappingTreeModel::deleteChild(const QModelIndex &idx){ if(item->childCount() > 0){ return false; } - mDeleteMappingParentQ->bindValue(":id", item->data(DescId)); + mDeleteMappingParentQ->bindValue(":id", item->data(MappingId)); if(mDeleteMappingParentQ->exec()){ removeRows(idx.row(), 1, idx.parent()); return true; @@ -311,7 +311,7 @@ MappingData MappingTreeModel::mappingDataFromIndex(QModelIndex &idx) const{ } retval.mappingId = idx.data(MappingTreeModel::MappingIdRole).toInt(); retval.parentId = idx.data(MappingTreeModel::MappingParentIdRole).toInt(); - retval.myId = idx.data(MappingTreeModel::DescIdRole).toInt(); + retval.descId = idx.data(MappingTreeModel::DescIdRole).toInt(); retval.name = idx.data(MappingTreeModel::NameRole).toString(); retval.path << path(idx); return retval; @@ -336,10 +336,10 @@ void MappingTreeModel::populate(){ SmTreeItem *rootItem = new SmTreeItem(NumFields); rootItem->setData(DescId, -1); rootItem->setData(MappingId, -1); - mSeen.clear(); + rootItem->setData(MappingParentId, -1); while(rootQ.next()){ QList childData; - childData << rootQ.value(2) << rootQ.value(1) << rootQ.value(3) << rootQ.value(0) << rootQ.value(4); + childData << rootQ.value(2) << rootQ.value(0) << rootQ.value(3) << rootQ.value(1) << rootQ.value(4); SmTreeItem *childItem = new SmTreeItem(childData, rootItem); rootItem->appendChild(childItem); getChildrenRecursive(childItem); @@ -398,7 +398,6 @@ void MappingTreeModel::getMappingTypes(){ } void MappingTreeModel::getChildrenRecursive(SmTreeItem *item){ - //static QList seenIds; QSqlQuery cq(mDb); cq.prepare(mSParentsQ); cq.bindValue(":type", mType); @@ -406,11 +405,7 @@ void MappingTreeModel::getChildrenRecursive(SmTreeItem *item){ if(cq.exec()){ while(cq.next()){ QList childData; - childData << cq.value(2) << cq.value(1) << cq.value(3) << cq.value(0) << cq.value(4); - if(mSeen.contains(childData.at((DescId)))){ - return; - } - mSeen << childData.at(DescId); + childData << cq.value(2) << cq.value(0) << cq.value(3) << cq.value(1) << cq.value(4); SmTreeItem *child = new SmTreeItem(childData, item); item->appendChild(child); getChildrenRecursive(child); @@ -518,7 +513,7 @@ void MappingTreeResultModel::addItem(const MappingData &data){ if(i == p.count() - 1){ mappingId = data.mappingId; parentId = data.parentId; - myId = data.myId; + myId = data.descId; } QModelIndex curIdx = insertChild(p.at(i), mappingId, parentId, myId, curItem); curItem = itemAt(curIdx); @@ -580,8 +575,8 @@ QList MappingTreeResultModel::columnValuesRecursive(SmTreeItem *parent return retval; } -MappingData::MappingData() : mappingId(-1), parentId(-1), myId(-1) {} +MappingData::MappingData() : mappingId(-1), parentId(-1), descId(-1) {} bool MappingData::isValid(){ - return !(mappingId == -1 && parentId == -1 && myId == -1); + return !(mappingId == -1 && parentId == -1 && descId == -1); } -- cgit v1.2.3-70-g09d2