libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
33#include "precisionwidget.h"
34#include <QHBoxLayout>
35#include <QDebug>
36
37
38namespace pappso
39{
40
41PrecisionWidget::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(6);
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, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
86
87 connect(
88 mp_daltonValueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setDaltonValueChanged(double)));
89
90 connect(mp_ppmValueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPpmValueChanged(double)));
91
92 connect(mp_resValueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setResValueChanged(double)));
93
94 m_oldIndex = -1;
95 // qDebug() << "PrecisionWidget::PrecisionWidget end";
96}
97
101
102void
104{
105 // qDebug() << "PrecisionWidget::setCurrentIndex index=" << index;
106
107 if(m_oldIndex != index)
108 {
109 m_oldIndex = index;
110
111 if(mp_unitComboBox->itemData(index) == "dalton")
112 {
113 mp_daltonValueSpinBox->setValue(mp_precisionDalton->getNominal());
114 mp_daltonValueSpinBox->setVisible(true);
115
116 mp_ppmValueSpinBox->setVisible(false);
117 mp_resValueSpinBox->setVisible(false);
118
120 }
121 else if(mp_unitComboBox->itemData(index) == "ppm")
122 {
123 mp_ppmValueSpinBox->setValue(mp_precisionPpm->getNominal());
124 mp_ppmValueSpinBox->setVisible(true);
125
126 mp_daltonValueSpinBox->setVisible(false);
127 mp_resValueSpinBox->setVisible(false);
128
130 }
131 else if(mp_unitComboBox->itemData(index) == "res")
132 {
133 mp_resValueSpinBox->setValue(mp_precisionRes->getNominal());
134 mp_resValueSpinBox->setVisible(true);
135
136 mp_daltonValueSpinBox->setVisible(false);
137 mp_ppmValueSpinBox->setVisible(false);
138
140 }
141 else
142 {
144 "precisionwidget.cpp @ setCurrentIndex(int index) -- ERROR "
145 "programming error.");
146 }
147 }
148}
149
150
151void
153{
154 // qDebug() << "dalton PrecisionWidget::setValueChanged value=" << value;
155
157 if(mp_precisionDalton != precision)
158 {
159 mp_precisionDalton = precision;
161 }
162}
163
164
165void
167{
168 // qDebug() << "ppm PrecisionWidget::setValueChanged value=" << value;
169
171 if(mp_precisionPpm != precision)
172 {
173 mp_precisionPpm = precision;
175 }
176}
177
178
179void
181{
182 // qDebug() << "res PrecisionWidget::setValueChanged value=" << value;
183
185 if(mp_precisionRes != precision)
186 {
187 mp_precisionRes = precision;
189 }
190}
191
192
193const PrecisionPtr &
195{
196 if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "dalton")
197 {
198 return mp_precisionDalton;
199 }
200 else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "ppm")
201 {
202 return mp_precisionPpm;
203 }
204 else if(mp_unitComboBox->itemData(mp_unitComboBox->currentIndex()) == "res")
205 {
206 return mp_precisionRes;
207 }
208 else
209 {
210 throw ExceptionNotPossible("precisionwidget.cpp @ getPrecision()-- ERROR programming error.");
211 }
212}
213
214
215void
217{
218
219 if(precision->unit() == Enums::PrecisionUnit::dalton)
220 {
221 mp_precisionDalton = precision;
222 mp_unitComboBox->setCurrentIndex(mp_unitComboBox->findData(QString("dalton")));
223
224 mp_daltonValueSpinBox->setValue(precision->getNominal());
225 mp_daltonValueSpinBox->setVisible(true);
226
227 mp_ppmValueSpinBox->setVisible(false);
228 mp_resValueSpinBox->setVisible(false);
229 }
230 else if(precision->unit() == Enums::PrecisionUnit::ppm)
231 {
232 mp_precisionPpm = precision;
233 mp_unitComboBox->setCurrentIndex(mp_unitComboBox->findData(QString("ppm")));
234
235 mp_ppmValueSpinBox->setValue(precision->getNominal());
236 mp_ppmValueSpinBox->setVisible(true);
237
238 mp_daltonValueSpinBox->setVisible(false);
239 mp_resValueSpinBox->setVisible(false);
240 }
241 else if(precision->unit() == Enums::PrecisionUnit::res)
242 {
243 mp_precisionRes = precision;
244 mp_unitComboBox->setCurrentIndex(mp_unitComboBox->findData(QString("res")));
245
246 mp_resValueSpinBox->setValue(precision->getNominal());
247 mp_resValueSpinBox->setVisible(true);
248
249 mp_daltonValueSpinBox->setVisible(false);
250 mp_ppmValueSpinBox->setVisible(false);
251 }
252 else
253 {
255 "precisionwidget.cpp @ setPrecision(PrecisionPtr precision)-- ERROR "
256 "programming error.");
257 }
258}
259
260
261} // namespace pappso
virtual pappso_double getNominal() const final
Definition precision.cpp:73
virtual Enums::PrecisionUnit unit() const =0
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
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
Q_SLOT void setPpmValueChanged(double)
void setPrecision(PrecisionPtr precision)
QDoubleSpinBox * mp_resValueSpinBox
PrecisionPtr mp_precisionDalton
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
const PrecisionBase * PrecisionPtr
Definition precision.h:122