Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
QmitkNodeSelectionPreferenceHelper.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 <internal/QmitkNodeSelectionConstants.h>
16 
18 
19 #include <berryIPreferences.h>
21 #include <berryPlatform.h>
22 
23 
24 #include "mitkExceptionMacro.h"
25 
27 {
30  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
32  prefNode->Node(mitk::NodeSelectionConstants::VISIBLE_INSPECTORS_NODE_ID.c_str());
33 
34  visNode->RemoveNode();
35  prefNode->Flush();
36 
37  // new empty preset node
38  visNode = prefNode->Node(mitk::NodeSelectionConstants::VISIBLE_INSPECTORS_NODE_ID.c_str());
39 
40  // store map in new node
41  for (const auto &inspector : inspectors)
42  {
43  std::ostringstream sstr;
44  sstr << inspector.first;
45  berry::IPreferences::Pointer aNode = visNode->Node(QString::fromStdString(sstr.str()));
46 
47  aNode->Put(mitk::NodeSelectionConstants::VISIBLE_INSPECTOR_ID.c_str(), inspector.second.c_str());
48  aNode->Flush();
49  }
50 
51  visNode->Flush();
52 }
53 
55 {
57 
59  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
61  prefNode->Node(mitk::NodeSelectionConstants::VISIBLE_INSPECTORS_NODE_ID.c_str());
62 
63  typedef QStringList NamesType;
64  NamesType names = visNode->ChildrenNames();
65 
67 
68  if (!names.empty())
69  {
70  for (NamesType::const_iterator pos = names.begin(); pos != names.end(); ++pos)
71  {
72  berry::IPreferences::Pointer aNode = visNode->Node(*pos);
73 
74  if (aNode.IsNull())
75  {
76  mitkThrow() << "Error in preference interface. Cannot find preset node under given name. Name: "
77  << (*pos).toStdString();
78  }
79 
80  std::istringstream isstr(pos->toStdString());
81  unsigned int order = 0;
82  isstr >> order;
83 
84  auto id = aNode->Get(mitk::NodeSelectionConstants::VISIBLE_INSPECTOR_ID.c_str(), "");
85  if (id.isEmpty())
86  {
87  mitkThrow() << "Error in preference interface. ID of visible inspector is not set. Inspector position: "
88  << order;
89  }
90 
91  visMap.insert(std::make_pair(order, id.toStdString()));
92  }
93  }
94  return visMap;
95 }
96 
98 {
100 
102  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
103 
104  auto id = prefNode->Get(mitk::NodeSelectionConstants::PREFERRED_INSPECTOR_ID.c_str(), "");
105 
106  mitk::DataStorageInspectorIDType result = id.toStdString();
107  return result;
108 }
109 
111 {
113 
115  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
116 
117  prefNode->Put(mitk::NodeSelectionConstants::PREFERRED_INSPECTOR_ID.c_str(), id.c_str());
118  prefNode->Flush();
119 }
120 
122 {
124 
126  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
127 
128  prefNode->PutBool(mitk::NodeSelectionConstants::SHOW_FAVORITE_INSPECTOR.c_str(), show);
129  prefNode->Flush();
130 }
131 
133 {
135 
137  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
138 
139  return prefNode->GetBool(mitk::NodeSelectionConstants::SHOW_FAVORITE_INSPECTOR.c_str(), true);
140 }
141 
143 {
145 
147  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
148 
149  prefNode->PutBool(mitk::NodeSelectionConstants::SHOW_HISTORY_INSPECTOR.c_str(), show);
150  prefNode->Flush();
151 }
152 
154 {
156 
158  prefService->GetSystemPreferences()->Node(mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID.c_str());
159 
160  return prefNode->GetBool(mitk::NodeSelectionConstants::SHOW_HISTORY_INSPECTOR.c_str(), true);
161 }
std::string DataStorageInspectorIDType
void PutShowHistoryInspector(bool show)
void PutPreferredDataStorageInspector(const DataStorageInspectorIDType &id)
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
VisibleDataStorageInspectorMapType GetVisibleDataStorageInspectors()
#define mitkThrow()
DataStorageInspectorIDType GetPreferredDataStorageInspector()
void PutVisibleDataStorageInspectors(const VisibleDataStorageInspectorMapType &inspectors)
void PutShowFavoritesInspector(bool show)
std::map< unsigned int, DataStorageInspectorIDType > VisibleDataStorageInspectorMapType
static IPreferencesService * GetPreferencesService()