summaryrefslogtreecommitdiffstats
path: root/mappingtreemodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-11-17 05:14:56 +0100
committerArno <am@disconnect.de>2012-11-17 05:14:56 +0100
commit2defc44300bd18917e6e5e2327ebb72f951ff7b1 (patch)
tree0f8e622deb1ae29d36113fe49a1758e5164278ae /mappingtreemodel.cpp
parent23692f9a516c21676829275c82b415957fc2dec3 (diff)
downloadSheMov-2defc44300bd18917e6e5e2327ebb72f951ff7b1.tar.gz
SheMov-2defc44300bd18917e6e5e2327ebb72f951ff7b1.tar.bz2
SheMov-2defc44300bd18917e6e5e2327ebb72f951ff7b1.zip
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!
Diffstat (limited to 'mappingtreemodel.cpp')
-rw-r--r--mappingtreemodel.cpp23
1 files changed, 9 insertions, 14 deletions
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<QVariant> 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<QVariant> 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<QVariant> 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<QVariant> 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);
}