From f295cfb8672d97bb5c804499bdb311a9a0d8039b Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 29 Jun 2014 09:41:30 +0200 Subject: Major rework of MappingTreeResultView + Model Well, I hope this fixes the crashes for good. String comparison for looking up the parents really wasn't a prudent thing to do... Use the ParentIds instead. --- picfilesmodel.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'picfilesmodel.cpp') diff --git a/picfilesmodel.cpp b/picfilesmodel.cpp index ea51beb..edb7a23 100644 --- a/picfilesmodel.cpp +++ b/picfilesmodel.cpp @@ -171,13 +171,32 @@ QList PicFilesModel::mappingDataFromFiles(const QList fileIds) return QList(); } QList retval; + QSqlQuery mpq(mDb); + mpq.prepare("SELECT imapping_parents_id, iparent_id, tdescription_name, mapping_parents.idescription_id FROM mapping_parents, mapping_description WHERE imapping_parents_id = :id AND mapping_parents.idescription_id = mapping_description.idescription_id"); foreach(int pId, parentIds){ - QModelIndex curIdx = mMappingTreeModel->findRecursive(pId, MappingTreeModel::MappingId, mMappingTreeModel->rootIndex()); MappingData curData; - curData.mappingId = curIdx.data(MappingTreeModel::MappingIdRole).toInt(); - curData.parentId = curIdx.data(MappingTreeModel::MappingParentIdRole).toInt(); - curData.name = curIdx.data(MappingTreeModel::NameRole).toString(); - curData.path << mMappingTreeModel->path(curIdx); + int curParent = -1; + mpq.bindValue(":id", pId); + mpq.exec(); + while(mpq.next()){ + curData.name = mpq.value(2).toString(); + curData.mappingId = pId; + curData.descId = mpq.value(3).toInt(); + curData.parents << pId; + curData.path << curData.name; + curParent = mpq.value(1).toInt(); + } + while(curParent != -1){ + mpq.bindValue(":id", curParent); + mpq.exec(); + while(mpq.next()){ + curData.parents << curParent; + curData.path << mpq.value(2).toString(); + curParent = mpq.value(1).toInt(); + } + } + std::reverse(curData.parents.begin(), curData.parents.end()); + std::reverse(curData.path.begin(), curData.path.end()); retval << curData; } return retval; -- cgit v1.2.3-70-g09d2