diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 713b7f620..e1e3030f3 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -391,14 +391,11 @@ QVariant RsFriendListModel::data(const QModelIndex &index, int role) const case FilterRole: return filterRole(entry,index.column()) ; case SortRole: return sortRole(entry,index.column()) ; case OnlineRole: return onlineRole(entry,index.column()) ; + case TypeRole: return QVariant((int)entry.type); default: return QVariant(); } - -// case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; -// case Qt::UserRole: return userRole (fmpe,index.column()) ; -// } QVariant RsFriendListModel::textColorRole(const EntryIndex& fmpe,int column) const @@ -1117,4 +1114,14 @@ void RsFriendListModel::updateInternalData() mLastInternalDataUpdate = time(NULL); } +QModelIndex RsFriendListModel::getIndexOfGroup(const RsNodeGroupId& mid) const +{ + if(mDisplayGroups) + for(uint32_t i=0;ivalue("open").toString().toStdString(); - RsGroupInfo ginfo ; - - if(rsPeers->getGroupInfoByName(gids,ginfo)) // backward compatibility - addGroupToExpand(ginfo.id) ; - else if(rsPeers->getGroupInfo(RsNodeGroupId(gids),ginfo)) // backward compatibility - addGroupToExpand(ginfo.id) ; - else - std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl; +// RsGroupInfo ginfo ; +// +// if(rsPeers->getGroupInfoByName(gids,ginfo)) // backward compatibility +// addGroupToExpand(ginfo.id) ; +// else if(rsPeers->getGroupInfo(RsNodeGroupId(gids),ginfo)) // backward compatibility +// addGroupToExpand(ginfo.id) ; +// else +// std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl; } Settings->endArray(); } @@ -452,15 +458,15 @@ void NewFriendList::processSettings(bool load) // sort Settings->setValue("sortByState", mProxyModel->sortByState()); - // open groups - Settings->beginWriteArray("Groups"); - int arrayIndex = 0; - std::set expandedPeers; - getExpandedGroups(expandedPeers); - foreach (RsNodeGroupId groupId, expandedPeers) { - Settings->setArrayIndex(arrayIndex++); - Settings->setValue("open", QString::fromStdString(groupId.toStdString())); - } +// // open groups +// Settings->beginWriteArray("Groups"); +// int arrayIndex = 0; +// std::set expandedPeers; +// getExpandedGroups(expandedPeers); +// foreach (RsNodeGroupId groupId, expandedPeers) { +// Settings->setArrayIndex(arrayIndex++); +// Settings->setValue("open", QString::fromStdString(groupId.toStdString())); +// } Settings->endArray(); } } @@ -715,97 +721,6 @@ static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay) return icon; } -// static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, ElidedLabel *&nameLabel, ElidedLabel *&textLabel) -// { -// QWidget *widget = treeWidget->itemWidget(item, NewFriendList::COLUMN_NAME); -// -// if (!widget) { -// widget = new QWidget; -// widget->setAttribute(Qt::WA_TranslucentBackground); -// nameLabel = new ElidedLabel(widget); -// textLabel = new ElidedLabel(widget); -// -// widget->setProperty("nameLabel", qVariantFromValue(nameLabel)); -// widget->setProperty("textLabel", qVariantFromValue(textLabel)); -// -// QVBoxLayout *layout = new QVBoxLayout; -// layout->setSpacing(0); -// layout->setContentsMargins(3, 0, 0, 0); -// -// nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); -// textLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); -// -// layout->addWidget(nameLabel); -// layout->addWidget(textLabel); -// -// widget->setLayout(layout); -// -// treeWidget->setItemWidget(item, NewFriendList::COLUMN_NAME, widget); -// } else { -// nameLabel = widget->property("nameLabel").value(); -// textLabel = widget->property("textLabel").value(); -// } -// } - -/** - * Returns a list with all groupIds that are expanded - */ -bool NewFriendList::getExpandedGroups(std::set &groups) const -{ -// int itemCount = ui->peerTreeWidget->topLevelItemCount(); -// for (int index = 0; index < itemCount; ++index) { -// QTreeWidgetItem *item = ui->peerTreeWidget->topLevelItem(index); -// if (item->type() == TYPE_GROUP && item->isExpanded()) { -// groups.insert(RsNodeGroupId(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString())); -// } -// } - return true; -} - -/** - * Returns a list with all gpg ids that are expanded - */ -bool NewFriendList::getExpandedPeers(std::set &peers) const -{ -// peers.clear(); -// QTreeWidgetItemIterator it(ui->peerTreeWidget); -// while (*it) { -// QTreeWidgetItem *item = *it; -// if (item->type() == TYPE_GPG && item->isExpanded()) { -// peers.insert(peers.end(), RsPgpId(getRsId(item))); -// } -// ++it; -// } - return true; -} - -// void NewFriendList::collapseItem(QTreeWidgetItem *item) -// { -// switch (item->type()) -// { -// case TYPE_GROUP: -// openGroups.erase(RsNodeGroupId(getRsId(item))) ; -// break; -// case TYPE_GPG: -// openPeers.erase(RsPgpId(getRsId(item))) ; -// default: -// break; -// } -// } -// void NewFriendList::expandItem(QTreeWidgetItem *item) -// { -// switch (item->type()) -// { -// case TYPE_GROUP: -// openGroups.insert(RsNodeGroupId(getRsId(item))) ; -// break; -// case TYPE_GPG: -// openPeers.insert(RsPgpId(getRsId(item))) ; -// default: -// break; -// } -// } - void NewFriendList::addFriend() { std::string groupId = getSelectedGroupId(); @@ -1043,7 +958,7 @@ void NewFriendList::addToGroup() return; // automatically expand the group, the peer is added to - addGroupToExpand(groupId); + expandGroup(groupId); // add to group rsPeers->assignPeerToGroup(groupId, gpgId, true); @@ -1076,7 +991,7 @@ void NewFriendList::moveToGroup() rsPeers->assignPeerToGroup(RsNodeGroupId(), gpgId, false); // automatically expand the group, the peer is added to - addGroupToExpand(groupId); + expandGroup(groupId); // add to group rsPeers->assignPeerToGroup(groupId, gpgId, true); @@ -1573,21 +1488,8 @@ void NewFriendList::filterItems(const QString &text) ui->peerTreeWidget->collapseAll(); } -/** - * Add a groupId to the openGroups list. These groups - * will be expanded, when they're added to the QTreeWidget - */ -void NewFriendList::addGroupToExpand(const RsNodeGroupId &groupId) +void NewFriendList::expandGroup(const RsNodeGroupId& gid) { - openGroups.insert(groupId); + QModelIndex index = mProxyModel->mapFromSource(mModel->getIndexOfGroup(gid)); + ui->peerTreeWidget->setExpanded(index,true) ; } - -/** - * Add a gpgId to the openPeers list. These peers - * will be expanded, when they're added to the QTreeWidget - */ -void NewFriendList::addPeerToExpand(const RsPgpId& gpgId) -{ - openPeers.insert(gpgId); -} - diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 0f024d77b..0c87aee6a 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -56,10 +56,6 @@ public: // Add a tool button to the tool area void addToolButton(QToolButton *toolButton); void processSettings(bool load); - void addGroupToExpand(const RsNodeGroupId &groupId); - bool getExpandedGroups(std::set &groups) const; - void addPeerToExpand(const RsPgpId &gpgId); - bool getExpandedPeers(std::set &peers) const; void setColumnVisible(int col,bool visible); bool isColumnVisible(int col) const; @@ -103,6 +99,7 @@ private: RsFriendListModel *mModel; QAction *mActionSortByState; + void expandGroup(const RsNodeGroupId& gid); void recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set& exp, const std::set &sel); void recursSaveExpandedItems(const QModelIndex& index,const QString& parent_path,std::set& exp, std::set& sel); void saveExpandedPathsAndSelection(std::set& expanded_indexes, std::set& selected_indexes);