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,8 +970,9 @@ void SharedFilesDialog::recursExpandAll(const QModelIndex& index)
}
}
void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set<std::string>& exp,
std::set<std::string>& vis,
void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,
std::set<std::string>& exp,
std::set<std::string>& hid,
std::set<std::string>& sel
)
{
@ -983,11 +984,12 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s
if(ui.dirTreeView->selectionModel()->selection().contains(index))
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) ;
hid.insert(local_path) ;
return ;
}
}*/
if(ui.dirTreeView->isExpanded(index))
{
@ -998,7 +1000,11 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s
exp.insert(local_path) ;
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
else
@ -1008,23 +1014,25 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s
void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path,
const std::set<std::string>& exp,
const std::set<std::string>& vis,
const std::set<std::string>& hid,
const std::set<std::string> &sel)
{
std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString();
#ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl;
#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();
ui.dirTreeView->setRowHidden(index.row(),index.parent(),invisible ) ;
// Disable hidden check as we don't use it and Qt bug: https://bugreports.qt.io/browse/QTBUG-11438
/*bool invisible = hid.find(local_path) != hid.end();
ui.dirTreeView->setRowHidden(index.row(),index.parent(),invisible ) ;*/
// if(invisible)
// mHiddenIndexes.push_back(proxyModel->mapToSource(index));
if(!invisible && exp.find(local_path) != exp.end())
if(/*!invisible &&*/ exp.find(local_path) != exp.end())
{
#ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "re expanding index " << local_path << std::endl;
@ -1032,7 +1040,11 @@ void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, con
ui.dirTreeView->setExpanded(index,true) ;
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
}
}