CustusX  2023.01.05-dev+develop.0da12
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxGeneralTab.h"
13 
14 #include <QLabel>
15 #include <QToolButton>
16 #include <QGridLayout>
17 #include <QFileDialog>
18 #include "cxSettings.h"
19 #include "cxStateService.h"
20 #include "cxVLCRecorder.h"
21 #include "cxHelperWidgets.h"
22 #include <QAction>
23 #include <QInputDialog>
24 #include <QGroupBox>
25 #include "cxProfile.h"
26 #include "cxLogicManager.h"
27 
28 namespace cx
29 {
30 
31 GeneralTab::GeneralTab(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent) :
32  PreferenceTab(parent), mVLCPath(""),
33  mViewService(viewService),
34  mPatientModelService(patientModelService)
35 {
36  this->setObjectName("preferences_general_widget");
37  mPatientDataFolderComboBox = NULL;
38  mVLCPathComboBox = NULL;
39  mToolConfigFolderComboBox = NULL;
40 // mChooseApplicationComboBox = NULL;
41 }
42 
44 {
45  mGlobalPatientDataFolder = profile()->getSessionRootFolder();
46  mVLCPath = settings()->value("vlcPath").toString();
47  if(!QFile::exists(mVLCPath))
48  this->searchForVLC();
49 
50 // connect(stateService().get(), &StateService::applicationStateChanged, this, &GeneralTab::applicationStateChangedSlot);
51 
52  // patientDataFolder
53  QLabel* patientDataFolderLabel = new QLabel(tr("Patient data folder:"));
54  mPatientDataFolderComboBox = new QComboBox;
55  mPatientDataFolderComboBox->addItem( mGlobalPatientDataFolder);
56  QAction* browsePatientFolderAction = new QAction(QIcon(":/icons/open.png"), tr("B&rowse..."), this);
57  connect(browsePatientFolderAction, SIGNAL(triggered()), this, SLOT(browsePatientDataFolderSlot()));
58  QToolButton* browsePatientFolderButton = new QToolButton(this);
59  browsePatientFolderButton->setDefaultAction(browsePatientFolderAction);
60 
61  // VLC
62  QLabel* vlcPathLabel = new QLabel(tr("VLC path:"));
63  mVLCPathComboBox = new QComboBox();
64  mVLCPathComboBox->addItem( mVLCPath);
65  QAction* browseVLCPathAction = new QAction(QIcon(":/icons/open.png"), tr("Browse for VLC..."), this);
66  connect(browseVLCPathAction, SIGNAL(triggered()), this, SLOT(browseVLCPathSlot()));
67  QToolButton* browseVLCPathButton = new QToolButton(this);
68  browseVLCPathButton->setDefaultAction(browseVLCPathAction);
69 
70  // Choose application name
71 
72  StringPropertyPtr profileSelector = this->getProfileSelector();
73 
74 // QLabel* chooseApplicationLabel = new QLabel(tr("Choose application:"));
75 // mChooseApplicationComboBox = new QComboBox();
76 // setApplicationComboBox();
77 // connect(mChooseApplicationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentApplicationChangedSlot(int)));
78 // this->applicationStateChangedSlot();
79 
80  bool filterToolPositions = settings()->value("TrackingPositionFilter/enabled").value<bool>();
81  mFilterToolPositions = BoolProperty::initialize("Tool smoothing", "",
82  "Smooth the tool tracking positions using a low-pass filter.",
83  filterToolPositions);
84 
85 
86  double filterToolPositionsCutoff = settings()->value("TrackingPositionFilter/cutoffFrequency").value<double>();
87  mFilterToolPositionsCutoff
88  = DoubleProperty::initialize("filterToolPositionsCutoff", "Cutoff Frequency",
89  "If filtering enabled,\nfilter out tool movements faster than this frequency (Hz)",
90  filterToolPositionsCutoff, DoubleRange(0.1, 10, 0.1), 1);
91 
92  QToolButton* addProfileButton = this->createAddProfileButton();
93 
94  // Layout
95  QGridLayout *mainLayout = new QGridLayout;
96  mainLayout->addWidget(patientDataFolderLabel, 0, 0);
97  mainLayout->addWidget(mPatientDataFolderComboBox, 0, 1);
98  mainLayout->addWidget(browsePatientFolderButton, 0, 2);
99 
100 // mainLayout->addWidget(chooseApplicationLabel, 1, 0);
101 // mainLayout->addWidget(mChooseApplicationComboBox, 1, 1);
102  createDataWidget(mViewService, mPatientModelService, this, profileSelector, mainLayout, 1);
103  mainLayout->addWidget(addProfileButton, 1, 2);
104 
105  mainLayout->addWidget(vlcPathLabel, 2, 0);
106  mainLayout->addWidget(mVLCPathComboBox, 2, 1);
107  mainLayout->addWidget(browseVLCPathButton, 2, 2);
108 
109  QGroupBox* filterToolPositionsGroupBox = new QGroupBox("Filter Tool Positions");
110  QGridLayout* filterToolPositionsLayout = new QGridLayout(filterToolPositionsGroupBox);
111  createDataWidget(mViewService, mPatientModelService, this, mFilterToolPositions, filterToolPositionsLayout, 0);
112  createDataWidget(mViewService, mPatientModelService, this, mFilterToolPositionsCutoff, filterToolPositionsLayout, 1);
113  mainLayout->addWidget(filterToolPositionsGroupBox, 3, 0, 1, 3 );
114 
115  mTopLayout->addLayout(mainLayout);
116 }
117 
119 {}
120 
121 QToolButton* GeneralTab::createAddProfileButton()
122 {
123  QString tip = "Create a new profile based on the current";
124  QAction* action = new QAction(QIcon(":/icons/preset_save.png"), "Add", this);
125  action->setStatusTip(tip);
126  action->setWhatsThis(tip);
127  action->setToolTip(tip);
128  connect(action, &QAction::triggered, this, &GeneralTab::onAddProfile);
129 
130  QToolButton* button = new QToolButton();
131  button->setDefaultAction(action);
132  return button;
133 }
134 
135 void GeneralTab::onAddProfile()
136 {
137  QString current = ProfileManager::getInstance()->activeProfile()->getUid();
138  QStringList profiles = ProfileManager::getInstance()->getProfiles();
139  QString name;
140  for(int i=0; ; ++i)
141  {
142  name = QString("%1(%2)").arg(current).arg(i);
143  if (!profiles.contains(name, Qt::CaseInsensitive))
144  break;
145  }
146 
147  bool ok = true;
148  QString text = QInputDialog::getText(this, "Select profile name",
149  "Name", QLineEdit::Normal, name, &ok);
150  if (!ok || text.isEmpty())
151  return;
152 
153  this->selectProfile(text);
154 }
155 
156 void GeneralTab::browsePatientDataFolderSlot()
157 {
158  mGlobalPatientDataFolder = QFileDialog::getExistingDirectory(this,
159  tr("Find Patient Data Folder"),
160  mGlobalPatientDataFolder,
161  QFileDialog::ShowDirsOnly);
162  if( !mGlobalPatientDataFolder.isEmpty() ) {
163  mPatientDataFolderComboBox->addItem( mGlobalPatientDataFolder );
164  mPatientDataFolderComboBox->setCurrentIndex( mPatientDataFolderComboBox->currentIndex() + 1 );
165  }
166 }
167 
168 void GeneralTab::browseVLCPathSlot()
169 {
170  mVLCPath = QFileDialog::getOpenFileName(this, tr("Find VLC executable"));
171 
172  if(!mVLCPath.isEmpty())
173  {
174  mVLCPathComboBox->addItem( mVLCPath );
175  mVLCPathComboBox->setCurrentIndex( mVLCPathComboBox->currentIndex() + 1 );
176  }
177 }
178 
179 StringPropertyPtr GeneralTab::getProfileSelector()
180 {
181  if (!mSelector)
182  {
184  QString defaultValue = profile()->getUid();
185  mSelector = StringProperty::initialize("profile", "Profile",
186  "Choose profile, containing settings and configuration",
187  defaultValue, manager->getProfiles(), QDomNode());
188 
189  connect(mSelector.get(), &StringProperty::valueWasSet, this, &GeneralTab::onProfileSelected);
190  connect(manager, &ProfileManager::activeProfileChanged, this, &GeneralTab::onProfileChanged);
191  }
192 
193  return mSelector;
194 }
195 
196 void GeneralTab::onProfileChanged()
197 {
198  mSelector->setValueRange(ProfileManager::getInstance()->getProfiles());
199  mSelector->setValue(profile()->getUid());
200 }
201 
202 void GeneralTab::onProfileSelected()
203 {
204  this->selectProfile(mSelector->getValue());
205 }
206 
207 void GeneralTab::selectProfile(QString uid)
208 {
209  this->rejectDialog();
211 }
212 
213 void GeneralTab::rejectDialog()
214 {
215  QObject* item = this;
216  while (item)
217  {
218  QDialog* dialog = dynamic_cast<QDialog*>(item);
219  if (dialog)
220  {
221  dialog->reject();
222  break;
223  }
224  item = item->parent();
225  }
226 }
227 
228 void GeneralTab::searchForVLC(QStringList searchPaths)
229 {
230  vlc()->findVLCApplication(searchPaths);
231  if(vlc()->hasVLCApplication())
232  mVLCPath = vlc()->getVLCPath();
233 }
234 
236 {
237  profile()->setSessionRootFolder(mGlobalPatientDataFolder);
238  settings()->setValue("vlcPath", mVLCPath);
239  settings()->setValue("TrackingPositionFilter/enabled", mFilterToolPositions->getValue());
240  settings()->setValue("TrackingPositionFilter/cutoffFrequency", mFilterToolPositionsCutoff->getValue());
241 
242  settings()->sync();
243 
244  emit savedParameters();
245 }
246 
247 } /* namespace cx */
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
void activeProfileChanged()
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
ProfilePtr activeProfile()
Definition: cxProfile.cpp:293
QVBoxLayout * mTopLayout
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
static ProfileManager * getInstance(QString defaultProfile=QString("Laboratory"))
returns the only instance of this class
Definition: cxProfile.cpp:167
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
boost::shared_ptr< class ViewService > ViewServicePtr
virtual ~GeneralTab()
QStringList getProfiles()
Definition: cxProfile.cpp:264
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:58
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:21
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.