fixed bug causing hidden/expanded items to be reset by show() event in SharedFilesDialog

This commit is contained in:
csoler 2018-01-24 22:02:49 +01:00
parent 1fbd9d1625
commit 11eef05a1b
2 changed files with 39 additions and 24 deletions

View File

@ -287,14 +287,14 @@ void SharedFilesDialog::showEvent(QShowEvent *)
{
if(model!=NULL)
{
std::set<std::string> expanded_indexes,selected_indexes ;
std::set<std::string> expanded_indexes,hidden_indexes,selected_indexes ;
saveExpandedPathsAndSelection(expanded_indexes,selected_indexes);
saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes);
model->setVisible(true) ;
model->update() ;
restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes);
restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes);
}
}
RemoteSharedFilesDialog::~RemoteSharedFilesDialog()
@ -391,9 +391,9 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex)
showProperColumns() ;
std::set<std::string> expanded_indexes,selected_indexes ;
std::set<std::string> expanded_indexes,hidden_indexes,selected_indexes ;
saveExpandedPathsAndSelection(expanded_indexes,selected_indexes);
saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes);
if(isVisible())
{
@ -407,7 +407,7 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex)
ui.dirTreeView->setModel(proxyModel);
ui.dirTreeView->update();
restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes);
restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes);
QHeaderView * header = ui.dirTreeView->header () ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Interactive);
@ -862,17 +862,19 @@ void SharedFilesDialog::preModDirectories(bool local)
ui.dirTreeView->setSortingEnabled(false);
std::set<std::string> expanded_indexes,selected_indexes;
saveExpandedPathsAndSelection(expanded_indexes,selected_indexes) ;
std::set<std::string> expanded_indexes,hidden_indexes,selected_indexes;
saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ;
/* Notify both models, only one is visible */
tree_model->preMods();
flat_model->preMods();
restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes) ;
restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ;
}
void SharedFilesDialog::saveExpandedPathsAndSelection(std::set<std::string>& expanded_indexes, std::set<std::string>& selected_indexes)
void SharedFilesDialog::saveExpandedPathsAndSelection(std::set<std::string>& expanded_indexes,
std::set<std::string>& hidden_indexes,
std::set<std::string>& selected_indexes)
{
if(ui.dirTreeView->model() == NULL)
return ;
@ -884,11 +886,13 @@ void SharedFilesDialog::saveExpandedPathsAndSelection(std::set<std::string>& exp
{
std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString();
recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes);
recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,hidden_indexes,selected_indexes);
}
}
void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set<std::string>& expanded_indexes, const std::set<std::string>& selected_indexes)
void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set<std::string>& expanded_indexes,
const std::set<std::string>& hidden_indexes,
const std::set<std::string>& selected_indexes)
{
if(ui.dirTreeView->model() == NULL)
return ;
@ -903,14 +907,17 @@ void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set<std::str
for(int row = 0; row < ui.dirTreeView->model()->rowCount(); ++row)
{
std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString();
recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes);
recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,hidden_indexes,selected_indexes);
}
QItemSelection selection ;
ui.dirTreeView->blockSignals(false) ;
}
void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set<std::string>& exp,std::set<std::string>& sel)
void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set<std::string>& exp,
std::set<std::string>& vis,
std::set<std::string>& sel
)
{
std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString();
#ifdef DEBUG_SHARED_FILES_DIALOG
@ -920,6 +927,9 @@ 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()))
vis.insert(local_path) ;
if(ui.dirTreeView->isExpanded(index))
{
#ifdef DEBUG_SHARED_FILES_DIALOG
@ -929,7 +939,7 @@ 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,sel) ;
recursSaveExpandedItems(index.child(row,0),local_path,exp,vis,sel) ;
}
#ifdef DEBUG_SHARED_FILES_DIALOG
else
@ -937,7 +947,10 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s
#endif
}
void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set<std::string>& exp, const std::set<std::string> &sel)
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> &sel)
{
std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString();
#ifdef DEBUG_SHARED_FILES_DIALOG
@ -946,6 +959,8 @@ void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, con
if(sel.find(local_path) != sel.end())
ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
ui.dirTreeView->setRowHidden(index.row(),index.parent(), vis.find(local_path) != vis.end()) ;
if(exp.find(local_path) != exp.end())
{
#ifdef DEBUG_SHARED_FILES_DIALOG
@ -954,7 +969,7 @@ 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,sel) ;
recursRestoreExpandedItems(index.child(row,0),local_path,exp,vis,sel) ;
}
}
@ -964,9 +979,9 @@ void SharedFilesDialog::postModDirectories(bool local)
if (isRemote() == local)
return;
std::set<std::string> expanded_indexes,selected_indexes;
std::set<std::string> expanded_indexes,selected_indexes,hidden_indexes;
saveExpandedPathsAndSelection(expanded_indexes,selected_indexes) ;
saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ;
#ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "Saving expanded items. " << expanded_indexes.size() << " items found" << std::endl;
#endif
@ -981,7 +996,7 @@ void SharedFilesDialog::postModDirectories(bool local)
ui.dirTreeView->setSortingEnabled(true);
restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes) ;
restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ;
#ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "****** updated directories! Re-enabling sorting ******" << std::endl;

View File

@ -87,10 +87,10 @@ protected:
Ui::SharedFilesDialog ui;
virtual void processSettings(bool bLoad) = 0;
void recursRestoreExpandedItems(const QModelIndex& index,const std::string& path,const std::set<std::string>& exp,const std::set<std::string>& sel);
void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set<std::string> &exp, std::set<std::string>& sel);
void saveExpandedPathsAndSelection(std::set<std::string>& paths, std::set<std::string>& selected_indexes) ;
void restoreExpandedPathsAndSelection(const std::set<std::string>& paths, const std::set<std::string>& selected_indexes) ;
void 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>& sel);
void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set<std::string> &exp,std::set<std::string>& vis, std::set<std::string>& sel);
void saveExpandedPathsAndSelection(std::set<std::string>& paths,std::set<std::string>& visible_indexes, std::set<std::string>& selected_indexes) ;
void restoreExpandedPathsAndSelection(const std::set<std::string>& paths,const std::set<std::string>& visible_indexes, const std::set<std::string>& selected_indexes) ;
protected:
//now context menu are created again every time theu are called ( in some