fixed model internals. Seems to work now.

This commit is contained in:
csoler 2019-07-28 09:12:55 +02:00
parent ca442a7113
commit 951b7f93fb
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
2 changed files with 20 additions and 2 deletions

View File

@ -193,6 +193,8 @@ QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex & pa
convertInternalIdToIndex(parent.internalId(),parent_index); convertInternalIdToIndex(parent.internalId(),parent_index);
RsDbg() << "Index row=" << row << " col=" << column << " parent=" << parent << std::endl;
EntryIndex new_index; EntryIndex new_index;
switch(parent_index.type) switch(parent_index.type)
@ -204,13 +206,14 @@ QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex & pa
case ENTRY_TYPE_PROFILE: new_index.type = ENTRY_TYPE_NODE; case ENTRY_TYPE_PROFILE: new_index.type = ENTRY_TYPE_NODE;
new_index.ind = mProfiles[parent_index.ind].child_indices[row]; new_index.ind = mProfiles[parent_index.ind].child_indices[row];
break; break;
break;
default: default:
return QModelIndex(); return QModelIndex();
} }
quintptr ref ; quintptr ref ;
convertIndexToInternalId(new_index,ref); convertIndexToInternalId(new_index,ref);
RsDbg() << " returning " << createIndex(row,column,ref) << std::endl;
return createIndex(row,column,ref); return createIndex(row,column,ref);
} }
@ -481,6 +484,8 @@ QVariant RsFriendListModel::sortRole(const EntryIndex& fmpe,int column) const
QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const
{ {
RsDbg() << " Display role " << e.type << "," << e.ind << " (col="<< col<<") : " << std::endl;
switch(e.type) switch(e.type)
{ {
case ENTRY_TYPE_GROUP: case ENTRY_TYPE_GROUP:
@ -714,6 +719,9 @@ void RsFriendListModel::updateInternalData()
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,mGroups.size()-1);
endInsertRows();
mGroups.clear(); mGroups.clear();
mLocations.clear(); mLocations.clear();
mProfiles.clear(); mProfiles.clear();
@ -788,9 +796,11 @@ void RsFriendListModel::updateInternalData()
if(it5 == ssl_indexes.end()) if(it5 == ssl_indexes.end())
{ {
RsNodeDetails nodedet; RsNodeDetails nodedet;
rsPeers->getPeerDetails(*it4,nodedet); rsPeers->getPeerDetails(*it4,nodedet);
if(nodedet.location.empty())
nodedet.location = tr("[Unknown]").toStdString();
ssl_indexes[*it4] = mNodeDetails.size(); ssl_indexes[*it4] = mNodeDetails.size();
mNodeDetails.push_back(nodedet); mNodeDetails.push_back(nodedet);
@ -815,6 +825,9 @@ void RsFriendListModel::updateInternalData()
mGroups.push_back(groupinfo); mGroups.push_back(groupinfo);
} }
beginInsertRows(QModelIndex(),0,mGroups.size()-1);
endInsertRows();
postMods(); postMods();
} }

View File

@ -839,6 +839,7 @@ void NewFriendList::addToGroup()
// add to group // add to group
rsPeers->assignPeerToGroup(groupId, gpgId, true); rsPeers->assignPeerToGroup(groupId, gpgId, true);
mModel->updateInternalData();
} }
void NewFriendList::moveToGroup() void NewFriendList::moveToGroup()
@ -862,6 +863,7 @@ void NewFriendList::moveToGroup()
// add to group // add to group
rsPeers->assignPeerToGroup(groupId, gpgId, true); rsPeers->assignPeerToGroup(groupId, gpgId, true);
mModel->updateInternalData();
} }
void NewFriendList::removeFromGroup() void NewFriendList::removeFromGroup()
@ -879,6 +881,7 @@ void NewFriendList::removeFromGroup()
// remove from (all) group(s) // remove from (all) group(s)
rsPeers->assignPeerToGroup(groupId, gpgId, false); rsPeers->assignPeerToGroup(groupId, gpgId, false);
mModel->updateInternalData();
} }
void NewFriendList::editGroup() void NewFriendList::editGroup()
@ -895,6 +898,7 @@ void NewFriendList::editGroup()
CreateGroup editGrpDialog(groupId, this); CreateGroup editGrpDialog(groupId, this);
editGrpDialog.exec(); editGrpDialog.exec();
} }
mModel->updateInternalData();
} }
void NewFriendList::removeGroup() void NewFriendList::removeGroup()
@ -905,6 +909,7 @@ void NewFriendList::removeGroup()
return; return;
rsPeers->removeGroup(pinfo.id); rsPeers->removeGroup(pinfo.id);
mModel->updateInternalData();
} }
void NewFriendList::exportFriendlistClicked() void NewFriendList::exportFriendlistClicked()