mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
improved safety of underlying data update for FriendListModel
This commit is contained in:
parent
3b7734c934
commit
7c5bf22931
@ -1058,14 +1058,16 @@ void RsFriendListModel::updateInternalData()
|
|||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(),0,mTopLevel.size()-1);
|
beginRemoveRows(QModelIndex(),0,mTopLevel.size()-1);
|
||||||
endRemoveRows();
|
|
||||||
|
|
||||||
mGroups.clear();
|
mGroups.clear();
|
||||||
mProfiles.clear();
|
mProfiles.clear();
|
||||||
mLocations.clear();
|
mLocations.clear();
|
||||||
|
|
||||||
mTopLevel.clear();
|
mTopLevel.clear();
|
||||||
|
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
|
auto TL = mTopLevel ; // This allows to fill TL without touching mTopLevel outside of [begin/end]InsertRows().
|
||||||
|
|
||||||
// create a map of profiles and groups
|
// create a map of profiles and groups
|
||||||
std::map<RsPgpId,uint32_t> pgp_indices;
|
std::map<RsPgpId,uint32_t> pgp_indices;
|
||||||
|
|
||||||
@ -1153,7 +1155,6 @@ void RsFriendListModel::updateInternalData()
|
|||||||
RsDbg() << "Creating top level list" << std::endl;
|
RsDbg() << "Creating top level list" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mTopLevel.clear();
|
|
||||||
std::set<RsPgpId> already_in_a_group;
|
std::set<RsPgpId> already_in_a_group;
|
||||||
|
|
||||||
if(mDisplayGroups) // in this case, we list all groups at the top level followed by the profiles without parent group
|
if(mDisplayGroups) // in this case, we list all groups at the top level followed by the profiles without parent group
|
||||||
@ -1168,7 +1169,7 @@ void RsFriendListModel::updateInternalData()
|
|||||||
e.type = ENTRY_TYPE_GROUP;
|
e.type = ENTRY_TYPE_GROUP;
|
||||||
e.group_index = i;
|
e.group_index = i;
|
||||||
|
|
||||||
mTopLevel.push_back(e);
|
TL.push_back(e);
|
||||||
|
|
||||||
for(uint32_t j=0;j<mGroups[i].child_profile_indices.size();++j)
|
for(uint32_t j=0;j<mGroups[i].child_profile_indices.size();++j)
|
||||||
already_in_a_group.insert(mProfiles[mGroups[i].child_profile_indices[j]].profile_info.gpg_id);
|
already_in_a_group.insert(mProfiles[mGroups[i].child_profile_indices[j]].profile_info.gpg_id);
|
||||||
@ -1187,12 +1188,15 @@ void RsFriendListModel::updateInternalData()
|
|||||||
e.profile_index = i;
|
e.profile_index = i;
|
||||||
e.group_index = UNDEFINED_GROUP_INDEX_VALUE;
|
e.group_index = UNDEFINED_GROUP_INDEX_VALUE;
|
||||||
|
|
||||||
mTopLevel.push_back(e);
|
TL.push_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally, tell the model client that layout has changed.
|
// finally, tell the model client that layout has changed.
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(),0,mTopLevel.size()-1);
|
beginInsertRows(QModelIndex(),0,TL.size()-1);
|
||||||
|
|
||||||
|
mTopLevel = TL;
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
|
Loading…
Reference in New Issue
Block a user