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

View File

@ -87,10 +87,10 @@ protected:
Ui::SharedFilesDialog ui; Ui::SharedFilesDialog ui;
virtual void processSettings(bool bLoad) = 0; 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 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>& 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>& selected_indexes) ; 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>& 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: protected:
//now context menu are created again every time theu are called ( in some //now context menu are created again every time theu are called ( in some