00001 #include "DetectorChooserPresenter.h"
00002 #include "DetectorChooserPresenter.moc"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 DetectorChooserPresenter::DetectorChooserPresenter(ParameterWidget* chooser):
00035 m_chooser(chooser),
00036 m_currentDetectorPresenter(NULL)
00037 {
00038 m_chooser->addEnumParameter("detector", "Type of detector");
00039 syncronize();
00040 reconnect();
00041 }
00042
00043
00044 void DetectorChooserPresenter::insertDetector(const QString& name, DetectorPresenter* detector){
00045 m_detectorPresenterNames.push_back(name);
00046 m_detectorPresenters.push_back(detector);
00047 m_chooser->insertEnumValue("detector", name);
00048 if(m_detectorPresenters.size() == 1){
00049 m_currentDetectorPresenter = detector;
00050 m_currentDetectorPresenterIndex = 0;
00051 connect(m_currentDetectorPresenter, SIGNAL(detectorChanged()), this, SIGNAL(detectorChanged()));
00052 m_currentDetectorPresenter->activate();
00053 } else{
00054 detector->deactivate();
00055 m_currentDetectorPresenter->activate();
00056 }
00057 }
00058
00059 void DetectorChooserPresenter::setChooser(ParameterWidget* chooser){
00060 disconnect(m_chooser, 0, this, 0);
00061 m_chooser = chooser;
00062 m_chooser->clearParameterMap();
00063 m_chooser->addEnumParameter("detector", "Type of detector");
00064 syncronize();
00065 reconnect();
00066 }
00067
00068 void DetectorChooserPresenter::changeParameter(const QString& name){
00069 if(!QString::compare(name, "detector")){
00070 int guiValue;
00071 bool valid = m_chooser->getEnumValue("detector", guiValue);
00072 if(valid) {changeDetector(guiValue);}
00073 }
00074 }
00075
00076 void DetectorChooserPresenter::changeDetector(int detector){
00077 if(m_currentDetectorPresenterIndex != detector){
00078 disconnect(m_currentDetectorPresenter, SIGNAL(detectorChanged()), this, SIGNAL(detectorChanged()));
00079 m_currentDetectorPresenter->deactivate();
00080 m_currentDetectorPresenterIndex = detector;
00081 m_currentDetectorPresenter = m_detectorPresenters[m_currentDetectorPresenterIndex];
00082 m_chooser->setEnumValue("detector", m_currentDetectorPresenterIndex);
00083 m_currentDetectorPresenter->activate();
00084 connect(m_currentDetectorPresenter, SIGNAL(detectorChanged()), this, SIGNAL(detectorChanged()));
00085 emit detectorChanged();
00086 }
00087 }
00088
00089
00090 void DetectorChooserPresenter::syncronize(){
00091 if(m_detectorPresenters.size()){
00092 m_chooser->clearEnumParameter("detector");
00093 for(int i = 0; i < m_detectorPresenterNames.size(); i++){
00094 m_chooser->insertEnumValue("detector", m_detectorPresenterNames[i]);
00095 }
00096 m_chooser->setEnumValue("detector", m_currentDetectorPresenterIndex);
00097 m_currentDetectorPresenter->activate();
00098 }
00099 }
00100
00101 void DetectorChooserPresenter::reconnect(){
00102 connect(m_chooser, SIGNAL(parameterChanged(const QString&)), this, SLOT(changeParameter(const QString&)));
00103 }