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 |
|
|
|
34 |
|
|
/////////////////////// Qt includes |
35 |
|
|
#include <QtDebug> |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
/////////////////////// Local includes |
39 |
|
|
#include "PropListHolder.hpp" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
namespace MsXpS |
43 |
|
|
{ |
44 |
|
|
|
45 |
|
|
namespace libXpertMass |
46 |
|
|
{ |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/*! |
50 |
|
|
\class MsXpS::libXpertMass::PropListHolder |
51 |
|
|
\inmodule libXpertMass |
52 |
|
|
\ingroup ThePropSystem |
53 |
|
|
\inheaderfile PropListHolder.hpp |
54 |
|
|
|
55 |
|
|
\brief The PropListHolder class is the base class for a number of |
56 |
|
|
classes that need storing Prop instances. |
57 |
|
|
|
58 |
|
|
\sa Modif, Monomer, Oligomer, PkaPhPi, |
59 |
|
|
*/ |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
/*! |
63 |
|
|
\variable int MsXpS::libXpertMass::PropListHolder::m_propList |
64 |
|
|
|
65 |
|
|
\brief The m_propList stores pointer to \l Prop instances. |
66 |
|
|
*/ |
67 |
|
|
|
68 |
|
|
/*! |
69 |
|
|
\brief Constructs a PropListHolder instance. |
70 |
|
|
*/ |
71 |
|
49240 |
PropListHolder::PropListHolder() |
72 |
|
|
{ |
73 |
|
49240 |
} |
74 |
|
|
|
75 |
|
|
/*! |
76 |
|
|
\brief Constructs a PropListHolder instance as a copy of \a other. |
77 |
|
|
|
78 |
|
|
The Prop instances in the \a other PropListHolder instance's member list of |
79 |
|
|
Prop instances are duplicated and stored in this instance using their own copy |
80 |
|
|
constructor. |
81 |
|
|
*/ |
82 |
|
2180 |
PropListHolder::PropListHolder(const PropListHolder &other) |
83 |
|
|
{ |
84 |
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2180 times.
|
2180 |
for(int iter = 0; iter < other.m_propList.size(); ++iter) |
85 |
|
|
{ |
86 |
|
✗ |
Prop *prop = other.m_propList.at(iter); |
87 |
|
✗ |
Q_ASSERT(prop); |
88 |
|
|
//qDebug() << "Prop name:" << prop->name(); |
89 |
|
|
|
90 |
|
|
// Each Prop-derived class produces a derived Prop class. |
91 |
|
✗ |
m_propList.append(prop->cloneOut()); |
92 |
|
|
} |
93 |
|
2180 |
} |
94 |
|
|
|
95 |
|
|
/*! |
96 |
|
|
\brief Destructs this PropListHolder instance. |
97 |
|
|
*/ |
98 |
|
65968 |
PropListHolder::~PropListHolder() |
99 |
|
|
{ |
100 |
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32984 times.
|
131936 |
while(!m_propList.isEmpty()) |
101 |
|
✗ |
delete(m_propList.takeFirst()); |
102 |
|
65968 |
} |
103 |
|
|
|
104 |
|
|
/*! |
105 |
|
|
\brief Assigns \a other to this PropListHolder instance. |
106 |
|
|
|
107 |
|
|
The Prop instances in the \a other PropListHolder instance's member list of |
108 |
|
|
Prop instances are duplicated and stored in this instance using their own copy |
109 |
|
|
constructor. |
110 |
|
|
|
111 |
|
|
Returns a reference to this PropListHolder instance. |
112 |
|
|
*/ |
113 |
|
|
PropListHolder & |
114 |
|
30512 |
PropListHolder::operator=(const PropListHolder &other) |
115 |
|
|
{ |
116 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30512 times.
|
30512 |
if(&other == this) |
117 |
|
✗ |
return *this; |
118 |
|
|
|
119 |
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30512 times.
|
30512 |
for(int iter = 0; iter < other.m_propList.size(); ++iter) |
120 |
|
|
{ |
121 |
|
✗ |
Prop *prop = other.m_propList.at(iter); |
122 |
|
✗ |
Q_ASSERT(prop); |
123 |
|
|
|
124 |
|
✗ |
m_propList.append(prop->cloneOut()); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
30512 |
return *this; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/*! |
131 |
|
|
\brief Returns a const reference to the member list of Prop instances. |
132 |
|
|
*/ |
133 |
|
|
const QList<Prop *> & |
134 |
|
✗ |
PropListHolder::propList() const |
135 |
|
|
{ |
136 |
|
✗ |
return m_propList; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
/*! |
140 |
|
|
\brief Returns a non-const reference to the member list of Prop instances. |
141 |
|
|
*/ |
142 |
|
|
QList<Prop *> & |
143 |
|
✗ |
PropListHolder::propList() |
144 |
|
|
{ |
145 |
|
✗ |
return m_propList; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
/*! |
149 |
|
|
\brief Searches in the member list of Prop instances a Prop having \a name. |
150 |
|
|
|
151 |
|
|
If the Prop instance was found and \a index is non-nullptr, its index in the |
152 |
|
|
list is set to this parameter. |
153 |
|
|
|
154 |
|
|
Returns the found Prop instance. |
155 |
|
|
*/ |
156 |
|
|
Prop * |
157 |
|
✗ |
PropListHolder::prop(const QString &name, int *index) |
158 |
|
|
{ |
159 |
|
✗ |
for(int iter = 0; iter < m_propList.size(); ++iter) |
160 |
|
|
{ |
161 |
|
✗ |
Prop *localProp = m_propList.at(iter); |
162 |
|
✗ |
Q_ASSERT(localProp); |
163 |
|
|
|
164 |
|
✗ |
if(localProp->name() == name) |
165 |
|
|
{ |
166 |
|
✗ |
if(index) |
167 |
|
✗ |
*index = iter; |
168 |
|
|
|
169 |
|
✗ |
return localProp; |
170 |
|
|
} |
171 |
|
|
} |
172 |
|
|
|
173 |
|
✗ |
return 0; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
|
177 |
|
|
/*! |
178 |
|
|
\brief Searches in the member list of Prop instances a Prop having \a name. |
179 |
|
|
|
180 |
|
|
If the Prop instance was found and \a prop is non-nullptr, its pointer is set |
181 |
|
|
to this parameter. |
182 |
|
|
|
183 |
|
|
Returns the index of the found Prop instance. |
184 |
|
|
*/ |
185 |
|
|
int |
186 |
|
✗ |
PropListHolder::propIndex(const QString &name, Prop **prop_pp) |
187 |
|
|
{ |
188 |
|
✗ |
for(int iter = 0; iter < m_propList.size(); ++iter) |
189 |
|
|
{ |
190 |
|
✗ |
Prop *localProp = m_propList.at(iter); |
191 |
|
✗ |
Q_ASSERT(localProp); |
192 |
|
|
|
193 |
|
✗ |
if(localProp->name() == name) |
194 |
|
|
{ |
195 |
|
✗ |
if(prop_pp) |
196 |
|
✗ |
*prop_pp = localProp; |
197 |
|
|
|
198 |
|
✗ |
return iter; |
199 |
|
|
} |
200 |
|
|
} |
201 |
|
|
|
202 |
|
✗ |
return -1; |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
/*! |
206 |
|
|
\brief Adds \a prop to the member list of Prop instances. |
207 |
|
|
|
208 |
|
|
Returns true. |
209 |
|
|
*/ |
210 |
|
|
bool |
211 |
|
✗ |
PropListHolder::appendProp(Prop *prop) |
212 |
|
|
{ |
213 |
|
✗ |
m_propList.append(prop); |
214 |
|
|
|
215 |
|
✗ |
return true; |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
/*! |
220 |
|
|
\brief Removes \a prop from the member list of Prop instances. |
221 |
|
|
|
222 |
|
|
Returns true if \a prop was removed, false otherwise. |
223 |
|
|
*/ |
224 |
|
|
bool |
225 |
|
✗ |
PropListHolder::removeProp(Prop *prop) |
226 |
|
|
{ |
227 |
|
✗ |
if(m_propList.removeAll(prop)) |
228 |
|
✗ |
return true; |
229 |
|
|
|
230 |
|
✗ |
return false; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
|
234 |
|
|
/*! |
235 |
|
|
\brief Removes the Prop instance having \a name from the member list of Prop |
236 |
|
|
instances. |
237 |
|
|
|
238 |
|
|
If more than one Prop instance by the \a name are in the list, only the first |
239 |
|
|
encountered Prop instance is removed. |
240 |
|
|
|
241 |
|
|
Returns true if a Prop instance was removed, false otherwise. |
242 |
|
|
*/ |
243 |
|
|
bool |
244 |
|
✗ |
PropListHolder::removeProp(const QString &name) |
245 |
|
|
{ |
246 |
|
✗ |
for(int iter = 0; iter < m_propList.size(); ++iter) |
247 |
|
|
{ |
248 |
|
✗ |
if(m_propList.at(iter)->name() == name) |
249 |
|
|
{ |
250 |
|
✗ |
m_propList.removeAt(iter); |
251 |
|
|
|
252 |
|
✗ |
return true; |
253 |
|
|
} |
254 |
|
|
} |
255 |
|
|
|
256 |
|
✗ |
return false; |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
} // namespace libXpertMass |
260 |
|
|
|
261 |
|
|
} // namespace MsXpS |
262 |
|
|
|