pappsomspp
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 "precisionwidget.h"
33 #include <QHBoxLayout>
34 #include <QDebug>
35 
36 
37 namespace pappso
38 {
39 
40 PrecisionWidget::PrecisionWidget(QWidget *parent) : QWidget(parent)
41 {
42  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__
43  //<< "PrecisionWidget::PrecisionWidget begin";
44  setLayout(new QHBoxLayout(this));
45 
46  this->layout()->setMargin(0);
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 
66  mp_precisionDalton = PrecisionFactory::getDaltonInstance(0.02);
67  mp_precisionPpm = PrecisionFactory::getPpmInstance(10);
68  mp_precisionRes = PrecisionFactory::getResInstance(20000);
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.
83  setPrecision(mp_precisionDalton);
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  {
124  mp_daltonValueSpinBox->setValue(mp_precisionDalton->getNominal());
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  {
134  mp_ppmValueSpinBox->setValue(mp_precisionPpm->getNominal());
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  {
144  mp_resValueSpinBox->setValue(mp_precisionRes->getNominal());
145  mp_resValueSpinBox->setVisible(true);
146 
147  mp_daltonValueSpinBox->setVisible(false);
148  mp_ppmValueSpinBox->setVisible(false);
149 
151  }
152  else
153  {
154  qFatal(
155  "Fatal error at %s@%d -- %s(). "
156  "Programming error."
157  "Program aborted.",
158  __FILE__,
159  __LINE__,
160  __FUNCTION__);
161  }
162  }
163 }
164 
165 
166 void
168 {
169  // qDebug() << "dalton PrecisionWidget::setValueChanged value=" << value;
170 
172  if(mp_precisionDalton != precision)
173  {
174  mp_precisionDalton = precision;
176  }
177 }
178 
179 
180 void
182 {
183  // qDebug() << "ppm PrecisionWidget::setValueChanged value=" << value;
184 
186  if(mp_precisionPpm != precision)
187  {
188  mp_precisionPpm = precision;
190  }
191 }
192 
193 
194 void
196 {
197  // qDebug() << "res PrecisionWidget::setValueChanged value=" << value;
198 
200  if(mp_precisionRes != precision)
201  {
202  mp_precisionRes = precision;
204  }
205 }
206 
207 
208 const PrecisionPtr &
210 {
211  if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "dalton")
212  {
213  return mp_precisionDalton;
214  }
215  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "ppm")
216  {
217  return mp_precisionPpm;
218  }
219  else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "res")
220  {
221  return mp_precisionRes;
222  }
223  else
224  {
225  qFatal(
226  "Fatal error at %s@%d -- %s(). "
227  "Programming error."
228  "Program aborted.",
229  __FILE__,
230  __LINE__,
231  __FUNCTION__);
232  }
233 }
234 
235 
236 void
238 {
239 
240  if(precision->unit() == PrecisionUnit::dalton)
241  {
242  mp_precisionDalton = precision;
243  mp_unitComboBox->setCurrentIndex(
244  mp_unitComboBox->findData(QString("dalton")));
245 
246  mp_daltonValueSpinBox->setValue(precision->getNominal());
247  mp_daltonValueSpinBox->setVisible(true);
248 
249  mp_ppmValueSpinBox->setVisible(false);
250  mp_resValueSpinBox->setVisible(false);
251  }
252  else if(precision->unit() == PrecisionUnit::ppm)
253  {
254  mp_precisionPpm = precision;
255  mp_unitComboBox->setCurrentIndex(
256  mp_unitComboBox->findData(QString("ppm")));
257 
258  mp_ppmValueSpinBox->setValue(precision->getNominal());
259  mp_ppmValueSpinBox->setVisible(true);
260 
261  mp_daltonValueSpinBox->setVisible(false);
262  mp_resValueSpinBox->setVisible(false);
263  }
264  else if(precision->unit() == PrecisionUnit::res)
265  {
266  mp_precisionRes = precision;
267  mp_unitComboBox->setCurrentIndex(
268  mp_unitComboBox->findData(QString("res")));
269 
270  mp_resValueSpinBox->setValue(precision->getNominal());
271  mp_resValueSpinBox->setVisible(true);
272 
273  mp_daltonValueSpinBox->setVisible(false);
274  mp_ppmValueSpinBox->setVisible(false);
275  }
276  else
277  qFatal(
278  "Fatal error at %s@%d -- %s(). "
279  "."
280  "Program aborted.",
281  __FILE__,
282  __LINE__,
283  __FUNCTION__);
284 }
285 
286 
287 } // namespace pappso
pappso::PrecisionWidget::setPrecision
void setPrecision(PrecisionPtr precision)
Definition: precisionwidget.cpp:257
pappso::PrecisionFactory::getPpmInstance
static PrecisionPtr getPpmInstance(pappso_double value)
Definition: precision.cpp:168
pappso::PrecisionWidget::precisionChanged
void precisionChanged(pappso::PrecisionPtr precision) const
pappso::PrecisionWidget::mp_unitComboBox
QComboBox * mp_unitComboBox
Definition: precisionwidget.h:89
pappso::PrecisionUnit::dalton
pappso::PrecisionWidget::getPrecision
const PrecisionPtr & getPrecision() const
Definition: precisionwidget.cpp:229
pappso::PrecisionWidget::mp_resValueSpinBox
QDoubleSpinBox * mp_resValueSpinBox
Definition: precisionwidget.h:92
pappso::PrecisionWidget::setPpmValueChanged
Q_SLOT void setPpmValueChanged(double)
Definition: precisionwidget.cpp:201
pappso
Definition: aa.cpp:38
pappso::PrecisionWidget::mp_daltonValueSpinBox
QDoubleSpinBox * mp_daltonValueSpinBox
Definition: precisionwidget.h:93
pappso::PrecisionWidget::mp_precisionDalton
PrecisionPtr mp_precisionDalton
Definition: precisionwidget.h:95
pappso::PrecisionWidget::m_oldIndex
int m_oldIndex
Definition: precisionwidget.h:99
precisionwidget.h
pappso::PrecisionWidget::~PrecisionWidget
~PrecisionWidget()
Definition: precisionwidget.cpp:129
pappso::PrecisionUnit::res
pappso::PrecisionFactory::getDaltonInstance
static PrecisionPtr getDaltonInstance(pappso_double value)
Definition: precision.cpp:148
pappso::PrecisionUnit::ppm
pappso::PrecisionWidget::setResValueChanged
Q_SLOT void setResValueChanged(double)
Definition: precisionwidget.cpp:215
pappso::PrecisionPtr
const typedef PrecisionBase * PrecisionPtr
Definition: precision.h:141
pappso::PrecisionWidget::mp_ppmValueSpinBox
QDoubleSpinBox * mp_ppmValueSpinBox
Definition: precisionwidget.h:91
pappso::PrecisionWidget::setCurrentIndex
Q_SLOT void setCurrentIndex(int)
Definition: precisionwidget.cpp:134
pappso::PrecisionWidget::mp_precisionRes
PrecisionPtr mp_precisionRes
Definition: precisionwidget.h:97
pappso::PrecisionFactory::getResInstance
static PrecisionPtr getResInstance(pappso_double value)
Definition: precision.cpp:198
pappso::PrecisionWidget::mp_precisionPpm
PrecisionPtr mp_precisionPpm
Definition: precisionwidget.h:96
pappso::PrecisionWidget::setDaltonValueChanged
Q_SLOT void setDaltonValueChanged(double)
Definition: precisionwidget.cpp:187
pappso::PrecisionWidget::PrecisionWidget
PrecisionWidget(QWidget *parent=0)
Definition: precisionwidget.cpp:60