diff options
author | Arno <am@disconnect.de> | 2014-06-29 09:41:30 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2014-06-29 09:41:30 +0200 |
commit | f295cfb8672d97bb5c804499bdb311a9a0d8039b (patch) | |
tree | 77b54514e17d6bb453bd9431707f9f37954c9fc2 /picfilesmodel.cpp | |
parent | b5bd9cf0b981ee0c87ead9e20c36247932de7818 (diff) | |
download | SheMov-f295cfb8672d97bb5c804499bdb311a9a0d8039b.tar.gz SheMov-f295cfb8672d97bb5c804499bdb311a9a0d8039b.tar.bz2 SheMov-f295cfb8672d97bb5c804499bdb311a9a0d8039b.zip |
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.
Diffstat (limited to 'picfilesmodel.cpp')
-rw-r--r-- | picfilesmodel.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/picfilesmodel.cpp b/picfilesmodel.cpp index ea51beb..edb7a23 100644 --- a/picfilesmodel.cpp +++ b/picfilesmodel.cpp @@ -171,13 +171,32 @@ QList<MappingData> PicFilesModel::mappingDataFromFiles(const QList<int> fileIds) return QList<MappingData>(); } QList<MappingData> 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; |