Maintain the workspace state even when refreshing
FossilOrigin-Name: 0eef20c8eb990a24b214a25b630b2786fee010d7
This commit is contained in:
@@ -690,6 +690,24 @@ static void addPathToTree(QStandardItem &root, const QString &path, const QIcon
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::updateWorkspaceView()
|
||||
{
|
||||
// Record expanded tree-node names, and selection
|
||||
name_modelindex_map_t name_map;
|
||||
BuildNameToModelIndex(name_map, getWorkspace().getTreeModel());
|
||||
stringset_t expanded_items;
|
||||
stringset_t selected_items;
|
||||
|
||||
const QItemSelection selection = ui->workspaceTreeView->selectionModel()->selection();
|
||||
|
||||
for(name_modelindex_map_t::const_iterator it=name_map.begin(); it!=name_map.end(); ++it)
|
||||
{
|
||||
const QModelIndex mi = it.value();
|
||||
if(ui->workspaceTreeView->isExpanded(mi))
|
||||
expanded_items.insert(it.key());
|
||||
|
||||
if(selection.contains(mi))
|
||||
selected_items.insert(it.key());
|
||||
}
|
||||
|
||||
// Clear content except headers
|
||||
getWorkspace().getTreeModel().removeRows(0, getWorkspace().getTreeModel().rowCount());
|
||||
|
||||
@@ -708,6 +726,9 @@ void MainWindow::updateWorkspaceView()
|
||||
|
||||
addPathToTree(*workspace, dir, getInternalIcon(":icons/icons/Folder-01.png"));
|
||||
}
|
||||
|
||||
// Expand root folder
|
||||
ui->workspaceTreeView->setExpanded(workspace->index(), true);
|
||||
}
|
||||
|
||||
// Branches
|
||||
@@ -778,8 +799,28 @@ void MainWindow::updateWorkspaceView()
|
||||
settings->setEditable(false);
|
||||
getWorkspace().getDirModel().appendRow(settings);
|
||||
#endif
|
||||
ui->workspaceTreeView->expandToDepth(0);
|
||||
//ui->workspaceTreeView->sortByColumn(0, Qt::AscendingOrder);
|
||||
|
||||
// Expand previously selected nodes
|
||||
name_map.clear();
|
||||
BuildNameToModelIndex(name_map, getWorkspace().getTreeModel());
|
||||
|
||||
for(stringset_t::const_iterator it=expanded_items.begin(); it!=expanded_items.end(); ++it)
|
||||
{
|
||||
name_modelindex_map_t::const_iterator mi_it = name_map.find(*it);
|
||||
if(mi_it!=name_map.end())
|
||||
ui->workspaceTreeView->setExpanded(mi_it.value(), true);
|
||||
}
|
||||
|
||||
// Select previous selected item
|
||||
for(stringset_t::const_iterator it=selected_items.begin(); it!=selected_items.end(); ++it)
|
||||
{
|
||||
name_modelindex_map_t::const_iterator mi_it = name_map.find(*it);
|
||||
if(mi_it!=name_map.end())
|
||||
{
|
||||
const QModelIndex &mi = mi_it.value();
|
||||
ui->workspaceTreeView->selectionModel()->select(mi, QItemSelectionModel::Select);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@@ -329,3 +329,41 @@ void ParseProperties(QStringMap &properties, const QStringList &lines, QChar sep
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GetStandardItemTextRecursive(QString &name, const QStandardItem &item, const QChar &separator)
|
||||
{
|
||||
if(item.parent())
|
||||
{
|
||||
GetStandardItemTextRecursive(name, *item.parent());
|
||||
name.append(separator);
|
||||
}
|
||||
|
||||
name.append(item.data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItem &item)
|
||||
{
|
||||
QString name;
|
||||
GetStandardItemTextRecursive(name, item);
|
||||
map.insert(name, item.index());
|
||||
|
||||
for(int i=0; i<item.rowCount(); ++i)
|
||||
{
|
||||
const QStandardItem *child = item.child(i);
|
||||
Q_ASSERT(child);
|
||||
BuildNameToModelIndex(map, *child);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel &model)
|
||||
{
|
||||
for(int i=0; i<model.rowCount(); ++i)
|
||||
{
|
||||
const QStandardItem *item = model.item(i);
|
||||
Q_ASSERT(item);
|
||||
BuildNameToModelIndex(map, *item);
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
#include <QMap>
|
||||
#include <QStandardItem>
|
||||
|
||||
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))
|
||||
#define FOSSIL_CHECKOUT1 "_FOSSIL_"
|
||||
@@ -15,6 +16,13 @@ QMessageBox::StandardButton DialogQuery(QWidget *parent, const QString &title, c
|
||||
QString QuotePath(const QString &path);
|
||||
QStringList QuotePaths(const QStringList &paths);
|
||||
|
||||
|
||||
typedef QMap<QString, QModelIndex> name_modelindex_map_t;
|
||||
void GetStandardItemTextRecursive(QString &name, const QStandardItem &item, const QChar &separator='/');
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItem &item);
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel &model);
|
||||
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
void ParseProperties(QStringMap &properties, const QStringList &lines, QChar separator=' ');
|
||||
|
||||
|
Reference in New Issue
Block a user