34 #include <boost/bind.hpp>
35 #include <boost/function.hpp>
37 #include <QVBoxLayout>
39 #include <QStackedWidget>
41 #include <QStringList>
56 mPluginContext(pluginContext),
58 mVerticalLayout(new QVBoxLayout(this)),
59 mOptions(
profile()->getXmlSettings().descend(
"RegistrationWidget"))
61 this->setObjectName(
"RegistrationWidget");
62 this->setWindowTitle(
"Registration");
63 this->setWhatsThis(this->defaultWhatsThis());
65 connect(
this, &QTabWidget::currentChanged,
this, &RegistrationWidget::onCurrentChanged);
66 this->initRegistrationTypesWidgets();
67 this->initServiceListener();
74 void RegistrationWidget::initRegistrationTypesWidgets()
76 mRegistrationTypes <<
"ImageToPatient" <<
"ImageToImage" <<
"ImageTransform";
80 "Select registration type",
84 this->blockSignals(
true);
86 for(
int i = 0; i < mRegistrationTypes.count(); ++i)
88 QWidget *widget =
new QWidget(
this);
89 QStackedWidget *registrationTypeWidget =
new QStackedWidget(widget);
90 mRegistrationTypeMap[mRegistrationTypes[i]] = registrationTypeWidget;
92 QVBoxLayout *layoutV =
new QVBoxLayout(widget);
97 "Select registration method",
101 mMethodsSelectorMap[mRegistrationTypes[i]] = methodSelector;
102 boost::function<void()> f = boost::bind(&RegistrationWidget::indexChanged,
this, mRegistrationTypes[i]);
106 layoutV->addWidget(registrationTypeWidget);
108 mVerticalLayout->addWidget(widget);
109 this->addTab(widget, mRegistrationTypes[i]);
111 if (mTypeSelector->getValue() == mRegistrationTypes[i])
112 this->setCurrentIndex(i);
115 this->blockSignals(
false);
118 void RegistrationWidget::onCurrentChanged(
int index)
122 mTypeSelector->setValue(mRegistrationTypes[index]);
125 void RegistrationWidget::indexChanged(QString registrationType)
128 QStackedWidget *stackedWidget = mRegistrationTypeMap[registrationType];
129 this->selectStackWidget(methodSelector, stackedWidget);
132 void RegistrationWidget::selectStackWidget(
StringPropertyPtr methodSelector, QStackedWidget *stackedWidget)
134 QString method = methodSelector->getValue();
135 int pos = methodSelector->getValueRange().indexOf(method);
136 stackedWidget->setCurrentIndex(pos);
139 void RegistrationWidget::initServiceListener()
141 mServiceListener.reset(
new ServiceTrackerListener<RegistrationMethodService>(
143 boost::bind(&RegistrationWidget::onServiceAdded,
this, _1),
144 boost::function<
void (RegistrationMethodService*)>(),
145 boost::bind(&RegistrationWidget::onServiceRemoved,
this, _1)
147 mServiceListener->open();
150 void RegistrationWidget::onServiceAdded(RegistrationMethodService* service)
152 if(!this->knownType(service->getRegistrationType()))
155 StringPropertyPtr methodSelector = mMethodsSelectorMap[service->getRegistrationType()];
156 QStackedWidget *stackedWidget = mRegistrationTypeMap[service->getRegistrationType()];
158 stackedWidget->addWidget(service->createWidget());
159 QStringList values = methodSelector->getValueRange();
160 values << service->getRegistrationMethod();
161 methodSelector->setValueRange(values);
164 if (methodSelector->getValue().isEmpty())
166 methodSelector->setValue(service->getRegistrationMethod());
169 if (methodSelector->getValue() == service->getRegistrationMethod())
170 this->selectStackWidget(methodSelector, stackedWidget);
173 bool RegistrationWidget::knownType(QString registrationType)
175 if(!mRegistrationTypes.contains(registrationType))
177 reportError(
"Unknown registrationType : " + registrationType);
183 void RegistrationWidget::onServiceRemoved(RegistrationMethodService *service)
185 QStackedWidget *stackedWidget = mRegistrationTypeMap[service->getRegistrationType()];
186 this->removeWidgetFromStackedWidget(service->getWidgetName(), stackedWidget);
188 StringPropertyPtr comboBox = mMethodsSelectorMap[service->getRegistrationType()];
189 QStringList values = comboBox->getValueRange();
190 if (!values.removeOne(service->getRegistrationMethod()))
191 reportWarning(
"RegistrationWidget::onServiceRemoved: Cannot find and remove service from combobox: "+ service->getRegistrationMethod());
192 comboBox->setValueRange(values);
195 void RegistrationWidget::removeWidgetFromStackedWidget(QString widgetName, QStackedWidget *stackedWidget)
197 for(
int i = 0; i < stackedWidget->count(); ++i)
199 QWidget* widget = stackedWidget->widget(i);
200 if(widget->objectName() == widgetName)
202 stackedWidget->removeWidget(widget);
208 QString RegistrationWidget::defaultWhatsThis()
const
211 "<h3>Example plugin.</h3>"
212 "<p>Collection of all registration methods</p>"
cxResource_EXPORT ProfilePtr profile()
void reportError(QString msg)
QDomElement getElement()
return the current element
boost::shared_ptr< class StringProperty > StringPropertyPtr
void reportWarning(QString msg)
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())