improved debug output and code in NewFriendList sorting

This commit is contained in:
csoler 2021-03-10 21:04:23 +01:00
parent 61a79b296e
commit e750a3fced

View File

@ -128,10 +128,10 @@ public:
bool online1 = (left .data(RsFriendListModel::OnlineRole).toInt() != RS_STATUS_OFFLINE); bool online1 = (left .data(RsFriendListModel::OnlineRole).toInt() != RS_STATUS_OFFLINE);
bool online2 = (right.data(RsFriendListModel::OnlineRole).toInt() != RS_STATUS_OFFLINE); bool online2 = (right.data(RsFriendListModel::OnlineRole).toInt() != RS_STATUS_OFFLINE);
if(online1 != online2 && m_sortByState) if((online1 != online2) && m_sortByState)
return (m_header->sortIndicatorOrder()==Qt::AscendingOrder)?online1:online2 ; // always put online nodes first return (m_header->sortIndicatorOrder()==Qt::AscendingOrder)?online1:online2 ; // always put online nodes first
return left.data(RsFriendListModel::SortRole) < right.data(RsFriendListModel::SortRole) ; return QSortFilterProxyModel::lessThan(left,right);
} }
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
@ -1123,6 +1123,7 @@ void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
std::cerr << "expanded paths are: " << std::endl; std::cerr << "expanded paths are: " << std::endl;
for(auto path:expanded_indexes) for(auto path:expanded_indexes)
std::cerr << " \"" << path.toStdString() << "\"" << std::endl; std::cerr << " \"" << path.toStdString() << "\"" << std::endl;
std::cerr << "Current sort column is: " << mLastSortColumn << " and order is " << mLastSortOrder << std::endl;
#endif #endif
whileBlocking(ui->peerTreeWidget)->clearSelection(); whileBlocking(ui->peerTreeWidget)->clearSelection();
@ -1140,7 +1141,9 @@ void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
col_sizes[i] = ui->peerTreeWidget->columnWidth(i); col_sizes[i] = ui->peerTreeWidget->columnWidth(i);
} }
#ifdef DEBUG_NEW_FRIEND_LIST
std::cerr << "Applying predicate..." << std::endl;
#endif
mProxyModel->setSourceModel(nullptr); mProxyModel->setSourceModel(nullptr);
predicate(); predicate();
@ -1158,6 +1161,9 @@ void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
// restore sorting // restore sorting
// sortColumn(mLastSortColumn,mLastSortOrder); // sortColumn(mLastSortColumn,mLastSortOrder);
#ifdef DEBUG_NEW_FRIEND_LIST
std::cerr << "Sorting again with sort column: " << mLastSortColumn << " and order " << mLastSortOrder << std::endl;
#endif
mProxyModel->sort(mLastSortColumn,mLastSortOrder); mProxyModel->sort(mLastSortColumn,mLastSortOrder);
if(selected_index.isValid()) if(selected_index.isValid())
@ -1166,6 +1172,9 @@ void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
void NewFriendList::sortColumn(int col,Qt::SortOrder so) void NewFriendList::sortColumn(int col,Qt::SortOrder so)
{ {
#ifdef DEBUG_NEW_FRIEND_LIST
std::cerr << "Sorting with column=" << col << " and order=" << so << std::endl;
#endif
std::set<QString> expanded_indexes; std::set<QString> expanded_indexes;
QString selected; QString selected;
QModelIndex selected_index; QModelIndex selected_index;