From 80b7f2a3cdc24832214a577cc85a0cd967e0b7ad Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 27 Apr 2020 17:00:13 +0200 Subject: [PATCH] fixed loading of already selected ids in FriendSelectionDialog and automatically display existing GxsGroupDialog moderators --- .../src/gui/common/FriendSelectionDialog.cpp | 2 +- .../src/gui/common/FriendSelectionWidget.cpp | 49 ++++++++++++++++--- .../src/gui/common/FriendSelectionWidget.h | 12 +++-- retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp | 4 ++ retroshare-gui/src/gui/gxs/GxsGroupDialog.ui | 9 ++-- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendSelectionDialog.cpp b/retroshare-gui/src/gui/common/FriendSelectionDialog.cpp index 9201a0458..9631054a0 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionDialog.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionDialog.cpp @@ -100,7 +100,7 @@ FriendSelectionDialog::FriendSelectionDialog(QWidget *parent,const QString& head friends_widget->setModus(modus) ; friends_widget->setShowType(show_type) ; friends_widget->start() ; - friends_widget->setSelectedIds(pre_selected_id_type, pre_selected_ids, false); + friends_widget->setSelectedIdsFromString(pre_selected_id_type, pre_selected_ids, false); QLayout *l = new QVBoxLayout ; setLayout(l) ; diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index 43179518a..53ded6615 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -278,18 +278,35 @@ void FriendSelectionWidget::secured_fillList() // get selected items std::set sslIdsSelected; - if (mShowTypes & SHOW_SSL) { + if (mShowTypes & SHOW_SSL) + { + if(!ui->friendList->topLevelItemCount()) // if not loaded yet, use the existing list. + for(auto& s:mPreSelectedIds) + sslIdsSelected.insert(RsPeerId(s)); + selectedIds(sslIdsSelected,true); } std::set groupIdsSelected; - if (mShowTypes & SHOW_GROUP) { + + if (mShowTypes & SHOW_GROUP) + { selectedIds(groupIdsSelected,true); + + if(!ui->friendList->topLevelItemCount()) // if not loaded yet, use the existing list. + for(auto& s:mPreSelectedIds) + groupIdsSelected.insert(RsNodeGroupId(s)); } std::set gpgIdsSelected; - if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) { + + if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) + { selectedIds(gpgIdsSelected,true); + + if(!ui->friendList->topLevelItemCount()) // if not loaded yet, use the existing list. + for(auto& s:mPreSelectedIds) + gpgIdsSelected.insert(RsPgpId(s)); } std::set gxsIdsSelected; @@ -299,7 +316,8 @@ void FriendSelectionWidget::secured_fillList() selectedIds(gxsIdsSelected,true); if(!ui->friendList->topLevelItemCount()) // if not loaded yet, use the existing list. - gxsIdsSelected = mPreSelectedGxsIds; + for(auto& s:mPreSelectedIds) + gxsIdsSelected.insert(RsGxsId(s)); } std::set gxsIdsSelected2; @@ -678,7 +696,12 @@ void FriendSelectionWidget::updateDisplay(bool) // This call is inlined so that there's no linking conflict with MinGW on Windows template<> inline void FriendSelectionWidget::setSelectedIds(const std::set& ids, bool add) { - mPreSelectedGxsIds = ids ; + if(!add) + mPreSelectedIds.clear(); + + for(auto& gxsId:ids) + mPreSelectedIds.insert(gxsId.toStdString()); + loadIdentities(); } @@ -981,7 +1004,7 @@ std::string FriendSelectionWidget::selectedId(IdType &idType) return idFromItem(item); } -void FriendSelectionWidget::selectedIds(IdType idType, std::set &ids, bool onlyDirectSelected) +void FriendSelectionWidget::selectedIds_internal(IdType idType, std::set &ids, bool onlyDirectSelected) { QTreeWidgetItemIterator itemIterator(ui->friendList); QTreeWidgetItem *item; @@ -1055,11 +1078,21 @@ void FriendSelectionWidget::selectAll() setSelected(mListModus, *itemIterator, true); } -void FriendSelectionWidget::setSelectedIds(IdType idType, const std::set &ids, bool add) +void FriendSelectionWidget::setSelectedIdsFromString(IdType type, const std::set& ids, bool add) { + setSelectedIds_internal(type,ids,add); +} + +void FriendSelectionWidget::setSelectedIds_internal(IdType idType, const std::set &ids, bool add) +{ + mPreSelectedIds = ids; + + // if items are already loaded, check them + QTreeWidgetItemIterator itemIterator(ui->friendList); QTreeWidgetItem *item; - while ((item = *itemIterator) != NULL) { + while ((item = *itemIterator) != NULL) + { ++itemIterator; std::string id = idFromItem(item); diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.h b/retroshare-gui/src/gui/common/FriendSelectionWidget.h index e770d4b43..7a2fb718e 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.h +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.h @@ -85,10 +85,12 @@ public: int selectedItemCount(); std::string selectedId(IdType &idType); + void setSelectedIdsFromString(IdType type,const std::set& ids,bool add); + template void selectedIds(std::set& ids, bool onlyDirectSelected) { std::set tmpids ; - selectedIds(TYPE, tmpids, onlyDirectSelected); + selectedIds_internal(TYPE, tmpids, onlyDirectSelected); ids.clear() ; for(std::set::const_iterator it(tmpids.begin());it!=tmpids.end();++it) ids.insert(ID_CLASS(*it)) ; @@ -98,7 +100,7 @@ public: std::set tmpids ; for(typename std::set::const_iterator it(ids.begin());it!=ids.end();++it) tmpids.insert((*it).toStdString()) ; - setSelectedIds(TYPE, tmpids, add); + setSelectedIds_internal(TYPE, tmpids, add); } void itemsFromId(IdType idType, const std::string &id, QList &items); @@ -145,8 +147,8 @@ private: void fillList(); void secured_fillList(); - void selectedIds(IdType idType, std::set &ids, bool onlyDirectSelected); - void setSelectedIds(IdType idType, const std::set &ids, bool add); + void selectedIds_internal(IdType idType, std::set &ids, bool onlyDirectSelected); + void setSelectedIds_internal(IdType idType, const std::set &ids, bool add); private: bool mStarted; @@ -170,7 +172,7 @@ private: std::vector gxsIds ; QList mContextMenuActions; - std::set mPreSelectedGxsIds; // because loading of GxsIds is asynchroneous we keep selected Ids from the client in a list here and use it to initialize after loading them. + std::set mPreSelectedIds; // because loading of GxsIds is asynchroneous we keep selected Ids from the client in a list here and use it to initialize after loading them. }; Q_DECLARE_OPERATORS_FOR_FLAGS(FriendSelectionWidget::ShowTypes) diff --git a/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp index 62e1101c9..240f321db 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp @@ -892,6 +892,10 @@ void GxsGroupDialog::getSelectedModerators(std::set& ids) void GxsGroupDialog::setSelectedModerators(const std::set& ids) { + ui.addAdmins_cb->setChecked(true); + ui.adminsList->show(); + ui.filtercomboBox->show(); + ui.adminsList->setSelectedIds(ids, false); QString moderatorsListString ; diff --git a/retroshare-gui/src/gui/gxs/GxsGroupDialog.ui b/retroshare-gui/src/gui/gxs/GxsGroupDialog.ui index bc417db65..88777cd59 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupDialog.ui +++ b/retroshare-gui/src/gui/gxs/GxsGroupDialog.ui @@ -6,8 +6,8 @@ 0 0 - 600 - 563 + 1231 + 967 @@ -223,14 +223,14 @@ - Required + Re&quired - Encrypted Msgs + Encrypted &Msgs @@ -856,7 +856,6 @@ -