libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
32
#include "
pappsomspp/core/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
66
mp_precisionDalton
=
PrecisionFactory::getDaltonInstance
(0.02);
67
mp_precisionPpm
=
PrecisionFactory::getPpmInstance
(10);
68
mp_precisionRes
=
PrecisionFactory::getResInstance
(20000);
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.
83
setPrecision
(
mp_precisionDalton
);
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
98
PrecisionWidget::~PrecisionWidget
()
99
{
100
}
101
102
void
103
PrecisionWidget::setCurrentIndex
(
int
index)
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
119
emit
precisionChanged
(
mp_precisionDalton
);
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
129
emit
precisionChanged
(
mp_precisionPpm
);
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
139
emit
precisionChanged
(
mp_precisionRes
);
140
}
141
else
142
{
143
throw
ExceptionNotPossible
(
144
"precisionwidget.cpp @ setCurrentIndex(int index) -- ERROR "
145
"programming error."
);
146
}
147
}
148
}
149
150
151
void
152
PrecisionWidget::setDaltonValueChanged
(
double
value)
153
{
154
// qDebug() << "dalton PrecisionWidget::setValueChanged value=" << value;
155
156
PrecisionPtr
precision =
PrecisionFactory::getDaltonInstance
(value);
157
if
(
mp_precisionDalton
!= precision)
158
{
159
mp_precisionDalton
= precision;
160
emit
precisionChanged
(
mp_precisionDalton
);
161
}
162
}
163
164
165
void
166
PrecisionWidget::setPpmValueChanged
(
double
value)
167
{
168
// qDebug() << "ppm PrecisionWidget::setValueChanged value=" << value;
169
170
PrecisionPtr
precision =
PrecisionFactory::getPpmInstance
(value);
171
if
(
mp_precisionPpm
!= precision)
172
{
173
mp_precisionPpm
= precision;
174
emit
precisionChanged
(
mp_precisionPpm
);
175
}
176
}
177
178
179
void
180
PrecisionWidget::setResValueChanged
(
double
value)
181
{
182
// qDebug() << "res PrecisionWidget::setValueChanged value=" << value;
183
184
PrecisionPtr
precision =
PrecisionFactory::getResInstance
(value);
185
if
(
mp_precisionRes
!= precision)
186
{
187
mp_precisionRes
= precision;
188
emit
precisionChanged
(
mp_precisionRes
);
189
}
190
}
191
192
193
const
PrecisionPtr
&
194
PrecisionWidget::getPrecision
()
const
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
215
void
216
PrecisionWidget::setPrecision
(
PrecisionPtr
precision)
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
{
254
throw
ExceptionNotPossible
(
255
"precisionwidget.cpp @ setPrecision(PrecisionPtr precision)-- ERROR "
256
"programming error."
);
257
}
258
}
259
260
261
}
// namespace pappso
pappso::ExceptionNotPossible
Definition
exceptionnotpossible.h:29
pappso::PrecisionBase::getNominal
virtual pappso_double getNominal() const final
Definition
precision.cpp:73
pappso::PrecisionBase::unit
virtual Enums::PrecisionUnit unit() const =0
pappso::PrecisionFactory::getResInstance
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
Definition
precision.cpp:181
pappso::PrecisionFactory::getPpmInstance
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
Definition
precision.cpp:155
pappso::PrecisionFactory::getDaltonInstance
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
Definition
precision.cpp:136
pappso::PrecisionWidget::getPrecision
const PrecisionPtr & getPrecision() const
Definition
precisionwidget.cpp:194
pappso::PrecisionWidget::mp_daltonValueSpinBox
QDoubleSpinBox * mp_daltonValueSpinBox
Definition
precisionwidget.h:54
pappso::PrecisionWidget::setDaltonValueChanged
Q_SLOT void setDaltonValueChanged(double)
Definition
precisionwidget.cpp:152
pappso::PrecisionWidget::PrecisionWidget
PrecisionWidget(QWidget *parent=0)
Definition
precisionwidget.cpp:41
pappso::PrecisionWidget::~PrecisionWidget
~PrecisionWidget()
Definition
precisionwidget.cpp:98
pappso::PrecisionWidget::mp_unitComboBox
QComboBox * mp_unitComboBox
Definition
precisionwidget.h:50
pappso::PrecisionWidget::mp_ppmValueSpinBox
QDoubleSpinBox * mp_ppmValueSpinBox
Definition
precisionwidget.h:52
pappso::PrecisionWidget::setResValueChanged
Q_SLOT void setResValueChanged(double)
Definition
precisionwidget.cpp:180
pappso::PrecisionWidget::setCurrentIndex
Q_SLOT void setCurrentIndex(int)
Definition
precisionwidget.cpp:103
pappso::PrecisionWidget::precisionChanged
void precisionChanged(pappso::PrecisionPtr precision) const
pappso::PrecisionWidget::mp_precisionRes
PrecisionPtr mp_precisionRes
Definition
precisionwidget.h:58
pappso::PrecisionWidget::setPpmValueChanged
Q_SLOT void setPpmValueChanged(double)
Definition
precisionwidget.cpp:166
pappso::PrecisionWidget::setPrecision
void setPrecision(PrecisionPtr precision)
Definition
precisionwidget.cpp:216
pappso::PrecisionWidget::mp_resValueSpinBox
QDoubleSpinBox * mp_resValueSpinBox
Definition
precisionwidget.h:53
pappso::PrecisionWidget::mp_precisionDalton
PrecisionPtr mp_precisionDalton
Definition
precisionwidget.h:56
pappso::PrecisionWidget::m_oldIndex
int m_oldIndex
Definition
precisionwidget.h:60
pappso::PrecisionWidget::mp_precisionPpm
PrecisionPtr mp_precisionPpm
Definition
precisionwidget.h:57
exceptionnotpossible.h
pappso::Enums::PrecisionUnit::res
@ res
Definition
types.h:94
pappso::Enums::PrecisionUnit::ppm
@ ppm
Definition
types.h:93
pappso::Enums::PrecisionUnit::dalton
@ dalton
Definition
types.h:92
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition
precision.h:122
precisionwidget.h
pappsomspp
gui
precisionwidget
precisionwidget.cpp
Generated on
for libpappsomspp by
1.17.0