mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Store tree view state in project file
p4#: 21342
This commit is contained in:
parent
2ea01e34df
commit
638e82d24c
@ -41,6 +41,9 @@ RimProject::RimProject(void)
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&scriptCollection, "ScriptCollection", "Scripts", ":/Default.png", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&treeViewState, "TreeViewState", "", "", "", "");
|
||||
treeViewState.setUiHidden(true);
|
||||
|
||||
scriptCollection = new RimScriptCollection();
|
||||
scriptCollection->directory.setUiHidden(true);
|
||||
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
caf::PdmPointersField<RimCase*> reservoirs;
|
||||
caf::PdmPointersField<RimIdenticalGridCaseGroup*> caseGroups;
|
||||
caf::PdmField<RimScriptCollection*> scriptCollection;
|
||||
caf::PdmField<QString> treeViewState;
|
||||
|
||||
void setUserScriptPath(const QString& path);
|
||||
|
||||
|
@ -1199,3 +1199,82 @@ bool RimUiTreeView::checkAndHandleToggleOfMultipleSelection()
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void setExpandedState(QStringList& nodes, QTreeView* view, QAbstractItemModel* model,
|
||||
const QModelIndex startIndex, QString path)
|
||||
{
|
||||
path += QString::number(startIndex.row()) + QString::number(startIndex.column());
|
||||
for (int i = 0; i < model->rowCount(startIndex); ++i)
|
||||
{
|
||||
QModelIndex nextIndex = model->index(i, 0, startIndex);
|
||||
QString nextPath = path + QString::number(nextIndex.row()) + QString::number(nextIndex.column());
|
||||
if(!nodes.contains(nextPath))
|
||||
continue;
|
||||
|
||||
setExpandedState(nodes, view, model, model->index(i, 0, startIndex), path);
|
||||
}
|
||||
|
||||
if (nodes.contains(path))
|
||||
{
|
||||
view->setExpanded( startIndex.sibling(startIndex.row(), 0), true );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void storeExpandedState(QStringList & nodes, QTreeView * view, QAbstractItemModel * model,
|
||||
const QModelIndex startIndex, QString path)
|
||||
{
|
||||
path += QString::number(startIndex.row()) + QString::number(startIndex.column());
|
||||
for (int i = 0; i < model->rowCount(startIndex); ++i)
|
||||
{
|
||||
if(!view->isExpanded(model->index(i, 0, startIndex)))
|
||||
continue;
|
||||
|
||||
storeExpandedState(nodes, view, model, model->index(i, 0, startIndex), path);
|
||||
}
|
||||
|
||||
if (view->isExpanded(startIndex))
|
||||
{
|
||||
nodes << path;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::applyTreeViewState(const QString& treeViewState)
|
||||
{
|
||||
if (this->model())
|
||||
{
|
||||
this->collapseAll();
|
||||
|
||||
QString stateString = RiaApplication::instance()->project()->treeViewState;
|
||||
|
||||
QStringList nodes = stateString.split("|");
|
||||
QString path;
|
||||
|
||||
setExpandedState(nodes, this, this->model(), QModelIndex(), path);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::storeTreeViewState(QString& treeViewState)
|
||||
{
|
||||
if (this->model())
|
||||
{
|
||||
QStringList nodes;
|
||||
QString path;
|
||||
|
||||
storeExpandedState(nodes, this, this->model(), QModelIndex(), path);
|
||||
|
||||
QString stateString = nodes.join("|");
|
||||
RiaApplication::instance()->project()->treeViewState = stateString;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,9 @@ public:
|
||||
|
||||
virtual void setModel(QAbstractItemModel* model);
|
||||
|
||||
void applyTreeViewState(const QString& treeViewState);
|
||||
void storeTreeViewState(QString& treeViewState);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
|
||||
|
@ -724,6 +724,8 @@ void RiuMainWindow::slotOpenProject()
|
||||
app->loadProject(fileName);
|
||||
}
|
||||
|
||||
restoreTreeViewState();
|
||||
|
||||
//m_mainViewer->setDefaultView();
|
||||
}
|
||||
|
||||
@ -734,6 +736,8 @@ void RiuMainWindow::slotOpenLastUsedProject()
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
app->loadLastUsedProject();
|
||||
|
||||
restoreTreeViewState();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -889,6 +893,8 @@ void RiuMainWindow::slotSaveProject()
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
|
||||
storeTreeViewState();
|
||||
|
||||
app->saveProject();
|
||||
}
|
||||
|
||||
@ -899,6 +905,8 @@ void RiuMainWindow::slotSaveProjectAs()
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
|
||||
storeTreeViewState();
|
||||
|
||||
app->saveProjectPromptForFileName();
|
||||
}
|
||||
|
||||
@ -1406,3 +1414,34 @@ void RiuMainWindow::refreshDrawStyleActions()
|
||||
m_drawStyleToggleFaultsAction->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindow::storeTreeViewState()
|
||||
{
|
||||
if (m_treeView)
|
||||
{
|
||||
QString treeViewState;
|
||||
|
||||
m_treeView->storeTreeViewState(treeViewState);
|
||||
|
||||
RiaApplication::instance()->project()->treeViewState = treeViewState;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindow::restoreTreeViewState()
|
||||
{
|
||||
if (m_treeView)
|
||||
{
|
||||
QString stateString = RiaApplication::instance()->project()->treeViewState;
|
||||
if (!stateString.isEmpty())
|
||||
{
|
||||
m_treeView->collapseAll();
|
||||
m_treeView->applyTreeViewState(stateString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class RiuViewer;
|
||||
class RiuResultInfoPanel;
|
||||
class RiuProcessMonitor;
|
||||
class RimUiTreeModelPdm;
|
||||
class RimUiTreeView;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -95,6 +96,9 @@ private:
|
||||
|
||||
QMdiSubWindow* findMdiSubWindow(RiuViewer* viewer);
|
||||
|
||||
void storeTreeViewState();
|
||||
void restoreTreeViewState();
|
||||
|
||||
private:
|
||||
static RiuMainWindow* sm_mainWindowInstance;
|
||||
|
||||
@ -222,7 +226,7 @@ public:
|
||||
void setPdmRoot(caf::PdmObject* pdmRoot);
|
||||
|
||||
private:
|
||||
QTreeView* m_treeView;
|
||||
RimUiTreeView* m_treeView;
|
||||
RimUiTreeModelPdm* m_treeModelPdm;
|
||||
caf::PdmObject* m_pdmRoot;
|
||||
caf::PdmUiPropertyView* m_pdmUiPropertyView;
|
||||
|
Loading…
Reference in New Issue
Block a user