mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
143 lines
5.1 KiB
C++
143 lines
5.1 KiB
C++
//##################################################################################################
|
|
//
|
|
// Custom Visualization Core library
|
|
// Copyright (C) 2015 Ceetron Solutions AS
|
|
//
|
|
// This library may be used under the terms of either the GNU General Public License or
|
|
// the GNU Lesser General Public License as follows:
|
|
//
|
|
// GNU General Public License Usage
|
|
// This library 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.
|
|
//
|
|
// This library 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>>
|
|
// for more details.
|
|
//
|
|
// GNU Lesser General Public License Usage
|
|
// This library is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation; either version 2.1 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
|
// for more details.
|
|
//
|
|
//##################################################################################################
|
|
|
|
|
|
#include "cafPdmSettings.h"
|
|
|
|
#include "cafPdmField.h"
|
|
#include "cafPdmXmlObjectHandle.h"
|
|
|
|
|
|
|
|
namespace caf
|
|
{
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void PdmSettings::readFieldsFromApplicationStore(caf::PdmObjectHandle* object, const QString context)
|
|
{
|
|
// Qt doc :
|
|
//
|
|
// Constructs a QSettings object for accessing settings of the application and organization
|
|
// set previously with a call to QCoreApplication::setOrganizationName(),
|
|
// QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().
|
|
QSettings settings;
|
|
std::vector<caf::PdmFieldHandle*> fields;
|
|
|
|
object->fields(fields);
|
|
size_t i;
|
|
for (i = 0; i < fields.size(); i++)
|
|
{
|
|
caf::PdmFieldHandle* fieldHandle = fields[i];
|
|
|
|
std::vector<caf::PdmObjectHandle*> children;
|
|
fieldHandle->childObjects(&children);
|
|
for (size_t childIdx = 0; childIdx < children.size(); childIdx++)
|
|
{
|
|
caf::PdmObjectHandle* child = children[childIdx];
|
|
caf::PdmXmlObjectHandle* xmlObjHandle = xmlObj(child);
|
|
|
|
QString subContext = context + xmlObjHandle->classKeyword() + "/";
|
|
readFieldsFromApplicationStore(child, subContext);
|
|
}
|
|
|
|
if (children.size() == 0)
|
|
{
|
|
QString key = context + fieldHandle->keyword();
|
|
if (settings.contains(key))
|
|
{
|
|
QVariant val = settings.value(key);
|
|
|
|
caf::PdmValueField* valueField = dynamic_cast<caf::PdmValueField*>(fieldHandle);
|
|
CAF_ASSERT(valueField);
|
|
valueField->setFromQVariant(val);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void PdmSettings::writeFieldsToApplicationStore(caf::PdmObjectHandle* object, const QString context)
|
|
{
|
|
CAF_ASSERT(object);
|
|
|
|
// Qt doc :
|
|
//
|
|
// Constructs a QSettings object for accessing settings of the application and organization
|
|
// set previously with a call to QCoreApplication::setOrganizationName(),
|
|
// QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().
|
|
QSettings settings;
|
|
|
|
std::vector<caf::PdmFieldHandle*> fields;
|
|
object->fields(fields);
|
|
|
|
size_t i;
|
|
for (i = 0; i < fields.size(); i++)
|
|
{
|
|
caf::PdmFieldHandle* fieldHandle = fields[i];
|
|
|
|
std::vector<caf::PdmObjectHandle*> children;
|
|
fieldHandle->childObjects(&children);
|
|
for (size_t childIdx = 0; childIdx < children.size(); childIdx++)
|
|
{
|
|
caf::PdmObjectHandle* child = children[childIdx];
|
|
QString subContext;
|
|
if (context.isEmpty())
|
|
{
|
|
caf::PdmXmlObjectHandle* xmlObjHandle = xmlObj(child);
|
|
|
|
subContext = xmlObjHandle->classKeyword() + "/";
|
|
}
|
|
|
|
writeFieldsToApplicationStore(child, subContext);
|
|
}
|
|
|
|
if (children.size() == 0)
|
|
{
|
|
caf::PdmValueField* valueField = dynamic_cast<caf::PdmValueField*>(fieldHandle);
|
|
CAF_ASSERT(valueField);
|
|
settings.setValue(context + fieldHandle->keyword(), valueField->toQVariant());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace caf
|