Computer Assisted Medical Intervention Tool Kit  version 5.2
camitk::PersistenceManager Class Reference

#include <PersistenceManager.h>

+ Collaboration diagram for camitk::PersistenceManager:

Static Public Member Functions

static QVariant fromProperties (const QObject *)
 
static void loadProperties (QObject *, QVariant)
 
static bool loadWorkspace (QString filepath)
 
static bool saveWorkspace (QString filepath)
 Save the whole Application workspace including components, settings (e.g. More...
 
static void updateVariantValueWhilePreservingType (QVariant &variant, QVariant &newValue, QString name="")
 Update the variant value while trying to preserve its type. More...
 

Static Protected Member Functions

static QVariant fromComponents (QList< Component * >, QDir rootPath)
 Converts component's filename and properties to QVariant. More...
 
static bool loadComponents (QVariant, QDir rootPath)
 Loads/Open the components from the QVariant and update the property values accordingly. More...
 
static QVariant stringToVariant (QString value)
 returns a valid QVariant for specific types corresponding to a specific string representation More...
 
static QString variantToString (const QVariant &variant)
 returns a specific string representation of (limited list of) some specific QVariant types More...
 

Member Function Documentation

◆ fromComponents()

QVariant camitk::PersistenceManager::fromComponents ( QList< Component * >  comps,
QDir  rootPath 
)
staticprotected

Converts component's filename and properties to QVariant.

Note
The filename is converted to a relative path using the rootPath parameter
Parameters
rootPathFilenames of the components will be stored relative to this path (if rootPath is /tmp, filename /tmp/test/t.obj will be saved as test/t.obj)

Referenced by saveWorkspace().

+ Here is the caller graph for this function:

◆ fromProperties()

QVariant camitk::PersistenceManager::fromProperties ( const QObject *  qobj)
static

References camitk::Property::getProperty(), camitk::Property::getReadOnly(), and variantToString().

Referenced by saveWorkspace(), camitk::Action::toVariant(), and camitk::Component::toVariant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadComponents()

bool camitk::PersistenceManager::loadComponents ( QVariant  comps,
QDir  rootPath 
)
staticprotected

Loads/Open the components from the QVariant and update the property values accordingly.

Parameters
rootPaththe root path to decipher the filename (which should be relative)
Returns
false if and only if the QVariant is not a list of components.

References CAMITK_WARNING_ALT, camitk::Component::fromVariant(), camitk::Component::getFrame(), camitk::Component::getFrameName(), camitk::Application::open(), and camitk::Application::refresh().

Referenced by loadWorkspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadProperties()

void camitk::PersistenceManager::loadProperties ( QObject *  qobj,
QVariant  props 
)
static

References updateVariantValueWhilePreservingType().

Referenced by camitk::Action::fromVariant(), camitk::Component::fromVariant(), camitk::PropertyObject::fromVariant(), and loadWorkspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadWorkspace()

bool camitk::PersistenceManager::loadWorkspace ( QString  filepath)
static

References CAMITK_WARNING_ALT, camitk::PropertyObject::fromVariant(), camitk::CamiTKFile::getContent(), camitk::Application::getMainWindow(), camitk::Application::getName(), camitk::Application::getPropertyObject(), camitk::Viewer::getPropertyObject(), camitk::CamiTKFile::getVersion(), camitk::Application::getViewer(), camitk::CamiTKFile::hasContent(), camitk::CamiTKFile::isValid(), camitk::CamiTKFile::load(), loadComponents(), loadProperties(), and camitk::CamiTKFile::version.

Referenced by camitk::Application::loadWorkspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveWorkspace()

bool camitk::PersistenceManager::saveWorkspace ( QString  filepath)
static

Save the whole Application workspace including components, settings (e.g.

viewers configuration, rendering options...), frames and transformations, action settings

References camitk::CamiTKFile::addContent(), fromComponents(), fromProperties(), camitk::Application::getAction(), camitk::Application::getMainWindow(), camitk::Application::getName(), camitk::Application::getPropertyObject(), camitk::Application::getTopLevelComponents(), camitk::Application::getViewers(), camitk::CamiTKFile::save(), camitk::Action::toVariant(), and camitk::PropertyObject::toVariant().

Referenced by camitk::Application::saveWorkspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringToVariant()

QVariant camitk::PersistenceManager::stringToVariant ( QString  value)
staticprotected

returns a valid QVariant for specific types corresponding to a specific string representation

This method use a specific string representation as produced by the variantToString(..) method to build a QVariant of the corresponding specific user type if possible.

The supported types are the same the one defined in the variantToString(..). See QSettings::stringToVariant https://codebrowser.dev/qt5/qtbase/src/corelib/io/qsettings.cpp.html#477

See also
variantToString(QVariant &variant)
Returns
If the parameter does not represent a supported QVariant (e.g. a normal QString), the method returns an invalid QVariant

Referenced by updateVariantValueWhilePreservingType().

+ Here is the caller graph for this function:

◆ updateVariantValueWhilePreservingType()

void camitk::PersistenceManager::updateVariantValueWhilePreservingType ( QVariant &  variant,
QVariant &  newValue,
QString  name = "" 
)
static

Update the variant value while trying to preserve its type.

This function updates the value of the given variant using the value of the newValue QVariant while preserving the QVariant type defined in variant (when possible). Note that name is informational only abd used for debug reason to print a more comprehensible message when preserving the type of variant is not possible.

Example: myVariant = QVariant<QUrl>("http://example.com"); newVariantValue = QVariant<QString>("http://newerexample.com"); updatePreservingType(myVariant, newVariantValue, "my url"); oldVariant is now a QUrl (not a QString) but with the new content "http://newerexample.com"

This is useful as saving to JSON might lose the type e.g. QUrl -> QString, QUuid -> QString

To properly restore variants (e.g. Property or Settings), without modifying the QVariant types, the type must be infered from the existing variant.

WARNING: if the given variant does not have the same structure as the newValue, data may not be copied. e.g. copying a QList<QString> into a QString will result in an empty QString.

References CAMITK_TRACE_ALT, and stringToVariant().

Referenced by loadProperties().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variantToString()

QString camitk::PersistenceManager::variantToString ( const QVariant &  variant)
staticprotected

returns a specific string representation of (limited list of) some specific QVariant types

The value of QRect and QByteArray values cannot be recovered directly from a QString if some specific conversion are not taken care of. For instance, as JSON has 6 predefined data types many QVariant types will be stored as QString or cannot be handle specifically during serialization and deserialization.

This methods reproduces the same principle as QSettings in order to use specific strings for specific QVariant type.

See QSettings::variantToString method https://codebrowser.dev/qt5/qtbase/src/corelib/io/qsettings.cpp.html#395

As for now only the following types are supported

  • QRect
  • QByteArray

References a.

Referenced by fromProperties().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: