libpappsomspp
Library for mass spectrometry
precisionwidget.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/widget/precision/precisionwidget.cpp
3  * \date 5/1/2018
4  * \author Olivier Langella
5  * \brief edit presicion in ppm or dalton
6  */
7 
8 
9 /*******************************************************************************
10  * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
11  *
12  * This file is part of the PAPPSOms++ library.
13  *
14  * PAPPSOms++ is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * PAPPSOms++ is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
26  *
27  * Contributors:
28  * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
29  *implementation
30  ******************************************************************************/
31 
32 #include "../../exception/exceptionnotpossible.h"
33 #include "precisionwidget.h"
34 #include <QHBoxLayout>
35 #include <QDebug>
36 
37 
38 namespace pappso
39 {
40 
41 PrecisionWidget::PrecisionWidget(QWidget *parent) : QWidget(parent)
42 {
43  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__
44  //<< "PrecisionWidget::PrecisionWidget begin";
45  setLayout(new QHBoxLayout(this));
46 
47  this->layout()->setMargin(0);
48  this->layout()->setContentsMargins(0, 0, 0, 0);
49 
50  // Each precision type has its own double spin box.
51  mp_daltonValueSpinBox = new QDoubleSpinBox();
52  this->layout()->addWidget(mp_daltonValueSpinBox);
53 
54  mp_ppmValueSpinBox = new QDoubleSpinBox();
55  this->layout()->addWidget(mp_ppmValueSpinBox);
56 
57  mp_resValueSpinBox = new QDoubleSpinBox();
58  this->layout()->addWidget(mp_resValueSpinBox);
59 
60  mp_unitComboBox = new QComboBox();
61  this->layout()->addWidget(mp_unitComboBox);
62 
63  mp_unitComboBox->addItem("dalton", QString("dalton"));
64  mp_unitComboBox->addItem("ppm", QString("ppm"));
65  mp_unitComboBox->addItem("res", QString("res"));
66 
67  mp_precisionDalton = PrecisionFactory::getDaltonInstance(0.02);
68  mp_precisionPpm = PrecisionFactory::getPpmInstance(10);
69  mp_precisionRes = PrecisionFactory::getResInstance(20000);
70 
71  mp_daltonValueSpinBox->setDecimals(3);
72  mp_daltonValueSpinBox->setSingleStep(0.01);
73  mp_daltonValueSpinBox->setRange(0, 30);
74 
75  mp_ppmValueSpinBox->setDecimals(4);
76  mp_ppmValueSpinBox->setSingleStep(10);
77  mp_ppmValueSpinBox->setRange(0.0001, 300);
78 
79  mp_resValueSpinBox->setDecimals(0);
80  mp_resValueSpinBox->setSingleStep(1000);
81  mp_resValueSpinBox->setRange(1, 2000000);
82 
83  // By default set precision to be of the Dalton type.
84  setPrecision(mp_precisionDalton);
85 
86  connect(mp_unitComboBox,
87  SIGNAL(currentIndexChanged(int)),
88  this,
89  SLOT(setCurrentIndex(int)));
90 
91  connect(mp_daltonValueSpinBox,
92  SIGNAL(valueChanged(double)),
93  this,
94  SLOT(setDaltonValueChanged(double)));
95 
96  connect(mp_ppmValueSpinBox,
97  SIGNAL(valueChanged(double)),
98  this,
99  SLOT(setPpmValueChanged(double)));
100 
101  connect(mp_resValueSpinBox,
102  SIGNAL(valueChanged(double)),
103  this,
104  SLOT(setResValueChanged(double)));
105 
106  m_oldIndex = -1;
107  // qDebug() << "PrecisionWidget::PrecisionWidget end";
108 }
109 
111 {
112 }
113 
114 void
116 {
117  // qDebug() << "PrecisionWidget::setCurrentIndex index=" << index;
118 
119  if(m_oldIndex != index)
120  {
121  m_oldIndex = index;
122 
123  if(mp_unitComboBox->itemData(index) == "dalton")
124  {
126  mp_daltonValueSpinBox->setVisible(true);
127 
128  mp_ppmValueSpinBox->setVisible(false);
129  mp_resValueSpinBox->setVisible(false);
130 
132  }
133  else if(mp_unitComboBox->itemData(index) == "ppm")
134  {
136  mp_ppmValueSpinBox->setVisible(true);
137 
138  mp_daltonValueSpinBox->setVisible(false);
139  mp_resValueSpinBox->setVisible(false);
140 
142  }
143  else if(mp_unitComboBox->itemData(index) == "res")
144  {
146  mp_resValueSpinBox->setVisible(true);
147 
148  mp_daltonValueSpinBox->setVisible(false);
149  mp_ppmValueSpinBox->setVisible(false);
150 
152  }
153  else
154  {
155  throw ExceptionNotPossible("precisionwidget.cpp @ setCurrentIndex(int index) -- ERROR programming error.");
156  }
157  }
158 }
159 
160 
161 void
163 {
164  // qDebug() << "dalton PrecisionWidget::setValueChanged value=" << value;
165 
167  if(mp_precisionDalton != precision)
168  {
169  mp_precisionDalton = precision;
171  }
172 }
173 
174 
175 void
177 {
178  // qDebug() << "ppm PrecisionWidget::setValueChanged value=" << value;
179 
181  if(mp_precisionPpm != precision)
182  {
183  mp_precisionPpm = precision;
185  }
186 }
187 
188 
189 void
191 {
192  // qDebug() << "res PrecisionWidget::setValueChanged value=" << value;
193 
195  if(mp_precisionRes != precision)
196  {
197  mp_precisionRes = precision;
199  }
200 }
201 
202 
203 const PrecisionPtr &
205 {
206  if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "dalton")
207  {
208  return mp_precisionDalton;
209  }
210  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "ppm")
211  {
212  return mp_precisionPpm;
213  }
214  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "res")
215  {
216  return mp_precisionRes;
217  }
218  else
219  {
220  throw ExceptionNotPossible("precisionwidget.cpp @ getPrecision()-- ERROR programming error.");
221  }
222 }
223 
224 
225 void
227 {
228 
229  if(precision->unit() == PrecisionUnit::dalton)
230  {
231  mp_precisionDalton = precision;
232  mp_unitComboBox->setCurrentIndex(
233  mp_unitComboBox->findData(QString("dalton")));
234 
235  mp_daltonValueSpinBox->setValue(precision->getNominal());
236  mp_daltonValueSpinBox->setVisible(true);
237 
238  mp_ppmValueSpinBox->setVisible(false);
239  mp_resValueSpinBox->setVisible(false);
240  }
241  else if(precision->unit() == PrecisionUnit::ppm)
242  {
243  mp_precisionPpm = precision;
244  mp_unitComboBox->setCurrentIndex(
245  mp_unitComboBox->findData(QString("ppm")));
246 
247  mp_ppmValueSpinBox->setValue(precision->getNominal());
248  mp_ppmValueSpinBox->setVisible(true);
249 
250  mp_daltonValueSpinBox->setVisible(false);
251  mp_resValueSpinBox->setVisible(false);
252  }
253  else if(precision->unit() == PrecisionUnit::res)
254  {
255  mp_precisionRes = precision;
256  mp_unitComboBox->setCurrentIndex(
257  mp_unitComboBox->findData(QString("res")));
258 
259  mp_resValueSpinBox->setValue(precision->getNominal());
260  mp_resValueSpinBox->setVisible(true);
261 
262  mp_daltonValueSpinBox->setVisible(false);
263  mp_ppmValueSpinBox->setVisible(false);
264  }
265  else
266  {
267  throw ExceptionNotPossible("precisionwidget.cpp @ setPrecision(PrecisionPtr precision)-- ERROR programming error.");
268  }
269 }
270 
271 
272 } // namespace pappso
pappso::PrecisionWidget::setPrecision
void setPrecision(PrecisionPtr precision)
Definition: precisionwidget.cpp:247
pappso::PrecisionFactory::getPpmInstance
static PrecisionPtr getPpmInstance(pappso_double value)
Definition: precision.cpp:170
pappso::PrecisionWidget::precisionChanged
void precisionChanged(pappso::PrecisionPtr precision) const
pappso::PrecisionWidget::mp_unitComboBox
QComboBox * mp_unitComboBox
Definition: precisionwidget.h:92
pappso::PrecisionUnit::dalton
@ dalton
pappso::PrecisionWidget::getPrecision
const PrecisionPtr & getPrecision() const
Definition: precisionwidget.cpp:225
pappso::PrecisionWidget::mp_resValueSpinBox
QDoubleSpinBox * mp_resValueSpinBox
Definition: precisionwidget.h:95
pappso::PrecisionWidget::setPpmValueChanged
Q_SLOT void setPpmValueChanged(double)
Definition: precisionwidget.cpp:197
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::PrecisionWidget::mp_daltonValueSpinBox
QDoubleSpinBox * mp_daltonValueSpinBox
Definition: precisionwidget.h:96
pappso::PrecisionWidget::mp_precisionDalton
PrecisionPtr mp_precisionDalton
Definition: precisionwidget.h:98
pappso::PrecisionWidget::m_oldIndex
int m_oldIndex
Definition: precisionwidget.h:102
precisionwidget.h
pappso::PrecisionWidget::~PrecisionWidget
~PrecisionWidget()
Definition: precisionwidget.cpp:131
pappso::PrecisionUnit::res
@ res
pappso::PrecisionFactory::getDaltonInstance
static PrecisionPtr getDaltonInstance(pappso_double value)
Definition: precision.cpp:150
pappso::PrecisionUnit::ppm
@ ppm
pappso::PrecisionBase::getNominal
virtual pappso_double getNominal() const final
Definition: precision.cpp:85
pappso::PrecisionWidget::setResValueChanged
Q_SLOT void setResValueChanged(double)
Definition: precisionwidget.cpp:211
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition: precision.h:143
pappso::PrecisionBase
Definition: precision.h:65
pappso::PrecisionWidget::mp_ppmValueSpinBox
QDoubleSpinBox * mp_ppmValueSpinBox
Definition: precisionwidget.h:94
pappso::PrecisionWidget::setCurrentIndex
Q_SLOT void setCurrentIndex(int)
Definition: precisionwidget.cpp:136
pappso::PrecisionWidget::mp_precisionRes
PrecisionPtr mp_precisionRes
Definition: precisionwidget.h:100
pappso::PrecisionFactory::getResInstance
static PrecisionPtr getResInstance(pappso_double value)
Definition: precision.cpp:197
pappso::PrecisionWidget::mp_precisionPpm
PrecisionPtr mp_precisionPpm
Definition: precisionwidget.h:99
pappso::PrecisionWidget::setDaltonValueChanged
Q_SLOT void setDaltonValueChanged(double)
Definition: precisionwidget.cpp:183
pappso::PrecisionBase::unit
virtual PrecisionUnit unit() const =0
pappso::PrecisionWidget::PrecisionWidget
PrecisionWidget(QWidget *parent=0)
Definition: precisionwidget.cpp:62