00001 #include "SimplePeakFinderPresenter.h" 00002 #include "SimplePeakFinderPresenter.moc" 00003 00004 #include <iostream> 00005 00006 SimplePeakFinderPresenter::SimplePeakFinderPresenter(SimplePeakFinder* peakFinder, ParameterWidget* peakParameter): 00007 PeakFinderPresenter(peakFinder, peakParameter) 00008 { 00009 m_peakFinderParameter->addDoubleParameter("minValue", "Minimum value", 0., 0.); 00010 m_peakFinderParameter->addDoubleParameter("minDifference", "Minimum difference", 0., 0., 10e16, 4, 0.01); 00011 syncronize(); 00012 reconnect(); 00013 } 00014 00015 void SimplePeakFinderPresenter::setPeakFinder(PeakFinder* peakFinder){ 00016 m_peakFinder = peakFinder; 00017 syncronize(); 00018 } 00019 00020 void SimplePeakFinderPresenter::setPeakFinderParameter(ParameterWidget* peakParameter){ 00021 disconnect(m_peakFinderParameter, 0, this, 0); 00022 m_peakFinderParameter = peakParameter; 00023 m_peakFinderParameter->clearParameterMap(); 00024 m_peakFinderParameter->addDoubleParameter("minValue", "Minimum value", 0., 0.); 00025 m_peakFinderParameter->addDoubleParameter("minDifference", "Minimum difference", 0., 0., 10e16, 4, 0.01); 00026 syncronize(); 00027 reconnect(); 00028 } 00029 00030 void SimplePeakFinderPresenter::changeParameter(const QString& name){ 00031 if(!QString::compare(name, "minValue")){ 00032 double guiValue; 00033 bool valid = m_peakFinderParameter->getDoubleValue("minValue", guiValue); 00034 if(valid) {changeMinValue(guiValue);} 00035 } else if(!QString::compare(name, "minDifference")){ 00036 double guiValue; 00037 bool valid = m_peakFinderParameter->getDoubleValue("minDifference", guiValue); 00038 if(valid) {changeMinDifference(guiValue);} 00039 } 00040 } 00041 00042 00043 void SimplePeakFinderPresenter::changeMinValue(double value){ 00044 SimplePeakFinder *peakFinder = (SimplePeakFinder *) m_peakFinder; 00045 double guiValue; 00046 m_peakFinderParameter->getDoubleValue(QString("minValue"), guiValue); 00047 if(peakFinder->getMinValue() != value || guiValue != value){ 00048 peakFinder->setMinValue(value); 00049 m_peakFinderParameter->setDoubleValue("minValue", peakFinder->getMinValue()); 00050 emit peakFinderChanged(); 00051 } 00052 } 00053 00054 void SimplePeakFinderPresenter::changeMinDifference(double value){ 00055 SimplePeakFinder *peakFinder = (SimplePeakFinder *) m_peakFinder; 00056 double guiValue; 00057 m_peakFinderParameter->getDoubleValue("minDifference", guiValue); 00058 if(peakFinder->getMinDifference() != value || guiValue != value){ 00059 peakFinder->setMinDifference(value); 00060 m_peakFinderParameter->setDoubleValue("minDifference", peakFinder->getMinDifference()); 00061 emit peakFinderChanged(); 00062 } 00063 } 00064 00065 void SimplePeakFinderPresenter::syncronize(){ 00066 SimplePeakFinder *peakFinder = (SimplePeakFinder *) m_peakFinder; 00067 m_peakFinderParameter->setDoubleValue("minValue", peakFinder->getMinValue()); 00068 m_peakFinderParameter->setDoubleValue("minDifference", peakFinder->getMinDifference()); 00069 } 00070 00071 void SimplePeakFinderPresenter::reconnect(){ 00072 connect(m_peakFinderParameter, SIGNAL(parameterChanged(const QString&)), this, SLOT(changeParameter(const QString&))); 00073 }