save/restore expanded items when sorting

This commit is contained in:
csoler 2019-08-23 16:39:57 +02:00
parent fdea4febbe
commit b5cdd0f4f0
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 12 additions and 9 deletions

View File

@ -126,8 +126,7 @@ FriendList::FriendList(QWidget *parent) :
#ifdef RS_DIRECT_CHAT
connect(ui->peerTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
#else
connect( ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
this, SLOT(expandItem(QTreeWidgetItem *)) );
connect( ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) );
#endif
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged()));

View File

@ -185,7 +185,7 @@ NewFriendList::NewFriendList(QWidget *parent) : RsAutoUpdatePage(5000,parent), u
ui->peerTreeWidget->setSortingEnabled(true);
/* Set sort */
sortByColumn(RsFriendListModel::COLUMN_THREAD_NAME, Qt::AscendingOrder);
sortColumn(RsFriendListModel::COLUMN_THREAD_NAME, Qt::AscendingOrder);
toggleSortByState(false);
// workaround for Qt bug, should be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
@ -229,6 +229,11 @@ NewFriendList::NewFriendList(QWidget *parent) : RsAutoUpdatePage(5000,parent), u
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)));
connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint)));
// #ifdef RS_DIRECT_CHAT
// connect(ui->peerTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(chatNode()));
// #endif
}
NewFriendList::~NewFriendList()
@ -238,9 +243,14 @@ NewFriendList::~NewFriendList()
void NewFriendList::sortColumn(int col,Qt::SortOrder so)
{
std::set<QString> expanded_indexes;
std::set<QString> selected_indexes;
saveExpandedPathsAndSelection(expanded_indexes, selected_indexes);
mProxyModel->setSortingEnabled(true);
mProxyModel->sort(col,so);
mProxyModel->setSortingEnabled(false);
restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes);
}
void NewFriendList::headerContextMenuRequested(QPoint p)
@ -1538,11 +1548,6 @@ void NewFriendList::toggleColumnVisible()
ui->peerTreeWidget->setColumnHidden(column, !visible);
}
void NewFriendList::sortByColumn(int column, Qt::SortOrder sortOrder)
{
ui->peerTreeWidget->sortByColumn(column, sortOrder);
}
void NewFriendList::setShowState(bool show)
{
mModel->setDisplayStatusString(show);

View File

@ -64,7 +64,6 @@ public:
bool isColumnVisible(int col) const;
std::string getSelectedGroupId() const;
void sortByColumn(int column, Qt::SortOrder sortOrder);
void updateDisplay() override;