35 #include <QVBoxLayout>
36 #include <QHBoxLayout>
55 mConfigFilesComboBox(new QComboBox()),
56 mConfigFileLineEdit(new QLineEdit()),
57 mReferenceComboBox(new QComboBox()),
62 mConfigFilesComboBox->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Expanding);
68 this->createTrackingSystemSelector();
76 QGridLayout* layout =
new QGridLayout(
this);
78 layout->addWidget(
new QLabel(
"Configuration: "), row, 0, 1, 1);
79 layout->addWidget(mConfigFilesComboBox, row, 1, 1, 1);
81 layout->addWidget(
new QLabel(
"File name: "), row, 0, 1, 1);
82 layout->addWidget(mConfigFileLineEdit, row, 1, 1, 1);
86 layout->addWidget(mToolListWidget, row, 0, 1, 2);
87 layout->setRowStretch(row, 1);
92 QHBoxLayout* refLayout =
new QHBoxLayout;
93 refLayout->addWidget(
new QLabel(
"Reference: "));
94 refLayout->addWidget(mReferenceComboBox);
95 refLayout->setMargin(0);
96 layout->addLayout(refLayout, row, 0, 1, 2);
99 connect(mConfigFilesComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(configChangedSlot()));
100 connect(mToolListWidget, SIGNAL(listSizeChanged()),
this, SLOT(toolsChangedSlot()));
104 connect(mConfigFileLineEdit, SIGNAL(textEdited(
const QString&)),
this, SLOT(configEditedSlot()));
105 connect(mToolListWidget, SIGNAL(userChangedList()),
this, SLOT(configEditedSlot()));
106 connect(mReferenceComboBox, SIGNAL(activated(
int)),
this, SLOT(configEditedSlot()));
108 this->onApplicationStateChanged();
116 QString cleanPath = QDir(configAbsoluteFilePath).absolutePath();
117 int currentIndex = mConfigFilesComboBox->findData(cleanPath, Qt::ToolTipRole);
121 if (!configAbsoluteFilePath.isEmpty())
122 reportWarning(
"Tool configuration doesn't exist: " + cleanPath);
124 mConfigFilesComboBox->setCurrentIndex(currentIndex);
132 retval = mConfigFilesComboBox->itemData(mConfigFilesComboBox->currentIndex(), Qt::ToolTipRole).toString();
136 void ToolConfigureGroupBox::createTrackingSystemSelector()
138 QString defaultValue =
"";
141 "Select tracking system to use",
143 config->getSupportedTrackingSystems(),
145 connect(mTrackingSystemSelector.get(), SIGNAL(changed()),
this, SLOT(filterToolsSlot()));
150 return mTrackingSystemSelector;
165 config->saveConfiguration(current);
168 this->populateConfigurations();
173 void ToolConfigureGroupBox::onApplicationStateChanged()
175 QString application =
stateService()->getApplicationStateName();
176 this->setTitle(
"Tool configurations for "+ application);
177 this->populateConfigurations();
180 void ToolConfigureGroupBox::configChangedSlot()
182 QString uid = mConfigFilesComboBox->itemData(mConfigFilesComboBox->currentIndex(),
183 Qt::ToolTipRole).toString();
186 TrackerConfiguration::Configuration data = config->getConfiguration(uid);
187 bool isNewConfig = mConfigFilesComboBox->currentText().contains(
"<new config>");
192 data.mName =
"MyConfig";
195 mConfigFileLineEdit->setText(data.mName);
196 mConfigFileLineEdit->setEnabled(isNewConfig);
197 mConfigFileLineEdit->setToolTip(data.mUid);
199 mTrackingSystemSelector->setValue(data.mTrackingSystem);
203 void ToolConfigureGroupBox::configEditedSlot()
208 void ToolConfigureGroupBox::toolsChangedSlot()
210 this->populateReference();
211 this->filterToolsSlot();
214 void ToolConfigureGroupBox::filterToolsSlot()
216 QString ts = mTrackingSystemSelector->getValue();
217 mToolListWidget->
filterSlot(QStringList() << ts);
221 void ToolConfigureGroupBox::populateConfigurations()
223 mConfigFilesComboBox->clear();
227 QStringList configurations = config->getConfigurationsGivenApplication();
229 foreach(QString filename, configurations)
231 TrackerConfiguration::Configuration configuration = config->getConfiguration(filename);
232 this->addConfigurationToComboBox(configuration.mName, configuration.mUid);
234 QString newConfig =
"<new config>";
235 this->addConfigurationToComboBox(newConfig, newConfig);
237 int currentIndex = mConfigFilesComboBox->findText(newConfig);
238 mConfigFilesComboBox->setCurrentIndex(currentIndex);
241 int ToolConfigureGroupBox::addConfigurationToComboBox(QString displayName, QString absoluteFilePath)
243 mConfigFilesComboBox->addItem(displayName);
244 int index = mConfigFilesComboBox->findText(displayName);
245 mConfigFilesComboBox->setItemData(index, absoluteFilePath, Qt::ToolTipRole);
250 TrackerConfiguration::Configuration ToolConfigureGroupBox::getCurrentConfiguration()
252 TrackerConfiguration::Configuration retval;
254 QString application =
stateService()->getApplicationStateName();
256 QString filename = mConfigFileLineEdit->text();
257 QString filepath = config->getConfigurationApplicationsPath();
259 retval.mUid = QString(
"%1/%2.xml").arg(filepath).arg(filename);
260 retval.mClinicalApplication = application;
261 retval.mTrackingSystem = mTrackingSystemSelector->getValue();
262 retval.mTools = mToolListWidget->
getTools();
263 retval.mReferenceTool = mReferenceComboBox->itemData(mReferenceComboBox->currentIndex(), Qt::ToolTipRole).toString();
268 void ToolConfigureGroupBox::populateReference()
270 mReferenceComboBox->clear();
272 int currentIndex = -1;
277 QStringList selectedTools = mToolListWidget->
getTools();
278 foreach(QString
string, selectedTools)
280 if (config->getTool(
string).mIsReference)
281 currentIndex = this->addRefrenceToComboBox(
string);
285 QString configAbsoluteFilePath = mConfigFilesComboBox->itemData(mConfigFilesComboBox->currentIndex(), Qt::ToolTipRole).toString();
286 QString reference = config->getConfiguration(configAbsoluteFilePath).mReferenceTool;
287 currentIndex = this->addRefrenceToComboBox(reference);
293 mReferenceComboBox->setCurrentIndex(currentIndex);
296 int ToolConfigureGroupBox::addRefrenceToComboBox(QString absoluteRefereneFilePath)
300 QFile file(absoluteRefereneFilePath);
301 QFileInfo info(file);
302 QString refUid = info.dir().dirName();
304 QStringList selectedTools = mToolListWidget->
getTools();
305 if (!selectedTools.count(absoluteRefereneFilePath))
308 if (refUid.isEmpty())
311 if (mReferenceComboBox->findText(refUid) < 0)
312 mReferenceComboBox->addItem(refUid);
313 index = mReferenceComboBox->findText(refUid);
314 mReferenceComboBox->setItemData(index, info.absoluteFilePath(), Qt::ToolTipRole);
tsPOLARIS
NDIs Polaris tracker.
void applicationStateChanged()
cxLogicManager_EXPORT StateServicePtr stateService()
boost::shared_ptr< class TrackerConfiguration > TrackerConfigurationPtr
void reportWarning(QString msg)
QString mUid
absolute path and filename for the new config file
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
cxLogicManager_EXPORT TrackingServicePtr trackingService()
QString enum2string(const ENUM &val)
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr