From 2744bc97506ac744d8d121550c0ff8e2a066d7ab Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 8 Feb 2018 09:07:48 +0100 Subject: [PATCH] fixed saving of expanded items --- .../src/gui/FileTransfer/TransfersDialog.cpp | 87 ++++--------------- 1 file changed, 17 insertions(+), 70 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index d5d45eda6..0f853b60d 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -1840,99 +1840,46 @@ void TransfersDialog::updateDisplay() void TransfersDialog::insertTransfers() { + // Since downloads use an AstractItemModel, we just need to update it, while saving the selected and expanded items. + std::set expanded_hashes ; std::set selected_hashes ; ui.downloadList->setSortingEnabled(false); + ui.downloadList->blockSignals(true) ; - for(int row = 0; row < DLListModel->rowCount(); ++row) + std::cerr << "Updating transfers..." << std::endl; + + QAbstractItemModel *model = ui.downloadList->model(); + + for(int row = 0; row < model->rowCount(); ++row) { - QModelIndex index = DLListModel->index(row,0,QModelIndex()); + QModelIndex index = model->index(row,0,QModelIndex()); if(ui.downloadList->isExpanded(index)) - expanded_hashes.insert(DLListModel->index(row,COLUMN_ID).data(Qt::DisplayRole).toString()); + expanded_hashes.insert(model->index(row,COLUMN_ID).data(Qt::DisplayRole).toString()); if(ui.downloadList->selectionModel()->selection().contains(index)) - selected_hashes.insert(DLListModel->index(row,COLUMN_ID).data(Qt::DisplayRole).toString()); + selected_hashes.insert(model->index(row,COLUMN_ID).data(Qt::DisplayRole).toString()); } DLListModel->update_transfers(); - for(int row = 0; row < DLListModel->rowCount(); ++row) + for(int row = 0; row < model->rowCount(); ++row) { - QModelIndex index = DLListModel->index(row,0,QModelIndex()); + QModelIndex index = model->index(row,0,QModelIndex()); - if(expanded_hashes.end() != expanded_hashes.find(DLListModel->index(row,COLUMN_ID).data(Qt::DisplayRole).toString())) + if(expanded_hashes.end() != expanded_hashes.find(model->index(row,COLUMN_ID).data(Qt::DisplayRole).toString())) ui.downloadList->setExpanded(index,true); - if(selected_hashes.end() != selected_hashes.find(DLListModel->index(row,COLUMN_ID).data(Qt::DisplayRole).toString())) + if(selected_hashes.end() != selected_hashes.find(model->index(row,COLUMN_ID).data(Qt::DisplayRole).toString())) ui.downloadList->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); } ui.downloadList->setSortingEnabled(true); + ui.downloadList->blockSignals(false) ; -// /* disable for performance issues, enable after insert all transfers */ -// -// /* get the download lists */ -// std::list downHashes; -// rsFiles->FileDownloads(downHashes); -// -// /* build set for quick search */ -// std::set hashs; -// -// for (std::list::iterator it = downHashes.begin(); it != downHashes.end(); ++it) { -// hashs.insert(*it); -// } -// -// /* add downloads, first iterate all rows in list */ -// -// int rowCount = DLListModel->rowCount(); -// -// for (int row = 0; row < rowCount; ) { -// RsFileHash hash ( DLListModel->item(row, COLUMN_ID)->data(Qt::UserRole).toString().toStdString()); -// -// std::set::iterator hashIt = hashs.find(hash); -// if (hashIt == hashs.end()) { -// // remove not existing downloads -// DLListModel->removeRow(row); -// rowCount = DLListModel->rowCount(); -// continue; -// } -// -// FileInfo fileInfo; -// if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, fileInfo)) { -// DLListModel->removeRow(row); -// rowCount = DLListModel->rowCount(); -// continue; -// } -// -// hashs.erase(hashIt); -// -// if (addDLItem(row, fileInfo) < 0) { -// DLListModel->removeRow(row); -// rowCount = DLListModel->rowCount(); -// continue; -// } -// -// ++row; -// } -// -// /* then add new downloads to the list */ -// -// for (std::set::iterator hashIt = hashs.begin() -// ; hashIt != hashs.end(); ++hashIt) -// { -// FileInfo fileInfo; -// if (!rsFiles->FileDetails(*hashIt, RS_FILE_HINTS_DOWNLOAD, fileInfo)) { -// continue; -// } -// -// addDLItem(-1, fileInfo); -// } -// -// ui.downloadList->setSortingEnabled(true); - - // Now show upload hashes + // Now show upload hashes. Here we use the "old" way, since the number of uploads is generally not so large. // /* disable for performance issues, enable after insert all transfers */