Fix SharedFilesDialog take long time to update.

This is due to Qt bug: https://bugreports.qt.io/browse/QTBUG-11438
Thanks to Jolavillette
This commit is contained in:
Phenom 2020-05-12 13:54:24 +02:00
parent d8ca92da1b
commit bc27863d23

View File

@ -970,70 +970,82 @@ void SharedFilesDialog::recursExpandAll(const QModelIndex& index)
} }
} }
void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set<std::string>& exp, void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,
std::set<std::string>& vis, std::set<std::string>& exp,
std::set<std::string>& hid,
std::set<std::string>& sel std::set<std::string>& sel
) )
{ {
std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString();
#ifdef DEBUG_SHARED_FILES_DIALOG #ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl;
#endif #endif
if(ui.dirTreeView->selectionModel()->selection().contains(index)) if(ui.dirTreeView->selectionModel()->selection().contains(index))
sel.insert(local_path) ; sel.insert(local_path) ;
if(ui.dirTreeView->isRowHidden(index.row(),index.parent())) // Disable hidden check as we don't use it and Qt bug: https://bugreports.qt.io/browse/QTBUG-11438
{ /*if(ui.dirTreeView->isRowHidden(index.row(),index.parent()))
vis.insert(local_path) ; {
return ; hid.insert(local_path) ;
} return ;
}*/
if(ui.dirTreeView->isExpanded(index)) if(ui.dirTreeView->isExpanded(index))
{ {
#ifdef DEBUG_SHARED_FILES_DIALOG #ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "Index " << local_path << " is expanded." << std::endl; std::cerr << "Index " << local_path << " is expanded." << std::endl;
#endif #endif
if(index.isValid()) if(index.isValid())
exp.insert(local_path) ; exp.insert(local_path) ;
for(int row=0;row<ui.dirTreeView->model()->rowCount(index);++row) for(int row=0;row<ui.dirTreeView->model()->rowCount(index);++row)
recursSaveExpandedItems(index.child(row,0),local_path,exp,vis,sel) ; #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
} recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0,index),local_path,exp,hid,sel) ;
#else
recursSaveExpandedItems(index.child(row,0),local_path,exp,hid,sel) ;
#endif
}
#ifdef DEBUG_SHARED_FILES_DIALOG #ifdef DEBUG_SHARED_FILES_DIALOG
else else
std::cerr << "Index is not expanded." << std::endl; std::cerr << "Index is not expanded." << std::endl;
#endif #endif
} }
void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path,
const std::set<std::string>& exp, const std::set<std::string>& exp,
const std::set<std::string>& vis, const std::set<std::string>& hid,
const std::set<std::string> &sel) const std::set<std::string> &sel)
{ {
std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString();
#ifdef DEBUG_SHARED_FILES_DIALOG #ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl;
#endif #endif
if(sel.find(local_path) != sel.end())
ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
bool invisible = vis.find(local_path) != vis.end(); if(sel.find(local_path) != sel.end())
ui.dirTreeView->setRowHidden(index.row(),index.parent(),invisible ) ; ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
// if(invisible) // Disable hidden check as we don't use it and Qt bug: https://bugreports.qt.io/browse/QTBUG-11438
// mHiddenIndexes.push_back(proxyModel->mapToSource(index)); /*bool invisible = hid.find(local_path) != hid.end();
ui.dirTreeView->setRowHidden(index.row(),index.parent(),invisible ) ;*/
if(!invisible && exp.find(local_path) != exp.end()) // if(invisible)
{ // mHiddenIndexes.push_back(proxyModel->mapToSource(index));
if(/*!invisible &&*/ exp.find(local_path) != exp.end())
{
#ifdef DEBUG_SHARED_FILES_DIALOG #ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "re expanding index " << local_path << std::endl; std::cerr << "re expanding index " << local_path << std::endl;
#endif #endif
ui.dirTreeView->setExpanded(index,true) ; ui.dirTreeView->setExpanded(index,true) ;
for(int row=0;row<ui.dirTreeView->model()->rowCount(index);++row) for(int row=0;row<ui.dirTreeView->model()->rowCount(index);++row)
recursRestoreExpandedItems(index.child(row,0),local_path,exp,vis,sel) ; #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
} recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0,index),local_path,exp,hid,sel) ;
#else
recursRestoreExpandedItems(index.child(row,0),local_path,exp,hid,sel) ;
#endif
}
} }