mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
keep groups sorted together, and auto-expand group when adding a profile to a group
This commit is contained in:
parent
0cea0e5217
commit
886d71e59c
@ -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;i<mGroups.size();++i)
|
||||
if(mGroups[i].group_info.id == mid)
|
||||
return index(i,0,QModelIndex());
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,7 +72,8 @@ public:
|
||||
StatusRole = Qt::UserRole+2,
|
||||
UnreadRole = Qt::UserRole+3,
|
||||
FilterRole = Qt::UserRole+4,
|
||||
OnlineRole = Qt::UserRole+5
|
||||
OnlineRole = Qt::UserRole+5,
|
||||
TypeRole = Qt::UserRole+6
|
||||
};
|
||||
|
||||
enum FilterType{ FILTER_TYPE_NONE = 0x00,
|
||||
|
@ -112,6 +112,12 @@ public:
|
||||
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
|
||||
{
|
||||
bool is_group_1 = left.data(RsFriendListModel::TypeRole).toUInt() == (uint)RsFriendListModel::ENTRY_TYPE_GROUP;
|
||||
bool is_group_2 = right.data(RsFriendListModel::TypeRole).toUInt() == (uint)RsFriendListModel::ENTRY_TYPE_GROUP;
|
||||
|
||||
if(is_group_1 ^ is_group_2) // if the two are different, put the group first.
|
||||
return is_group_1 ;
|
||||
|
||||
bool online1 = left .data(RsFriendListModel::OnlineRole).toBool();
|
||||
bool online2 = right.data(RsFriendListModel::OnlineRole).toBool();
|
||||
|
||||
@ -425,14 +431,14 @@ void NewFriendList::processSettings(bool load)
|
||||
|
||||
std::string gids = Settings->value("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<RsNodeGroupId> 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<RsNodeGroupId> 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<ElidedLabel*>();
|
||||
// textLabel = widget->property("textLabel").value<ElidedLabel*>();
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns a list with all groupIds that are expanded
|
||||
*/
|
||||
bool NewFriendList::getExpandedGroups(std::set<RsNodeGroupId> &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<RsPgpId> &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);
|
||||
}
|
||||
|
||||
|
@ -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<RsNodeGroupId> &groups) const;
|
||||
void addPeerToExpand(const RsPgpId &gpgId);
|
||||
bool getExpandedPeers(std::set<RsPgpId> &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<QString>& exp, const std::set<QString> &sel);
|
||||
void recursSaveExpandedItems(const QModelIndex& index,const QString& parent_path,std::set<QString>& exp, std::set<QString>& sel);
|
||||
void saveExpandedPathsAndSelection(std::set<QString>& expanded_indexes, std::set<QString>& selected_indexes);
|
||||
|
Loading…
Reference in New Issue
Block a user