Fraxinus  17.12
An IGT application
cxGeneralTab.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxGeneralTab.h"
34 
35 #include <QLabel>
36 #include <QToolButton>
37 #include <QGridLayout>
38 #include <QFileDialog>
39 #include "cxSettings.h"
40 #include "cxStateService.h"
41 #include "cxVLCRecorder.h"
42 #include "cxHelperWidgets.h"
43 #include <QAction>
44 #include <QInputDialog>
45 #include <QGroupBox>
46 #include "cxProfile.h"
47 #include "cxLogicManager.h"
48 
49 namespace cx
50 {
51 
52 GeneralTab::GeneralTab(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent) :
53  PreferenceTab(parent), mVLCPath(""),
54  mViewService(viewService),
55  mPatientModelService(patientModelService)
56 {
57  this->setObjectName("preferences_general_widget");
58  mPatientDataFolderComboBox = NULL;
59  mVLCPathComboBox = NULL;
60  mToolConfigFolderComboBox = NULL;
61 // mChooseApplicationComboBox = NULL;
62 }
63 
65 {
66  mGlobalPatientDataFolder = profile()->getSessionRootFolder();
67  mVLCPath = settings()->value("vlcPath").toString();
68  if(!QFile::exists(mVLCPath))
69  this->searchForVLC();
70 
71 // connect(stateService().get(), &StateService::applicationStateChanged, this, &GeneralTab::applicationStateChangedSlot);
72 
73  // patientDataFolder
74  QLabel* patientDataFolderLabel = new QLabel(tr("Patient data folder:"));
75  mPatientDataFolderComboBox = new QComboBox;
76  mPatientDataFolderComboBox->addItem( mGlobalPatientDataFolder);
77  QAction* browsePatientFolderAction = new QAction(QIcon(":/icons/open.png"), tr("B&rowse..."), this);
78  connect(browsePatientFolderAction, SIGNAL(triggered()), this, SLOT(browsePatientDataFolderSlot()));
79  QToolButton* browsePatientFolderButton = new QToolButton(this);
80  browsePatientFolderButton->setDefaultAction(browsePatientFolderAction);
81 
82  // VLC
83  QLabel* vlcPathLabel = new QLabel(tr("VLC path:"));
84  mVLCPathComboBox = new QComboBox();
85  mVLCPathComboBox->addItem( mVLCPath);
86  QAction* browseVLCPathAction = new QAction(QIcon(":/icons/open.png"), tr("Browse for VLC..."), this);
87  connect(browseVLCPathAction, SIGNAL(triggered()), this, SLOT(browseVLCPathSlot()));
88  QToolButton* browseVLCPathButton = new QToolButton(this);
89  browseVLCPathButton->setDefaultAction(browseVLCPathAction);
90 
91  // Choose application name
92 
93  StringPropertyPtr profileSelector = this->getProfileSelector();
94 
95 // QLabel* chooseApplicationLabel = new QLabel(tr("Choose application:"));
96 // mChooseApplicationComboBox = new QComboBox();
97 // setApplicationComboBox();
98 // connect(mChooseApplicationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentApplicationChangedSlot(int)));
99 // this->applicationStateChangedSlot();
100 
101  bool filterToolPositions = settings()->value("TrackingPositionFilter/enabled").value<bool>();
102  mFilterToolPositions = BoolProperty::initialize("Tool smoothing", "",
103  "Smooth the tool tracking positions using a low-pass filter.",
104  filterToolPositions);
105 
106 
107  double filterToolPositionsCutoff = settings()->value("TrackingPositionFilter/cutoffFrequency").value<double>();
108  mFilterToolPositionsCutoff
109  = DoubleProperty::initialize("filterToolPositionsCutoff", "Cutoff Frequency",
110  "If filtering enabled,\nfilter out tool movements faster than this frequency (Hz)",
111  filterToolPositionsCutoff, DoubleRange(0.1, 10, 0.1), 1);
112 
113  QToolButton* addProfileButton = this->createAddProfileButton();
114 
115  // Layout
116  QGridLayout *mainLayout = new QGridLayout;
117  mainLayout->addWidget(patientDataFolderLabel, 0, 0);
118  mainLayout->addWidget(mPatientDataFolderComboBox, 0, 1);
119  mainLayout->addWidget(browsePatientFolderButton, 0, 2);
120 
121 // mainLayout->addWidget(chooseApplicationLabel, 1, 0);
122 // mainLayout->addWidget(mChooseApplicationComboBox, 1, 1);
123  createDataWidget(mViewService, mPatientModelService, this, profileSelector, mainLayout, 1);
124  mainLayout->addWidget(addProfileButton, 1, 2);
125 
126  mainLayout->addWidget(vlcPathLabel, 2, 0);
127  mainLayout->addWidget(mVLCPathComboBox, 2, 1);
128  mainLayout->addWidget(browseVLCPathButton, 2, 2);
129 
130  QGroupBox* filterToolPositionsGroupBox = new QGroupBox("Filter Tool Positions");
131  QGridLayout* filterToolPositionsLayout = new QGridLayout(filterToolPositionsGroupBox);
132  createDataWidget(mViewService, mPatientModelService, this, mFilterToolPositions, filterToolPositionsLayout, 0);
133  createDataWidget(mViewService, mPatientModelService, this, mFilterToolPositionsCutoff, filterToolPositionsLayout, 1);
134  mainLayout->addWidget(filterToolPositionsGroupBox, 3, 0, 1, 3 );
135 
136  mTopLayout->addLayout(mainLayout);
137 }
138 
140 {}
141 
142 QToolButton* GeneralTab::createAddProfileButton()
143 {
144  QString tip = "Create a new profile based on the current";
145  QAction* action = new QAction(QIcon(":/icons/preset_save.png"), "Add", this);
146  action->setStatusTip(tip);
147  action->setWhatsThis(tip);
148  action->setToolTip(tip);
149  connect(action, &QAction::triggered, this, &GeneralTab::onAddProfile);
150 
151  QToolButton* button = new QToolButton();
152  button->setDefaultAction(action);
153  return button;
154 }
155 
156 void GeneralTab::onAddProfile()
157 {
158  QString current = ProfileManager::getInstance()->activeProfile()->getUid();
159  QStringList profiles = ProfileManager::getInstance()->getProfiles();
160  QString name;
161  for(int i=0; ; ++i)
162  {
163  name = QString("%1(%2)").arg(current).arg(i);
164  if (!profiles.contains(name, Qt::CaseInsensitive))
165  break;
166  }
167 
168  bool ok = true;
169  QString text = QInputDialog::getText(this, "Select profile name",
170  "Name", QLineEdit::Normal, name, &ok);
171  if (!ok || text.isEmpty())
172  return;
173 
174  this->selectProfile(text);
175 }
176 
177 void GeneralTab::browsePatientDataFolderSlot()
178 {
179  mGlobalPatientDataFolder = QFileDialog::getExistingDirectory(this,
180  tr("Find Patient Data Folder"),
181  mGlobalPatientDataFolder,
182  QFileDialog::ShowDirsOnly);
183  if( !mGlobalPatientDataFolder.isEmpty() ) {
184  mPatientDataFolderComboBox->addItem( mGlobalPatientDataFolder );
185  mPatientDataFolderComboBox->setCurrentIndex( mPatientDataFolderComboBox->currentIndex() + 1 );
186  }
187 }
188 
189 void GeneralTab::browseVLCPathSlot()
190 {
191  mVLCPath = QFileDialog::getOpenFileName(this, tr("Find VLC executable"));
192 
193  if(!mVLCPath.isEmpty())
194  {
195  mVLCPathComboBox->addItem( mVLCPath );
196  mVLCPathComboBox->setCurrentIndex( mVLCPathComboBox->currentIndex() + 1 );
197  }
198 }
199 
200 StringPropertyPtr GeneralTab::getProfileSelector()
201 {
202  if (!mSelector)
203  {
205  QString defaultValue = profile()->getUid();
206  mSelector = StringProperty::initialize("profile", "Profile",
207  "Choose profile, containing settings and configuration",
208  defaultValue, manager->getProfiles(), QDomNode());
209 
210  connect(mSelector.get(), &StringProperty::valueWasSet, this, &GeneralTab::onProfileSelected);
211  connect(manager, &ProfileManager::activeProfileChanged, this, &GeneralTab::onProfileChanged);
212  }
213 
214  return mSelector;
215 }
216 
217 void GeneralTab::onProfileChanged()
218 {
219  mSelector->setValueRange(ProfileManager::getInstance()->getProfiles());
220  mSelector->setValue(profile()->getUid());
221 }
222 
223 void GeneralTab::onProfileSelected()
224 {
225  this->selectProfile(mSelector->getValue());
226 }
227 
228 void GeneralTab::selectProfile(QString uid)
229 {
230  this->rejectDialog();
232 }
233 
234 void GeneralTab::rejectDialog()
235 {
236  QObject* item = this;
237  while (item)
238  {
239  QDialog* dialog = dynamic_cast<QDialog*>(item);
240  if (dialog)
241  {
242  dialog->reject();
243  break;
244  }
245  item = item->parent();
246  }
247 }
248 
249 void GeneralTab::searchForVLC(QStringList searchPaths)
250 {
251  vlc()->findVLCApplication(searchPaths);
252  if(vlc()->hasVLCApplication())
253  mVLCPath = vlc()->getVLCPath();
254 }
255 
257 {
258  profile()->setSessionRootFolder(mGlobalPatientDataFolder);
259  settings()->setValue("vlcPath", mVLCPath);
260  settings()->setValue("TrackingPositionFilter/enabled", mFilterToolPositions->getValue());
261  settings()->setValue("TrackingPositionFilter/cutoffFrequency", mFilterToolPositionsCutoff->getValue());
262 
263  settings()->sync();
264 
265  emit savedParameters();
266 }
267 
268 } /* namespace cx */
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:181
void activeProfileChanged()
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
ProfilePtr activeProfile()
Definition: cxProfile.cpp:306
QVBoxLayout * mTopLayout
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
static ProfileManager * getInstance(QString defaultProfile=QString("Laboratory"))
returns the only instance of this class
Definition: cxProfile.cpp:188
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:87
boost::shared_ptr< class ViewService > ViewServicePtr
virtual ~GeneralTab()
QStringList getProfiles()
Definition: cxProfile.cpp:277
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
boost::shared_ptr< class StringProperty > StringPropertyPtr
void findVLCApplication(QStringList suggestedVLCLocations=QStringList())
GeneralTab(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent=0)
static LogicManager * getInstance()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void saveParametersSlot()
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void restartWithNewProfile(QString uid)
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
QString getVLCPath()
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.
Namespace for all CustusX production code.