mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-02 09:39:37 -05:00
#6106 Apply clang-format on AppFwk
This commit is contained in:
@@ -1,99 +1,98 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "cafQTreeViewStateSerializer.h"
|
||||
|
||||
|
||||
#include <QTreeView>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void setExpandedState(QStringList& nodes, QTreeView* view, QAbstractItemModel* model,
|
||||
const QModelIndex startIndex, QString path)
|
||||
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)
|
||||
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);
|
||||
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))
|
||||
|
||||
if ( nodes.contains( path ) )
|
||||
{
|
||||
view->setExpanded( startIndex.sibling(startIndex.row(), 0), true );
|
||||
view->setExpanded( startIndex.sibling( startIndex.row(), 0 ), true );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void storeExpandedState(QStringList & nodes, const QTreeView * view, QAbstractItemModel * model,
|
||||
const QModelIndex startIndex, QString path)
|
||||
void storeExpandedState( QStringList& nodes,
|
||||
const 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)
|
||||
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;
|
||||
if ( !view->isExpanded( model->index( i, 0, startIndex ) ) ) continue;
|
||||
|
||||
storeExpandedState(nodes, view, model, model->index(i, 0, startIndex), path);
|
||||
storeExpandedState( nodes, view, model, model->index( i, 0, startIndex ), path );
|
||||
}
|
||||
|
||||
if (view->isExpanded(startIndex))
|
||||
if ( view->isExpanded( startIndex ) )
|
||||
{
|
||||
nodes << path;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::QTreeViewStateSerializer::applyTreeViewStateFromString( QTreeView* treeView, const QString& treeViewState)
|
||||
void caf::QTreeViewStateSerializer::applyTreeViewStateFromString( QTreeView* treeView, const QString& treeViewState )
|
||||
{
|
||||
if (treeView->model())
|
||||
if ( treeView->model() )
|
||||
{
|
||||
treeView->collapseAll();
|
||||
|
||||
QStringList nodes = treeViewState.split(";");
|
||||
QStringList nodes = treeViewState.split( ";" );
|
||||
|
||||
QString path;
|
||||
setExpandedState(nodes, treeView, treeView->model(), QModelIndex(), path);
|
||||
setExpandedState( nodes, treeView, treeView->model(), QModelIndex(), path );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::QTreeViewStateSerializer::storeTreeViewStateToString(const QTreeView* treeView, QString& treeViewState)
|
||||
void caf::QTreeViewStateSerializer::storeTreeViewStateToString( const QTreeView* treeView, QString& treeViewState )
|
||||
{
|
||||
if (treeView->model())
|
||||
if ( treeView->model() )
|
||||
{
|
||||
QStringList nodes;
|
||||
QString path;
|
||||
QString path;
|
||||
|
||||
storeExpandedState(nodes, treeView, treeView->model(), QModelIndex(), path);
|
||||
storeExpandedState( nodes, treeView, treeView->model(), QModelIndex(), path );
|
||||
|
||||
treeViewState = nodes.join(";");
|
||||
treeViewState = nodes.join( ";" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,47 +100,50 @@ void caf::QTreeViewStateSerializer::storeTreeViewStateToString(const QTreeView*
|
||||
/// Find index based of an encode QString <row> <column>;<row> <column>;...;<row> <column>
|
||||
/// Set the decoded index as current index in the QAbstractItemView
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QModelIndex caf::QTreeViewStateSerializer::getModelIndexFromString(QAbstractItemModel* model, const QString& currentIndexString)
|
||||
QModelIndex caf::QTreeViewStateSerializer::getModelIndexFromString( QAbstractItemModel* model,
|
||||
const QString& currentIndexString )
|
||||
{
|
||||
QStringList modelIndexStringList = currentIndexString.split(";");
|
||||
QStringList modelIndexStringList = currentIndexString.split( ";" );
|
||||
|
||||
QModelIndex mi;
|
||||
|
||||
foreach (QString modelIndexString, modelIndexStringList)
|
||||
foreach ( QString modelIndexString, modelIndexStringList )
|
||||
{
|
||||
QStringList items = modelIndexString.split(" ");
|
||||
QStringList items = modelIndexString.split( " " );
|
||||
|
||||
if (items.size() != 2) continue;
|
||||
if ( items.size() != 2 ) continue;
|
||||
|
||||
int row = items[0].toInt();
|
||||
int col = items[1].toInt();
|
||||
|
||||
mi = model->index(row, col, mi);
|
||||
mi = model->index( row, col, mi );
|
||||
}
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Store path to model index in item view using follwoing encoding into a QString <row> <column>;<row> <column>;...;<row> <column>
|
||||
/// Store path to model index in item view using follwoing encoding into a QString <row> <column>;<row>
|
||||
/// <column>;...;<row> <column>
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::QTreeViewStateSerializer::encodeStringFromModelIndex(const QModelIndex mi, QString& encodedModelIndex)
|
||||
void caf::QTreeViewStateSerializer::encodeStringFromModelIndex( const QModelIndex mi, QString& encodedModelIndex )
|
||||
{
|
||||
if (!mi.isValid()) return;
|
||||
if ( !mi.isValid() ) return;
|
||||
|
||||
QModelIndex localModelIdx = mi;
|
||||
|
||||
while (localModelIdx.isValid())
|
||||
while ( localModelIdx.isValid() )
|
||||
{
|
||||
if (encodedModelIndex.isEmpty())
|
||||
if ( encodedModelIndex.isEmpty() )
|
||||
{
|
||||
encodedModelIndex = QString("%1 %2").arg(localModelIdx.row()).arg(localModelIdx.column()) + encodedModelIndex;
|
||||
encodedModelIndex = QString( "%1 %2" ).arg( localModelIdx.row() ).arg( localModelIdx.column() ) +
|
||||
encodedModelIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
encodedModelIndex = QString("%1 %2;").arg(localModelIdx.row()).arg(localModelIdx.column()) + encodedModelIndex;
|
||||
encodedModelIndex = QString( "%1 %2;" ).arg( localModelIdx.row() ).arg( localModelIdx.column() ) +
|
||||
encodedModelIndex;
|
||||
}
|
||||
localModelIdx = localModelIdx.parent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user