Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryRegistryToggleState.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 
18 
19 #include "berryObjects.h"
20 #include "berryObjectString.h"
21 #include "berryObjectStringMap.h"
22 
23 namespace berry {
24 
25 const QString RegistryToggleState::STATE_ID = "org.blueberry.ui.commands.toggleState";
26 
28  const SmartPointer<IConfigurationElement>& /*configurationElement*/,
29  const QString& /*propertyName*/, const Object::Pointer& data)
30 {
31  if (ObjectString::Pointer objStr = data.Cast<ObjectString>())
32  {
33  // This is the default value.
34  ReadDefault(*objStr);
35  SetShouldPersist(true);
36  }
37  else if (ObjectStringMap::Pointer parameters = data.Cast<ObjectStringMap>())
38  {
39  QString defaultObject = parameters->value("default");
40  if (!defaultObject.isNull())
41  {
42  ReadDefault(defaultObject);
43  }
44 
45  QString persistedObject = parameters->value("persisted");
46  if (!persistedObject.isNull())
47  {
48  ReadPersisted(persistedObject);
49  }
50  }
51  else
52  {
53  SetShouldPersist(true);
54  }
55 }
56 
57 void RegistryToggleState::ReadDefault(const QString& defaultString)
58 {
59  if (defaultString.compare("true", Qt::CaseInsensitive) == 0)
60  {
61  Object::Pointer newValue(new ObjectBool(true));
62  SetValue(newValue);
63  }
64 }
65 
66 void RegistryToggleState::ReadPersisted(const QString& persistedString)
67 {
68  if (persistedString.compare("false", Qt::CaseInsensitive) == 0)
69  {
70  SetShouldPersist(false);
71  }
72  else
73  {
74  SetShouldPersist(true);
75  }
76 }
77 
78 }
Implements transparent reference counting.
void SetInitializationData(const SmartPointer< IConfigurationElement > &configurationElement, const QString &propertyName, const Object::Pointer &data) override
void SetValue(const Object::Pointer &value) override
SmartPointer< Other > Cast() const