Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryRadioState.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "berryRadioState.h"
18 
19 #include "berryObjectString.h"
20 #include "berryObjectStringMap.h"
21 
22 #include "berryIPreferences.h"
23 
24 namespace berry {
25 
26 const QString RadioState::STATE_ID = "org.blueberry.ui.commands.radioState";
27 const QString RadioState::PARAMETER_ID = "org.blueberry.ui.commands.radioStateParameter";
28 
30 {
31  SetShouldPersist(true);
32 }
33 
35  const QString& /*propertyName*/, const Object::Pointer& data)
36 {
37  bool shouldPersist = true; // persist by default
38  if (data.Cast<ObjectString>())
39  {
40  SetValue(data);
41  }
42  else if (ObjectStringMap::Pointer parameters = data.Cast<ObjectStringMap>())
43  {
44  const QString defaultString = parameters->value("default");
45  if (!defaultString.isNull())
46  {
47  Object::Pointer value(new ObjectString(defaultString));
48  SetValue(value);
49  }
50 
51  const QString persistedString = parameters->value("persisted");
52  if (!persistedString.isNull()
53  && persistedString.compare("false", Qt::CaseInsensitive) == 0)
54  shouldPersist = false;
55  }
56  SetShouldPersist(shouldPersist);
57 }
58 
59 void RadioState::Load(const SmartPointer<IPreferences>& store, const QString& preferenceKey)
60 {
61  if (!ShouldPersist())
62  return;
63 
64  const QString prefValue = store->Get(preferenceKey, QString());
65  if (!prefValue.isEmpty())
66  {
67  Object::Pointer value(new ObjectString(prefValue));
68  SetValue(value);
69  }
70 }
71 
72 void RadioState::Save(const SmartPointer<IPreferences>& store, const QString& preferenceKey)
73 {
74  if (!ShouldPersist())
75  return;
76 
77  const Object::Pointer value = GetValue();
78  if (ObjectString::Pointer objStr = value.Cast<ObjectString>())
79  {
80  store->Put(preferenceKey, *objStr);
81  }
82 }
83 
85 {
86  if (!(value.Cast<ObjectString>()))
87  return; // we set only String values
88  PersistentState::SetValue(value);
89 }
90 
91 }
void SetInitializationData(const SmartPointer< IConfigurationElement > &config, const QString &propertyName, const Object::Pointer &data) override
Implements transparent reference counting.
static const QString STATE_ID
static const QString PARAMETER_ID
void SetValue(const Object::Pointer &value) override
void Load(const SmartPointer< IPreferences > &store, const QString &preferenceKey) override
SmartPointer< Other > Cast() const
void Save(const SmartPointer< IPreferences > &store, const QString &preferenceKey) override