13 #include <boost/bind.hpp>
14 #include <boost/function.hpp>
16 #include <QVBoxLayout>
18 #include <QStackedWidget>
20 #include <QStringList>
38 mStackedWidget =
new QStackedWidget(
this);
39 mStackedWidget->setFocusPolicy(Qt::StrongFocus);
41 QVBoxLayout *layoutV =
new QVBoxLayout(
this);
46 "Select registration method",
53 layoutV->addWidget(mStackedWidget);
61 void RegistrationTypeWidget::onIndexChanged()
63 QString method = mMethodSelector->getValue();
64 int pos = mMethodSelector->getValueRange().indexOf(method);
65 mStackedWidget->setCurrentIndex(pos);
66 this->setObjectName(mStackedWidget->currentWidget()->objectName());
72 QStringList values = mMethodSelector->getValueRange();
74 mMethodSelector->setValueRange(values);
77 if (mMethodSelector->getValue().isEmpty())
83 this->onIndexChanged();
88 this->removeWidgetFromStackedWidget(service->
getWidgetName());
90 QStringList values = mMethodSelector->getValueRange();
93 mMethodSelector->setValueRange(values);
96 void RegistrationTypeWidget::removeWidgetFromStackedWidget(QString widgetName)
98 for(
int i = 0; i < mStackedWidget->count(); ++i)
100 QWidget* widget = mStackedWidget->widget(i);
101 if(widget->objectName() == widgetName)
103 mStackedWidget->removeWidget(widget);
116 TabbedWidget(parent,
"org_custusx_registration_gui_widget",
"Registration"),
117 mPluginContext(pluginContext),
118 mOptions(
profile()->getXmlSettings().descend(
"RegistrationWidget"))
120 connect(
mTabWidget, &QTabWidget::currentChanged,
this, &RegistrationWidget::onCurrentChanged);
121 this->initRegistrationTypesWidgets();
122 this->initServiceListener();
132 void RegistrationWidget::initRegistrationTypesWidgets()
134 mRegistrationTypes <<
"ImageToPatient" <<
"ImageToImage" <<
"ImageTransform";
135 QStringList typeDefaults;
136 typeDefaults <<
"Landmark" <<
"Landmark" <<
"";
138 for(
int i = 0; i < mRegistrationTypes.count(); ++i)
140 QString type = mRegistrationTypes[i];
146 mRegistrationTypeMap[type] = widget;
147 this->
addTab(widget, type);
154 "Registration Types",
155 "Select registration type",
159 if (mRegistrationTypeMap.count(mTypeSelector->getValue()))
160 mTabWidget->setCurrentWidget(mRegistrationTypeMap[mTypeSelector->getValue()]);
163 void RegistrationWidget::onCurrentChanged(
int index)
168 mTypeSelector->setValue(mRegistrationTypes[index]);
171 void RegistrationWidget::initServiceListener()
173 mServiceListener.reset(
new ServiceTrackerListener<RegistrationMethodService>(
175 boost::bind(&RegistrationWidget::onServiceAdded,
this, _1),
176 boost::function<
void (RegistrationMethodService*)>(),
177 boost::bind(&RegistrationWidget::onServiceRemoved,
this, _1)
179 mServiceListener->open();
182 void RegistrationWidget::onServiceAdded(RegistrationMethodService* service)
184 QString type = service->getRegistrationType();
185 if(!mRegistrationTypeMap.count(type))
190 mRegistrationTypeMap[type]->addMethod(service);
193 void RegistrationWidget::onServiceRemoved(RegistrationMethodService *service)
195 QString type = service->getRegistrationType();
196 mRegistrationTypeMap[type]->removeMethod(service);