From 49c450890eda93d483b8ae1fe2bc2435fb8219d8 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Jun 2019 23:55:38 +0200 Subject: [PATCH] fixed hierarchical info --- .../src/gui/common/FriendListModel.cpp | 190 ++++++++++-------- .../src/gui/common/FriendListModel.h | 29 +-- 2 files changed, 116 insertions(+), 103 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index f0c541ee5..8ecc1c20c 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -87,7 +87,10 @@ int RsFriendListModel::rowCount(const QModelIndex& parent) const return 0; if(index.type == ENTRY_TYPE_GROUP) - return mGroups[index.ind].peerIds.size(); + return mGroups[index.ind].child_indices.size(); + + if(index.type == ENTRY_TYPE_PROFILE) + return mProfiles[index.ind].child_indices.size(); return 0; } @@ -122,9 +125,9 @@ bool RsFriendListModel::hasChildren(const QModelIndex &parent) const if(parent_index.type == ENTRY_TYPE_NODE) return false; if(parent_index.type == ENTRY_TYPE_PROFILE) - return false; // TODO + return !mProfiles[parent_index.ind].child_indices.empty(); if(parent_index.type == ENTRY_TYPE_GROUP) - return !mGroups[parent_index.ind].peerIds.empty(); + return !mGroups[parent_index.ind].child_indices.empty(); return false; } @@ -218,28 +221,20 @@ QModelIndex RsFriendListModel::parent(const QModelIndex& index) const return QModelIndex(); if(I.type == ENTRY_TYPE_PROFILE) - if(mDisplayGroups) - { - for(int i=0;i& e1,cons void RsFriendListModel::debug_dump() const { for(auto it(mGroups.begin());it!=mGroups.end();++it) - std::cerr << "Group: " << *it << std::endl; + { + std::cerr << "Group: " << (*it).group.name << std::endl; + } } bool RsFriendListModel::getGroupData (const QModelIndex& i,RsGroupInfo & data) const @@ -652,7 +649,7 @@ bool RsFriendListModel::getGroupData (const QModelIndex& i,RsGroupInfo & da if(!convertInternalIdToIndex(i.internalId(),e) || e.type != ENTRY_TYPE_GROUP || e.ind >= mGroups.size()) return false; - data = mGroups[e.ind]; + data = mGroups[e.ind].group; return true; } bool RsFriendListModel::getProfileData(const QModelIndex& i,RsProfileDetails& data) const @@ -664,7 +661,7 @@ bool RsFriendListModel::getProfileData(const QModelIndex& i,RsProfileDetails& da if(!convertInternalIdToIndex(i.internalId(),e) || e.type != ENTRY_TYPE_PROFILE || e.ind >= mProfiles.size()) return false; - data = mProfiles[e.ind]; + data = mProfileDetails[mProfiles[e.ind].profile_index]; return true; } bool RsFriendListModel::getNodeData (const QModelIndex& i,RsNodeDetails & data) const @@ -676,7 +673,7 @@ bool RsFriendListModel::getNodeData (const QModelIndex& i,RsNodeDetails & da if(!convertInternalIdToIndex(i.internalId(),e) || e.type != ENTRY_TYPE_NODE || e.ind >= mLocations.size()) return false; - data = mLocations[e.ind]; + data = mNodeDetails[mLocations[e.ind].node_index]; return true; } @@ -700,80 +697,95 @@ void RsFriendListModel::updateInternalData() mLocations.clear(); mProfiles.clear(); - mHG.clear(); - mHL.clear(); - mHP.clear(); + mNodeDetails.clear(); + mProfileDetails.clear(); // create a map of profiles and groups std::map pgp_indexes; std::map ssl_indexes; std::map grp_indexes; - // groups + // we start from the top and fill in the blanks as needed + + // groups std::list groupInfoList; rsPeers->getGroupInfoList(groupInfoList) ; + uint32_t group_row = 0; - for(auto it(groupInfoList.begin());it!=groupInfoList.end();++it) + for(auto it(groupInfoList.begin());it!=groupInfoList.end();++it,++group_row) { - grp_indexes[it->group_id] = mGroups.size(); - mGroups.push_back(*it); - } + // first, fill the group hierarchical info - // profiles + HierarchicalGroupInformation groupinfo; + groupinfo.group = *it; + groupinfo.parent_row = group_row; - std::list gpg_ids; - rsPeers->getGPGAcceptedList(gpg_ids); + uint32_t profile_row = 0; - for(auto it(gpg_ids.begin());it!=gpg_ids.end();++it) - { - RsProfileDetails det; - - if(!rsPeers->getGPGDetails(*it,det)) - continue; - - pgp_indexes[det.gpg_id] = mProfiles.size(); - mProfiles.push_back(det); - } - - // locations - - std::list peer_ids; - rsPeers->getFriendList(peer_ids); - - for(auto it(peer_ids.begin());it!=peer_ids.end();++it) - { - RsNodeDetails det; - - if(!rsPeers->getPeerDetails(*it,det)) - continue; - - ssl_indexes[det.id] = mLocations.size(); - mLocations.push_back(det); - } - - // now build the hierarchy information for the model - - for(uint32_t i=0;isecond); + // Then for each peer in this group, make sure that the peer is already known, and if not create it + + auto it3 = pgp_indexes.find(*it2); + if(it3 == pgp_indexes.end())// not found + { + RsProfileDetails profdet; + + rsPeers->getGPGDetails(*it2,profdet); + + pgp_indexes[*it2] = mProfileDetails.size(); + mProfileDetails.push_back(profdet); + + it3 = pgp_indexes.find(*it2); + } + + // ...and also fill the hierarchical profile info + + HierarchicalProfileInformation profinfo; + + profinfo.parent_row = profile_row; + profinfo.parent_group_index = mGroups.size(); + profinfo.profile_index = it3->second; + + // now fill the children nodes of the profile + + std::list ssl_ids ; + rsPeers->getAssociatedSSLIds(*it2, ssl_ids); + + uint32_t node_row = 0; + + for(auto it4(ssl_ids.begin());it4!=ssl_ids.end();++it4,++node_row) + { + auto it5 = ssl_indexes.find(*it4); + if(it5 == ssl_indexes.end()) + { + RsNodeDetails nodedet; + + rsPeers->getPeerDetails(*it4,nodedet); + + ssl_indexes[*it4] = mNodeDetails.size(); + mNodeDetails.push_back(nodedet); + + it5 = ssl_indexes.find(*it4); + } + + HierarchicalNodeInformation nodeinfo; + nodeinfo.parent_row = node_row; + nodeinfo.node_index = it5->second; + nodeinfo.parent_profile_index = mProfiles.size(); + + profinfo.child_indices.push_back(mLocations.size()); + + mLocations.push_back(nodeinfo); + } + + mProfiles.push_back(profinfo); } - mHG.push_back(inf); + mGroups.push_back(groupinfo); } -#warning Missing code here !!! - postMods(); } diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index 7e2b06dd7..0cdd78e8a 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -49,22 +49,24 @@ public: struct HierarchicalGroupInformation { - uint32_t group_index; - std::vector child_indices; + RsGroupInfo group; + std::vector child_indices; // index in the array of hierarchical profiles + uint32_t parent_row; }; struct HierarchicalProfileInformation { - uint32_t profile_index; - std::vector child_indices; - uint32_t parent_group_index; + uint32_t profile_index; // index in the array of profiles. We cannot store the profile here because of duplication + uint32_t parent_group_index; // index in the array of hierarchical groups + std::vector child_indices; // index in the array of hierarchical nodes + uint32_t parent_row; }; struct HierarchicalNodeInformation { - uint32_t node_index; - uint32_t parent_profile_index; + uint32_t node_index; // index in the array of nodes + uint32_t parent_profile_index; // index in the array of hierarchical profiles + uint32_t parent_row; }; - enum Columns { COLUMN_THREAD_NAME = 0x00, COLUMN_THREAD_LAST_CONTACT = 0x01, @@ -184,12 +186,11 @@ private: // A given profile may belong to multiple groups, so the hierarchy is stored using the 3 variables below. - std::vector mHG; - std::vector mHP; - std::vector mHL; + std::vector mGroups; + std::vector mProfiles; + std::vector mLocations; - std::vector mGroups; - std::vector mProfiles; - std::vector mLocations; + std::vector mProfileDetails; + std::vector mNodeDetails; };