mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
In RimProject, encode/decode into a string the currentIndex from QTreeView.
This will also make sure the active view is restored when opening a project p4#: 21463
This commit is contained in:
parent
3806ff9baf
commit
ab8dfb4aad
@ -44,6 +44,9 @@ RimProject::RimProject(void)
|
|||||||
CAF_PDM_InitFieldNoDefault(&treeViewState, "TreeViewState", "", "", "", "");
|
CAF_PDM_InitFieldNoDefault(&treeViewState, "TreeViewState", "", "", "", "");
|
||||||
treeViewState.setUiHidden(true);
|
treeViewState.setUiHidden(true);
|
||||||
|
|
||||||
|
CAF_PDM_InitFieldNoDefault(¤tModelIndexPath, "TreeViewCurrentModelIndexPath", "", "", "", "");
|
||||||
|
currentModelIndexPath.setUiHidden(true);
|
||||||
|
|
||||||
scriptCollection = new RimScriptCollection();
|
scriptCollection = new RimScriptCollection();
|
||||||
scriptCollection->directory.setUiHidden(true);
|
scriptCollection->directory.setUiHidden(true);
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
caf::PdmPointersField<RimIdenticalGridCaseGroup*> caseGroups;
|
caf::PdmPointersField<RimIdenticalGridCaseGroup*> caseGroups;
|
||||||
caf::PdmField<RimScriptCollection*> scriptCollection;
|
caf::PdmField<RimScriptCollection*> scriptCollection;
|
||||||
caf::PdmField<QString> treeViewState;
|
caf::PdmField<QString> treeViewState;
|
||||||
|
caf::PdmField<QString> currentModelIndexPath;
|
||||||
|
|
||||||
void setScriptDirectories(const QString& scriptDirectories);
|
void setScriptDirectories(const QString& scriptDirectories);
|
||||||
|
|
||||||
|
@ -1297,6 +1297,55 @@ void RimUiTreeView::storeTreeViewStateToString(QString& treeViewState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Find index based of an encode QString <row> <column>;<row> <column>;...;<row> <column>
|
||||||
|
/// Set the decoded index as current index in the QAbstractItemView
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimUiTreeView::applyCurrentIndexFromString(QAbstractItemView& itemView, const QString& currentIndexString)
|
||||||
|
{
|
||||||
|
QStringList modelIndexStringList = currentIndexString.split(";");
|
||||||
|
|
||||||
|
QModelIndex mi;
|
||||||
|
|
||||||
|
foreach (QString modelIndexString, modelIndexStringList)
|
||||||
|
{
|
||||||
|
QStringList items = modelIndexString.split(" ");
|
||||||
|
|
||||||
|
if (items.size() != 2) continue;
|
||||||
|
|
||||||
|
int row = items[0].toInt();
|
||||||
|
int col = items[1].toInt();
|
||||||
|
|
||||||
|
mi = itemView.model()->index(row, col, mi);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mi.isValid())
|
||||||
|
{
|
||||||
|
itemView.setCurrentIndex(mi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Store path to current index in item view using follwoing encoding into a QString <row> <column>;<row> <column>;...;<row> <column>
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimUiTreeView::storeCurrentIndexToString(const QAbstractItemView& itemView, QString& currentIndexString)
|
||||||
|
{
|
||||||
|
QModelIndex mi = itemView.currentIndex();
|
||||||
|
if (!mi.isValid()) return;
|
||||||
|
|
||||||
|
QString path = QString("%1 %2").arg(mi.row()).arg(mi.column());
|
||||||
|
mi = mi.parent();
|
||||||
|
|
||||||
|
while (mi.isValid())
|
||||||
|
{
|
||||||
|
path = QString("%1 %2;").arg(mi.row()).arg(mi.column()) + path;
|
||||||
|
mi = mi.parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentIndexString = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -46,6 +46,9 @@ public:
|
|||||||
void applyTreeViewStateFromString(const QString& treeViewState);
|
void applyTreeViewStateFromString(const QString& treeViewState);
|
||||||
void storeTreeViewStateToString(QString& treeViewState);
|
void storeTreeViewStateToString(QString& treeViewState);
|
||||||
|
|
||||||
|
static void applyCurrentIndexFromString(QAbstractItemView& itemView, const QString& currentIndexString);
|
||||||
|
static void storeCurrentIndexToString(const QAbstractItemView& itemView, QString& currentIndexString);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent* event);
|
void contextMenuEvent(QContextMenuEvent* event);
|
||||||
|
|
||||||
|
@ -1428,10 +1428,13 @@ void RiuMainWindow::storeTreeViewState()
|
|||||||
if (m_treeView)
|
if (m_treeView)
|
||||||
{
|
{
|
||||||
QString treeViewState;
|
QString treeViewState;
|
||||||
|
|
||||||
m_treeView->storeTreeViewStateToString(treeViewState);
|
m_treeView->storeTreeViewStateToString(treeViewState);
|
||||||
|
|
||||||
|
QString currentIndexString;
|
||||||
|
RimUiTreeView::storeCurrentIndexToString(*m_treeView, currentIndexString);
|
||||||
|
|
||||||
RiaApplication::instance()->project()->treeViewState = treeViewState;
|
RiaApplication::instance()->project()->treeViewState = treeViewState;
|
||||||
|
RiaApplication::instance()->project()->currentModelIndexPath = currentIndexString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1448,6 +1451,12 @@ void RiuMainWindow::restoreTreeViewState()
|
|||||||
m_treeView->collapseAll();
|
m_treeView->collapseAll();
|
||||||
m_treeView->applyTreeViewStateFromString(stateString);
|
m_treeView->applyTreeViewStateFromString(stateString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString currentIndexString = RiaApplication::instance()->project()->currentModelIndexPath;
|
||||||
|
if (!currentIndexString.isEmpty())
|
||||||
|
{
|
||||||
|
RimUiTreeView::applyCurrentIndexFromString(*m_treeView, currentIndexString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user