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