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()->setContentsMargins(0, 0, 0, 0);
48 
49  // Each precision type has its own double spin box.
50  mp_daltonValueSpinBox = new QDoubleSpinBox();
51  this->layout()->addWidget(mp_daltonValueSpinBox);
52 
53  mp_ppmValueSpinBox = new QDoubleSpinBox();
54  this->layout()->addWidget(mp_ppmValueSpinBox);
55 
56  mp_resValueSpinBox = new QDoubleSpinBox();
57  this->layout()->addWidget(mp_resValueSpinBox);
58 
59  mp_unitComboBox = new QComboBox();
60  this->layout()->addWidget(mp_unitComboBox);
61 
62  mp_unitComboBox->addItem("dalton", QString("dalton"));
63  mp_unitComboBox->addItem("ppm", QString("ppm"));
64  mp_unitComboBox->addItem("res", QString("res"));
65 
69 
70  mp_daltonValueSpinBox->setDecimals(3);
71  mp_daltonValueSpinBox->setSingleStep(0.01);
72  mp_daltonValueSpinBox->setRange(0, 30);
73 
74  mp_ppmValueSpinBox->setDecimals(4);
75  mp_ppmValueSpinBox->setSingleStep(10);
76  mp_ppmValueSpinBox->setRange(0.0001, 300);
77 
78  mp_resValueSpinBox->setDecimals(0);
79  mp_resValueSpinBox->setSingleStep(1000);
80  mp_resValueSpinBox->setRange(1, 2000000);
81 
82  // By default set precision to be of the Dalton type.
84 
85  connect(mp_unitComboBox,
86  SIGNAL(currentIndexChanged(int)),
87  this,
88  SLOT(setCurrentIndex(int)));
89 
90  connect(mp_daltonValueSpinBox,
91  SIGNAL(valueChanged(double)),
92  this,
93  SLOT(setDaltonValueChanged(double)));
94 
95  connect(mp_ppmValueSpinBox,
96  SIGNAL(valueChanged(double)),
97  this,
98  SLOT(setPpmValueChanged(double)));
99 
100  connect(mp_resValueSpinBox,
101  SIGNAL(valueChanged(double)),
102  this,
103  SLOT(setResValueChanged(double)));
104 
105  m_oldIndex = -1;
106  // qDebug() << "PrecisionWidget::PrecisionWidget end";
107 }
108 
110 {
111 }
112 
113 void
115 {
116  // qDebug() << "PrecisionWidget::setCurrentIndex index=" << index;
117 
118  if(m_oldIndex != index)
119  {
120  m_oldIndex = index;
121 
122  if(mp_unitComboBox->itemData(index) == "dalton")
123  {
125  mp_daltonValueSpinBox->setVisible(true);
126 
127  mp_ppmValueSpinBox->setVisible(false);
128  mp_resValueSpinBox->setVisible(false);
129 
131  }
132  else if(mp_unitComboBox->itemData(index) == "ppm")
133  {
135  mp_ppmValueSpinBox->setVisible(true);
136 
137  mp_daltonValueSpinBox->setVisible(false);
138  mp_resValueSpinBox->setVisible(false);
139 
141  }
142  else if(mp_unitComboBox->itemData(index) == "res")
143  {
145  mp_resValueSpinBox->setVisible(true);
146 
147  mp_daltonValueSpinBox->setVisible(false);
148  mp_ppmValueSpinBox->setVisible(false);
149 
151  }
152  else
153  {
154  throw ExceptionNotPossible(
155  "precisionwidget.cpp @ setCurrentIndex(int index) -- ERROR "
156  "programming error.");
157  }
158  }
159 }
160 
161 
162 void
164 {
165  // qDebug() << "dalton PrecisionWidget::setValueChanged value=" << value;
166 
168  if(mp_precisionDalton != precision)
169  {
170  mp_precisionDalton = precision;
172  }
173 }
174 
175 
176 void
178 {
179  // qDebug() << "ppm PrecisionWidget::setValueChanged value=" << value;
180 
182  if(mp_precisionPpm != precision)
183  {
184  mp_precisionPpm = precision;
186  }
187 }
188 
189 
190 void
192 {
193  // qDebug() << "res PrecisionWidget::setValueChanged value=" << value;
194 
196  if(mp_precisionRes != precision)
197  {
198  mp_precisionRes = precision;
200  }
201 }
202 
203 
204 const PrecisionPtr &
206 {
207  if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "dalton")
208  {
209  return mp_precisionDalton;
210  }
211  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "ppm")
212  {
213  return mp_precisionPpm;
214  }
215  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "res")
216  {
217  return mp_precisionRes;
218  }
219  else
220  {
221  throw ExceptionNotPossible(
222  "precisionwidget.cpp @ getPrecision()-- ERROR programming error.");
223  }
224 }
225 
226 
227 void
229 {
230 
231  if(precision->unit() == PrecisionUnit::dalton)
232  {
233  mp_precisionDalton = precision;
234  mp_unitComboBox->setCurrentIndex(
235  mp_unitComboBox->findData(QString("dalton")));
236 
237  mp_daltonValueSpinBox->setValue(precision->getNominal());
238  mp_daltonValueSpinBox->setVisible(true);
239 
240  mp_ppmValueSpinBox->setVisible(false);
241  mp_resValueSpinBox->setVisible(false);
242  }
243  else if(precision->unit() == PrecisionUnit::ppm)
244  {
245  mp_precisionPpm = precision;
246  mp_unitComboBox->setCurrentIndex(
247  mp_unitComboBox->findData(QString("ppm")));
248 
249  mp_ppmValueSpinBox->setValue(precision->getNominal());
250  mp_ppmValueSpinBox->setVisible(true);
251 
252  mp_daltonValueSpinBox->setVisible(false);
253  mp_resValueSpinBox->setVisible(false);
254  }
255  else if(precision->unit() == PrecisionUnit::res)
256  {
257  mp_precisionRes = precision;
258  mp_unitComboBox->setCurrentIndex(
259  mp_unitComboBox->findData(QString("res")));
260 
261  mp_resValueSpinBox->setValue(precision->getNominal());
262  mp_resValueSpinBox->setVisible(true);
263 
264  mp_daltonValueSpinBox->setVisible(false);
265  mp_ppmValueSpinBox->setVisible(false);
266  }
267  else
268  {
269  throw ExceptionNotPossible(
270  "precisionwidget.cpp @ setPrecision(PrecisionPtr precision)-- ERROR "
271  "programming error.");
272  }
273 }
274 
275 
276 } // namespace pappso
virtual pappso_double getNominal() const final
Definition: precision.cpp:65
virtual PrecisionUnit unit() const =0
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
Definition: precision.cpp:177
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
Definition: precision.cpp:150
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
Definition: precision.cpp:130
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