Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDataManagerHotkeysPrefPage.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,
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 #include <QmitkHotkeyLineEdit.h>
19 
21 #include "berryPlatform.h"
22 
23 #include <QLabel>
24 #include <QPushButton>
25 #include <QLineEdit>
26 #include <QGridLayout>
27 #include <QMessageBox>
28 #include <QApplication>
29 
30 #include <map>
31 
32 using namespace berry;
33 
35 : m_MainControl(nullptr)
36 {
37 
38 }
39 
41 {
42 
43 }
44 
46 {
47  IPreferencesService* prefService = Platform::GetPreferencesService();
48  berry::IPreferences::Pointer _DataManagerHotkeysPreferencesNode = prefService->GetSystemPreferences()->Node("/DataManager/Hotkeys");
49  m_DataManagerHotkeysPreferencesNode = _DataManagerHotkeysPreferencesNode;
50 
51  m_HotkeyEditors["Make all nodes invisible"] = new QmitkHotkeyLineEdit("Ctrl+, V");
52 
53  m_HotkeyEditors["Toggle visibility of selected nodes"] = new QmitkHotkeyLineEdit("V");
54 
55  m_HotkeyEditors["Delete selected nodes"] = new QmitkHotkeyLineEdit("Del");
56 
57  m_HotkeyEditors["Reinit selected nodes"] = new QmitkHotkeyLineEdit("R");
58 
59  m_HotkeyEditors["Global Reinit"] = new QmitkHotkeyLineEdit("Ctrl+, R");
60 
61  m_HotkeyEditors["Show Node Information"] = new QmitkHotkeyLineEdit("Ctrl+, I");
62 
63  m_MainControl = new QWidget(parent);
64 
65  auto layout = new QGridLayout;
66  int i = 0;
67  for (auto it = m_HotkeyEditors.begin()
68  ; it != m_HotkeyEditors.end(); ++it)
69  {
70  layout->addWidget(new QLabel(it->first), i,0);
71  layout->addWidget(it->second, i,1);
72  layout->setRowStretch(i,0);
73  ++i;
74  }
75  layout->setRowStretch(i+1,10);
76 
77  m_MainControl->setLayout(layout);
78  this->Update();
79 }
80 
82 {
83  return m_MainControl;
84 }
85 
87 {
88  IPreferences::Pointer _DataManagerHotkeysPreferencesNode = m_DataManagerHotkeysPreferencesNode.Lock();
89  if(_DataManagerHotkeysPreferencesNode.IsNotNull())
90  {
91  bool duplicate = false;
92  QString keyString;
93  QString errString;
94  for (auto it = m_HotkeyEditors.begin()
95  ; it != m_HotkeyEditors.end(); ++it)
96  {
97  keyString = it->second->GetKeySequenceAsString();
98 
99  if(keyString.isEmpty())
100  errString = QString("No valid key sequence for \"%1\"").arg(it->first);
101 
102  if(errString.isEmpty())
103  {
104  std::map<QString, QmitkHotkeyLineEdit*>::iterator it2;
105  // search for duplicated key
106  for (it2 = m_HotkeyEditors.begin(); it2 != m_HotkeyEditors.end(); ++it2)
107  {
108  if(it->first != it2->first && keyString == it2->second->GetKeySequenceAsString())
109  {
110  duplicate = true;
111  break;
112  }
113  }
114  if(duplicate == true)
115  errString = QString("Duplicate hot key for \"%1\" and \"%2\"").arg(it->first).arg(it2->first);
116  }
117 
118  if(!errString.isEmpty())
119  {
120  QMessageBox::critical(QApplication::activeWindow(), "Error", errString);
121  return false;
122  }
123  }
124 
125  //# no errors -> save all values and flush to file
126  for (auto it = m_HotkeyEditors.begin()
127  ; it != m_HotkeyEditors.end(); ++it)
128  _DataManagerHotkeysPreferencesNode->Put(it->first
129  , it->second->GetKeySequenceAsString());
130 
131  _DataManagerHotkeysPreferencesNode->Flush();
132 
133  return true;
134  }
135  return false;
136 }
137 
139 {
140 
141 }
142 
144 {
145  IPreferences::Pointer _DataManagerHotkeysPreferencesNode = m_DataManagerHotkeysPreferencesNode.Lock();
146  if(_DataManagerHotkeysPreferencesNode.IsNotNull())
147  {
148  for (auto it = m_HotkeyEditors.begin()
149  ; it != m_HotkeyEditors.end(); ++it)
150  {
151  it->second->setText(_DataManagerHotkeysPreferencesNode->Get(it->first, it->second->text()));
152  }
153  }
154 }
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
berry::IPreferences::WeakPtr m_DataManagerHotkeysPreferencesNode
std::map< QString, QmitkHotkeyLineEdit * > m_HotkeyEditors
void CreateQtControl(QWidget *parent) override
SmartPointer< ObjectType > Lock() const
void Init(berry::IWorkbench::Pointer workbench) override