File: polymerModificationDlg.cpp

package info (click to toggle)
massxpert 2.3.6-1squeeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 20,736 kB
  • ctags: 3,541
  • sloc: cpp: 44,108; xml: 7,381; sh: 604; makefile: 108; ansic: 7
file content (300 lines) | stat: -rw-r--r-- 7,601 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/* massXpert - the true massist's program.
   --------------------------------------
   Copyright(C) 2006,2007 Filippo Rusconi

   http://www.massxpert.org/massXpert

   This file is part of the massXpert project.

   The massxpert project is the successor to the "GNU polyxmass"
   project that is an official GNU project package(see
   www.gnu.org). The massXpert project is not endorsed by the GNU
   project, although it is released ---in its entirety--- under the
   GNU General Public License. A huge part of the code in massXpert
   is actually a C++ rewrite of code in GNU polyxmass. As such
   massXpert was started at the Centre National de la Recherche
   Scientifique(FRANCE), that granted me the formal authorization to
   publish it under this Free Software License.

   This software is free software; you can redistribute it and/or
   modify it under the terms of the GNU  General Public
   License version 3, as published by the Free Software Foundation.
   

   This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this software; if not, write to the

   Free Software Foundation, Inc.,

   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/


/////////////////////// Qt includes
#include <QMessageBox>


/////////////////////// Local includes
#include "application.hpp"
#include "polymerModificationDlg.hpp"


namespace massXpert
{

  PolymerModificationDlg::PolymerModificationDlg(QWidget *parent, 
						  PolymerEnd end)
    : QDialog(parent)
  {

    m_ui.setupUi(this);
    Q_ASSERT(parent);
  
    mp_editorWnd = static_cast<SequenceEditorWnd *>(parent);

    populateModificationList();
    
    if (mp_editorWnd)
      updateModificationLineEdits();
    
    
    if (end & MXT_END_LEFT)
      m_ui.leftEndCheckBox->setChecked(true);
    
    if (end & MXT_END_RIGHT)
      m_ui.rightEndCheckBox->setChecked(true);
    
  
    QSettings settings 
     (static_cast<Application *>(qApp)->configSettingsFilePath(), 
       QSettings::IniFormat);
  
    settings.beginGroup("polymer_modification_dlg");

    restoreGeometry(settings.value("geometry").toByteArray());
  
    settings.endGroup();

    connect(this,
	     SIGNAL(rejected()),
	     this,
	     SLOT(close()));

    connect(m_ui.modifyPushButton,
	     SIGNAL(clicked()),
	     this,
	     SLOT(modify()));

    connect(m_ui.unmodifyPushButton,
	     SIGNAL(clicked()),
	     this,
	     SLOT(unmodify()));
  }


  PolymerModificationDlg::~PolymerModificationDlg()
  {
  }


  void 
  PolymerModificationDlg::closeEvent(QCloseEvent *event)
  {
    if (event)
      printf("%s", "");
  
    QSettings settings 
     (static_cast<Application *>(qApp)->configSettingsFilePath(), 
       QSettings::IniFormat);
  
    settings.beginGroup("polymer_modification_dlg");

    settings.setValue("geometry", saveGeometry());

    settings.endGroup();
  }



  void
  PolymerModificationDlg::updateModificationLineEdits()
  {
    Polymer *polymer = mp_editorWnd->polymer();

    m_ui.leftEndLineEdit->setText(QString("%1 = %2")
				   .arg(polymer->leftEndModif().formula())
				   .arg(polymer->leftEndModif().name()));

    m_ui.rightEndLineEdit->setText(QString("%1 = %2")
				    .arg(polymer->rightEndModif().formula())
				    .arg(polymer->rightEndModif().name()));
  }


  bool
  PolymerModificationDlg::populateModificationList()
  {
    PolChemDef *polChemDef = mp_editorWnd->polChemDef();
    Q_ASSERT(polChemDef);
  
    for (int iter = 0; iter < polChemDef->modifList().size(); ++iter)
      {
	Modif *modif = polChemDef->modifList().at(iter);
	Q_ASSERT(modif);
      
	m_ui.modifListWidget->addItem(modif->name());
      }
  
    return true;
  }


  bool 
  PolymerModificationDlg::parseModifDefinition(Modif *modif)
  {
    Q_ASSERT(modif);
  
    QString text = m_ui.modifNameLineEdit->text();
  
    modif->setName(text);
  
    text = m_ui.modifFormulaLineEdit->text();
  
    modif->setFormula(text);

    // Attention, we have to compute the masses of the modif !

    if (!modif->calculateMasses())
      return false;
  
    // We do not actually care of the targets of the modification. This
    // member datum should be '*' by default anyway.

    //  modif->setTargets("*");
  
    if (!modif->validate())
      return false;

    return true;
  }


  void
  PolymerModificationDlg::modify()
  {
    Polymer *polymer = mp_editorWnd->polymer();

    // There are two ways to perform a modification: either select one
    // modification from the list of available modifications as defined
    // in the polymer chemistry definition, or perform a quick and dirty
    // modification definition in the dialog.

    Modif modif(polymer->polChemDef(), "NOT_SET");
  
    if (m_ui.defineModifGroupBox->isChecked())
      {
	// The user wants to use a self-defined modification.
      
	if(!parseModifDefinition(&modif))
	  {
	    return;
	  }
      }
    else
      {
	// The user should have selected one item from the list of
	// available modifications. Let's get to the modification in
	// question.

	QList<QListWidgetItem *> selectedList = 
	  m_ui.modifListWidget->selectedItems();
  
	if(selectedList.size() != 1)
	  return;
  
	QString text = selectedList.at(0)->text();
	Q_ASSERT(!text.isEmpty());
	//       qDebug() << __FILE__ << __LINE__
	// 		<< "Selected modif:" << text;
      
	// Change modif so that it has its name, and we can ask the
	// polymer chemistry definition to fully qualify it by its name.

	modif.setName(text);
      
	// Find the proper modification in the list of modifs in the
	// polymer chemistry definition and update all the data from the
	// reference one in the polymer chemistry definition.
	if(Modif::isNameInList(text, polymer->polChemDef()->modifList(),
				 &modif) == -1)
	  {
	    QMessageBox::warning(this,
				  tr("massXpert - Polymer Modification"),
				  tr("Failed to find formula(%1) in list.")
				  .arg(modif.name()),
				  QMessageBox::Ok);

	    return;
	  }
      }
  
    // At this point, whatever the way the modification was created, we
    // have it full and working. Use it to perform the modification
    // according to the user's requests.

    if (m_ui.leftEndCheckBox->checkState() == Qt::Checked)
      {
	polymer->setLeftEndModif(modif);
	mp_editorWnd->setWindowModified(true);
      }
  
    if (m_ui.rightEndCheckBox->checkState() == Qt::Checked)
      {
	polymer->setRightEndModif(modif);
	mp_editorWnd->setWindowModified(true);
      }
  
    updateModificationLineEdits();
  
    mp_editorWnd->updatePolymerEndsModifs();

    mp_editorWnd->updateWholeSequenceMasses(true);
    mp_editorWnd->updateSelectedSequenceMasses(true);
  
    return;
  }


  void
  PolymerModificationDlg::unmodify()
  {
    Polymer *polymer = mp_editorWnd->polymer();

    if (m_ui.leftEndCheckBox->checkState() == Qt::Checked)
      {
	polymer->setLeftEndModif();
	mp_editorWnd->setWindowModified(true);
      }
  
    if (m_ui.rightEndCheckBox->checkState() == Qt::Checked)
      {
	polymer->setRightEndModif();
	mp_editorWnd->setWindowModified(true);
      }

    updateModificationLineEdits();

    // Also update the labels of the buttons in the sequence editor
    // window.
    mp_editorWnd->updatePolymerEndsModifs();

    mp_editorWnd->updateWholeSequenceMasses(true);
    mp_editorWnd->updateSelectedSequenceMasses(true);
  }

} // namespace massXpert