Medical Imaging Interaction Toolkit  2018.4.99-6aa36ba9
Medical Imaging Interaction Toolkit
berryRegistryToggleState.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "berryObjects.h"
16 #include "berryObjectString.h"
17 #include "berryObjectStringMap.h"
18 
19 namespace berry {
20 
21 const QString RegistryToggleState::STATE_ID = "org.blueberry.ui.commands.toggleState";
22 
24  const SmartPointer<IConfigurationElement>& /*configurationElement*/,
25  const QString& /*propertyName*/, const Object::Pointer& data)
26 {
27  if (ObjectString::Pointer objStr = data.Cast<ObjectString>())
28  {
29  // This is the default value.
30  ReadDefault(*objStr);
31  SetShouldPersist(true);
32  }
33  else if (ObjectStringMap::Pointer parameters = data.Cast<ObjectStringMap>())
34  {
35  QString defaultObject = parameters->value("default");
36  if (!defaultObject.isNull())
37  {
38  ReadDefault(defaultObject);
39  }
40 
41  QString persistedObject = parameters->value("persisted");
42  if (!persistedObject.isNull())
43  {
44  ReadPersisted(persistedObject);
45  }
46  }
47  else
48  {
49  SetShouldPersist(true);
50  }
51 }
52 
53 void RegistryToggleState::ReadDefault(const QString& defaultString)
54 {
55  if (defaultString.compare("true", Qt::CaseInsensitive) == 0)
56  {
57  Object::Pointer newValue(new ObjectBool(true));
58  SetValue(newValue);
59  }
60 }
61 
62 void RegistryToggleState::ReadPersisted(const QString& persistedString)
63 {
64  if (persistedString.compare("false", Qt::CaseInsensitive) == 0)
65  {
66  SetShouldPersist(false);
67  }
68  else
69  {
70  SetShouldPersist(true);
71  }
72 }
73 
74 }
SmartPointer< Other > Cast() const
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