keep expand state when showing/hiding IPs and last connection state

This commit is contained in:
csoler 2020-08-22 19:14:46 +02:00
parent 335cd9a7c2
commit da21a40eda
2 changed files with 16 additions and 7 deletions

View file

@ -453,6 +453,7 @@ void NewFriendList::processSettings(bool load)
if (load) // load settings if (load) // load settings
{ {
std::cerr <<"Re-loading settings..." << std::endl;
// states // states
setShowUnconnected(!Settings->value("hideUnconnected", !mProxyModel->showOfflineNodes()).toBool()); setShowUnconnected(!Settings->value("hideUnconnected", !mProxyModel->showOfflineNodes()).toBool());
setShowState(Settings->value("showState", mModel->getDisplayStatusString()).toBool()); setShowState(Settings->value("showState", mModel->getDisplayStatusString()).toBool());
@ -1087,7 +1088,7 @@ void NewFriendList::removeGroup()
checkInternalData(true); checkInternalData(true);
} }
void NewFriendList::checkInternalData(bool force) void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
{ {
std::set<QString> expanded_indexes; std::set<QString> expanded_indexes;
std::set<QString> selected_indexes; std::set<QString> selected_indexes;
@ -1099,12 +1100,17 @@ void NewFriendList::checkInternalData(bool force)
mProxyModel->setSourceModel(nullptr); mProxyModel->setSourceModel(nullptr);
mModel->checkInternalData(force); predicate();
mProxyModel->setSourceModel(mModel); mProxyModel->setSourceModel(mModel);
restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes); restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes);
} }
void NewFriendList::checkInternalData(bool force)
{
applyWhileKeepingTree([force,this]() { mModel->checkInternalData(force) ; });
}
void NewFriendList::exportFriendlistClicked() void NewFriendList::exportFriendlistClicked()
{ {
QString fileName; QString fileName;
@ -1490,6 +1496,7 @@ bool NewFriendList::isColumnVisible(int col) const
} }
void NewFriendList::setColumnVisible(int col,bool visible) void NewFriendList::setColumnVisible(int col,bool visible)
{ {
std::cerr << "Setting column " << col << " to be visible: " << visible << std::endl;
ui->peerTreeWidget->setColumnHidden(col, !visible); ui->peerTreeWidget->setColumnHidden(col, !visible);
} }
void NewFriendList::toggleColumnVisible() void NewFriendList::toggleColumnVisible()
@ -1507,12 +1514,12 @@ void NewFriendList::toggleColumnVisible()
void NewFriendList::setShowState(bool show) void NewFriendList::setShowState(bool show)
{ {
mModel->setDisplayStatusString(show); applyWhileKeepingTree([show,this]() { mModel->setDisplayStatusString(show) ; });
} }
void NewFriendList::setShowGroups(bool show) void NewFriendList::setShowGroups(bool show)
{ {
mModel->setDisplayGroups(show); applyWhileKeepingTree([show,this]() { mModel->setDisplayGroups(show) ; });
} }
/** /**

View file

@ -102,6 +102,8 @@ private:
RsFriendListModel *mModel; RsFriendListModel *mModel;
QAction *mActionSortByState; QAction *mActionSortByState;
void applyWhileKeepingTree(std::function<void()> predicate);
void expandGroup(const RsNodeGroupId& gid); 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 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 recursSaveExpandedItems(const QModelIndex& index,const QString& parent_path,std::set<QString>& exp, std::set<QString>& sel);