libpappsomspp
Library for mass spectrometry
precisionwidget.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/widget/precisionwidget/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 
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.
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(
156  "precisionwidget.cpp @ setCurrentIndex(int index) -- ERROR "
157  "programming error.");
158  }
159  }
160 }
161 
162 
163 void
165 {
166  // qDebug() << "dalton PrecisionWidget::setValueChanged value=" << value;
167 
169  if(mp_precisionDalton != precision)
170  {
171  mp_precisionDalton = precision;
173  }
174 }
175 
176 
177 void
179 {
180  // qDebug() << "ppm PrecisionWidget::setValueChanged value=" << value;
181 
183  if(mp_precisionPpm != precision)
184  {
185  mp_precisionPpm = precision;
187  }
188 }
189 
190 
191 void
193 {
194  // qDebug() << "res PrecisionWidget::setValueChanged value=" << value;
195 
197  if(mp_precisionRes != precision)
198  {
199  mp_precisionRes = precision;
201  }
202 }
203 
204 
205 const PrecisionPtr &
207 {
208  if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "dalton")
209  {
210  return mp_precisionDalton;
211  }
212  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "ppm")
213  {
214  return mp_precisionPpm;
215  }
216  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "res")
217  {
218  return mp_precisionRes;
219  }
220  else
221  {
222  throw ExceptionNotPossible(
223  "precisionwidget.cpp @ getPrecision()-- ERROR programming error.");
224  }
225 }
226 
227 
228 void
230 {
231 
232  if(precision->unit() == PrecisionUnit::dalton)
233  {
234  mp_precisionDalton = precision;
235  mp_unitComboBox->setCurrentIndex(
236  mp_unitComboBox->findData(QString("dalton")));
237 
238  mp_daltonValueSpinBox->setValue(precision->getNominal());
239  mp_daltonValueSpinBox->setVisible(true);
240 
241  mp_ppmValueSpinBox->setVisible(false);
242  mp_resValueSpinBox->setVisible(false);
243  }
244  else if(precision->unit() == PrecisionUnit::ppm)
245  {
246  mp_precisionPpm = precision;
247  mp_unitComboBox->setCurrentIndex(
248  mp_unitComboBox->findData(QString("ppm")));
249 
250  mp_ppmValueSpinBox->setValue(precision->getNominal());
251  mp_ppmValueSpinBox->setVisible(true);
252 
253  mp_daltonValueSpinBox->setVisible(false);
254  mp_resValueSpinBox->setVisible(false);
255  }
256  else if(precision->unit() == PrecisionUnit::res)
257  {
258  mp_precisionRes = precision;
259  mp_unitComboBox->setCurrentIndex(
260  mp_unitComboBox->findData(QString("res")));
261 
262  mp_resValueSpinBox->setValue(precision->getNominal());
263  mp_resValueSpinBox->setVisible(true);
264 
265  mp_daltonValueSpinBox->setVisible(false);
266  mp_ppmValueSpinBox->setVisible(false);
267  }
268  else
269  {
270  throw ExceptionNotPossible(
271  "precisionwidget.cpp @ setPrecision(PrecisionPtr precision)-- ERROR "
272  "programming error.");
273  }
274 }
275 
276 
277 } // namespace pappso
virtual pappso_double getNominal() const final
Definition: precision.cpp:64
virtual PrecisionUnit unit() const =0
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
Definition: precision.cpp:176
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
Definition: precision.cpp:149
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
Definition: precision.cpp:129
const PrecisionPtr & getPrecision() const
QDoubleSpinBox * mp_daltonValueSpinBox
Q_SLOT void setDaltonValueChanged(double)
PrecisionWidget(QWidget *parent=0)
QDoubleSpinBox * mp_ppmValueSpinBox
Q_SLOT void setResValueChanged(double)
Q_SLOT void setCurrentIndex(int)
void precisionChanged(pappso::PrecisionPtr precision) const
PrecisionPtr mp_precisionRes
Q_SLOT void setPpmValueChanged(double)
void setPrecision(PrecisionPtr precision)
QDoubleSpinBox * mp_resValueSpinBox
PrecisionPtr mp_precisionDalton
PrecisionPtr mp_precisionPpm
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
edit presicion in ppm or dalton