Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
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 (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 // mitk qt widgets ext module
16 #include <QmitkHotkeyLineEdit.h>
17 
18 // berry
20 #include <berryPlatform.h>
21 
22 // qt
23 #include <QLabel>
24 #include <QPushButton>
25 #include <QLineEdit>
26 #include <QGridLayout>
27 #include <QMessageBox>
28 #include <QApplication>
29 
31  : m_MainControl(nullptr)
32 {
33 }
34 
36 {
37 }
38 
40 {
42  berry::IPreferences::Pointer dataManagerHotkeysPreferencesNode = prefService->GetSystemPreferences()->Node("/DataManager/Hotkeys");
43  m_DataManagerHotkeysPreferencesNode = dataManagerHotkeysPreferencesNode;
44 
45  m_HotkeyEditors["Make all nodes invisible"] = new QmitkHotkeyLineEdit("Ctrl+V");
46  m_HotkeyEditors["Toggle visibility of selected nodes"] = new QmitkHotkeyLineEdit("V");
47  m_HotkeyEditors["Delete selected nodes"] = new QmitkHotkeyLineEdit("Del");
48  m_HotkeyEditors["Reinit selected nodes"] = new QmitkHotkeyLineEdit("R");
49  m_HotkeyEditors["Global reinit"] = new QmitkHotkeyLineEdit("Ctrl+R");
50  m_HotkeyEditors["Show node information"] = new QmitkHotkeyLineEdit("Ctrl+I");
51 
52  m_MainControl = new QWidget(parent);
53 
54  auto layout = new QGridLayout;
55  int i = 0;
56  for (auto it = m_HotkeyEditors.begin(); it != m_HotkeyEditors.end(); ++it)
57  {
58  layout->addWidget(new QLabel(it->first), i, 0);
59  layout->addWidget(it->second, i, 1);
60  layout->setRowStretch(i, 0);
61  ++i;
62  }
63  layout->setRowStretch(i + 1, 10);
64 
65  m_MainControl->setLayout(layout);
66  Update();
67 }
68 
70 {
71  return m_MainControl;
72 }
73 
75 {
76  berry::IPreferences::Pointer dataManagerHotkeysPreferencesNode = m_DataManagerHotkeysPreferencesNode.Lock();
77  if (dataManagerHotkeysPreferencesNode.IsNotNull())
78  {
79  QString keyString;
80  QString errString;
81  for (auto it = m_HotkeyEditors.begin(); it != m_HotkeyEditors.end(); ++it)
82  {
83  keyString = it->second->GetKeySequenceAsString();
84 
85  if (keyString.isEmpty())
86  {
87  errString = QString("No valid key sequence for \"%1\"").arg(it->first);
88  }
89 
90  if (errString.isEmpty())
91  {
92  std::map<QString, QmitkHotkeyLineEdit*>::iterator it2;
93  // search for duplicated key
94  for (it2 = m_HotkeyEditors.begin(); it2 != m_HotkeyEditors.end(); ++it2)
95  {
96  if (it->first != it2->first && keyString == it2->second->GetKeySequenceAsString())
97  {
98  errString = QString("Duplicate hot key for \"%1\" and \"%2\"").arg(it->first).arg(it2->first);
99  break;
100  }
101  }
102  }
103 
104  if (!errString.isEmpty())
105  {
106  QMessageBox::critical(QApplication::activeWindow(), "Error", errString);
107  return false;
108  }
109  }
110 
111  // no errors -> save all values and flush to file
112  for (auto it = m_HotkeyEditors.begin(); it != m_HotkeyEditors.end(); ++it)
113  {
114  QString keySequence = it->second->GetKeySequenceAsString();
115  dataManagerHotkeysPreferencesNode->Put(it->first, it->second->GetKeySequenceAsString());
116  }
117 
118  dataManagerHotkeysPreferencesNode->Flush();
119  return true;
120  }
121 
122  return false;
123 }
124 
126 {
127 }
128 
130 {
131  berry::IPreferences::Pointer dataManagerHotkeysPreferencesNode = m_DataManagerHotkeysPreferencesNode.Lock();
132  if (dataManagerHotkeysPreferencesNode.IsNotNull())
133  {
134  for (auto it = m_HotkeyEditors.begin(); it != m_HotkeyEditors.end(); ++it)
135  {
136  it->second->setText(dataManagerHotkeysPreferencesNode->Get(it->first, it->second->text()));
137  }
138  }
139 }
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
berry::IPreferences::WeakPtr m_DataManagerHotkeysPreferencesNode
The node from which the properties are taken (will be catched from the preferences service in ctor) ...
SmartPointer< ObjectType > Lock() const
std::map< QString, QmitkHotkeyLineEdit * > m_HotkeyEditors
Maps a label to hotkey lineedit, e.g. "Toggle Visibility of selected nodes" => QmitkHotkeyLineEdit.
void CreateQtControl(QWidget *parent) override
void Init(berry::IWorkbench::Pointer workbench) override
static IPreferencesService * GetPreferencesService()