1 /* massXpert - the true massist's program.
2    --------------------------------------
3    Copyright(C) 2006,2007 Filippo Rusconi
4 
5    http://www.massxpert.org/massXpert
6 
7    This file is part of the massXpert project.
8 
9    The massxpert project is the successor to the "GNU polyxmass"
10    project that is an official GNU project package(see
11    www.gnu.org). The massXpert project is not endorsed by the GNU
12    project, although it is released ---in its entirety--- under the
13    GNU General Public License. A huge part of the code in massXpert
14    is actually a C++ rewrite of code in GNU polyxmass. As such
15    massXpert was started at the Centre National de la Recherche
16    Scientifique(FRANCE), that granted me the formal authorization to
17    publish it under this Free Software License.
18 
19    This software is free software; you can redistribute it and/or
20    modify it under the terms of the GNU  General Public
21    License version 3, as published by the Free Software Foundation.
22 
23 
24    This software is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28 
29    You should have received a copy of the GNU General Public License
30    along with this software; if not, write to the
31 
32    Free Software Foundation, Inc.,
33 
34    51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
35 */
36 
37 #include "globals.hpp"
38 
39 
40 #include <QRegExp>
41 
42 int MXP_ATOM_DEC_PLACES = 10;
43 int MXP_OLIGOMER_DEC_PLACES = 5;
44 int MXP_POLYMER_DEC_PLACES = 3;
45 int MXP_PH_PKA_DEC_PLACES = 2;
46 
47 // How many times the whole gaussian/lorentzian curve should span
48 // around the centroid mz ratio. 4 means that the peak will span
49 // [ mzRatio - (2 * FWHM) --> mzRatio + (2 * FWHM) ]
50 
51 int MXP_FWHM_PEAK_SPAN_FACTOR = 4;
52 
53 QString &
GlobUnspacifyQString(QString & src)54 GlobUnspacifyQString(QString &src)
55 {
56   if (src.isEmpty())
57     return src;
58 
59   src.remove(QRegExp("\\s+"));
60 
61   return src;
62 }
63 
64 
65 QString
GlobBinaryRepresentation(int value)66 GlobBinaryRepresentation(int value)
67 {
68   QString string;
69   string = QString("%1")
70     .arg(value, 32, 2);
71 
72   return string;
73 }
74 
75 
76 QString
GlobElideText(const QString & text,int charsLeft,int charsRight,const QString & delimitor)77 GlobElideText(const QString &text, int charsLeft, int charsRight,
78               const QString &delimitor)
79 {
80   // We want to elide text. For example, imagine we have text = "that
81   // is beautiful stuff", with charsLeft 4 and charsLeft 4 and
82   // delimitor "...". Then the result would be "that...tuff"
83 
84   if(charsLeft < 1 || charsRight < 1)
85     return text;
86 
87   int size = text.size();
88 
89   // If the text string is already too short, no need to elide
90   // anything.
91   if((charsLeft + charsRight + delimitor.size()) >= size)
92     return text;
93 
94   QString result = text.left(charsLeft);
95   result.append(delimitor);
96   result.append(text.right(charsRight));
97 
98   return result;
99 }
100 
101