Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryToggleState.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 "berryToggleState.h"
18 
19 #include "berryObjects.h"
20 
21 #include "berryIPreferences.h"
22 
23 #include <QStringList>
24 
25 namespace berry {
26 
28 {
29  Object::Pointer value(new ObjectBool(false));
30  SetValue(value);
31 }
32 
34  const QString& preferenceKey)
35 {
36  bool currentValue = GetValue().Cast<ObjectBool>()->GetValue();
37  //store.setDefault(preferenceKey, currentValue);
38  if (ShouldPersist() && (store->Keys().contains(preferenceKey)))
39  {
40  const bool value = store->GetBool(preferenceKey, currentValue);
41  if (value != currentValue)
42  {
43  Object::Pointer newValue(new ObjectBool(value));
44  SetValue(newValue);
45  }
46  }
47 }
48 
50  const QString& preferenceKey)
51 {
52  if (ShouldPersist())
53  {
54  const Object::Pointer value = GetValue();
55  if (ObjectBool::Pointer boolValue = value.Cast<ObjectBool>())
56  {
57  store->PutBool(preferenceKey, boolValue->GetValue());
58  }
59  }
60 }
61 
63 {
64  if (!(value.Cast<ObjectBool>()))
65  {
66  throw ctkInvalidArgumentException("ToggleState takes a Boolean as a value");
67  }
68 
69  PersistentState::SetValue(value);
70 }
71 
72 }
void Load(const SmartPointer< IPreferences > &store, const QString &preferenceKey) override
void Save(const SmartPointer< IPreferences > &store, const QString &preferenceKey) override
void SetValue(const Object::Pointer &value) override
SmartPointer< Other > Cast() const