Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmitkFileOpenAction.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 
17 #include "QmitkFileOpenAction.h"
18 
19 #include "internal/org_mitk_gui_qt_application_Activator.h"
20 
21 #include <mitkWorkbenchUtil.h>
22 
23 #include <QmitkIOUtil.h>
24 
25 #include <berryIPreferences.h>
26 
27 #include <QFileDialog>
28 
29 class QmitkFileOpenActionPrivate
30 {
31 public:
32 
33  void init ( berry::IWorkbenchWindow* window, QmitkFileOpenAction* action )
34  {
35  m_Window = window;
36  action->setText("&Open File...");
37  action->setToolTip("Open data files (images, surfaces,...)");
38 
39  QObject::connect(action, SIGNAL(triggered(bool)), action, SLOT(Run()));
40  }
41 
42  berry::IPreferences::Pointer GetPreferences() const
43  {
44  berry::IPreferencesService* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService();
45  if (prefService)
46  {
47  return prefService->GetSystemPreferences()->Node("/General");
48  }
50  }
51 
52  QString getLastFileOpenPath() const
53  {
54  berry::IPreferences::Pointer prefs = GetPreferences();
55  if(prefs.IsNotNull())
56  {
57  return prefs->Get("LastFileOpenPath", "");
58  }
59  return QString();
60  }
61 
62  void setLastFileOpenPath(const QString& path) const
63  {
64  berry::IPreferences::Pointer prefs = GetPreferences();
65  if(prefs.IsNotNull())
66  {
67  prefs->Put("LastFileOpenPath", path);
68  prefs->Flush();
69  }
70  }
71 
72  bool GetOpenEditor() const
73  {
74  berry::IPreferences::Pointer prefs = GetPreferences();
75  if(prefs.IsNotNull())
76  {
77  return prefs->GetBool("OpenEditor", true);
78  }
79  return true;
80  }
81 
82  berry::IWorkbenchWindow* m_Window;
83 };
84 
86  : QAction(0), d(new QmitkFileOpenActionPrivate)
87 {
88  d->init(window.GetPointer(), this);
89 }
90 
92  : QAction(0), d(new QmitkFileOpenActionPrivate)
93 {
94  d->init(window.GetPointer(), this);
95  this->setIcon(icon);
96 }
97 
99  : QAction(0), d(new QmitkFileOpenActionPrivate)
100 {
101  d->init(window, this);
102  this->setIcon(icon);
103 }
104 
106 {
107 }
108 
110 {
111 
112  // Ask the user for a list of files to open
113  QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Open",
114  d->getLastFileOpenPath(),
116 
117  if (fileNames.empty())
118  return;
119 
120  d->setLastFileOpenPath(fileNames.front());
122  d->GetOpenEditor());
123 }
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
Implements transparent reference counting.
static void LoadFiles(const QStringList &fileNames, berry::IWorkbenchWindow::Pointer wnd, bool openEditor=true)
static QString GetFileOpenFilterString()
GetFilterString.
Definition: QmitkIOUtil.cpp:86
ObjectType * GetPointer() const
berry::SmartPointer< Self > Pointer
QmitkFileOpenAction(berry::IWorkbenchWindow::Pointer window)