Medical Imaging Interaction Toolkit  2021.02.99-f0b8f189
Medical Imaging Interaction Toolkit
Persistence Concept

In general, persistence referes to the capability of an application to permanently store data, settings, states, etc. so that they outlive a restart. Normal data objects, such as images, surfaces, etc., which are visible in the data storage of MITK can be saved easily by the save/load functions, see Data Management Concept for more details. This page focus on the persistence of settings, configurations, object states and parameters of the application. Depending on the component, e.g. plugin, module, etc., where you want to store your settings, MITK offers various ways to do so:

  1. For code inside UI independent modules with low dependencies to other libraries the mitk::PersistenceService inside the MITK persistence module can be used to store parameters by using the mitk::PropertyList class: MITK Persistence Service
  2. UI dependent code where the Qt library is available can use QSettings: Qt Settings
  3. If the UI setting of Plugins should be stored permanently, the persistence features of blueberry can be used: Persistence Features of Blueberry
  4. Extended features, which include persistence, are provided by the configuration service. Configuration Service

MITK Persistence Service

For persistence of member variables and parameters, the interface mitk::IPersistenceService in the MITK core provides an API to store variables permanently by means of mitk::PropertyList objects. These properties can be stored inside a MITK scene together with the data so that the user loads data and restores the application state at once. The current actual implementation of this interface can be found in the module Persistence. The class mitk::PersistenceService offers a rather simple way to store variables permanently.

To enable MITK persistence inside your class, simply include the persistence interface and use PERSISTENCE_GET_SERVICE_METHOD_MACRO in the private part of your class, as shown in the next code snippet:

You can then access a persistent property list by using a unique id, e.g. the name of your plugin. Variables can be added to this property list and will be available after restarting the application.

mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList("org.mitk.myUniqueModule");
//set a variable:
propList->Set("deviceNumber", m_Controls->GrabbingDeviceNumber->value());
//get a variable:
int grabbingDeviceNumber = 0;
propList->Get("deviceNumber", deviceNumber);

When a MITK scene with stored property list is loaded within MITK the list will change automatically. However a class can be informed by the service object by when the list is changed by adding it as observer to the service object.


An example implementation for the use of the mitk::PersistenceService can be found in the module OpenCVVideoSupport (class QmitkOpenCVVideoControls) and in the corresponding unit test mitkPersistenceTest in the Persistence module.

Qt Settings

Within the UI dependent modules inside MITK, the Qt::settings class can also be used to store variables permanently. The following code snippet shows an example:

//in the header:
#include <QSettings>
QSettings m_MySettings;
//in the cpp file:
//initialize the settings object (e.g. constructor):
//store settings:
//load settings:
int intExample = m_MySettings.value("identifier").toInt();

However, integration into a MITK scene file is not possible with Qt::settings.

Persistence Features of Blueberry

In blueberry, the view states can be saved and restored which is described here: Save and Restore your View State. Additionally, there is a possibility to make the preferences of a view persistent, which is documented in the class API documentation of the persistence service.

Configuration Service

An implementation of a configuration service is planned for MITK in near future but not available yet.