GCC Code Coverage Report


source/XpertMassCore/src/
File: source/XpertMassCore/src/Tolerance.cpp
Date: 2025-11-20 01:41:33
Lines:
0/76
0.0%
Functions:
0/14
0.0%
Branches:
0/62
0.0%

Line Branch Exec Source
1 /* BEGIN software license
2 *
3 * MsXpertSuite - mass spectrometry software suite
4 * -----------------------------------------------
5 * Copyright(C) 2009,...,2018 Filippo Rusconi
6 *
7 * http://www.msxpertsuite.org
8 *
9 * This file is part of the MsXpertSuite project.
10 *
11 * The MsXpertSuite project is the successor of the massXpert project. This
12 * project now includes various independent modules:
13 *
14 * - massXpert, model polymer chemistries and simulate mass spectrometric data;
15 * - mineXpert, a powerful TIC chromatogram/mass spectrum viewer/miner;
16 *
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 *
30 * END software license
31 */
32
33 /////////////////////// stdlib includes
34
35
36 /////////////////////// Qt includes
37 #include <QDebug>
38
39
40 /////////////////////// pappsomspp includes
41
42
43 /////////////////////// libXpertMassGui includes
44
45
46 /////////////////////// Local includes
47 #include "MsXpS/libXpertMassCore/Tolerance.hpp"
48
49
50 namespace MsXpS
51 {
52 namespace libXpertMassCore
53 {
54
55 Tolerance::Tolerance(QObject *parent) : QObject(parent)
56 {
57 }
58
59 Tolerance::Tolerance(Tolerance::Type type, double nominal, QObject *parent)
60 : QObject(parent), m_nominal(nominal), m_type(type)
61 {
62 }
63
64 void
65 Tolerance::setNominal(double nominal)
66 {
67 if(m_nominal == nominal)
68 return;
69
70 m_nominal = nominal;
71
72 emit nominalChangedSignal();
73 emit toleranceChangedSignal(
74 std::pair<double, Tolerance::Type>(m_nominal, m_type));
75 }
76
77
78 double
79 Tolerance::getNominal() const
80 {
81 return m_nominal;
82 }
83
84 void
85 Tolerance::setType(Type type)
86 {
87 if(m_type == type)
88 return;
89
90 m_type = type;
91
92 emit typeChangedSignal();
93 emit toleranceChangedSignal(
94 std::pair<double, Tolerance::Type>(m_nominal, m_type));
95 }
96
97 void
98 Tolerance::setType(const QString &text)
99 {
100 std::map<Type, QString>::const_iterator the_iterator_cst =
101 std::find_if(m_typeToStringMap.cbegin(),
102 m_typeToStringMap.cend(),
103 [&](const std::pair<Type, QString> &pair) {
104 if(pair.second == text)
105 return true;
106 return false;
107 });
108
109 if(the_iterator_cst != m_typeToStringMap.cend())
110 m_type = (*the_iterator_cst).first;
111 else
112 qFatalStream() << "Programming error. Tolerance type as string is not known.";
113
114 emit typeChangedSignal();
115 emit toleranceChangedSignal(
116 std::pair<double, Tolerance::Type>(m_nominal, m_type));
117 }
118
119 Tolerance::Type
120 Tolerance::getType() const
121 {
122 return m_type;
123 }
124
125 Tolerance::Type
126 Tolerance::getType(const QString &text) const
127 {
128 std::map<Type, QString>::const_iterator the_iterator_cst =
129 std::find_if(m_typeToStringMap.cbegin(),
130 m_typeToStringMap.cend(),
131 [&](const std::pair<Type, QString> &pair) {
132 if(pair.second == text)
133 return true;
134 return false;
135 });
136
137 if(the_iterator_cst != m_typeToStringMap.cend())
138 return (*the_iterator_cst).first;
139
140 return Tolerance::Type::NOT_SET;
141 }
142
143 QString
144 Tolerance::getTypeAsString() const
145 {
146 std::map<Type, QString>::const_iterator the_iterator_cst =
147 std::find_if(m_typeToStringMap.cbegin(),
148 m_typeToStringMap.cend(),
149 [&](const std::pair<Type, QString> &pair) {
150 if(pair.first == m_type)
151 return true;
152 return false;
153 });
154
155 if(the_iterator_cst != m_typeToStringMap.cend())
156 return (*the_iterator_cst).second;
157
158 return QString();
159 }
160
161 void
162 Tolerance::initialize(double nominal, Type type)
163 {
164 m_nominal = nominal;
165 m_type = type;
166
167 emit toleranceChangedSignal(
168 std::pair<double, Tolerance::Type>(m_nominal, m_type));
169 }
170
171
172 void
173 Tolerance::initialize(const Tolerance &tolerance)
174 {
175 initialize(tolerance.m_nominal, tolerance.m_type);
176 }
177
178
179 Tolerance *
180 Tolerance::clone(QObject *parent)
181 {
182 Tolerance *copy = new Tolerance(m_type, m_nominal, parent);
183 return copy;
184 }
185
186 double
187 Tolerance::calculateWidth(double reason) const
188 {
189 double width = 0;
190
191 if(m_type == Type::DALTON)
192 width = m_nominal;
193 else if(m_type == Type::RES)
194 width = reason / m_nominal;
195 else if(m_type == Type::PPM)
196 width = reason / 1000000 * m_nominal;
197 else
198 qFatalStream() << "Programming error. The Type is not valid.";
199
200 emit widthChangedSignal(width);
201
202 return width;
203 }
204
205 QString
206 Tolerance::toString() const
207 {
208 QString type_as_text = getTypeAsString();
209
210 return QString("%1 %2").arg(m_nominal).arg(type_as_text);
211 }
212
213
214 } // namespace libXpertMassCore
215 } // namespace MsXpS
216