~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/VISUAL/APPLICATIONS/TOPPViewBase.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
// --------------------------------------------------------------------------
6
 
//                   OpenMS Mass Spectrometry Framework
7
 
// --------------------------------------------------------------------------
8
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
 
//
10
 
//  This library is free software; you can redistribute it and/or
11
 
//  modify it under the terms of the GNU Lesser General Public
12
 
//  License as published by the Free Software Foundation; either
13
 
//  version 2.1 of the License, or (at your option) any later version.
14
 
//
15
 
//  This library is distributed in the hope that it will be useful,
16
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
 
//  Lesser General Public License for more details.
19
 
//
20
 
//  You should have received a copy of the GNU Lesser General Public
21
 
//  License along with this library; if not, write to the Free Software
22
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 
//
24
 
// --------------------------------------------------------------------------
25
 
// $Maintainer: Timo Sachsenberg$
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
//
 
30
// --------------------------------------------------------------------------
 
31
// $Maintainer: Timo Sachsenberg $
26
32
// $Authors: Timo Sachsenberg, Marc Sturm $
27
33
// --------------------------------------------------------------------------
28
34
 
44
50
#include <OpenMS/FORMAT/FileTypes.h>
45
51
#include <OpenMS/FORMAT/FeatureXMLFile.h>
46
52
#include <OpenMS/FORMAT/ConsensusXMLFile.h>
 
53
#include <OpenMS/FORMAT/ParamXMLFile.h>
47
54
#include <OpenMS/KERNEL/MSExperiment.h>
48
55
#include <OpenMS/METADATA/Precursor.h>
49
56
#include <OpenMS/SYSTEM/FileWatcher.h>
74
81
#include <OpenMS/VISUAL/EnhancedTabBar.h>
75
82
#include <OpenMS/VISUAL/EnhancedWorkspace.h>
76
83
 
77
 
// OpenMS TOPPAS
78
 
#include <OpenMS/VISUAL/APPLICATIONS/TOPPASBase.h>
79
 
#include <OpenMS/VISUAL/TOPPASScene.h>
80
 
#include <OpenMS/VISUAL/TOPPASMergerVertex.h>
81
 
#include <OpenMS/VISUAL/TOPPASInputFileListVertex.h>
82
 
#include <OpenMS/VISUAL/TOPPASOutputFileListVertex.h>
83
 
#include <OpenMS/VISUAL/TOPPASToolVertex.h>
84
 
 
85
84
 
86
85
//Qt
87
86
#include <QtCore/QDate>
111
110
#include <QtGui/QTreeWidget>
112
111
#include <QtGui/QTreeWidgetItem>
113
112
#include <QtGui/QWhatsThis>
 
113
#include <QTextCodec>
114
114
 
115
115
#include <boost/math/special_functions/fpclassify.hpp>
116
116
 
122
122
namespace OpenMS
123
123
{
124
124
  using namespace Internal;
125
 
        using namespace Math;
126
 
 
127
 
qreal TOPPViewBase::toppas_z_value_ = 42.0;
128
 
Int TOPPViewBase::toppas_node_offset_ = 0;
129
 
 
130
 
TOPPViewBase::TOPPViewBase(QWidget* parent):
131
 
        QMainWindow(parent),
132
 
        DefaultParamHandler("TOPPViewBase"),
133
 
        watcher_(0),
134
 
        watcher_msgbox_(false),
135
 
        toppas_clipboard_scene_(0)
136
 
        {
137
 
          setWindowTitle("TOPPView");
138
 
          setWindowIcon(QIcon(":/TOPPView.png"));
139
 
 
140
 
          //prevents errors caused by too small width,height values
141
 
          setMinimumSize(400,400);
142
 
 
143
 
          //enable drag-and-drop
144
 
          setAcceptDrops(true);
145
 
 
146
 
          // get geometry of first screen
147
 
          QRect screen_geometry = QApplication::desktop()->screenGeometry();
148
 
          // center main window
149
 
          setGeometry(
150
 
            (int)(0.1 * screen_geometry.width()),
151
 
            (int)(0.1 * screen_geometry.height()),
152
 
            (int)(0.8 * screen_geometry.width()),
153
 
            (int)(0.8 * screen_geometry.height())
154
 
            );
155
 
 
156
 
          //set & create temporary path -- make sure its a new subdirectory, as TOPPASScene will delete it when its done
157
 
          toppas_tmp_path_ =  (File::getTempDirectory() + String(QDir::separator()) + File::getUniqueName()).toQString();
158
 
          QDir qd;
159
 
          qd.mkpath(toppas_tmp_path_);
160
 
 
161
 
          // create dummy widget (to be able to have a layout), Tab bar and workspace
162
 
          QWidget* dummy = new QWidget(this);
163
 
          setCentralWidget(dummy);
164
 
          QVBoxLayout* box_layout = new QVBoxLayout(dummy);
165
 
 
166
 
          // create empty tab bar and workspace which will hold the main visualization widgets (e.g. spectra widgets...)
167
 
          tab_bar_ = new EnhancedTabBar(dummy);
168
 
          tab_bar_->setWhatsThis("Tab bar<BR><BR>Close tabs through the context menu or by double-clicking them.<BR>The tab bar accepts drag-and-drop from the layer bar.");
169
 
          tab_bar_->addTab("dummy",4710);
170
 
          tab_bar_->setMinimumSize(tab_bar_->sizeHint());
171
 
          tab_bar_->removeId(4710);
172
 
 
173
 
          connect(tab_bar_,SIGNAL(currentIdChanged(int)),this,SLOT(enhancedWorkspaceWindowChanged(int)));
174
 
          connect(tab_bar_,SIGNAL(aboutToCloseId(int)),this,SLOT(closeByTab(int)));
175
 
 
176
 
          //connect signals ans slots for drag-and-drop
177
 
          connect(tab_bar_,SIGNAL(dropOnWidget(const QMimeData*,QWidget*)),this,SLOT(copyLayer(const QMimeData*,QWidget*)));
178
 
          connect(tab_bar_,SIGNAL(dropOnTab(const QMimeData*,QWidget*,int)),this,SLOT(copyLayer(const QMimeData*,QWidget*,int)));
179
 
          box_layout->addWidget(tab_bar_);
180
 
 
181
 
          ws_= new EnhancedWorkspace(dummy);
182
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateToolBar()));
183
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateTabBar(QWidget*)));
184
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateLayerBar()));
185
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateViewBar()));
186
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateFilterBar()));
187
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateMenu()));
188
 
          connect(ws_,SIGNAL(windowActivated(QWidget*)),this,SLOT(updateCurrentPath()));
189
 
          connect(ws_,SIGNAL(dropReceived(const QMimeData*,QWidget*,int)),this,SLOT(copyLayer(const QMimeData*,QWidget*,int)));
190
 
 
191
 
          box_layout->addWidget(ws_);
192
 
 
193
 
          //################## MENUS #################
194
 
          // File menu          
195
 
          QMenu* file = new QMenu("&File",this);
196
 
          menuBar()->addMenu(file);
197
 
          file->addAction("&Open file",this,SLOT(openFileDialog()), Qt::CTRL+Qt::Key_O);
198
 
          file->addAction("Open from &database",this,SLOT(openDatabaseDialog()), Qt::CTRL+Qt::Key_D);
199
 
          file->addAction("Open &example file",this,SLOT(openExampleDialog()));
200
 
          file->addAction("&Close",this,SLOT(closeFile()), Qt::CTRL+Qt::Key_W);
201
 
          file->addSeparator();
202
 
 
203
 
          // File menu: TOPPAS section
204
 
          file->addAction("&New TOPPAS pipeline",this,SLOT(newPipeline()), Qt::CTRL+Qt::Key_N);
205
 
          file->addAction("&Include TOPPAS pipeline",this,SLOT(includePipeline()), Qt::CTRL+Qt::Key_I);
206
 
          file->addAction("&Save TOPPAS pipeline",this,SLOT(savePipeline()), Qt::CTRL+Qt::Key_S);
207
 
          file->addAction("Save TOPPAS pipeline &As",this,SLOT(saveCurrentPipelineAs()), Qt::CTRL+Qt::SHIFT+Qt::Key_S);
208
 
          file->addAction("&Load TOPPAS resource file",this,SLOT(loadPipelineResourceFile()));
209
 
          file->addAction("Save TOPPAS &resource file",this,SLOT(savePipelineResourceFile()));
210
 
          file->addAction("Refresh TOPPAS &parameters",this,SLOT(refreshPipelineParameters()), Qt::CTRL+Qt::SHIFT+Qt::Key_P);
211
 
          file->addSeparator();
212
 
 
213
 
          //Meta data
214
 
          file->addAction("&Show meta data (file)",this,SLOT(metadataFileDialog()));
215
 
          file->addAction("&Show meta data (database)",this,SLOT(metadataDatabaseDialog()));
216
 
          file->addSeparator();
217
 
 
218
 
          //Recent files
219
 
          QMenu* recent_menu = new QMenu("&Recent files", this);
220
 
          recent_actions_.resize(20);
221
 
          for (Size i = 0; i<20; ++i)
222
 
          {
223
 
            recent_actions_[i] = recent_menu->addAction("",this,SLOT(openRecentFile()));
224
 
            recent_actions_[i]->setVisible(false);
225
 
          }
226
 
          file->addMenu(recent_menu);
227
 
 
228
 
          file->addSeparator();
229
 
          file->addAction("&Preferences",this, SLOT(preferencesDialog()));
230
 
          file->addAction("&Quit",qApp,SLOT(quit()));
231
 
 
232
 
          //Tools menu
233
 
          QMenu* tools = new QMenu("&Tools",this);
234
 
          menuBar()->addMenu(tools);
235
 
          tools->addAction("&Go to",this,SLOT(showGoToDialog()), Qt::CTRL+Qt::Key_G);
236
 
          tools->addAction("&Edit meta data",this,SLOT(editMetadata()), Qt::CTRL+Qt::Key_M);
237
 
          tools->addAction("&Statistics",this,SLOT(layerStatistics()));
238
 
          tools->addSeparator();
239
 
 
240
 
          tools->addAction("Apply TOPP tool (whole layer)", this, SLOT(showTOPPDialog()), Qt::CTRL+Qt::Key_T)->setData(false);
241
 
          tools->addAction("Apply TOPP tool (visible layer data)", this, SLOT(showTOPPDialog()), Qt::CTRL+Qt::SHIFT+Qt::Key_T)->setData(true);
242
 
          tools->addAction("Rerun TOPP tool", this, SLOT(rerunTOPPTool()),Qt::Key_F4);
243
 
          tools->addSeparator();
244
 
          tools->addAction("&Annotate with identification", this, SLOT(annotateWithID()), Qt::CTRL+Qt::Key_I);
245
 
          tools->addAction("Align spectra", this, SLOT(showSpectrumAlignmentDialog()));
246
 
          tools->addAction("Generate theoretical spectrum", this, SLOT(showSpectrumGenerationDialog()));
247
 
 
248
 
          // TOPPAS menu
249
 
          // pipeline menu (TOPPAS pipeline)
250
 
          QMenu* toppas_pipeline = new QMenu("TOPPAS &Pipeline", this);
251
 
          toppas_pipeline->addAction("&Run (F5)",this,SLOT(runPipeline()));
252
 
          toppas_pipeline->addAction("&Abort",this,SLOT(abortPipeline()));
253
 
          menuBar()->addMenu(toppas_pipeline);
254
 
 
255
 
          //Layer menu
256
 
          QMenu* layer = new QMenu("&Layer",this);
257
 
          menuBar()->addMenu(layer);
258
 
          layer->addAction("Save all data", this, SLOT(saveLayerAll()), Qt::CTRL+Qt::Key_S);
259
 
          layer->addAction("Save visible data", this, SLOT(saveLayerVisible()), Qt::CTRL+Qt::SHIFT+Qt::Key_S);
260
 
          layer->addSeparator();
261
 
          layer->addAction("Show/hide grid lines", this, SLOT(toggleGridLines()), Qt::CTRL+Qt::Key_R);
262
 
          layer->addAction("Show/hide axis legends", this, SLOT(toggleAxisLegends()), Qt::CTRL+Qt::Key_L);
263
 
          layer->addSeparator();
264
 
          layer->addAction("Preferences", this, SLOT(showPreferences()));
265
 
 
266
 
          //Windows menu
267
 
          QMenu* windows = new QMenu("&Windows", this);
268
 
          menuBar()->addMenu(windows);
269
 
          windows->addAction("&Cascade",this->ws_,SLOT(cascade()));
270
 
          windows->addAction("&Tile automatic",this->ws_,SLOT(tile()));
271
 
          windows->addAction(QIcon(":/tile_horizontal.png"),"Tile &vertical",this,SLOT(tileHorizontal()));
272
 
          windows->addAction(QIcon(":/tile_vertical.png"),"Tile &horizontal",this,SLOT(tileVertical()));
273
 
          windows->addSeparator();
274
 
 
275
 
          //Help menu
276
 
          QMenu* help = new QMenu("&Help", this);
277
 
          menuBar()->addMenu(help);
278
 
          help->addAction(QWhatsThis::createAction(help));
279
 
          help->addSeparator();
280
 
          QAction* action = help->addAction("OpenMS website",this,SLOT(showURL()));
281
 
          action->setData("http://www.OpenMS.de");
282
 
          action = help->addAction("Tutorials and documentation",this,SLOT(showURL()), Qt::Key_F1);
283
 
          action->setData(String(File::getOpenMSDocPath() + "/html/index.html").toQString());
284
 
 
285
 
          help->addSeparator();
286
 
          help->addAction("&About",this,SLOT(showAboutDialog()));
287
 
 
288
 
          //create status bar
289
 
          message_label_ = new QLabel(statusBar());
290
 
          statusBar()->addWidget(message_label_,1);
291
 
 
292
 
          rt_label_ = new QLabel("RT: 12345678", statusBar());
293
 
          rt_label_->setMinimumSize(rt_label_->sizeHint());
294
 
          rt_label_->setText("");
295
 
          statusBar()->addPermanentWidget(rt_label_,0);
296
 
          mz_label_ = new QLabel("m/z: 123456780912", statusBar());
297
 
          mz_label_->setMinimumSize(mz_label_->sizeHint());
298
 
          mz_label_->setText("");
299
 
          statusBar()->addPermanentWidget(mz_label_,0);
300
 
 
301
 
          //################## TOOLBARS #################
302
 
          //create toolbars and connect signals
303
 
          QToolButton* b;
304
 
 
305
 
          //--Basic tool bar for all views--
306
 
          tool_bar_ = addToolBar("Basic tool bar");
307
 
 
308
 
          //intensity modes
309
 
          intensity_button_group_ = new QButtonGroup(tool_bar_);
310
 
          intensity_button_group_->setExclusive(true);
311
 
 
312
 
          b = new QToolButton(tool_bar_);
313
 
          b->setIcon(QIcon(":/lin.png"));
314
 
          b->setToolTip("Intensity: Normal");
315
 
          b->setShortcut(Qt::Key_N);
316
 
          b->setCheckable(true);
317
 
          b->setWhatsThis("Intensity: Normal<BR><BR>Intensity is displayed unmodified.<BR>(Hotkey: N)");
318
 
          intensity_button_group_->addButton(b,SpectrumCanvas::IM_NONE);
319
 
          tool_bar_->addWidget(b);
320
 
 
321
 
          b = new QToolButton(tool_bar_);
322
 
          b->setIcon(QIcon(":/percentage.png"));
323
 
          b->setToolTip("Intensity: Percentage");
324
 
          b->setShortcut(Qt::Key_P);
325
 
          b->setCheckable(true);
326
 
          b->setWhatsThis("Intensity: Percentage<BR><BR>Intensity is displayed as a percentage of the layer"
327
 
                          " maximum intensity. If only one layer is displayed this mode behaves like the"
328
 
                          " normal mode. If more than one layer is displayed intensities are aligned."
329
 
                          "<BR>(Hotkey: P)");
330
 
          intensity_button_group_->addButton(b,SpectrumCanvas::IM_PERCENTAGE);
331
 
          tool_bar_->addWidget(b);
332
 
 
333
 
          b = new QToolButton(tool_bar_);
334
 
          b->setIcon(QIcon(":/snap.png"));
335
 
          b->setToolTip("Intensity: Snap to maximum displayed intensity");
336
 
          b->setShortcut(Qt::Key_S);
337
 
          b->setCheckable(true);
338
 
          b->setWhatsThis("Intensity: Snap to maximum displayed intensity<BR><BR> In this mode the"
339
 
                          " color gradient is adapted to the maximum currently displayed intensity."
340
 
                          "<BR>(Hotkey: S)");
341
 
          intensity_button_group_->addButton(b,SpectrumCanvas::IM_SNAP);
342
 
          tool_bar_->addWidget(b);
343
 
 
344
 
          b = new QToolButton(tool_bar_);
345
 
          b->setIcon(QIcon(":/log.png"));
346
 
          b->setToolTip("Intensity: Use log scaling for colors");
347
 
          b->setCheckable(true);
348
 
          b->setWhatsThis("Intensity: Logarithmic scaling of intensities for color calculation");
349
 
          intensity_button_group_->addButton(b,SpectrumCanvas::IM_LOG);
350
 
          tool_bar_->addWidget(b);
351
 
 
352
 
          connect(intensity_button_group_,SIGNAL(buttonClicked(int)),this,SLOT(setIntensityMode(int)));
353
 
          tool_bar_->addSeparator();
354
 
 
355
 
          //common buttons
356
 
          QAction* reset_zoom_button = tool_bar_->addAction(QIcon(":/reset_zoom.png"), "Reset Zoom", this, SLOT(resetZoom()));
357
 
          reset_zoom_button->setWhatsThis("Reset zoom: Zooms out as far as possible and resets the zoom history.<BR>(Hotkey: Backspace)");
358
 
 
359
 
          tool_bar_->show();
360
 
 
361
 
          //--1D toolbar--
362
 
          tool_bar_1d_ = addToolBar("1D tool bar");
363
 
 
364
 
          //draw modes 1D
365
 
          draw_group_1d_ = new QButtonGroup(tool_bar_1d_);
366
 
          draw_group_1d_->setExclusive(true);
367
 
 
368
 
          b = new QToolButton(tool_bar_1d_);
369
 
          b->setIcon(QIcon(":/peaks.png"));
370
 
          b->setToolTip("Peak mode");
371
 
          b->setShortcut(Qt::Key_I);
372
 
          b->setCheckable(true);
373
 
          b->setWhatsThis("1D Draw mode: Peaks<BR><BR>Peaks are diplayed as sticks.");
374
 
          draw_group_1d_->addButton(b,Spectrum1DCanvas::DM_PEAKS);
375
 
          tool_bar_1d_->addWidget(b);
376
 
 
377
 
          b = new QToolButton(tool_bar_1d_);
378
 
          b->setIcon(QIcon(":/lines.png"));
379
 
          b->setToolTip("Raw data mode");
380
 
          b->setShortcut(Qt::Key_R);
381
 
          b->setCheckable(true);
382
 
          b->setWhatsThis("1D Draw mode: Raw data<BR><BR>Peaks are diplayed as a continous line.");
383
 
          draw_group_1d_->addButton(b,Spectrum1DCanvas::DM_CONNECTEDLINES);
384
 
          tool_bar_1d_->addWidget(b);
385
 
 
386
 
          connect(draw_group_1d_,SIGNAL(buttonClicked(int)),this,SLOT(setDrawMode1D(int)));
387
 
          tool_bar_->addSeparator();
388
 
 
389
 
          //--2D peak toolbar--
390
 
          tool_bar_2d_peak_ = addToolBar("2D peak tool bar");
391
 
 
392
 
          dm_precursors_2d_ = tool_bar_2d_peak_->addAction(QIcon(":/precursors.png"),"Show fragment scan precursors");
393
 
          dm_precursors_2d_->setCheckable(true);
394
 
          dm_precursors_2d_->setWhatsThis("2D peak draw mode: Precursors<BR><BR>fragment scan precursor peaks are marked.<BR>(Hotkey: 1)");
395
 
          dm_precursors_2d_->setShortcut(Qt::Key_1);
396
 
 
397
 
          connect(dm_precursors_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
398
 
 
399
 
          projections_2d_ = tool_bar_2d_peak_->addAction(QIcon(":/projections.png"), "Show Projections" ,this, SLOT(toggleProjections()));
400
 
          projections_2d_->setWhatsThis("Projections: Shows projections of peak data along RT and MZ axis.<BR>(Hotkey: 2)");
401
 
          projections_2d_->setShortcut(Qt::Key_2);
402
 
 
403
 
          //--2D feature toolbar--
404
 
          tool_bar_2d_feat_ = addToolBar("2D feature tool bar");
405
 
 
406
 
          dm_hull_2d_ = tool_bar_2d_feat_->addAction(QIcon(":/convexhull.png"),"Show feature convex hull");
407
 
          dm_hull_2d_->setCheckable(true);
408
 
          dm_hull_2d_->setWhatsThis("2D feature draw mode: Convex hull<BR><BR>The convex hull of the feature is displayed.<BR>(Hotkey: 5)");
409
 
          dm_hull_2d_->setShortcut(Qt::Key_5);
410
 
          connect(dm_hull_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
411
 
 
412
 
          dm_hulls_2d_ = tool_bar_2d_feat_->addAction(QIcon(":/convexhulls.png"),"Show feature convex hulls");
413
 
          dm_hulls_2d_->setCheckable(true);
414
 
          dm_hulls_2d_->setWhatsThis("2D feature draw mode: Convex hulls<BR><BR>The convex hulls of the feature are displayed: One for each mass trace.<BR>(Hotkey: 6)");
415
 
          dm_hulls_2d_->setShortcut(Qt::Key_6);
416
 
          connect(dm_hulls_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
417
 
 
418
 
          // feature labels:
419
 
          dm_label_2d_ = new QToolButton(tool_bar_2d_feat_);
420
 
          dm_label_2d_->setPopupMode(QToolButton::MenuButtonPopup);
421
 
          QAction* action2 = new QAction(QIcon(":/labels.png"), "Show feature label", dm_label_2d_);
422
 
          action2->setCheckable(true);
423
 
          action2->setWhatsThis("2D feature draw mode: Labels<BR><BR>Display different kinds of annotation next to features.<BR>(Hotkey: 7)");
424
 
          action2->setShortcut(Qt::Key_7);
425
 
          dm_label_2d_->setDefaultAction(action2);
426
 
          tool_bar_2d_feat_->addWidget(dm_label_2d_);
427
 
          connect(dm_label_2d_, SIGNAL(triggered(QAction*)), this, SLOT(changeLabel(QAction*)));
428
 
          //button menu
429
 
          group_label_2d_ = new QActionGroup(dm_label_2d_);
430
 
          QMenu* menu = new QMenu(dm_label_2d_);
431
 
          for (Size i = 0; i < LayerData::SIZE_OF_LABEL_TYPE; ++i)
432
 
          {
433
 
            QAction* temp = group_label_2d_->addAction(
434
 
                QString(LayerData::NamesOfLabelType[i].c_str()));
435
 
            temp->setCheckable(true);
436
 
            if (i == 0) temp->setChecked(true);
437
 
            menu->addAction(temp);
438
 
          }
439
 
          dm_label_2d_->setMenu(menu);
440
 
 
441
 
          // unassigned peptide identifications:
442
 
          dm_unassigned_2d_ = new QToolButton(tool_bar_2d_feat_);
443
 
          dm_unassigned_2d_->setPopupMode(QToolButton::MenuButtonPopup);
444
 
          QAction* action_unassigned = new QAction(QIcon(":/unassigned.png"), "Show unassigned peptide identifications", dm_unassigned_2d_);
445
 
          action_unassigned->setCheckable(true);
446
 
          action_unassigned->setWhatsThis("2D feature draw mode: Unassigned peptide identifications<BR><BR>Show unassigned peptide identifications by precursor m/z or by peptide mass.<BR>(Hotkey: 8)");
447
 
          action_unassigned->setShortcut(Qt::Key_8);
448
 
          dm_unassigned_2d_->setDefaultAction(action_unassigned);
449
 
          tool_bar_2d_feat_->addWidget(dm_unassigned_2d_);
450
 
          connect(dm_unassigned_2d_, SIGNAL(triggered(QAction*)), this, SLOT(changeUnassigned(QAction*)));
451
 
          //button menu
452
 
          group_unassigned_2d_ = new QActionGroup(dm_unassigned_2d_);
453
 
          menu = new QMenu(dm_unassigned_2d_);
454
 
          StringList options = StringList::create(
455
 
              "Don't show,Show by precursor m/z,Show by peptide mass");
456
 
          for (StringList::iterator opt_it = options.begin(); opt_it != options.end();
457
 
          ++opt_it)
458
 
          {
459
 
            QAction* temp = group_unassigned_2d_->addAction(opt_it->toQString());
460
 
            temp->setCheckable(true);
461
 
            if (opt_it == options.begin()) temp->setChecked(true);
462
 
            menu->addAction(temp);
463
 
          }
464
 
          dm_unassigned_2d_->setMenu(menu);
465
 
 
466
 
          //--2D consensus toolbar--
467
 
          tool_bar_2d_cons_ = addToolBar("2D peak tool bar");
468
 
 
469
 
          dm_elements_2d_ = tool_bar_2d_cons_->addAction(QIcon(":/elements.png"),"Show consensus feature element positions");
470
 
          dm_elements_2d_->setCheckable(true);
471
 
          dm_elements_2d_->setWhatsThis("2D consensus feature draw mode: Elements<BR><BR>The individual elements that make up the  consensus feature are drawn.<BR>(Hotkey: 9)");
472
 
          dm_elements_2d_->setShortcut(Qt::Key_9);
473
 
          connect(dm_elements_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
474
 
 
475
 
          //--2D identifications toolbar--
476
 
          tool_bar_2d_ident_ = addToolBar("2D identifications tool bar");
477
 
 
478
 
          dm_ident_2d_ = tool_bar_2d_ident_->addAction(QIcon(":/peptidemz.png"), "Use theoretical peptide mass for m/z positions (default: precursor mass)");
479
 
          dm_ident_2d_->setCheckable(true);
480
 
          dm_ident_2d_->setWhatsThis("2D peptide identification draw mode: m/z source<BR><BR>Toggle between precursor mass (default) and theoretical peptide mass as source for the m/z positions of peptide identifications.<BR>(Hotkey: 5)");
481
 
          dm_ident_2d_->setShortcut(Qt::Key_5);
482
 
          connect(dm_ident_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
483
 
 
484
 
          //################## Dock widgets #################
485
 
          // layer dock widget
486
 
          layer_dock_widget_ = new QDockWidget("Layers", this);
487
 
          addDockWidget(Qt::RightDockWidgetArea, layer_dock_widget_);
488
 
          layer_manager_ = new QListWidget(layer_dock_widget_);
489
 
          layer_manager_->setWhatsThis("Layer bar<BR><BR>Here the available layers are shown. Left-click on a layer to select it.<BR>Layers can be shown and hidden using the checkboxes in front of the name.<BR> Renaming and removing a layer is possible through the context menu.<BR>Dragging a layer to the tab bar copies the layer.<BR>Double-clicking a layer open its preferences.<BR>You can use the 'PageUp' and 'PageDown' buttons to change the selected layer.");
490
 
 
491
 
          layer_dock_widget_->setWidget(layer_manager_);
492
 
          layer_manager_->setContextMenuPolicy(Qt::CustomContextMenu);
493
 
          layer_manager_->setDragEnabled(true);
494
 
          connect(layer_manager_,SIGNAL(currentRowChanged(int)),this,SLOT(layerSelectionChange(int)));
495
 
          connect(layer_manager_,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(layerContextMenu(const QPoint&)));
496
 
          connect(layer_manager_,SIGNAL(itemChanged(QListWidgetItem*)),this,SLOT(layerVisibilityChange(QListWidgetItem*)));
497
 
          connect(layer_manager_,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(layerEdit(QListWidgetItem*)));
498
 
 
499
 
          windows->addAction(layer_dock_widget_->toggleViewAction());
500
 
 
501
 
          // Views dock widget
502
 
          views_dockwidget_ = new QDockWidget("Views", this);
503
 
          addDockWidget(Qt::RightDockWidgetArea, views_dockwidget_);
504
 
          views_tabwidget_ = new QTabWidget(views_dockwidget_);
505
 
          views_dockwidget_->setWidget(views_tabwidget_);
506
 
 
507
 
          spectra_view_widget_ = new SpectraViewWidget();
508
 
          connect(spectra_view_widget_, SIGNAL(showSpectrumMetaData(int)), this, SLOT(showSpectrumMetaData(int)));
509
 
          connect(spectra_view_widget_, SIGNAL(showSpectrumAs1D(int)), this, SLOT(showSpectrumAs1D(int)));
510
 
          connect(spectra_view_widget_, SIGNAL(spectrumSelected(int)), this, SLOT(activate1DSpectrum(int)));
511
 
          connect(spectra_view_widget_, SIGNAL(spectrumDoubleClicked(int)), this, SLOT(showSpectrumAs1D(int)));
512
 
          spectraview_behavior_ = new TOPPViewSpectraViewBehavior(this);
513
 
          view_behavior_ = spectraview_behavior_;
514
 
 
515
 
          spectra_identification_view_widget_ = new SpectraIdentificationViewWidget(Param());
516
 
          connect(spectra_identification_view_widget_, SIGNAL(spectrumDeselected(int)), this, SLOT(deactivate1DSpectrum(int)));
517
 
          connect(spectra_identification_view_widget_, SIGNAL(showSpectrumAs1D(int)), this, SLOT(showSpectrumAs1D(int)));
518
 
          connect(spectra_identification_view_widget_, SIGNAL(spectrumSelected(int)), this, SLOT(activate1DSpectrum(int)));
519
 
          identificationview_behavior_ = new TOPPViewIdentificationViewBehavior(this);
520
 
          connect(spectra_identification_view_widget_, SIGNAL(requestVisibleArea1D(DoubleReal, DoubleReal)), identificationview_behavior_, SLOT(setVisibleArea1D(DoubleReal, DoubleReal)));
521
 
 
522
 
          // topp tool dock widget          
523
 
          TOPPASTreeView* tools_tree_view = TOPPASBase::createTOPPToolsTreeWidget();
524
 
          connect (tools_tree_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(insertNewVertexInCenter_(QTreeWidgetItem*)));
525
 
 
526
 
          views_tabwidget_->addTab(spectra_view_widget_, "Scan view");
527
 
          views_tabwidget_->addTab(spectra_identification_view_widget_, "Identification view");
528
 
          views_tabwidget_->setTabEnabled(1, false);
529
 
          views_tabwidget_->addTab(tools_tree_view, "TOPPAS view");
530
 
          views_tabwidget_->setTabEnabled(2, false);
531
 
 
532
 
          // switch between different view tabs
533
 
          connect(views_tabwidget_, SIGNAL(currentChanged(int)), this, SLOT(viewChanged(int)));
534
 
 
535
 
          // add hide/show option to dock widget
536
 
          windows->addAction(views_dockwidget_->toggleViewAction());
537
 
 
538
 
          // filter dock widget
539
 
          filter_dock_widget_ = new QDockWidget("Data filters", this);
540
 
          addDockWidget(Qt::RightDockWidgetArea, filter_dock_widget_);
541
 
          QWidget* tmp_widget = new QWidget(); //dummy widget as QDockWidget takes only one widget
542
 
          filter_dock_widget_->setWidget(tmp_widget);
543
 
 
544
 
          QVBoxLayout* vbl = new QVBoxLayout(tmp_widget);
545
 
 
546
 
          filters_ = new QListWidget(tmp_widget);
547
 
          filters_->setSelectionMode(QAbstractItemView::NoSelection);
548
 
          filters_->setWhatsThis("Data filter bar<BR><BR>Here filtering options for the current layer can be set.<BR>Through the context menu you can add, remove and edit filters.<BR>For convenience, editing filters is also possible by double-clicking them.");
549
 
          filters_->setContextMenuPolicy(Qt::CustomContextMenu);
550
 
          connect(filters_,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(filterContextMenu(const QPoint&)));
551
 
          connect(filters_,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(filterEdit(QListWidgetItem*)));
552
 
          vbl->addWidget(filters_);
553
 
 
554
 
          filters_check_box_ = new QCheckBox("Enable/disable all filters", tmp_widget);
555
 
          connect(filters_check_box_,SIGNAL(toggled(bool)),this,SLOT(layerFilterVisibilityChange(bool)));
556
 
          vbl->addWidget(filters_check_box_);
557
 
 
558
 
          windows->addAction(filter_dock_widget_->toggleViewAction());
559
 
 
560
 
          //log window
561
 
          QDockWidget* log_bar = new QDockWidget("Log", this);
562
 
          addDockWidget(Qt::BottomDockWidgetArea, log_bar);
563
 
          log_ = new QTextEdit(log_bar);
564
 
          log_->setReadOnly(true);
565
 
          log_->setContextMenuPolicy(Qt::CustomContextMenu);
566
 
          connect(log_,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(logContextMenu(const QPoint&)));
567
 
          log_bar->setWidget(log_);
568
 
          log_bar->hide();
569
 
          windows->addAction(log_bar->toggleViewAction());
570
 
 
571
 
          //################## DEFAULTS #################
572
 
          initializeDefaultParameters_();
573
 
 
574
 
          // store defaults in param_
575
 
          defaultsToParam_();
576
 
 
577
 
          //load param file
578
 
          loadPreferences();
579
 
 
580
 
          //set current path
581
 
          current_path_ = param_.getValue("preferences:default_path");
582
 
 
583
 
          //update the menu
584
 
          updateMenu();
585
 
 
586
 
          topp_.process = 0;
587
 
 
588
 
          //######################### File System Watcher ###########################################
589
 
          watcher_ = new FileWatcher(this);
590
 
          connect(watcher_,SIGNAL(fileChanged(const String&)),this, SLOT(fileChanged_(const String&)));
591
 
        }
 
125
  using namespace Math;
 
126
 
 
127
  const String TOPPViewBase::CAPTION_3D_SUFFIX_ = " (3D)";
 
128
 
 
129
  TOPPViewBase::TOPPViewBase(QWidget* parent) :
 
130
    QMainWindow(parent),
 
131
    DefaultParamHandler("TOPPViewBase"),
 
132
    watcher_(0),
 
133
    watcher_msgbox_(false)
 
134
  {
 
135
#if defined(__APPLE__)
 
136
    // we do not want to load plugins as this leads to serious problems
 
137
    // when shipping on mac os x
 
138
    QApplication::setLibraryPaths(QStringList());
 
139
#endif
 
140
 
 
141
    setWindowTitle("TOPPView");
 
142
    setWindowIcon(QIcon(":/TOPPView.png"));
 
143
 
 
144
    // ensure correct encoding of paths
 
145
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
 
146
 
 
147
    //prevents errors caused by too small width, height values
 
148
    setMinimumSize(400, 400);
 
149
 
 
150
    //enable drag-and-drop
 
151
    setAcceptDrops(true);
 
152
 
 
153
    //by default, linked zooming is turned off
 
154
    zoom_together_ = false;
 
155
 
 
156
    // get geometry of first screen
 
157
    QRect screen_geometry = QApplication::desktop()->screenGeometry();
 
158
    // center main window
 
159
    setGeometry(
 
160
      (int)(0.1 * screen_geometry.width()),
 
161
      (int)(0.1 * screen_geometry.height()),
 
162
      (int)(0.8 * screen_geometry.width()),
 
163
      (int)(0.8 * screen_geometry.height())
 
164
      );
 
165
 
 
166
    // create dummy widget (to be able to have a layout), Tab bar and workspace
 
167
    QWidget* dummy = new QWidget(this);
 
168
    setCentralWidget(dummy);
 
169
    QVBoxLayout* box_layout = new QVBoxLayout(dummy);
 
170
 
 
171
    // create empty tab bar and workspace which will hold the main visualization widgets (e.g. spectrawidgets...)
 
172
    tab_bar_ = new EnhancedTabBar(dummy);
 
173
    tab_bar_->setWhatsThis("Tab bar<BR><BR>Close tabs through the context menu or by double-clicking them.<BR>The tab bar accepts drag-and-drop from the layer bar.");
 
174
    tab_bar_->addTab("dummy", 4710);
 
175
    tab_bar_->setMinimumSize(tab_bar_->sizeHint());
 
176
    tab_bar_->removeId(4710);
 
177
 
 
178
    connect(tab_bar_, SIGNAL(currentIdChanged(int)), this, SLOT(enhancedWorkspaceWindowChanged(int)));
 
179
    connect(tab_bar_, SIGNAL(aboutToCloseId(int)), this, SLOT(closeByTab(int)));
 
180
 
 
181
    //connect signals ans slots for drag-and-drop
 
182
    connect(tab_bar_, SIGNAL(dropOnWidget(const QMimeData*, QWidget*)), this, SLOT(copyLayer(const QMimeData*, QWidget*)));
 
183
    connect(tab_bar_, SIGNAL(dropOnTab(const QMimeData*, QWidget*, int)), this, SLOT(copyLayer(const QMimeData*, QWidget*, int)));
 
184
    box_layout->addWidget(tab_bar_);
 
185
 
 
186
    ws_ = new EnhancedWorkspace(dummy);
 
187
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateToolBar()));
 
188
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateTabBar(QWidget*)));
 
189
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateLayerBar()));
 
190
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateViewBar()));
 
191
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateFilterBar()));
 
192
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateMenu()));
 
193
    connect(ws_, SIGNAL(windowActivated(QWidget*)), this, SLOT(updateCurrentPath()));
 
194
    connect(ws_, SIGNAL(dropReceived(const QMimeData*, QWidget*, int)), this, SLOT(copyLayer(const QMimeData*, QWidget*, int)));
 
195
 
 
196
    box_layout->addWidget(ws_);
 
197
 
 
198
    //################## MENUS #################
 
199
    // File menu
 
200
    QMenu* file = new QMenu("&File", this);
 
201
    menuBar()->addMenu(file);
 
202
    file->addAction("&Open file", this, SLOT(openFileDialog()), Qt::CTRL + Qt::Key_O);
 
203
    file->addAction("Open from &database", this, SLOT(openDatabaseDialog()), Qt::CTRL + Qt::Key_D);
 
204
    file->addAction("Open &example file", this, SLOT(openExampleDialog()));
 
205
    file->addAction("&Close", this, SLOT(closeFile()), Qt::CTRL + Qt::Key_W);
 
206
    file->addSeparator();
 
207
 
 
208
    //Meta data
 
209
    file->addAction("&Show meta data (file)", this, SLOT(metadataFileDialog()));
 
210
    file->addAction("&Show meta data (database)", this, SLOT(metadataDatabaseDialog()));
 
211
    file->addSeparator();
 
212
 
 
213
    //Recent files
 
214
    QMenu* recent_menu = new QMenu("&Recent files", this);
 
215
    recent_actions_.resize(20);
 
216
    for (Size i = 0; i < 20; ++i)
 
217
    {
 
218
      recent_actions_[i] = recent_menu->addAction("", this, SLOT(openRecentFile()));
 
219
      recent_actions_[i]->setVisible(false);
 
220
    }
 
221
    file->addMenu(recent_menu);
 
222
 
 
223
    file->addSeparator();
 
224
    file->addAction("&Preferences", this, SLOT(preferencesDialog()));
 
225
    file->addAction("&Quit", qApp, SLOT(quit()));
 
226
 
 
227
    //Tools menu
 
228
    QMenu* tools = new QMenu("&Tools", this);
 
229
    menuBar()->addMenu(tools);
 
230
    tools->addAction("&Go to", this, SLOT(showGoToDialog()), Qt::CTRL + Qt::Key_G);
 
231
    tools->addAction("&Edit meta data", this, SLOT(editMetadata()), Qt::CTRL + Qt::Key_M);
 
232
    tools->addAction("&Statistics", this, SLOT(layerStatistics()));
 
233
    tools->addSeparator();
 
234
 
 
235
    tools->addAction("Apply TOPP tool (whole layer)", this, SLOT(showTOPPDialog()), Qt::CTRL + Qt::Key_T)->setData(false);
 
236
    tools->addAction("Apply TOPP tool (visible layer data)", this, SLOT(showTOPPDialog()), Qt::CTRL + Qt::SHIFT + Qt::Key_T)->setData(true);
 
237
    tools->addAction("Rerun TOPP tool", this, SLOT(rerunTOPPTool()), Qt::Key_F4);
 
238
    tools->addSeparator();
 
239
    tools->addAction("&Annotate with identification", this, SLOT(annotateWithID()), Qt::CTRL + Qt::Key_I);
 
240
    tools->addAction("Align spectra", this, SLOT(showSpectrumAlignmentDialog()));
 
241
    tools->addAction("Generate theoretical spectrum", this, SLOT(showSpectrumGenerationDialog()));
 
242
 
 
243
    //Layer menu
 
244
    QMenu* layer = new QMenu("&Layer", this);
 
245
    menuBar()->addMenu(layer);
 
246
    layer->addAction("Save all data", this, SLOT(saveLayerAll()), Qt::CTRL + Qt::Key_S);
 
247
    layer->addAction("Save visible data", this, SLOT(saveLayerVisible()), Qt::CTRL + Qt::SHIFT + Qt::Key_S);
 
248
    layer->addSeparator();
 
249
    layer->addAction("Show/hide grid lines", this, SLOT(toggleGridLines()), Qt::CTRL + Qt::Key_R);
 
250
    layer->addAction("Show/hide axis legends", this, SLOT(toggleAxisLegends()), Qt::CTRL + Qt::Key_L);
 
251
    layer->addSeparator();
 
252
    layer->addAction("Preferences", this, SLOT(showPreferences()));
 
253
 
 
254
    //Windows menu
 
255
    QMenu* windows = new QMenu("&Windows", this);
 
256
    menuBar()->addMenu(windows);
 
257
    windows->addAction("&Cascade", this->ws_, SLOT(cascade()));
 
258
    windows->addAction("&Tile automatic", this->ws_, SLOT(tile()));
 
259
    windows->addAction(QIcon(":/tile_horizontal.png"), "Tile &vertical", this, SLOT(tileHorizontal()));
 
260
    windows->addAction(QIcon(":/tile_vertical.png"), "Tile &horizontal", this, SLOT(tileVertical()));
 
261
    linkZoom_action_ = windows->addAction("Link &Zoom", this, SLOT(linkZoom()));
 
262
    windows->addSeparator();
 
263
 
 
264
    //Help menu
 
265
    QMenu* help = new QMenu("&Help", this);
 
266
    menuBar()->addMenu(help);
 
267
    help->addAction(QWhatsThis::createAction(help));
 
268
    help->addSeparator();
 
269
    QAction* action = help->addAction("OpenMS website", this, SLOT(showURL()));
 
270
    action->setData("http://www.OpenMS.de");
 
271
    action = help->addAction("Tutorials and documentation", this, SLOT(showURL()), Qt::Key_F1);
 
272
    action->setData(String("html/index.html").toQString());
 
273
 
 
274
    help->addSeparator();
 
275
    help->addAction("&About", this, SLOT(showAboutDialog()));
 
276
 
 
277
    //create status bar
 
278
    message_label_ = new QLabel(statusBar());
 
279
    statusBar()->addWidget(message_label_, 1);
 
280
 
 
281
    rt_label_ = new QLabel("RT: 12345678", statusBar());
 
282
    rt_label_->setMinimumSize(rt_label_->sizeHint());
 
283
    rt_label_->setText("");
 
284
    statusBar()->addPermanentWidget(rt_label_, 0);
 
285
    mz_label_ = new QLabel("m/z: 123456780912", statusBar());
 
286
    mz_label_->setMinimumSize(mz_label_->sizeHint());
 
287
    mz_label_->setText("");
 
288
    statusBar()->addPermanentWidget(mz_label_, 0);
 
289
 
 
290
    //################## TOOLBARS #################
 
291
    //create toolbars and connect signals
 
292
    QToolButton* b;
 
293
 
 
294
    //--Basic tool bar for all views--
 
295
    tool_bar_ = addToolBar("Basic tool bar");
 
296
 
 
297
    //intensity modes
 
298
    intensity_button_group_ = new QButtonGroup(tool_bar_);
 
299
    intensity_button_group_->setExclusive(true);
 
300
 
 
301
    b = new QToolButton(tool_bar_);
 
302
    b->setIcon(QIcon(":/lin.png"));
 
303
    b->setToolTip("Intensity: Normal");
 
304
    b->setShortcut(Qt::Key_N);
 
305
    b->setCheckable(true);
 
306
    b->setWhatsThis("Intensity: Normal<BR><BR>Intensity is displayed unmodified.<BR>(Hotkey: N)");
 
307
    intensity_button_group_->addButton(b, SpectrumCanvas::IM_NONE);
 
308
    tool_bar_->addWidget(b);
 
309
 
 
310
    b = new QToolButton(tool_bar_);
 
311
    b->setIcon(QIcon(":/percentage.png"));
 
312
    b->setToolTip("Intensity: Percentage");
 
313
    b->setShortcut(Qt::Key_P);
 
314
    b->setCheckable(true);
 
315
    b->setWhatsThis("Intensity: Percentage<BR><BR>Intensity is displayed as a percentage of the layer"
 
316
                    " maximum intensity. If only one layer is displayed this mode behaves like the"
 
317
                    " normal mode. If more than one layer is displayed intensities are aligned."
 
318
                    "<BR>(Hotkey: P)");
 
319
    intensity_button_group_->addButton(b, SpectrumCanvas::IM_PERCENTAGE);
 
320
    tool_bar_->addWidget(b);
 
321
 
 
322
    b = new QToolButton(tool_bar_);
 
323
    b->setIcon(QIcon(":/snap.png"));
 
324
    b->setToolTip("Intensity: Snap to maximum displayed intensity");
 
325
    b->setShortcut(Qt::Key_S);
 
326
    b->setCheckable(true);
 
327
    b->setWhatsThis("Intensity: Snap to maximum displayed intensity<BR><BR> In this mode the"
 
328
                    " color gradient is adapted to the maximum currently displayed intensity."
 
329
                    "<BR>(Hotkey: S)");
 
330
    intensity_button_group_->addButton(b, SpectrumCanvas::IM_SNAP);
 
331
    tool_bar_->addWidget(b);
 
332
 
 
333
    b = new QToolButton(tool_bar_);
 
334
    b->setIcon(QIcon(":/log.png"));
 
335
    b->setToolTip("Intensity: Use log scaling for colors");
 
336
    b->setCheckable(true);
 
337
    b->setWhatsThis("Intensity: Logarithmic scaling of intensities for color calculation");
 
338
    intensity_button_group_->addButton(b, SpectrumCanvas::IM_LOG);
 
339
    tool_bar_->addWidget(b);
 
340
 
 
341
    connect(intensity_button_group_, SIGNAL(buttonClicked(int)), this, SLOT(setIntensityMode(int)));
 
342
    tool_bar_->addSeparator();
 
343
 
 
344
    //common buttons
 
345
    QAction* reset_zoom_button = tool_bar_->addAction(QIcon(":/reset_zoom.png"), "Reset Zoom", this, SLOT(resetZoom()));
 
346
    reset_zoom_button->setWhatsThis("Reset zoom: Zooms out as far as possible and resets the zoom history.<BR>(Hotkey: Backspace)");
 
347
 
 
348
    tool_bar_->show();
 
349
 
 
350
    //--1D toolbar--
 
351
    tool_bar_1d_ = addToolBar("1D tool bar");
 
352
 
 
353
    //draw modes 1D
 
354
    draw_group_1d_ = new QButtonGroup(tool_bar_1d_);
 
355
    draw_group_1d_->setExclusive(true);
 
356
 
 
357
    b = new QToolButton(tool_bar_1d_);
 
358
    b->setIcon(QIcon(":/peaks.png"));
 
359
    b->setToolTip("Peak mode");
 
360
    b->setShortcut(Qt::Key_I);
 
361
    b->setCheckable(true);
 
362
    b->setWhatsThis("1D Draw mode: Peaks<BR><BR>Peaks are diplayed as sticks.");
 
363
    draw_group_1d_->addButton(b, Spectrum1DCanvas::DM_PEAKS);
 
364
    tool_bar_1d_->addWidget(b);
 
365
 
 
366
    b = new QToolButton(tool_bar_1d_);
 
367
    b->setIcon(QIcon(":/lines.png"));
 
368
    b->setToolTip("Raw data mode");
 
369
    b->setShortcut(Qt::Key_R);
 
370
    b->setCheckable(true);
 
371
    b->setWhatsThis("1D Draw mode: Raw data<BR><BR>Peaks are diplayed as a continuous line.");
 
372
    draw_group_1d_->addButton(b, Spectrum1DCanvas::DM_CONNECTEDLINES);
 
373
    tool_bar_1d_->addWidget(b);
 
374
 
 
375
    connect(draw_group_1d_, SIGNAL(buttonClicked(int)), this, SLOT(setDrawMode1D(int)));
 
376
    tool_bar_->addSeparator();
 
377
 
 
378
    //--2D peak toolbar--
 
379
    tool_bar_2d_peak_ = addToolBar("2D peak tool bar");
 
380
 
 
381
    dm_precursors_2d_ = tool_bar_2d_peak_->addAction(QIcon(":/precursors.png"), "Show fragment scan precursors");
 
382
    dm_precursors_2d_->setCheckable(true);
 
383
    dm_precursors_2d_->setWhatsThis("2D peak draw mode: Precursors<BR><BR>fragment scan precursor peaks are marked.<BR>(Hotkey: 1)");
 
384
    dm_precursors_2d_->setShortcut(Qt::Key_1);
 
385
 
 
386
    connect(dm_precursors_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
 
387
 
 
388
    projections_2d_ = tool_bar_2d_peak_->addAction(QIcon(":/projections.png"), "Show Projections", this, SLOT(toggleProjections()));
 
389
    projections_2d_->setWhatsThis("Projections: Shows projections of peak data along RT and MZ axis.<BR>(Hotkey: 2)");
 
390
    projections_2d_->setShortcut(Qt::Key_2);
 
391
 
 
392
    //--2D feature toolbar--
 
393
    tool_bar_2d_feat_ = addToolBar("2D feature tool bar");
 
394
 
 
395
    dm_hull_2d_ = tool_bar_2d_feat_->addAction(QIcon(":/convexhull.png"), "Show feature convex hull");
 
396
    dm_hull_2d_->setCheckable(true);
 
397
    dm_hull_2d_->setWhatsThis("2D feature draw mode: Convex hull<BR><BR>The convex hull of the feature is displayed.<BR>(Hotkey: 5)");
 
398
    dm_hull_2d_->setShortcut(Qt::Key_5);
 
399
    connect(dm_hull_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
 
400
 
 
401
    dm_hulls_2d_ = tool_bar_2d_feat_->addAction(QIcon(":/convexhulls.png"), "Show feature convex hulls");
 
402
    dm_hulls_2d_->setCheckable(true);
 
403
    dm_hulls_2d_->setWhatsThis("2D feature draw mode: Convex hulls<BR><BR>The convex hulls of the feature are displayed: One for each mass trace.<BR>(Hotkey: 6)");
 
404
    dm_hulls_2d_->setShortcut(Qt::Key_6);
 
405
    connect(dm_hulls_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
 
406
 
 
407
    // feature labels:
 
408
    dm_label_2d_ = new QToolButton(tool_bar_2d_feat_);
 
409
    dm_label_2d_->setPopupMode(QToolButton::MenuButtonPopup);
 
410
    QAction* action2 = new QAction(QIcon(":/labels.png"), "Show feature annotation", dm_label_2d_);
 
411
    action2->setCheckable(true);
 
412
    action2->setWhatsThis("2D feature draw mode: Labels<BR><BR>Display different kinds of annotation next to features.<BR>(Hotkey: 7)");
 
413
    action2->setShortcut(Qt::Key_7);
 
414
    dm_label_2d_->setDefaultAction(action2);
 
415
    tool_bar_2d_feat_->addWidget(dm_label_2d_);
 
416
    connect(dm_label_2d_, SIGNAL(triggered(QAction*)), this, SLOT(changeLabel(QAction*)));
 
417
    //button menu
 
418
    group_label_2d_ = new QActionGroup(dm_label_2d_);
 
419
    QMenu* menu = new QMenu(dm_label_2d_);
 
420
    for (Size i = 0; i < LayerData::SIZE_OF_LABEL_TYPE; ++i)
 
421
    {
 
422
      QAction* temp = group_label_2d_->addAction(
 
423
        QString(LayerData::NamesOfLabelType[i].c_str()));
 
424
      temp->setCheckable(true);
 
425
      if (i == 0) temp->setChecked(true);
 
426
      menu->addAction(temp);
 
427
    }
 
428
    dm_label_2d_->setMenu(menu);
 
429
 
 
430
    // unassigned peptide identifications:
 
431
    dm_unassigned_2d_ = new QToolButton(tool_bar_2d_feat_);
 
432
    dm_unassigned_2d_->setPopupMode(QToolButton::MenuButtonPopup);
 
433
    QAction* action_unassigned = new QAction(QIcon(":/unassigned.png"), "Show unassigned peptide identifications", dm_unassigned_2d_);
 
434
    action_unassigned->setCheckable(true);
 
435
    action_unassigned->setWhatsThis("2D feature draw mode: Unassigned peptide identifications<BR><BR>Show unassigned peptide identifications by precursor m/z or by peptide mass.<BR>(Hotkey: 8)");
 
436
    action_unassigned->setShortcut(Qt::Key_8);
 
437
    dm_unassigned_2d_->setDefaultAction(action_unassigned);
 
438
    tool_bar_2d_feat_->addWidget(dm_unassigned_2d_);
 
439
    connect(dm_unassigned_2d_, SIGNAL(triggered(QAction*)), this, SLOT(changeUnassigned(QAction*)));
 
440
    //button menu
 
441
    group_unassigned_2d_ = new QActionGroup(dm_unassigned_2d_);
 
442
    menu = new QMenu(dm_unassigned_2d_);
 
443
    StringList options = StringList::create(
 
444
      "Don't show,Show by precursor m/z,Show by peptide mass");
 
445
    for (StringList::iterator opt_it = options.begin(); opt_it != options.end();
 
446
         ++opt_it)
 
447
    {
 
448
      QAction* temp = group_unassigned_2d_->addAction(opt_it->toQString());
 
449
      temp->setCheckable(true);
 
450
      if (opt_it == options.begin())
 
451
        temp->setChecked(true);
 
452
      menu->addAction(temp);
 
453
    }
 
454
    dm_unassigned_2d_->setMenu(menu);
 
455
 
 
456
    //--2D consensus toolbar--
 
457
    tool_bar_2d_cons_ = addToolBar("2D peak tool bar");
 
458
 
 
459
    dm_elements_2d_ = tool_bar_2d_cons_->addAction(QIcon(":/elements.png"), "Show consensus feature element positions");
 
460
    dm_elements_2d_->setCheckable(true);
 
461
    dm_elements_2d_->setWhatsThis("2D consensus feature draw mode: Elements<BR><BR>The individual elements that make up the  consensus feature are drawn.<BR>(Hotkey: 9)");
 
462
    dm_elements_2d_->setShortcut(Qt::Key_9);
 
463
    connect(dm_elements_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
 
464
 
 
465
    //--2D identifications toolbar--
 
466
    tool_bar_2d_ident_ = addToolBar("2D identifications tool bar");
 
467
 
 
468
    dm_ident_2d_ = tool_bar_2d_ident_->addAction(QIcon(":/peptidemz.png"), "Use theoretical peptide mass for m/z positions (default: precursor mass)");
 
469
    dm_ident_2d_->setCheckable(true);
 
470
    dm_ident_2d_->setWhatsThis("2D peptide identification draw mode: m/z source<BR><BR>Toggle between precursor mass (default) and theoretical peptide mass as source for the m/z positions of peptide identifications.<BR>(Hotkey: 5)");
 
471
    dm_ident_2d_->setShortcut(Qt::Key_5);
 
472
    connect(dm_ident_2d_, SIGNAL(toggled(bool)), this, SLOT(changeLayerFlag(bool)));
 
473
 
 
474
    //################## Dock widgets #################
 
475
    // layer dock widget
 
476
    layer_dock_widget_ = new QDockWidget("Layers", this);
 
477
    addDockWidget(Qt::RightDockWidgetArea, layer_dock_widget_);
 
478
    layer_manager_ = new QListWidget(layer_dock_widget_);
 
479
    layer_manager_->setWhatsThis("Layer bar<BR><BR>Here the available layers are shown. Left-click on a layer to select it.<BR>Layers can be shown and hidden using the checkboxes in front of the name.<BR> Renaming and removing a layer is possible through the context menu.<BR>Dragging a layer to the tab bar copies the layer.<BR>Double-clicking a layer open its preferences.<BR>You can use the 'PageUp' and 'PageDown' buttons to change the selected layer.");
 
480
 
 
481
    layer_dock_widget_->setWidget(layer_manager_);
 
482
    layer_manager_->setContextMenuPolicy(Qt::CustomContextMenu);
 
483
    layer_manager_->setDragEnabled(true);
 
484
    connect(layer_manager_, SIGNAL(currentRowChanged(int)), this, SLOT(layerSelectionChange(int)));
 
485
    connect(layer_manager_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(layerContextMenu(const QPoint &)));
 
486
    connect(layer_manager_, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(layerVisibilityChange(QListWidgetItem*)));
 
487
    connect(layer_manager_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(layerEdit(QListWidgetItem*)));
 
488
 
 
489
    windows->addAction(layer_dock_widget_->toggleViewAction());
 
490
 
 
491
    // Views dock widget
 
492
    views_dockwidget_ = new QDockWidget("Views", this);
 
493
    addDockWidget(Qt::RightDockWidgetArea, views_dockwidget_);
 
494
    views_tabwidget_ = new QTabWidget(views_dockwidget_);
 
495
    views_dockwidget_->setWidget(views_tabwidget_);
 
496
 
 
497
    spectra_view_widget_ = new SpectraViewWidget();
 
498
    connect(spectra_view_widget_, SIGNAL(showSpectrumMetaData(int)), this, SLOT(showSpectrumMetaData(int)));
 
499
    connect(spectra_view_widget_, SIGNAL(showSpectrumAs1D(int)), this, SLOT(showSpectrumAs1D(int)));
 
500
    connect(spectra_view_widget_, SIGNAL(showSpectrumAs1D(std::vector<int, std::allocator<int> >)), this, SLOT(showSpectrumAs1D(std::vector<int, std::allocator<int> >)));
 
501
    connect(spectra_view_widget_, SIGNAL(spectrumSelected(int)), this, SLOT(activate1DSpectrum(int)));
 
502
    connect(spectra_view_widget_, SIGNAL(spectrumSelected(std::vector<int, std::allocator<int> >)), this, SLOT(activate1DSpectrum(std::vector<int, std::allocator<int> >)));
 
503
    connect(spectra_view_widget_, SIGNAL(spectrumDoubleClicked(int)), this, SLOT(showSpectrumAs1D(int)));
 
504
    connect(spectra_view_widget_, SIGNAL(spectrumDoubleClicked(std::vector<int, std::allocator<int> >)), this, SLOT(showSpectrumAs1D(std::vector<int, std::allocator<int> >)));
 
505
 
 
506
    spectraview_behavior_ = new TOPPViewSpectraViewBehavior(this);
 
507
    view_behavior_ = spectraview_behavior_;
 
508
 
 
509
    spectra_identification_view_widget_ = new SpectraIdentificationViewWidget(Param());
 
510
    connect(spectra_identification_view_widget_, SIGNAL(spectrumDeselected(int)), this, SLOT(deactivate1DSpectrum(int)));
 
511
    connect(spectra_identification_view_widget_, SIGNAL(showSpectrumAs1D(int)), this, SLOT(showSpectrumAs1D(int)));
 
512
    // connect(spectra_identification_view_widget_, SIGNAL(showSpectrumAs1D(std::vector<int, std::allocator<int> >)), this, SLOT(showSpectrumAs1D(std::vector<int, std::allocator<int> >)));
 
513
    connect(spectra_identification_view_widget_, SIGNAL(spectrumSelected(int)), this, SLOT(activate1DSpectrum(int)));
 
514
    //connect(spectra_identification_view_widget_, SIGNAL(spectrumSelected(std::vector<int, std::allocator<int> >)), this, SLOT(activate1DSpectrum(std::vector<int, std::allocator<int> >)));
 
515
    identificationview_behavior_ = new TOPPViewIdentificationViewBehavior(this);
 
516
    connect(spectra_identification_view_widget_, SIGNAL(requestVisibleArea1D(DoubleReal, DoubleReal)), identificationview_behavior_, SLOT(setVisibleArea1D(DoubleReal, DoubleReal)));
 
517
 
 
518
    views_tabwidget_->addTab(spectra_view_widget_, "Scan view");
 
519
    views_tabwidget_->addTab(spectra_identification_view_widget_, "Identification view");
 
520
    views_tabwidget_->setTabEnabled(0, false);
 
521
    views_tabwidget_->setTabEnabled(1, false);
 
522
 
 
523
    // switch between different view tabs
 
524
    connect(views_tabwidget_, SIGNAL(currentChanged(int)), this, SLOT(viewChanged(int)));
 
525
 
 
526
    // add hide/show option to dock widget
 
527
    windows->addAction(views_dockwidget_->toggleViewAction());
 
528
 
 
529
    // filter dock widget
 
530
    filter_dock_widget_ = new QDockWidget("Data filters", this);
 
531
    addDockWidget(Qt::RightDockWidgetArea, filter_dock_widget_);
 
532
    QWidget* tmp_widget = new QWidget(); //dummy widget as QDockWidget takes only one widget
 
533
    filter_dock_widget_->setWidget(tmp_widget);
 
534
 
 
535
    QVBoxLayout* vbl = new QVBoxLayout(tmp_widget);
 
536
 
 
537
    filters_ = new QListWidget(tmp_widget);
 
538
    filters_->setSelectionMode(QAbstractItemView::NoSelection);
 
539
    filters_->setWhatsThis("Data filter bar<BR><BR>Here filtering options for the current layer can be set.<BR>Through the context menu you can add, remove and edit filters.<BR>For convenience, editing filters is also possible by double-clicking them.");
 
540
    filters_->setContextMenuPolicy(Qt::CustomContextMenu);
 
541
    connect(filters_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(filterContextMenu(const QPoint &)));
 
542
    connect(filters_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(filterEdit(QListWidgetItem*)));
 
543
    vbl->addWidget(filters_);
 
544
 
 
545
    filters_check_box_ = new QCheckBox("Enable all filters", tmp_widget);
 
546
    connect(filters_check_box_, SIGNAL(toggled(bool)), this, SLOT(layerFilterVisibilityChange(bool)));
 
547
    vbl->addWidget(filters_check_box_);
 
548
 
 
549
    windows->addAction(filter_dock_widget_->toggleViewAction());
 
550
 
 
551
    //log window
 
552
    QDockWidget* log_bar = new QDockWidget("Log", this);
 
553
    addDockWidget(Qt::BottomDockWidgetArea, log_bar);
 
554
    log_ = new QTextEdit(log_bar);
 
555
    log_->setReadOnly(true);
 
556
    log_->setContextMenuPolicy(Qt::CustomContextMenu);
 
557
    connect(log_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(logContextMenu(const QPoint &)));
 
558
    log_bar->setWidget(log_);
 
559
    log_bar->hide();
 
560
    windows->addAction(log_bar->toggleViewAction());
 
561
 
 
562
    //################## DEFAULTS #################
 
563
    initializeDefaultParameters_();
 
564
 
 
565
    // store defaults in param_
 
566
    defaultsToParam_();
 
567
 
 
568
    //load param file
 
569
    loadPreferences();
 
570
 
 
571
    //set current path
 
572
    current_path_ = param_.getValue("preferences:default_path");
 
573
 
 
574
    //update the menu
 
575
    updateMenu();
 
576
 
 
577
    topp_.process = 0;
 
578
 
 
579
    //######################### File System Watcher ###########################################
 
580
    watcher_ = new FileWatcher(this);
 
581
    connect(watcher_, SIGNAL(fileChanged(const String &)), this, SLOT(fileChanged_(const String &)));
 
582
  }
592
583
 
593
584
  void TOPPViewBase::initializeDefaultParameters_()
594
585
  {
595
586
    //general
596
587
    defaults_.setValue("preferences:default_map_view", "2d", "Default visualization mode for maps.");
597
 
    defaults_.setValidStrings("preferences:default_map_view",StringList::create("2d,3d"));
 
588
    defaults_.setValidStrings("preferences:default_map_view", StringList::create("2d,3d"));
598
589
    defaults_.setValue("preferences:default_path", ".", "Default path for loading and storing files.");
599
590
    defaults_.setValue("preferences:default_path_current", "true", "If the current path is preferred over the default path.");
600
 
    defaults_.setValidStrings("preferences:default_path_current",StringList::create("true,false"));
 
591
    defaults_.setValidStrings("preferences:default_path_current", StringList::create("true,false"));
601
592
    defaults_.setValue("preferences:tmp_file_path", QDir::tempPath(), "Path where temporary files can be created.");
602
593
    defaults_.setValue("preferences:number_of_recent_files", 15, "Number of recent files in the main menu.");
603
 
    defaults_.setMinInt("preferences:number_of_recent_files",5);
604
 
    defaults_.setMaxInt("preferences:number_of_recent_files",20);
 
594
    defaults_.setMinInt("preferences:number_of_recent_files", 5);
 
595
    defaults_.setMaxInt("preferences:number_of_recent_files", 20);
605
596
    defaults_.setValue("preferences:legend", "show", "Legend visibility");
606
 
    defaults_.setValidStrings("preferences:legend",StringList::create("show,hide"));
607
 
    defaults_.setValue("preferences:intensity_cutoff", "off","Low intensity cutoff for maps.");
608
 
    defaults_.setValidStrings("preferences:intensity_cutoff",StringList::create("on,off"));
609
 
    defaults_.setValue("preferences:on_file_change","ask","What action to take, when a data file changes. Do nothing, update automatically or ask the user.");
610
 
    defaults_.setValidStrings("preferences:on_file_change",StringList::create("none,ask,update automatically"));
 
597
    defaults_.setValidStrings("preferences:legend", StringList::create("show,hide"));
 
598
    defaults_.setValue("preferences:intensity_cutoff", "off", "Low intensity cutoff for maps.");
 
599
    defaults_.setValidStrings("preferences:intensity_cutoff", StringList::create("on,off"));
 
600
    defaults_.setValue("preferences:on_file_change", "ask", "What action to take, when a data file changes. Do nothing, update automatically or ask the user.");
 
601
    defaults_.setValidStrings("preferences:on_file_change", StringList::create("none,ask,update automatically"));
611
602
    defaults_.setValue("preferences:topp_cleanup", "true", "If the temporary files for calling of TOPP tools should be removed after the call.");
612
 
    defaults_.setValidStrings("preferences:topp_cleanup",StringList::create("true,false"));
 
603
    defaults_.setValidStrings("preferences:topp_cleanup", StringList::create("true,false"));
613
604
    //db
614
605
    defaults_.setValue("preferences:db:host", "localhost", "Database server host name.");
615
606
    defaults_.setValue("preferences:db:login", "NoName", "Database login.");
616
607
    defaults_.setValue("preferences:db:name", "OpenMS", "Database name.");
617
608
    defaults_.setValue("preferences:db:port", 3306, "Database server port.");
618
 
    defaults_.setSectionDescription("preferences:db","Database settings.");
 
609
    defaults_.setSectionDescription("preferences:db", "Database settings.");
619
610
    // 1d view
620
 
    Spectrum1DCanvas* def1 = new Spectrum1DCanvas(Param(),0);
621
 
    defaults_.insert("preferences:1d:",def1->getDefaults());
 
611
    Spectrum1DCanvas* def1 = new Spectrum1DCanvas(Param(), 0);
 
612
    defaults_.insert("preferences:1d:", def1->getDefaults());
622
613
    delete def1;
623
 
    defaults_.setSectionDescription("preferences:1d","Settings for single spectrum view.");
 
614
    defaults_.setSectionDescription("preferences:1d", "Settings for single spectrum view.");
624
615
    // 2d view
625
 
    Spectrum2DCanvas* def2 = new Spectrum2DCanvas(Param(),0);
626
 
    defaults_.insert("preferences:2d:",def2->getDefaults());
627
 
    defaults_.setSectionDescription("preferences:2d","Settings for 2D map view.");
 
616
    Spectrum2DCanvas* def2 = new Spectrum2DCanvas(Param(), 0);
 
617
    defaults_.insert("preferences:2d:", def2->getDefaults());
 
618
    defaults_.setSectionDescription("preferences:2d", "Settings for 2D map view.");
628
619
    delete def2;
629
620
    // 3d view
630
 
    Spectrum3DCanvas* def3 = new Spectrum3DCanvas(Param(),0);
631
 
    defaults_.insert("preferences:3d:",def3->getDefaults());
 
621
    Spectrum3DCanvas* def3 = new Spectrum3DCanvas(Param(), 0);
 
622
    defaults_.insert("preferences:3d:", def3->getDefaults());
632
623
    delete def3;
633
 
    defaults_.setSectionDescription("preferences:3d","Settings for 3D map view.");
 
624
    defaults_.setSectionDescription("preferences:3d", "Settings for 3D map view.");
634
625
    // identification view
635
 
    SpectraIdentificationViewWidget* def4 = new SpectraIdentificationViewWidget(Param(),0);
636
 
    defaults_.insert("preferences:idview:",def4->getDefaults());
 
626
    SpectraIdentificationViewWidget* def4 = new SpectraIdentificationViewWidget(Param(), 0);
 
627
    defaults_.insert("preferences:idview:", def4->getDefaults());
637
628
    delete def4;
638
 
    defaults_.setSectionDescription("preferences:idview","Settings for identification view.");
639
 
    defaults_.setValue("preferences:version","none","OpenMS version, used to check if the TOPPView.ini is up-to-date");
 
629
    defaults_.setSectionDescription("preferences:idview", "Settings for identification view.");
 
630
    defaults_.setValue("preferences:version", "none", "OpenMS version, used to check if the TOPPView.ini is up-to-date");
640
631
    subsections_.push_back("preferences:RecentFiles");
641
632
  }
642
633
 
646
637
    event->accept();
647
638
  }
648
639
 
 
640
 
649
641
  void TOPPViewBase::showURL()
650
642
  {
651
 
      QAction* action = qobject_cast<QAction*>(sender());
652
 
      if (!QDesktopServices::openUrl(QUrl(action->data().toString())))
653
 
      {
654
 
          QMessageBox::warning(this, tr("Error"),
655
 
                               tr("Unable to open\n") +
656
 
                               action->data().toString() +
657
 
                               tr("\n\nPossible reason: security settings or misconfigured Operating System"));
658
 
      }
 
643
    // NOTE: This code identical to TOPPASBase::showURL(), if you change anything here
 
644
    //       you probably need to change it also there.
 
645
    
 
646
    QAction* action = qobject_cast<QAction*>(sender());
 
647
    QString target = action->data().toString();
 
648
    QUrl url_target;
 
649
    
 
650
    // add protocol handler if none is given
 
651
    if (!(target.startsWith("http://") || target.startsWith("https://")))
 
652
    {
 
653
      // we expect all unqualified urls to be file urls
 
654
      try
 
655
      {
 
656
        String local_url = File::findDoc(target);
 
657
        url_target = QUrl::fromLocalFile(local_url.toQString());
 
658
      }
 
659
      catch (Exception::FileNotFound&)
 
660
      {
 
661
        // we fall back to the web url
 
662
        url_target = QUrl(QString("http://www.openms.de/current_doxygen/%1").arg(target), QUrl::TolerantMode);
 
663
      }
 
664
    }
 
665
    else
 
666
    {
 
667
      url_target = QUrl(target, QUrl::TolerantMode);
 
668
    }
 
669
    
 
670
    if (!QDesktopServices::openUrl(url_target))
 
671
    {
 
672
      QMessageBox::warning(this, tr("Error"),
 
673
                           tr("Unable to open\n") +
 
674
                           action->data().toString() +
 
675
                           tr("\n\nPossible reason: security settings or misconfigured Operating System"));
 
676
    }
659
677
  }
660
678
 
 
679
 
661
680
  void TOPPViewBase::addDataDB(UInt db_id, bool show_options, String caption, UInt window_id)
662
681
  {
663
682
    //set wait cursor
692
711
    }
693
712
    catch (Exception::BaseException& e)
694
713
    {
695
 
      QMessageBox::critical(this,"Error",(String("Error while reading data: ")+e.what()).c_str());
 
714
      QMessageBox::critical(this, "Error", (String("Error while reading data: ") + e.what()).c_str());
696
715
      setCursor(Qt::ArrowCursor);
697
716
      return;
698
717
    }
700
719
    exp_sptr->updateRanges(1);
701
720
 
702
721
    //determine if the data is 1D or 2D
703
 
    QSqlQuery result = con.executeQuery(String("SELECT count(id) from DATA_Spectrum where fid_MSExperiment='")+db_id+"' and MSLevel='1'");
704
 
    LayerData::DataType data_type = ((result.value(0).toInt()>1) ?
 
722
    QSqlQuery result = con.executeQuery(String("SELECT count(id) from DATA_Spectrum where fid_MSExperiment='") + db_id + "' and MSLevel='1'");
 
723
    LayerData::DataType data_type = ((result.value(0).toInt() > 1) ?
705
724
                                     LayerData::DT_PEAK :
706
725
                                     LayerData::DT_CHROMATOGRAM);
707
726
 
708
727
    //add data
709
 
    if (caption=="") caption = String("DB entry ")+db_id;
 
728
    if (caption == "")
 
729
      caption = String("DB entry ") + db_id;
710
730
    addData(dummy_map_sptr, dummy_map2_sptr, dummy_peptides, exp_sptr, data_type, false, show_options, true, "", caption, window_id);
711
731
 
712
732
    //Reset cursor
720
740
    bool ms1_present = false;
721
741
    for (Size i = 0; i < exp.size(); ++i)
722
742
    {
723
 
        if (exp[i].getMSLevel() == 1)
724
 
        {
725
 
            ms1_present = true;
726
 
            break;
727
 
        }
 
743
      if (exp[i].getMSLevel() == 1)
 
744
      {
 
745
        ms1_present = true;
 
746
        break;
 
747
      }
728
748
    }
729
749
    return ms1_present;
730
750
  }
742
762
    srand(time(0));
743
763
    while (count < n_scans)
744
764
    {
745
 
      UInt scan = (UInt)( (double)rand() / ((double)(RAND_MAX)+1.0f) * (double)(exp.size()-1) );
 
765
      UInt scan = (UInt)((double)rand() / ((double)(RAND_MAX)+1.0f) * (double)(exp.size() - 1));
746
766
 
747
 
      if (scan < exp.size() && exp[scan].getMSLevel()==1 && exp[scan].size()!=0)
 
767
      if (scan < exp.size() && exp[scan].getMSLevel() == 1 && exp[scan].size() != 0)
748
768
      {
749
769
        vector<float> tmp;
750
770
        tmp.reserve(exp[scan].size());
751
 
        for(SpectrumType::ConstIterator it = exp[scan].begin()
752
 
          ; it != exp[scan].end()
753
 
              ; ++it)
 
771
        for (SpectrumType::ConstIterator it = exp[scan].begin()
 
772
             ; it != exp[scan].end()
 
773
             ; ++it)
754
774
        {
755
775
          tmp.push_back(it->getIntensity());
756
776
        }
757
 
        std::sort(tmp.begin(),tmp.end());
758
 
        noise += tmp[(UInt)ceil((float)(tmp.size()-1)/1.25f)];
 
777
        std::sort(tmp.begin(), tmp.end());
 
778
        noise += tmp[(UInt)ceil((float)(tmp.size() - 1) / 1.25f)];
759
779
        ++count;
760
780
      }
761
781
    }
777
797
      {
778
798
        continue;
779
799
      }
780
 
      for(Size j = 0; j != exp[i].size(); ++j)
 
800
      for (Size j = 0; j != exp[i].size(); ++j)
781
801
      {
782
802
        DoubleReal intensity = exp[i][j].getIntensity();
783
803
        if (intensity == 0.0)
792
812
  // static
793
813
  bool TOPPViewBase::hasPeptideIdentifications(const ExperimentType& map)
794
814
  {
795
 
    for(Size i = 0; i!= map.size(); ++i)
 
815
    for (Size i = 0; i != map.size(); ++i)
796
816
    {
797
 
      if ( !map[i].getPeptideIdentifications().empty())
 
817
      if (!map[i].getPeptideIdentifications().empty())
798
818
      {
799
819
        return true;
800
820
      }
804
824
 
805
825
  void TOPPViewBase::preferencesDialog()
806
826
  {
807
 
                Internal::TOPPViewPrefDialog dlg(this);
 
827
    Internal::TOPPViewPrefDialog dlg(this);
808
828
 
809
829
    // --------------------------------------------------------------------
810
830
    // Get pointers to the widget in the preferences dialog
811
831
 
812
832
    // default tab
813
 
                QLineEdit* default_path = dlg.findChild<QLineEdit*>("default_path");
814
 
                QCheckBox* default_path_current = dlg.findChild<QCheckBox*>("default_path_current");
815
 
                QLineEdit* temp_path = dlg.findChild<QLineEdit*>("temp_path");
816
 
                QSpinBox* recent_files = dlg.findChild<QSpinBox*>("recent_files");
817
 
                QComboBox* map_default = dlg.findChild<QComboBox*>("map_default");
818
 
                QComboBox* map_cutoff = dlg.findChild<QComboBox*>("map_cutoff");
819
 
                QComboBox* on_file_change = dlg.findChild<QComboBox*>("on_file_change");
 
833
    QLineEdit* default_path = dlg.findChild<QLineEdit*>("default_path");
 
834
    QCheckBox* default_path_current = dlg.findChild<QCheckBox*>("default_path_current");
 
835
    QLineEdit* temp_path = dlg.findChild<QLineEdit*>("temp_path");
 
836
    QSpinBox* recent_files = dlg.findChild<QSpinBox*>("recent_files");
 
837
    QComboBox* map_default = dlg.findChild<QComboBox*>("map_default");
 
838
    QComboBox* map_cutoff = dlg.findChild<QComboBox*>("map_cutoff");
 
839
    QComboBox* on_file_change = dlg.findChild<QComboBox*>("on_file_change");
820
840
 
821
841
    // db tab
822
 
                QLineEdit* db_host = dlg.findChild<QLineEdit*>("db_host");
823
 
                QSpinBox* db_port = dlg.findChild<QSpinBox*>("db_port");
824
 
                QLineEdit* db_name = dlg.findChild<QLineEdit*>("db_name");
825
 
                QLineEdit* db_login = dlg.findChild<QLineEdit*>("db_login");
 
842
    QLineEdit* db_host = dlg.findChild<QLineEdit*>("db_host");
 
843
    QSpinBox* db_port = dlg.findChild<QSpinBox*>("db_port");
 
844
    QLineEdit* db_name = dlg.findChild<QLineEdit*>("db_name");
 
845
    QLineEdit* db_login = dlg.findChild<QLineEdit*>("db_login");
826
846
 
827
847
    // 1D view tab
828
 
                ColorSelector* color_1D = dlg.findChild<ColorSelector*>("color_1D");
829
 
                ColorSelector* selected_1D = dlg.findChild<ColorSelector*>("selected_1D");
830
 
                ColorSelector* icon_1D = dlg.findChild<ColorSelector*>("icon_1D");
 
848
    ColorSelector* color_1D = dlg.findChild<ColorSelector*>("color_1D");
 
849
    ColorSelector* selected_1D = dlg.findChild<ColorSelector*>("selected_1D");
 
850
    ColorSelector* icon_1D = dlg.findChild<ColorSelector*>("icon_1D");
831
851
 
832
852
    // 2D view tab
833
 
                MultiGradientSelector* peak_2D = dlg.findChild<MultiGradientSelector*>("peak_2D");
834
 
                QComboBox* mapping_2D = dlg.findChild<QComboBox*>("mapping_2D");
835
 
                QComboBox* feature_icon_2D = dlg.findChild<QComboBox*>("feature_icon_2D");
836
 
                QSpinBox* feature_icon_size_2D = dlg.findChild<QSpinBox*>("feature_icon_size_2D");
 
853
    MultiGradientSelector* peak_2D = dlg.findChild<MultiGradientSelector*>("peak_2D");
 
854
    QComboBox* mapping_2D = dlg.findChild<QComboBox*>("mapping_2D");
 
855
    QComboBox* feature_icon_2D = dlg.findChild<QComboBox*>("feature_icon_2D");
 
856
    QSpinBox* feature_icon_size_2D = dlg.findChild<QSpinBox*>("feature_icon_size_2D");
837
857
 
838
858
    // 3D view tab
839
 
                MultiGradientSelector* peak_3D = dlg.findChild<MultiGradientSelector*>("peak_3D");
840
 
                QComboBox* shade_3D = dlg.findChild<QComboBox*>("shade_3D");
841
 
                QSpinBox* line_width_3D  = dlg.findChild<QSpinBox*>("line_width_3D");
 
859
    MultiGradientSelector* peak_3D = dlg.findChild<MultiGradientSelector*>("peak_3D");
 
860
    QComboBox* shade_3D = dlg.findChild<QComboBox*>("shade_3D");
 
861
    QSpinBox* line_width_3D  = dlg.findChild<QSpinBox*>("line_width_3D");
842
862
 
843
863
    // identification view tab
844
864
    QListWidget* id_view_ions = dlg.findChild<QListWidget*>("ions_list_widget");
850
870
    QDoubleSpinBox* z_intensity = dlg.findChild<QDoubleSpinBox*>("z_intensity");
851
871
 
852
872
    QDoubleSpinBox* tolerance = dlg.findChild<QDoubleSpinBox*>("tolerance");
853
 
    QCheckBox* is_relative_tolerance = dlg.findChild<QCheckBox*>("unit_is_ppm");
854
873
 
855
874
    QDoubleSpinBox* relative_loss_intensity = dlg.findChild<QDoubleSpinBox*>("relative_loss_intensity");
856
 
    QSpinBox* max_isotopes = dlg.findChild<QSpinBox*>("max_isotopes");
857
 
    QSpinBox* charge = dlg.findChild<QSpinBox*>("charge");
858
875
 
859
876
    QList<QListWidgetItem*> a_ions = id_view_ions->findItems("A-ions", Qt::MatchFixedString);
860
877
    QList<QListWidgetItem*> b_ions = id_view_ions->findItems("B-ions", Qt::MatchFixedString);
871
888
    // Set dialog entries from current parameter object (default values)
872
889
 
873
890
    // default
874
 
                default_path->setText(param_.getValue("preferences:default_path").toQString());
875
 
                if ((String)param_.getValue("preferences:default_path_current")=="true")
876
 
                {
877
 
                        default_path_current->setChecked(true);
878
 
                }
879
 
                else
880
 
                {
881
 
                        default_path_current->setChecked(false);
882
 
                }
883
 
                temp_path->setText(param_.getValue("preferences:tmp_file_path").toQString());
884
 
                recent_files->setValue((Int)param_.getValue("preferences:number_of_recent_files"));
885
 
                map_default->setCurrentIndex(map_default->findText(param_.getValue("preferences:default_map_view").toQString()));
886
 
                map_cutoff->setCurrentIndex(map_cutoff->findText(param_.getValue("preferences:intensity_cutoff").toQString()));
887
 
                on_file_change->setCurrentIndex(on_file_change->findText(param_.getValue("preferences:on_file_change").toQString()));
 
891
    default_path->setText(param_.getValue("preferences:default_path").toQString());
 
892
    if ((String)param_.getValue("preferences:default_path_current") == "true")
 
893
    {
 
894
      default_path_current->setChecked(true);
 
895
    }
 
896
    else
 
897
    {
 
898
      default_path_current->setChecked(false);
 
899
    }
 
900
    temp_path->setText(param_.getValue("preferences:tmp_file_path").toQString());
 
901
    recent_files->setValue((Int)param_.getValue("preferences:number_of_recent_files"));
 
902
    map_default->setCurrentIndex(map_default->findText(param_.getValue("preferences:default_map_view").toQString()));
 
903
    map_cutoff->setCurrentIndex(map_cutoff->findText(param_.getValue("preferences:intensity_cutoff").toQString()));
 
904
    on_file_change->setCurrentIndex(on_file_change->findText(param_.getValue("preferences:on_file_change").toQString()));
888
905
 
889
906
    // db
890
 
                db_host->setText(param_.getValue("preferences:db:host").toQString());
891
 
                db_port->setValue((Int)param_.getValue("preferences:db:port"));
892
 
                db_name->setText(param_.getValue("preferences:db:name").toQString());
893
 
                db_login->setText(param_.getValue("preferences:db:login").toQString());
 
907
    db_host->setText(param_.getValue("preferences:db:host").toQString());
 
908
    db_port->setValue((Int)param_.getValue("preferences:db:port"));
 
909
    db_name->setText(param_.getValue("preferences:db:name").toQString());
 
910
    db_login->setText(param_.getValue("preferences:db:login").toQString());
894
911
 
895
912
    // 1D view
896
 
                color_1D->setColor(QColor(param_.getValue("preferences:1d:peak_color").toQString()));
897
 
                selected_1D->setColor(QColor(param_.getValue("preferences:1d:highlighted_peak_color").toQString()));
898
 
                icon_1D->setColor(QColor(param_.getValue("preferences:1d:icon_color").toQString()));
 
913
    color_1D->setColor(QColor(param_.getValue("preferences:1d:peak_color").toQString()));
 
914
    selected_1D->setColor(QColor(param_.getValue("preferences:1d:highlighted_peak_color").toQString()));
 
915
    icon_1D->setColor(QColor(param_.getValue("preferences:1d:icon_color").toQString()));
899
916
 
900
917
    // 2D view
901
 
                peak_2D->gradient().fromString(param_.getValue("preferences:2d:dot:gradient"));
902
 
                mapping_2D->setCurrentIndex(mapping_2D->findText(param_.getValue("preferences:2d:mapping_of_mz_to").toQString()));
903
 
                feature_icon_2D->setCurrentIndex(feature_icon_2D->findText(param_.getValue("preferences:2d:dot:feature_icon").toQString()));
904
 
                feature_icon_size_2D->setValue((Int)param_.getValue("preferences:2d:dot:feature_icon_size"));
 
918
    peak_2D->gradient().fromString(param_.getValue("preferences:2d:dot:gradient"));
 
919
    mapping_2D->setCurrentIndex(mapping_2D->findText(param_.getValue("preferences:2d:mapping_of_mz_to").toQString()));
 
920
    feature_icon_2D->setCurrentIndex(feature_icon_2D->findText(param_.getValue("preferences:2d:dot:feature_icon").toQString()));
 
921
    feature_icon_size_2D->setValue((Int)param_.getValue("preferences:2d:dot:feature_icon_size"));
905
922
 
906
923
    // 3D view
907
 
                peak_3D->gradient().fromString(param_.getValue("preferences:3d:dot:gradient"));
908
 
                shade_3D->setCurrentIndex((Int)param_.getValue("preferences:3d:dot:shade_mode"));
909
 
                line_width_3D->setValue((Int)param_.getValue("preferences:3d:dot:line_width"));
 
924
    peak_3D->gradient().fromString(param_.getValue("preferences:3d:dot:gradient"));
 
925
    shade_3D->setCurrentIndex((Int)param_.getValue("preferences:3d:dot:shade_mode"));
 
926
    line_width_3D->setValue((Int)param_.getValue("preferences:3d:dot:line_width"));
910
927
 
911
928
    // id view
912
929
    a_intensity->setValue((DoubleReal)param_.getValue("preferences:idview:a_intensity"));
918
935
    tolerance->setValue((DoubleReal)param_.getValue("preferences:idview:tolerance"));
919
936
 
920
937
    relative_loss_intensity->setValue((DoubleReal)param_.getValue("preferences:idview:relative_loss_intensity"));
921
 
    max_isotopes->setValue((Int)param_.getValue("preferences:idview:max_isotope"));
922
 
    charge->setValue((Int)param_.getValue("preferences:idview:charge"));
923
938
 
924
 
    if(a_ions.empty())
 
939
    if (a_ions.empty())
925
940
    {
926
 
      showLogMessage_(LS_ERROR,"", "String 'A-ions' doesn't exist in identification dialog.");
927
 
    } else
 
941
      showLogMessage_(LS_ERROR, "", "String 'A-ions' does not exist in identification dialog.");
 
942
    }
 
943
    else
928
944
    {
929
945
      Qt::CheckState state = param_.getValue("preferences:idview:show_a_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
930
946
      a_ions[0]->setCheckState(state);
931
947
    }
932
948
 
933
 
    if(b_ions.empty())
 
949
    if (b_ions.empty())
934
950
    {
935
 
      showLogMessage_(LS_ERROR,"", "String 'B-ions' doesn't exist in identification dialog.");
936
 
    } else
 
951
      showLogMessage_(LS_ERROR, "", "String 'B-ions' does not exist in identification dialog.");
 
952
    }
 
953
    else
937
954
    {
938
955
      Qt::CheckState state = param_.getValue("preferences:idview:show_b_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
939
956
      b_ions[0]->setCheckState(state);
940
957
    }
941
958
 
942
 
    if(c_ions.empty())
 
959
    if (c_ions.empty())
943
960
    {
944
 
      showLogMessage_(LS_ERROR,"", "String 'C-ions' doesn't exist in identification dialog.");
945
 
    } else
 
961
      showLogMessage_(LS_ERROR, "", "String 'C-ions' does not exist in identification dialog.");
 
962
    }
 
963
    else
946
964
    {
947
965
      Qt::CheckState state = param_.getValue("preferences:idview:show_c_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
948
966
      c_ions[0]->setCheckState(state);
949
967
    }
950
968
 
951
 
    if(x_ions.empty())
 
969
    if (x_ions.empty())
952
970
    {
953
 
      showLogMessage_(LS_ERROR,"", "String 'X-ions' doesn't exist in identification dialog.");
954
 
    } else
 
971
      showLogMessage_(LS_ERROR, "", "String 'X-ions' does not exist in identification dialog.");
 
972
    }
 
973
    else
955
974
    {
956
975
      Qt::CheckState state = param_.getValue("preferences:idview:show_x_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
957
976
      x_ions[0]->setCheckState(state);
958
977
    }
959
978
 
960
 
    if(y_ions.empty())
 
979
    if (y_ions.empty())
961
980
    {
962
 
      showLogMessage_(LS_ERROR,"", "String 'Y-ions' doesn't exist in identification dialog.");
963
 
    } else
 
981
      showLogMessage_(LS_ERROR, "", "String 'Y-ions' does not exist in identification dialog.");
 
982
    }
 
983
    else
964
984
    {
965
985
      Qt::CheckState state = param_.getValue("preferences:idview:show_y_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
966
986
      y_ions[0]->setCheckState(state);
967
987
    }
968
988
 
969
 
    if(z_ions.empty())
 
989
    if (z_ions.empty())
970
990
    {
971
 
      showLogMessage_(LS_ERROR,"", "String 'Z-ions' doesn't exist in identification dialog.");
972
 
    } else
 
991
      showLogMessage_(LS_ERROR, "", "String 'Z-ions' does not exist in identification dialog.");
 
992
    }
 
993
    else
973
994
    {
974
995
      Qt::CheckState state = param_.getValue("preferences:idview:show_z_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
975
996
      z_ions[0]->setCheckState(state);
976
997
    }
977
998
 
978
 
    if(pc_ions.empty())
 
999
    if (pc_ions.empty())
979
1000
    {
980
 
      showLogMessage_(LS_ERROR,"", "String 'Precursor' doesn't exist in identification dialog.");
981
 
    } else
 
1001
      showLogMessage_(LS_ERROR, "", "String 'Precursor' does not exist in identification dialog.");
 
1002
    }
 
1003
    else
982
1004
    {
983
1005
      Qt::CheckState state = param_.getValue("preferences:idview:show_precursor").toBool() == true ? Qt::Checked : Qt::Unchecked;
984
1006
      pc_ions[0]->setCheckState(state);
985
1007
    }
986
1008
 
987
 
    if(nl_ions.empty())
 
1009
    if (nl_ions.empty())
988
1010
    {
989
 
      showLogMessage_(LS_ERROR,"", "String 'Neutral losses' doesn't exist in identification dialog.");
990
 
    } else
 
1011
      showLogMessage_(LS_ERROR, "", "String 'Neutral losses' does not exist in identification dialog.");
 
1012
    }
 
1013
    else
991
1014
    {
992
1015
      Qt::CheckState state = param_.getValue("preferences:idview:add_losses").toBool() == true ? Qt::Checked : Qt::Unchecked;
993
1016
      nl_ions[0]->setCheckState(state);
994
1017
    }
995
1018
 
996
 
    if(ic_ions.empty())
 
1019
    if (ic_ions.empty())
997
1020
    {
998
 
      showLogMessage_(LS_ERROR,"", "String 'Isotope clusters' doesn't exist in identification dialog.");
999
 
    } else
 
1021
      showLogMessage_(LS_ERROR, "", "String 'Isotope clusters' does not exist in identification dialog.");
 
1022
    }
 
1023
    else
1000
1024
    {
1001
1025
      Qt::CheckState state = param_.getValue("preferences:idview:add_isotopes").toBool() == true ? Qt::Checked : Qt::Unchecked;
1002
1026
      ic_ions[0]->setCheckState(state);
1003
1027
    }
1004
1028
 
1005
 
    if(ai_ions.empty())
 
1029
    if (ai_ions.empty())
1006
1030
    {
1007
 
      showLogMessage_(LS_ERROR,"", "String 'Abundant immonium-ions' doesn't exist in identification dialog.");
1008
 
    } else
 
1031
      showLogMessage_(LS_ERROR, "", "String 'Abundant immonium-ions' does not exist in identification dialog.");
 
1032
    }
 
1033
    else
1009
1034
    {
1010
1035
      Qt::CheckState state = param_.getValue("preferences:idview:add_abundant_immonium_ions").toBool() == true ? Qt::Checked : Qt::Unchecked;
1011
1036
      ai_ions[0]->setCheckState(state);
1012
1037
    }
1013
1038
 
1014
 
    if(is_relative_tolerance == 0)
1015
 
    {
1016
 
      showLogMessage_(LS_ERROR,"", "String 'unit is ppm' doesn't exist in identification dialog.");
1017
 
    } else
1018
 
    {
1019
 
      Qt::CheckState state = param_.getValue("preferences:idview:is_relative_tolerance").toBool() == true ? Qt::Checked : Qt::Unchecked;
1020
 
      is_relative_tolerance->setCheckState(state);
1021
 
    }
1022
 
 
1023
1039
    // --------------------------------------------------------------------
1024
1040
    // Execute dialog and update parameter object with user modified values
1025
 
                if (dlg.exec())
1026
 
                {
1027
 
                        param_.setValue("preferences:default_path", default_path->text());
1028
 
                        if (default_path_current->isChecked())
1029
 
                        {
1030
 
                                param_.setValue("preferences:default_path_current","true");
1031
 
                        }
1032
 
                        else
1033
 
                        {
1034
 
                                param_.setValue("preferences:default_path_current","false");
1035
 
                        }
1036
 
                        param_.setValue("preferences:tmp_file_path", temp_path->text());
1037
 
                        param_.setValue("preferences:number_of_recent_files", recent_files->value());
1038
 
                        param_.setValue("preferences:default_map_view", map_default->currentText());
1039
 
                        param_.setValue("preferences:intensity_cutoff", map_cutoff->currentText());
1040
 
                        param_.setValue("preferences:on_file_change", on_file_change->currentText());
1041
 
 
1042
 
                        param_.setValue("preferences:db:host",db_host->text());
1043
 
                        param_.setValue("preferences:db:port",db_port->value());
1044
 
                        param_.setValue("preferences:db:name",db_name->text());
1045
 
                        param_.setValue("preferences:db:login",db_login->text());
1046
 
                        param_.remove("DBPassword");
1047
 
 
1048
 
                        param_.setValue("preferences:1d:peak_color",color_1D->getColor().name());
1049
 
                        param_.setValue("preferences:1d:highlighted_peak_color",selected_1D->getColor().name());
1050
 
                        param_.setValue("preferences:1d:icon_color",icon_1D->getColor().name());
1051
 
 
1052
 
                        param_.setValue("preferences:2d:dot:gradient",peak_2D->gradient().toString());
1053
 
                        param_.setValue("preferences:2d:mapping_of_mz_to",mapping_2D->currentText());
1054
 
                        param_.setValue("preferences:2d:dot:feature_icon",feature_icon_2D->currentText());
1055
 
                        param_.setValue("preferences:2d:dot:feature_icon_size",feature_icon_size_2D->value());
1056
 
 
1057
 
                        param_.setValue("preferences:3d:dot:gradient",peak_3D->gradient().toString());
1058
 
                        param_.setValue("preferences:3d:dot:shade_mode", shade_3D->currentIndex());
1059
 
                        param_.setValue("preferences:3d:dot:line_width",line_width_3D->value());
 
1041
    if (dlg.exec())
 
1042
    {
 
1043
      param_.setValue("preferences:default_path", default_path->text());
 
1044
      if (default_path_current->isChecked())
 
1045
      {
 
1046
        param_.setValue("preferences:default_path_current", "true");
 
1047
      }
 
1048
      else
 
1049
      {
 
1050
        param_.setValue("preferences:default_path_current", "false");
 
1051
      }
 
1052
      param_.setValue("preferences:tmp_file_path", temp_path->text());
 
1053
      param_.setValue("preferences:number_of_recent_files", recent_files->value());
 
1054
      param_.setValue("preferences:default_map_view", map_default->currentText());
 
1055
      param_.setValue("preferences:intensity_cutoff", map_cutoff->currentText());
 
1056
      param_.setValue("preferences:on_file_change", on_file_change->currentText());
 
1057
 
 
1058
      param_.setValue("preferences:db:host", db_host->text());
 
1059
      param_.setValue("preferences:db:port", db_port->value());
 
1060
      param_.setValue("preferences:db:name", db_name->text());
 
1061
      param_.setValue("preferences:db:login", db_login->text());
 
1062
      param_.remove("DBPassword");
 
1063
 
 
1064
      param_.setValue("preferences:1d:peak_color", color_1D->getColor().name());
 
1065
      param_.setValue("preferences:1d:highlighted_peak_color", selected_1D->getColor().name());
 
1066
      param_.setValue("preferences:1d:icon_color", icon_1D->getColor().name());
 
1067
 
 
1068
      param_.setValue("preferences:2d:dot:gradient", peak_2D->gradient().toString());
 
1069
      param_.setValue("preferences:2d:mapping_of_mz_to", mapping_2D->currentText());
 
1070
      param_.setValue("preferences:2d:dot:feature_icon", feature_icon_2D->currentText());
 
1071
      param_.setValue("preferences:2d:dot:feature_icon_size", feature_icon_size_2D->value());
 
1072
 
 
1073
      param_.setValue("preferences:3d:dot:gradient", peak_3D->gradient().toString());
 
1074
      param_.setValue("preferences:3d:dot:shade_mode", shade_3D->currentIndex());
 
1075
      param_.setValue("preferences:3d:dot:line_width", line_width_3D->value());
1060
1076
 
1061
1077
      // id view
1062
1078
      param_.setValue("preferences:idview:a_intensity", a_intensity->value(), "Default intensity of a-ions");
1066
1082
      param_.setValue("preferences:idview:y_intensity", y_intensity->value(), "Default intensity of y-ions");
1067
1083
      param_.setValue("preferences:idview:z_intensity", z_intensity->value(), "Default intensity of z-ions");
1068
1084
      param_.setValue("preferences:idview:relative_loss_intensity", relative_loss_intensity->value(), "Relativ loss in percent");
1069
 
      param_.setValue("preferences:idview:max_isotope", max_isotopes->value(), "Maximum number of isotopes");
1070
 
      param_.setValue("preferences:idview:charge", charge->value(), "Charge state");
1071
1085
      param_.setValue("preferences:idview:tolerance", tolerance->value(), "Alignment tolerance");
1072
1086
 
1073
1087
      String checked;
1101
1115
      ai_ions[0]->checkState() == Qt::Checked ? checked = "true" : checked = "false";
1102
1116
      param_.setValue("preferences:idview:add_abundant_immonium_ions", checked, "Show abundant immonium ions");
1103
1117
 
1104
 
      is_relative_tolerance->checkState() == Qt::Checked ? checked = "true" : checked = "false";
1105
 
      param_.setValue("preferences:idview:is_relative_tolerance", checked, "Use ppm instead of Da for the automatic alignment");
1106
 
                        savePreferences();
1107
 
                }
 
1118
      savePreferences();
 
1119
    }
1108
1120
  }
1109
1121
 
1110
1122
  std::set<String> TOPPViewBase::getFilenamesOfOpenFiles_()
1112
1124
    set<String> filename_set;
1113
1125
    // iterate over all windows
1114
1126
    QWidgetList wl = ws_->windowList();
1115
 
    for(int i=0; i!=ws_->windowList().count(); ++i)
 
1127
    for (int i = 0; i != ws_->windowList().count(); ++i)
1116
1128
    {
1117
1129
      QWidget* w = wl[i];
1118
1130
      // iterate over all widgets
1119
1131
      const SpectrumWidget* sw = qobject_cast<const SpectrumWidget*>(w);
1120
 
      if (sw!=0)
 
1132
      if (sw != 0)
1121
1133
      {
1122
1134
        Size lc = sw->canvas()->getLayerCount();
1123
1135
        // iterate over all layers
1124
 
        for (Size j=0; j!= lc; ++j)
 
1136
        for (Size j = 0; j != lc; ++j)
1125
1137
        {
1126
1138
          filename_set.insert(sw->canvas()->getLayer(j).filename);
1127
1139
        }
1134
1146
  {
1135
1147
    setCursor(Qt::WaitCursor);
1136
1148
 
1137
 
        String abs_filename = File::absolutePath(filename);
 
1149
    String abs_filename = File::absolutePath(filename);
1138
1150
 
1139
1151
    // check if the file exists
1140
1152
    if (!File::exists(abs_filename))
1141
1153
    {
1142
 
      showLogMessage_(LS_ERROR, "Open file error",String("The file '") + abs_filename + "' does not exist!");
1143
 
        setCursor(Qt::ArrowCursor);
 
1154
      showLogMessage_(LS_ERROR, "Open file error", String("The file '") + abs_filename + "' does not exist!");
 
1155
      setCursor(Qt::ArrowCursor);
1144
1156
      return;
1145
1157
    }
1146
1158
 
1147
1159
    // determine file type
1148
 
        FileHandler fh;
1149
 
                FileTypes::Type file_type = fh.getType(abs_filename);
 
1160
    FileHandler fh;
 
1161
    FileTypes::Type file_type = fh.getType(abs_filename);
1150
1162
    if (file_type == FileTypes::UNKNOWN)
1151
 
                {
1152
 
      showLogMessage_(LS_ERROR,"Open file error",String("Could not determine file type of '") + abs_filename + "'!");
1153
 
        setCursor(Qt::ArrowCursor);
 
1163
    {
 
1164
      showLogMessage_(LS_ERROR, "Open file error", String("Could not determine file type of '") + abs_filename + "'!");
 
1165
      setCursor(Qt::ArrowCursor);
1154
1166
      return;
1155
 
                }
 
1167
    }
1156
1168
 
1157
1169
    // abort if file type unsupported
1158
1170
    if (file_type == FileTypes::INI)
1159
 
                {
1160
 
      showLogMessage_(LS_ERROR,"Open file error",String("The type '") + fh.typeToName(file_type) + "' is not supported!");
1161
 
                setCursor(Qt::ArrowCursor);
 
1171
    {
 
1172
      showLogMessage_(LS_ERROR, "Open file error", String("The type '") + FileTypes::typeToName(file_type) + "' is not supported!");
 
1173
      setCursor(Qt::ArrowCursor);
1162
1174
      return;
1163
 
                }
 
1175
    }
1164
1176
 
1165
 
                //try to load data and determine if it's 1D or 2D data
 
1177
    //try to load data and determine if it's 1D or 2D data
1166
1178
 
1167
1179
    // create shared pointer to main data types
1168
1180
    FeatureMapType* feature_map = new FeatureMapType();
1174
1186
    ConsensusMapType* consensus_map = new ConsensusMapType();
1175
1187
    ConsensusMapSharedPtrType consensus_map_sptr(consensus_map);
1176
1188
 
1177
 
                vector<PeptideIdentification> peptides;
 
1189
    vector<PeptideIdentification> peptides;
1178
1190
 
1179
 
                LayerData::DataType data_type;
 
1191
    LayerData::DataType data_type;
1180
1192
 
1181
1193
    try
1182
1194
    {
1183
1195
      if (file_type == FileTypes::FEATUREXML)
1184
 
            {
 
1196
      {
1185
1197
        FeatureXMLFile().load(abs_filename, *feature_map);
1186
 
                                data_type = LayerData::DT_FEATURE;
 
1198
        data_type = LayerData::DT_FEATURE;
1187
1199
      }
1188
1200
      else if (file_type == FileTypes::CONSENSUSXML)
1189
 
            {
 
1201
      {
1190
1202
        ConsensusXMLFile().load(abs_filename, *consensus_map);
1191
 
                                data_type = LayerData::DT_CONSENSUS;
1192
 
      }
1193
 
                        else if (file_type == FileTypes::IDXML)
1194
 
                        {
1195
 
                                vector<ProteinIdentification> proteins; // not needed later
1196
 
                                IdXMLFile().load(abs_filename, proteins, peptides);
1197
 
                                data_type = LayerData::DT_IDENT;
1198
 
                        }
 
1203
        data_type = LayerData::DT_CONSENSUS;
 
1204
      }
 
1205
      else if (file_type == FileTypes::IDXML)
 
1206
      {
 
1207
        vector<ProteinIdentification> proteins; // not needed later
 
1208
        IdXMLFile().load(abs_filename, proteins, peptides);
 
1209
        if (peptides.empty())
 
1210
        {
 
1211
          throw Exception::MissingInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__, "No peptide identifications found");
 
1212
        }
 
1213
        // check if RT (and sequence) information is present:
 
1214
        vector<PeptideIdentification> peptides_with_rt;
 
1215
        for (vector<PeptideIdentification>::const_iterator it =
 
1216
               peptides.begin(); it != peptides.end(); ++it)
 
1217
        {
 
1218
          if (!it->getHits().empty() && it->metaValueExists("RT"))
 
1219
          {
 
1220
            peptides_with_rt.push_back(*it);
 
1221
          }
 
1222
        }
 
1223
        Int diff = peptides.size() - peptides_with_rt.size();
 
1224
        if (diff)
 
1225
        {
 
1226
          String msg = String(diff) + " peptide identification(s) without "
 
1227
                                      "sequence and/or retention time information were removed.\n" +
 
1228
                       peptides_with_rt.size() + " peptide identification(s) remaining.";
 
1229
          showLogMessage_(LS_WARNING, "While loading file:", msg);
 
1230
        }
 
1231
        if (peptides_with_rt.empty())
 
1232
        {
 
1233
          throw Exception::MissingInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__, "No peptide identifications with sufficient information remaining.");
 
1234
        }
 
1235
        peptides.swap(peptides_with_rt);
 
1236
        data_type = LayerData::DT_IDENT;
 
1237
      }
1199
1238
      else
1200
1239
      {
 
1240
        // a mzML file may contain both, chromatogram and peak data
 
1241
        // -> this is handled in SpectrumCanvas::addLayer
1201
1242
        fh.loadExperiment(abs_filename, *peak_map, file_type, ProgressLogger::GUI);
1202
1243
        data_type = LayerData::DT_CHROMATOGRAM;
1203
1244
        if (TOPPViewBase::containsMS1Scans(*peak_map))
1206
1247
        }
1207
1248
      }
1208
1249
    }
1209
 
    catch(Exception::BaseException& e)
 
1250
    catch (Exception::BaseException& e)
1210
1251
    {
1211
 
      showLogMessage_(LS_ERROR,"Error while loading file", e.what());
1212
 
        setCursor(Qt::ArrowCursor);
 
1252
      showLogMessage_(LS_ERROR, "Error while loading file:", e.what());
 
1253
      setCursor(Qt::ArrowCursor);
1213
1254
      return;
1214
1255
    }
1215
1256
 
1219
1260
 
1220
1261
    // try to add the data
1221
1262
    if (caption == "")
1222
 
                {
1223
 
                        caption = File::basename(abs_filename);
 
1263
    {
 
1264
      caption = File::basename(abs_filename);
1224
1265
    }
1225
1266
    else
1226
1267
    {
1227
 
        abs_filename = "";
 
1268
      abs_filename = "";
1228
1269
    }
1229
1270
 
1230
1271
    addData(feature_map_sptr, consensus_map_sptr, peptides, peak_map_sptr, data_type, false, show_options, true, abs_filename, caption, window_id, spectrum_id);
1245
1286
  void TOPPViewBase::addData(FeatureMapSharedPtrType feature_map, ConsensusMapSharedPtrType consensus_map, vector<PeptideIdentification>& peptides, ExperimentSharedPtrType peak_map, LayerData::DataType data_type, bool show_as_1d, bool show_options, bool as_new_window, const String& filename, const String& caption, UInt window_id, Size spectrum_id)
1246
1287
  {
1247
1288
    // initialize flags with defaults from the parameters
1248
 
        bool maps_as_2d = ((String)param_.getValue("preferences:default_map_view")=="2d");
1249
 
        bool maps_as_1d = false;
1250
 
    bool use_intensity_cutoff = ((String)param_.getValue("preferences:intensity_cutoff")=="on");
 
1289
    bool maps_as_2d = ((String)param_.getValue("preferences:default_map_view") == "2d");
 
1290
    bool maps_as_1d = false;
 
1291
    bool use_intensity_cutoff = ((String)param_.getValue("preferences:intensity_cutoff") == "on");
1251
1292
 
1252
1293
    // feature, consensus feature and identifications can be merged
1253
 
                bool mergeable = ((data_type == LayerData::DT_FEATURE) ||
1254
 
                                                                                        (data_type == LayerData::DT_CONSENSUS) ||
1255
 
                                                                                        (data_type == LayerData::DT_IDENT));
 
1294
    bool mergeable = ((data_type == LayerData::DT_FEATURE) ||
 
1295
                      (data_type == LayerData::DT_CONSENSUS) ||
 
1296
                      (data_type == LayerData::DT_IDENT));
1256
1297
 
1257
1298
    // only one peak spectrum? disable 2D as default
1258
1299
    if (peak_map->size() == 1)
1268
1309
    SpectrumWidget* target_window = dynamic_cast<SpectrumWidget*>(tab_bar_target);
1269
1310
 
1270
1311
    if (tab_bar_target == 0)
1271
 
                {
 
1312
    {
1272
1313
      target_window = getActiveSpectrumWidget();
1273
 
                }
 
1314
    }
1274
1315
    else
1275
 
                {
1276
 
                        as_new_window = false;
1277
 
                }
 
1316
    {
 
1317
      as_new_window = false;
 
1318
    }
1278
1319
 
1279
1320
    //create dialog no matter if it is shown or not. It is used to determine the flags.
1280
1321
    TOPPViewOpenDialog dialog(caption, as_new_window, maps_as_2d, use_intensity_cutoff, this);
1281
1322
 
1282
1323
    //disable opening in new window when there is no active window or feature/ID data is to be opened, but the current window is a 3D window
1283
1324
    if (target_window == 0 || (mergeable && dynamic_cast<Spectrum3DWidget*>(target_window) != 0))
1284
 
                {
1285
 
                        dialog.disableLocation(true);
1286
 
                }
 
1325
    {
 
1326
      dialog.disableLocation(true);
 
1327
    }
1287
1328
 
1288
1329
    //disable 1d/2d/3d option for feature/consensus/identification maps
1289
 
                if (mergeable)
1290
 
                {
1291
 
                        dialog.disableDimension(true);
1292
 
                }
 
1330
    if (mergeable)
 
1331
    {
 
1332
      dialog.disableDimension(true);
 
1333
    }
1293
1334
 
1294
1335
    //disable cutoff for feature/consensus/identification maps
1295
1336
    if (mergeable)
1297
1338
      dialog.disableCutoff(false);
1298
1339
    }
1299
1340
 
1300
 
                //enable merge layers if a feature layer is opened and there are already features layers to merge it to
 
1341
    //enable merge layers if a feature layer is opened and there are already features layers to merge it to
1301
1342
    if (mergeable && target_window != 0) //TODO merge
1302
 
                {
 
1343
    {
1303
1344
      SpectrumCanvas* open_canvas = target_window->canvas();
1304
 
                        Map<Size,String> layers;
1305
 
                        for (Size i=0; i<open_canvas->getLayerCount(); ++i)
1306
 
                        {
1307
 
                                if (data_type == open_canvas->getLayer(i).type)
1308
 
                                {
1309
 
                                        layers[i] = open_canvas->getLayer(i).name;
1310
 
                                }
1311
 
                        }
1312
 
                        dialog.setMergeLayers(layers);
1313
 
                }
 
1345
      Map<Size, String> layers;
 
1346
      for (Size i = 0; i < open_canvas->getLayerCount(); ++i)
 
1347
      {
 
1348
        if (data_type == open_canvas->getLayer(i).type)
 
1349
        {
 
1350
          layers[i] = open_canvas->getLayer(i).name;
 
1351
        }
 
1352
      }
 
1353
      dialog.setMergeLayers(layers);
 
1354
    }
1314
1355
 
1315
 
                //show options if requested
1316
 
                if (show_options && !dialog.exec())
1317
 
                {
1318
 
                        return;
1319
 
                }
1320
 
                as_new_window = dialog.openAsNewWindow();
1321
 
                maps_as_2d = dialog.viewMapAs2D();
1322
 
                maps_as_1d = dialog.viewMapAs1D();
1323
 
                if (show_as_1d)
1324
 
                {
1325
 
                        maps_as_1d = true;
1326
 
                        maps_as_2d = false;
1327
 
                }
 
1356
    //show options if requested
 
1357
    if (show_options && !dialog.exec())
 
1358
    {
 
1359
      return;
 
1360
    }
 
1361
    as_new_window = dialog.openAsNewWindow();
 
1362
    maps_as_2d = dialog.viewMapAs2D();
 
1363
    maps_as_1d = dialog.viewMapAs1D();
 
1364
    if (show_as_1d)
 
1365
    {
 
1366
      maps_as_1d = true;
 
1367
      maps_as_2d = false;
 
1368
    }
1328
1369
 
1329
1370
    use_intensity_cutoff = dialog.isCutoffEnabled();
1330
 
        Int merge_layer = dialog.getMergeLayer();
 
1371
    Int merge_layer = dialog.getMergeLayer();
1331
1372
 
1332
 
                //determine the window to open the data in
1333
 
                if (as_new_window) //new window
 
1373
    //determine the window to open the data in
 
1374
    if (as_new_window) //new window
1334
1375
    {
1335
1376
      if (maps_as_1d) // 2d in 1d window
1336
1377
      {
1348
1389
 
1349
1390
    if (merge_layer == -1) //add layer to the window
1350
1391
    {
1351
 
            if (data_type == LayerData::DT_FEATURE) //features
1352
 
                        {
 
1392
      if (data_type == LayerData::DT_FEATURE) //features
 
1393
      {
1353
1394
        if (!target_window->canvas()->addLayer(feature_map, filename))
1354
1395
        {
1355
1396
          return;
1356
1397
        }
1357
 
                        }
1358
 
                        else if (data_type == LayerData::DT_CONSENSUS) //consensus features
1359
 
                        {
1360
 
        if (!target_window->canvas()->addLayer(consensus_map,filename)) return;
1361
 
                        }
1362
 
                        else if (data_type == LayerData::DT_IDENT)
1363
 
                        {
1364
 
        if (!target_window->canvas()->addLayer(peptides, filename)) return;
1365
 
                        }
1366
 
            else //peaks
1367
 
            {
1368
 
        if (!target_window->canvas()->addLayer(peak_map,filename)) return;
 
1398
      }
 
1399
      else if (data_type == LayerData::DT_CONSENSUS) //consensus features
 
1400
      {
 
1401
        if (!target_window->canvas()->addLayer(consensus_map, filename))
 
1402
          return;
 
1403
      }
 
1404
      else if (data_type == LayerData::DT_IDENT)
 
1405
      {
 
1406
        if (!target_window->canvas()->addLayer(peptides, filename))
 
1407
          return;
 
1408
      }
 
1409
      else //peaks
 
1410
      {
 
1411
        if (!target_window->canvas()->addLayer(peak_map, filename))
 
1412
          return;
1369
1413
 
1370
 
              //calculate noise
 
1414
        //calculate noise
1371
1415
        if (use_intensity_cutoff)
1372
 
              {
 
1416
        {
1373
1417
          DoubleReal cutoff = estimateNoiseFromRandomMS1Scans(*(target_window->canvas()->getCurrentLayer().getPeakData()));
1374
 
                                        //create filter
1375
 
                                        DataFilters::DataFilter filter;
1376
 
                                        filter.field = DataFilters::INTENSITY;
1377
 
                                        filter.op = DataFilters::GREATER_EQUAL;
1378
 
                                        filter.value = cutoff;
1379
 
                                        ///add filter
1380
 
                                        DataFilters filters;
1381
 
                                        filters.add(filter);
 
1418
          //create filter
 
1419
          DataFilters::DataFilter filter;
 
1420
          filter.field = DataFilters::INTENSITY;
 
1421
          filter.op = DataFilters::GREATER_EQUAL;
 
1422
          filter.value = cutoff;
 
1423
          ///add filter
 
1424
          DataFilters filters;
 
1425
          filters.add(filter);
1382
1426
          target_window->canvas()->setFilters(filters);
1383
 
        } else  // no mower, hide zeros if wanted
 
1427
        }
 
1428
        else // no mower, hide zeros if wanted
1384
1429
        {
1385
1430
          Int n_zeros = TOPPViewBase::countMS1Zeros(*(target_window->canvas()->getCurrentLayer().getPeakData()));
1386
1431
          if (n_zeros > 0)
1399
1444
        }
1400
1445
 
1401
1446
        Spectrum1DWidget* open_1d_window = dynamic_cast<Spectrum1DWidget*>(target_window);
1402
 
              if (open_1d_window)
1403
 
              {
1404
 
                open_1d_window->canvas()->activateSpectrum(spectrum_id);
1405
 
              }
1406
 
                        }
 
1447
        if (open_1d_window)
 
1448
        {
 
1449
          open_1d_window->canvas()->activateSpectrum(spectrum_id);
 
1450
        }
 
1451
      }
1407
1452
 
1408
 
                        //set caption
 
1453
      //set caption
1409
1454
      target_window->canvas()->setLayerName(target_window->canvas()->activeLayerIndex(), caption);
1410
 
                }
1411
 
                else //merge feature/ID data into feature layer
1412
 
                {
 
1455
    }
 
1456
    else //merge feature/ID data into feature layer
 
1457
    {
1413
1458
      Spectrum2DCanvas* canvas = qobject_cast<Spectrum2DCanvas*>(target_window->canvas());
1414
 
                        if (data_type == LayerData::DT_CONSENSUS)
1415
 
                        {
 
1459
      if (data_type == LayerData::DT_CONSENSUS)
 
1460
      {
1416
1461
        canvas->mergeIntoLayer(merge_layer, consensus_map);
1417
 
                        }
1418
 
                        else if (data_type == LayerData::DT_FEATURE)
1419
 
                        {
 
1462
      }
 
1463
      else if (data_type == LayerData::DT_FEATURE)
 
1464
      {
1420
1465
        canvas->mergeIntoLayer(merge_layer, feature_map);
1421
 
                        }
1422
 
                        else if (data_type == LayerData::DT_IDENT)
1423
 
                        {
1424
 
                                canvas->mergeIntoLayer(merge_layer, peptides);
1425
 
                        }
1426
 
                }
 
1466
      }
 
1467
      else if (data_type == LayerData::DT_IDENT)
 
1468
      {
 
1469
        canvas->mergeIntoLayer(merge_layer, peptides);
 
1470
      }
 
1471
    }
1427
1472
 
1428
1473
    if (as_new_window)
1429
1474
    {
1430
 
      showSpectrumWidgetInWindow(target_window,caption);
1431
 
                }
 
1475
      showSpectrumWidgetInWindow(target_window, caption);
 
1476
    }
 
1477
 
 
1478
    // enable spectra view tab
 
1479
    views_tabwidget_->setTabEnabled(0, true);
 
1480
 
1432
1481
    //updateDataBar();
1433
 
                updateLayerBar();
 
1482
    updateLayerBar();
1434
1483
    updateViewBar();
1435
 
                updateFilterBar();
1436
 
        updateMenu();
1437
 
        }
 
1484
    updateFilterBar();
 
1485
    updateMenu();
 
1486
  }
1438
1487
 
1439
1488
  void TOPPViewBase::addRecentFile_(const String& filename)
1440
1489
  {
1441
 
        //find out absolute path
 
1490
    //find out absolute path
1442
1491
    String tmp = File::absolutePath(filename);
1443
1492
 
1444
 
                // remove the new file if already in the recent list and prepend it
1445
 
                recent_files_.removeAll(tmp.toQString());
1446
 
                recent_files_.prepend(tmp.toQString());
 
1493
    // remove the new file if already in the recent list and prepend it
 
1494
    recent_files_.removeAll(tmp.toQString());
 
1495
    recent_files_.prepend(tmp.toQString());
1447
1496
 
1448
 
                //remove those files exceeding the defined number
1449
 
                UInt number_of_recent_files = UInt(param_.getValue("preferences:number_of_recent_files"));
1450
 
                while ((UInt)recent_files_.size() > number_of_recent_files)
1451
 
                {
1452
 
                        recent_files_.removeLast();
1453
 
                }
 
1497
    //remove those files exceeding the defined number
 
1498
    UInt number_of_recent_files = UInt(param_.getValue("preferences:number_of_recent_files"));
 
1499
    while ((UInt)recent_files_.size() > number_of_recent_files)
 
1500
    {
 
1501
      recent_files_.removeLast();
 
1502
    }
1454
1503
    updateRecentMenu_();
1455
1504
  }
1456
1505
 
1457
1506
  void TOPPViewBase::updateRecentMenu_()
1458
1507
  {
1459
1508
    // get/correct number of recent files
1460
 
                UInt number_of_recent_files = UInt(param_.getValue("preferences:number_of_recent_files"));
1461
 
                if (number_of_recent_files>20)
1462
 
                {
1463
 
                        number_of_recent_files = 20;
1464
 
                        param_.setValue("preferences:number_of_recent_files",20);
1465
 
                }
 
1509
    UInt number_of_recent_files = UInt(param_.getValue("preferences:number_of_recent_files"));
 
1510
    if (number_of_recent_files > 20)
 
1511
    {
 
1512
      number_of_recent_files = 20;
 
1513
      param_.setValue("preferences:number_of_recent_files", 20);
 
1514
    }
1466
1515
 
1467
 
                for (Size i = 0; i < 20; ++i)
1468
 
                {
1469
 
                        if (i < (UInt)(recent_files_.size()))
1470
 
                        {
1471
 
                                recent_actions_[i]->setText(recent_files_[(int)i]);
1472
 
                                recent_actions_[i]->setVisible(true);
1473
 
                        }
1474
 
                        else
1475
 
                        {
1476
 
                                recent_actions_[i]->setVisible(false);
1477
 
                        }
1478
 
                }
 
1516
    for (Size i = 0; i < 20; ++i)
 
1517
    {
 
1518
      if (i < (UInt)(recent_files_.size()))
 
1519
      {
 
1520
        recent_actions_[i]->setText(recent_files_[(int)i]);
 
1521
        recent_actions_[i]->setVisible(true);
 
1522
      }
 
1523
      else
 
1524
      {
 
1525
        recent_actions_[i]->setVisible(false);
 
1526
      }
 
1527
    }
1479
1528
  }
1480
1529
 
1481
1530
  EnhancedTabBarWidgetInterface* TOPPViewBase::window_(int id) const
1482
1531
  {
1483
1532
    // return window with window_id == id
1484
 
        QList<QWidget*> windows = ws_->windowList();
 
1533
    QList<QWidget*> windows = ws_->windowList();
1485
1534
 
1486
 
    for(int i = 0; i < windows.size(); ++i)
 
1535
    for (int i = 0; i < windows.size(); ++i)
1487
1536
    {
1488
1537
      EnhancedTabBarWidgetInterface* w = dynamic_cast<EnhancedTabBarWidgetInterface*>(windows.at(i));
1489
1538
      if (w->getWindowId() == id)
1490
 
                        {
 
1539
      {
1491
1540
        return w;
1492
 
                        }
1493
 
                }
1494
 
                return 0;
 
1541
      }
 
1542
    }
 
1543
    return 0;
1495
1544
  }
1496
1545
 
1497
1546
  void TOPPViewBase::closeByTab(int id)
1498
1547
  {
1499
1548
    QWidget* w = dynamic_cast<QWidget*>(window_(id));
1500
1549
    if (w)
1501
 
        {
 
1550
    {
1502
1551
      w->close();
1503
 
                updateMenu();
1504
 
        }
 
1552
      updateMenu();
 
1553
    }
1505
1554
  }
1506
1555
 
1507
1556
  void TOPPViewBase::enhancedWorkspaceWindowChanged(int id)
1508
 
  {    
 
1557
  {
1509
1558
    QWidget* w = dynamic_cast<QWidget*>(window_(id));
1510
1559
    if (w)
1511
 
        {
 
1560
    {
1512
1561
      w->setFocus();
1513
 
      TOPPASWidget* tw = dynamic_cast<TOPPASWidget*>(w);
1514
1562
      SpectrumWidget* sw = dynamic_cast<SpectrumWidget*>(w);
1515
 
      if (tw)  // TOPPASWidget
1516
 
      {
1517
 
        setTOPPASTabEnabled(true);
1518
 
        views_tabwidget_->setCurrentIndex(2);
1519
 
        views_tabwidget_->setTabEnabled(0, false);  // switch scan view off
1520
 
        views_tabwidget_->setTabEnabled(1, false);  // switch identification view off
1521
 
      }
1522
 
      else if (sw)  // SpectrumWidget
 
1563
      if (sw) // SpectrumWidget
1523
1564
      {
1524
1565
        views_tabwidget_->setTabEnabled(0, true);
1525
1566
 
1526
1567
        // check if there is a layer before requesting data from it
1527
 
        if(sw->canvas()->getLayerCount() > 0)
 
1568
        if (sw->canvas()->getLayerCount() > 0)
1528
1569
        {
1529
1570
          const ExperimentType& map = *sw->canvas()->getCurrentLayer().getPeakData();
1530
 
          if(hasPeptideIdentifications(map))
 
1571
          if (hasPeptideIdentifications(map))
1531
1572
          {
1532
1573
            views_tabwidget_->setTabEnabled(1, true);
1533
1574
            if (dynamic_cast<Spectrum2DWidget*>(w))
1534
1575
            {
1535
 
              views_tabwidget_->setCurrentIndex(0);  // switch to scan tab for 2D widget
1536
 
            } else if (dynamic_cast<Spectrum1DWidget*>(w))
 
1576
              views_tabwidget_->setCurrentIndex(0); // switch to scan tab for 2D widget
 
1577
            }
 
1578
            else if (dynamic_cast<Spectrum1DWidget*>(w))
1537
1579
            {
1538
 
              views_tabwidget_->setCurrentIndex(1);  // switch to identification tab for 1D widget
 
1580
              views_tabwidget_->setCurrentIndex(1); // switch to identification tab for 1D widget
1539
1581
            }
1540
1582
          }
1541
1583
          else
1543
1585
            views_tabwidget_->setTabEnabled(1, false);
1544
1586
            views_tabwidget_->setCurrentIndex(0); // stay on scan view tab
1545
1587
          }
1546
 
          setTOPPASTabEnabled(false);
1547
1588
        }
1548
1589
      }
1549
 
        }
 
1590
    }
1550
1591
  }
1551
1592
 
1552
1593
  void TOPPViewBase::closeFile()
1560
1601
    SpectrumCanvas* canvas = getActiveCanvas();
1561
1602
 
1562
1603
    // warn if hidden layer => wrong layer selected...
1563
 
        if (!canvas->getCurrentLayer().visible)
1564
 
        {
1565
 
                showLogMessage_(LS_NOTICE,"The current layer is not visible","Have you selected the right layer for this action?");
1566
 
        }
 
1604
    if (!canvas->getCurrentLayer().visible)
 
1605
    {
 
1606
      showLogMessage_(LS_NOTICE, "The current layer is not visible", "Have you selected the right layer for this action?");
 
1607
    }
1567
1608
 
1568
 
        //show editable meta data dialog
1569
 
        canvas->showMetaData(true);
 
1609
    //show editable meta data dialog
 
1610
    canvas->showMetaData(true);
1570
1611
  }
1571
1612
 
1572
1613
  void TOPPViewBase::layerStatistics()
1573
1614
  {
1574
1615
    getActiveSpectrumWidget()->showStatistics();
1575
 
        updateFilterBar();
 
1616
    updateFilterBar();
1576
1617
  }
1577
1618
 
1578
1619
  void TOPPViewBase::showStatusMessage(string msg, OpenMS::UInt time)
1586
1627
    {
1587
1628
      statusBar()->showMessage(msg.c_str(), time);
1588
1629
    }
1589
 
    QApplication::processEvents();
1590
1630
  }
1591
1631
 
1592
1632
  void TOPPViewBase::showCursorStatusInvert(double mz, double rt)
1603
1643
      mz_label_->setText("m/z: ");
1604
1644
    }
1605
1645
    else if (boost::math::isinf(mz) || boost::math::isnan(mz))
1606
 
                {
 
1646
    {
1607
1647
      mz_label_->setText("m/z: n/a");
1608
 
                }
 
1648
    }
1609
1649
    else
1610
1650
    {
1611
 
      mz_label_->setText((String("m/z: ")+String::number(mz,6).fillLeft(' ',8)).toQString());
 
1651
      mz_label_->setText((String("m/z: ") + String::number(mz, 6).fillLeft(' ', 8)).toQString());
1612
1652
    }
1613
1653
 
1614
1654
    if (rt == -1)
1616
1656
      rt_label_->setText("RT: ");
1617
1657
    }
1618
1658
    else if (boost::math::isinf(rt) || boost::math::isnan(rt))
1619
 
                {
 
1659
    {
1620
1660
      rt_label_->setText("RT: n/a");
1621
 
                }
 
1661
    }
1622
1662
    else
1623
1663
    {
1624
 
      rt_label_->setText((String("RT: ")+String::number(rt,1).fillLeft(' ',8)).toQString());
 
1664
      rt_label_->setText((String("RT: ") + String::number(rt, 1).fillLeft(' ', 8)).toQString());
1625
1665
    }
1626
1666
    statusBar()->update();
1627
1667
  }
1649
1689
        {
1650
1690
          w2d->canvas()->getCurrentLayer().param.setValue("dot:gradient", MultiGradient::getDefaultGradientLogarithmicIntensityMode().toString());
1651
1691
          w2d->canvas()->recalculateCurrentLayerDotGradient();
1652
 
        } else if (index != OpenMS::SpectrumCanvas::IM_LOG)
 
1692
        }
 
1693
        else if (index != OpenMS::SpectrumCanvas::IM_LOG)
1653
1694
        {
1654
1695
          w2d->canvas()->getCurrentLayer().param.setValue("dot:gradient", MultiGradient::getDefaultGradientLinearIntensityMode().toString());
1655
1696
          w2d->canvas()->recalculateCurrentLayerDotGradient();
1656
1697
        }
1657
1698
      }
1658
 
        w->setIntensityMode((OpenMS::SpectrumCanvas::IntensityModes)index);
1659
 
        }
 
1699
      w->setIntensityMode((OpenMS::SpectrumCanvas::IntensityModes)index);
 
1700
    }
1660
1701
  }
1661
1702
 
1662
1703
  void TOPPViewBase::setDrawMode1D(int index)
1665
1706
    if (w)
1666
1707
    {
1667
1708
      draw_group_1d_->button(Spectrum1DCanvas::DM_PEAKS)->setChecked(true);
1668
 
        w->canvas()->setDrawMode((OpenMS::Spectrum1DCanvas::DrawModes)index);
1669
 
        }
 
1709
      w->canvas()->setDrawMode((OpenMS::Spectrum1DCanvas::DrawModes)index);
 
1710
    }
1670
1711
  }
1671
1712
 
1672
 
        void TOPPViewBase::changeLabel(QAction* action)
1673
 
        {
 
1713
  void TOPPViewBase::changeLabel(QAction* action)
 
1714
  {
1674
1715
    bool set = false;
1675
1716
 
1676
 
                //label type is selected
1677
 
                for (Size i=0; i<LayerData::SIZE_OF_LABEL_TYPE; ++i)
1678
 
                {
 
1717
    //label type is selected
 
1718
    for (Size i = 0; i < LayerData::SIZE_OF_LABEL_TYPE; ++i)
 
1719
    {
1679
1720
      if (action->text().toStdString() == LayerData::NamesOfLabelType[i])
1680
 
                        {
 
1721
      {
1681
1722
        getActive2DWidget()->canvas()->setLabel(LayerData::LabelType(i));
1682
 
                                set = true;
1683
 
                        }
1684
 
                }
 
1723
        set = true;
 
1724
      }
 
1725
    }
1685
1726
 
1686
 
                //button is simply pressed
1687
 
                if (!set)
1688
 
                {
 
1727
    //button is simply pressed
 
1728
    if (!set)
 
1729
    {
1689
1730
      if (getActive2DWidget()->canvas()->getCurrentLayer().label == LayerData::L_NONE)
1690
 
                        {
 
1731
      {
1691
1732
        getActive2DWidget()->canvas()->setLabel(LayerData::L_INDEX);
1692
 
                                dm_label_2d_->menu()->actions()[1]->setChecked(true);
1693
 
                        }
1694
 
                        else
1695
 
                        {
 
1733
        dm_label_2d_->menu()->actions()[1]->setChecked(true);
 
1734
      }
 
1735
      else
 
1736
      {
1696
1737
        getActive2DWidget()->canvas()->setLabel(LayerData::L_NONE);
1697
 
                                dm_label_2d_->menu()->actions()[0]->setChecked(true);
1698
 
                        }
1699
 
                }
1700
 
 
1701
 
                updateToolBar();
1702
 
        }
1703
 
 
1704
 
        void TOPPViewBase::changeUnassigned(QAction* action)
1705
 
        {
1706
 
                bool set = false;
1707
 
 
1708
 
                // mass reference is selected
1709
 
                if (action->text().toStdString() == "Don't show")
1710
 
                {
 
1738
        dm_label_2d_->menu()->actions()[0]->setChecked(true);
 
1739
      }
 
1740
    }
 
1741
 
 
1742
    updateToolBar();
 
1743
  }
 
1744
 
 
1745
  void TOPPViewBase::changeUnassigned(QAction* action)
 
1746
  {
 
1747
    bool set = false;
 
1748
 
 
1749
    // mass reference is selected
 
1750
    if (action->text().toStdString() == "Don't show")
 
1751
    {
1711
1752
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::F_UNASSIGNED, false);
1712
1753
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::I_PEPTIDEMZ, false);
1713
 
                        set = true;
1714
 
                }
1715
 
                else if (action->text().toStdString() == "Show by precursor m/z")
1716
 
                {
 
1754
      set = true;
 
1755
    }
 
1756
    else if (action->text().toStdString() == "Show by precursor m/z")
 
1757
    {
1717
1758
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::F_UNASSIGNED, true);
1718
1759
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::I_PEPTIDEMZ, false);
1719
 
                        set = true;
1720
 
                }
1721
 
                else if (action->text().toStdString() == "Show by peptide mass")
1722
 
                {
 
1760
      set = true;
 
1761
    }
 
1762
    else if (action->text().toStdString() == "Show by peptide mass")
 
1763
    {
1723
1764
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::F_UNASSIGNED, true);
1724
1765
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::I_PEPTIDEMZ, true);
1725
 
                        set = true;
1726
 
                }
 
1766
      set = true;
 
1767
    }
1727
1768
 
1728
 
                // button is simply pressed
1729
 
                if (!set)
1730
 
                {
 
1769
    // button is simply pressed
 
1770
    if (!set)
 
1771
    {
1731
1772
      bool previous = getActive2DWidget()->canvas()->getLayerFlag(LayerData::F_UNASSIGNED);
1732
1773
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::F_UNASSIGNED,
1733
 
                                                                                                                                                                                                !previous);
1734
 
                        if (previous) // now: don't show
1735
 
                        {
1736
 
                                dm_unassigned_2d_->menu()->actions()[0]->setChecked(true);
1737
 
                        }
1738
 
                        else // now: show by precursor
1739
 
                        {
1740
 
                                dm_unassigned_2d_->menu()->actions()[1]->setChecked(true);
1741
 
                        }
 
1774
                                                  !previous);
 
1775
      if (previous) // now: don't show
 
1776
      {
 
1777
        dm_unassigned_2d_->menu()->actions()[0]->setChecked(true);
 
1778
      }
 
1779
      else // now: show by precursor
 
1780
      {
 
1781
        dm_unassigned_2d_->menu()->actions()[1]->setChecked(true);
 
1782
      }
1742
1783
      getActive2DWidget()->canvas()->setLayerFlag(LayerData::I_PEPTIDEMZ, false);
1743
 
                }
 
1784
    }
1744
1785
 
1745
 
                updateToolBar();
1746
 
        }
 
1786
    updateToolBar();
 
1787
  }
1747
1788
 
1748
1789
  void TOPPViewBase::changeLayerFlag(bool on)
1749
1790
  {
1750
 
                QAction* action = qobject_cast<QAction *>(sender());
1751
 
    if (Spectrum2DWidget* win = getActive2DWidget())
 
1791
    QAction* action = qobject_cast<QAction*>(sender());
 
1792
    if (Spectrum2DWidget * win = getActive2DWidget())
1752
1793
    {
1753
 
        //peaks
1754
 
                        if (action == dm_precursors_2d_)
1755
 
                        {
1756
 
                    win->canvas()->setLayerFlag(LayerData::P_PRECURSORS,on);
1757
 
                        }
1758
 
                        //features
1759
 
                        else if (action == dm_hulls_2d_)
1760
 
                        {
1761
 
                    win->canvas()->setLayerFlag(LayerData::F_HULLS,on);
1762
 
                        }
1763
 
                        else if (action == dm_hull_2d_)
1764
 
                        {
1765
 
                    win->canvas()->setLayerFlag(LayerData::F_HULL,on);
1766
 
                        }
1767
 
                        //consensus features
1768
 
                        else if (action == dm_elements_2d_)
1769
 
                        {
1770
 
                                 win->canvas()->setLayerFlag(LayerData::C_ELEMENTS,on);
1771
 
                        }
1772
 
                        // identifications
1773
 
                        else if (action == dm_ident_2d_)
1774
 
                        {
1775
 
                                win->canvas()->setLayerFlag(LayerData::I_PEPTIDEMZ, on);
1776
 
                        }
1777
 
                }
 
1794
      //peaks
 
1795
      if (action == dm_precursors_2d_)
 
1796
      {
 
1797
        win->canvas()->setLayerFlag(LayerData::P_PRECURSORS, on);
 
1798
      }
 
1799
      //features
 
1800
      else if (action == dm_hulls_2d_)
 
1801
      {
 
1802
        win->canvas()->setLayerFlag(LayerData::F_HULLS, on);
 
1803
      }
 
1804
      else if (action == dm_hull_2d_)
 
1805
      {
 
1806
        win->canvas()->setLayerFlag(LayerData::F_HULL, on);
 
1807
      }
 
1808
      //consensus features
 
1809
      else if (action == dm_elements_2d_)
 
1810
      {
 
1811
        win->canvas()->setLayerFlag(LayerData::C_ELEMENTS, on);
 
1812
      }
 
1813
      // identifications
 
1814
      else if (action == dm_ident_2d_)
 
1815
      {
 
1816
        win->canvas()->setLayerFlag(LayerData::I_PEPTIDEMZ, on);
 
1817
      }
 
1818
    }
1778
1819
  }
1779
1820
 
1780
1821
  void TOPPViewBase::updateToolBar()
1784
1825
    if (w)
1785
1826
    {
1786
1827
      //set intensity mode
1787
 
      if(intensity_button_group_->button(w->canvas()->getIntensityMode()))
 
1828
      if (intensity_button_group_->button(w->canvas()->getIntensityMode()))
1788
1829
      {
1789
1830
        intensity_button_group_->button(w->canvas()->getIntensityMode())->setChecked(true);
1790
 
      } else
 
1831
      }
 
1832
      else
1791
1833
      {
1792
 
        showLogMessage_(LS_ERROR, __PRETTY_FUNCTION__ ,"Button for intensity mode doesn't exist");
 
1834
        showLogMessage_(LS_ERROR, __PRETTY_FUNCTION__, "Button for intensity mode does not exist");
1793
1835
      }
1794
1836
    }
1795
1837
 
1805
1847
      tool_bar_2d_peak_->hide();
1806
1848
      tool_bar_2d_feat_->hide();
1807
1849
      tool_bar_2d_cons_->hide();
1808
 
                        tool_bar_2d_ident_->hide();
 
1850
      tool_bar_2d_ident_->hide();
1809
1851
    }
1810
1852
 
1811
1853
    // 2D
1814
1856
    {
1815
1857
      tool_bar_1d_->hide();
1816
1858
      // check if there is a layer before requesting data from it
1817
 
      if(w2->canvas()->getLayerCount() > 0)
 
1859
      if (w2->canvas()->getLayerCount() > 0)
1818
1860
      {
1819
1861
        //peak draw modes
1820
1862
        if (w2->canvas()->getCurrentLayer().type == LayerData::DT_PEAK)
1831
1873
          dm_hulls_2d_->setChecked(w2->canvas()->getLayerFlag(LayerData::F_HULLS));
1832
1874
          dm_hull_2d_->setChecked(w2->canvas()->getLayerFlag(LayerData::F_HULL));
1833
1875
          dm_unassigned_2d_->setChecked(w2->canvas()->getLayerFlag(LayerData::F_UNASSIGNED));
1834
 
          dm_label_2d_->setChecked(w2->canvas()->getCurrentLayer().label!=LayerData::L_NONE);
 
1876
          dm_label_2d_->setChecked(w2->canvas()->getCurrentLayer().label != LayerData::L_NONE);
1835
1877
          tool_bar_2d_peak_->hide();
1836
1878
          tool_bar_2d_feat_->show();
1837
1879
          tool_bar_2d_cons_->hide();
1866
1908
      tool_bar_2d_peak_->hide();
1867
1909
      tool_bar_2d_feat_->hide();
1868
1910
      tool_bar_2d_cons_->hide();
1869
 
                        tool_bar_2d_ident_->hide();
 
1911
      tool_bar_2d_ident_->hide();
1870
1912
    }
1871
1913
  }
1872
1914
 
1873
1915
  void TOPPViewBase::updateLayerBar()
1874
1916
  {
1875
 
        //reset
1876
 
                layer_manager_->clear();
 
1917
    //reset
 
1918
    layer_manager_->clear();
1877
1919
    SpectrumCanvas* cc = getActiveCanvas();
1878
 
    if (cc == 0) return;
1879
 
 
1880
 
                //determine if this is a 1D view (for text color)
1881
 
                bool is_1d_view = false;
1882
 
                if (dynamic_cast<Spectrum1DCanvas*>(cc)) is_1d_view = true;
1883
 
 
1884
 
                layer_manager_->blockSignals(true);
1885
 
                QListWidgetItem* item = 0;
1886
 
                QString name;
1887
 
    for (Size i = 0; i<cc->getLayerCount(); ++i)
 
1920
    if (cc == 0)
 
1921
      return;
 
1922
 
 
1923
    //determine if this is a 1D view (for text color)
 
1924
    bool is_1d_view = false;
 
1925
    if (dynamic_cast<Spectrum1DCanvas*>(cc))
 
1926
      is_1d_view = true;
 
1927
 
 
1928
    layer_manager_->blockSignals(true);
 
1929
    QString name;
 
1930
    for (Size i = 0; i < cc->getLayerCount(); ++i)
1888
1931
    {
1889
 
        const LayerData& layer = cc->getLayer(i);
1890
 
        //add item
1891
 
        item = new QListWidgetItem( layer_manager_ );
1892
 
                        name = layer.name.toQString();
1893
 
                        if (layer.flipped)
1894
 
                        {
1895
 
                                name += " [flipped]";
1896
 
                        }
1897
 
                        item->setText(name);
1898
 
                        if (is_1d_view && cc->getLayerCount()>1)
1899
 
                        {
1900
 
                                QPixmap icon(7,7);
1901
 
                                icon.fill(QColor(layer.param.getValue("peak_color").toQString()));
1902
 
                                item->setIcon(icon);
1903
 
                        }
1904
 
        if (layer.visible)
1905
 
        {
1906
 
                item->setCheckState(Qt::Checked);
1907
 
        }
1908
 
        else
1909
 
        {
1910
 
                item->setCheckState(Qt::Unchecked);
1911
 
        }
1912
 
        if (layer.modified)
1913
 
        {
1914
 
                item->setText(item->text() + '*');
1915
 
        }
1916
 
        //highlight active item
1917
 
        if (i == cc->activeLayerIndex())
1918
 
        {
1919
 
                                layer_manager_->setCurrentItem(item);
1920
 
        }
1921
 
                }
1922
 
                layer_manager_->blockSignals(false);
 
1932
      const LayerData& layer = cc->getLayer(i);
 
1933
      //add item
 
1934
      QListWidgetItem* item = new QListWidgetItem(layer_manager_);
 
1935
      name = layer.name.toQString();
 
1936
      if (layer.flipped)
 
1937
      {
 
1938
        name += " [flipped]";
 
1939
      }
 
1940
      item->setText(name);
 
1941
      if (is_1d_view && cc->getLayerCount() > 1)
 
1942
      {
 
1943
        QPixmap icon(7, 7);
 
1944
        icon.fill(QColor(layer.param.getValue("peak_color").toQString()));
 
1945
        item->setIcon(icon);
 
1946
      }
 
1947
      if (layer.visible)
 
1948
      {
 
1949
        item->setCheckState(Qt::Checked);
 
1950
      }
 
1951
      else
 
1952
      {
 
1953
        item->setCheckState(Qt::Unchecked);
 
1954
      }
 
1955
      if (layer.modified)
 
1956
      {
 
1957
        item->setText(item->text() + '*');
 
1958
      }
 
1959
      //highlight active item
 
1960
      if (i == cc->activeLayerIndex())
 
1961
      {
 
1962
        layer_manager_->setCurrentItem(item);
 
1963
      }
 
1964
    }
 
1965
    layer_manager_->blockSignals(false);
1923
1966
  }
1924
1967
 
1925
1968
  void TOPPViewBase::updateViewBar()
1929
1972
 
1930
1973
    if (layer_row == -1 || cc == 0)
1931
1974
    {
1932
 
      // TODO: we need to clean up the SpectraViewWidget & friends
 
1975
      if (spectra_view_widget_)
 
1976
      {
 
1977
        spectra_view_widget_->getTreeWidget()->clear();
 
1978
        spectra_view_widget_->getComboBox()->clear();
 
1979
      }
 
1980
 
 
1981
      if (spectra_identification_view_widget_)
 
1982
      {
 
1983
        spectra_identification_view_widget_->attachLayer(0);
 
1984
        // remove all entries
 
1985
        QTableWidget* w = spectra_identification_view_widget_->getTableWidget();
 
1986
        for (int i = w->rowCount() - 1; i >= 0; --i)
 
1987
        {
 
1988
          w->removeRow(i);
 
1989
        }
 
1990
        for (int i = w->columnCount() - 1; i >= 0; --i)
 
1991
        {
 
1992
          w->removeColumn(i);
 
1993
        }
 
1994
        w->clear();
 
1995
        views_tabwidget_->setTabEnabled(1, false);
 
1996
        views_tabwidget_->setTabEnabled(0, true);
 
1997
      }
1933
1998
      return;
1934
1999
    }
1935
2000
 
1956
2021
      layer_dock_widget_->show();
1957
2022
      filter_dock_widget_->show();
1958
2023
      view_behavior_ = spectraview_behavior_;
1959
 
    } else if (views_tabwidget_->tabText(tab_index) == "Identification view")
 
2024
    }
 
2025
    else if (views_tabwidget_->tabText(tab_index) == "Identification view")
1960
2026
    {
1961
2027
      layer_dock_widget_->show();
1962
2028
      filter_dock_widget_->show();
1963
 
      if (getActive2DWidget())  // currently 2D window is open
 
2029
      if (getActive2DWidget()) // currently 2D window is open
1964
2030
      {
1965
2031
        showSpectrumAs1D(0);
1966
2032
      }
1967
2033
      view_behavior_ = identificationview_behavior_;
1968
 
    } else if (views_tabwidget_->tabText(tab_index) == "TOPPAS view")
1969
 
    {
1970
 
      layer_dock_widget_->hide();
1971
 
      filter_dock_widget_->hide();
1972
 
      // no complex behavior for TOPPAS view needed
1973
 
    } else
 
2034
    }
 
2035
    else
1974
2036
    {
1975
2037
      cerr << "Error: tab_index " << tab_index << endl;
1976
2038
      throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
1999
2061
    layer_manager_->blockSignals(false);
2000
2062
  }
2001
2063
*/
2002
 
        void TOPPViewBase::layerSelectionChange(int i)
2003
 
        {
2004
 
                if (i!=-1)
2005
 
                {
2006
 
      getActiveCanvas()->activateLayer(i);
2007
 
                        updateFilterBar();
2008
 
      updateViewBar();
2009
 
                }
2010
 
        }
 
2064
  void TOPPViewBase::layerSelectionChange(int i)
 
2065
  {
 
2066
    // after adding a layer i is -1. TODO: check if this is the correct behaviour
 
2067
    if (i != -1)
 
2068
    {
 
2069
      getActiveCanvas()->activateLayer(i); // also triggers update of viewBar
 
2070
      updateFilterBar();
 
2071
    }
 
2072
  }
2011
2073
 
2012
 
        void TOPPViewBase::layerContextMenu(const QPoint & pos)
2013
 
        {
2014
 
                QListWidgetItem* item = layer_manager_->itemAt(pos);
2015
 
                if (item)
2016
 
                {
2017
 
                        QAction* new_action = 0;
2018
 
                        int layer = layer_manager_->row(item);
2019
 
                        QMenu* context_menu = new QMenu(layer_manager_);
2020
 
                        context_menu->addAction("Rename");
2021
 
                        context_menu->addAction("Delete");
 
2074
  void TOPPViewBase::layerContextMenu(const QPoint& pos)
 
2075
  {
 
2076
    QListWidgetItem* item = layer_manager_->itemAt(pos);
 
2077
    if (item)
 
2078
    {
 
2079
      QAction* new_action = 0;
 
2080
      int layer = layer_manager_->row(item);
 
2081
      QMenu* context_menu = new QMenu(layer_manager_);
 
2082
      context_menu->addAction("Rename");
 
2083
      context_menu->addAction("Delete");
2022
2084
 
2023
2085
      if (getActiveCanvas()->getLayer(layer).flipped)
2024
 
                        {
2025
 
                                new_action = context_menu->addAction("Flip upwards (1D)");
2026
 
                        }
2027
 
                        else
2028
 
                        {
2029
 
                                new_action = context_menu->addAction("Flip downwards (1D)");
2030
 
                        }
 
2086
      {
 
2087
        new_action = context_menu->addAction("Flip upwards (1D)");
 
2088
      }
 
2089
      else
 
2090
      {
 
2091
        new_action = context_menu->addAction("Flip downwards (1D)");
 
2092
      }
2031
2093
      if (!getActive1DWidget())
2032
 
                        {
2033
 
                                new_action->setEnabled(false);
2034
 
                        }
2035
 
 
2036
 
                        context_menu->addSeparator();
2037
 
                        context_menu->addAction("Preferences");
2038
 
 
2039
 
                        QAction* selected = context_menu->exec(layer_manager_->mapToGlobal(pos));
2040
 
                        //delete layer
2041
 
                        if (selected!=0 && selected->text()=="Delete")
2042
 
                        {
 
2094
      {
 
2095
        new_action->setEnabled(false);
 
2096
      }
 
2097
 
 
2098
      context_menu->addSeparator();
 
2099
      context_menu->addAction("Preferences");
 
2100
 
 
2101
      QAction* selected = context_menu->exec(layer_manager_->mapToGlobal(pos));
 
2102
      //delete layer
 
2103
      if (selected != 0 && selected->text() == "Delete")
 
2104
      {
2043
2105
        getActiveCanvas()->removeLayer(layer);
2044
 
                        }
2045
 
                        //rename layer
2046
 
                        else if (selected!=0 && selected->text()=="Rename")
2047
 
                        {
2048
 
                                QString name = QInputDialog::getText(this,"Rename layer","Name:");
2049
 
                                if (name!="")
2050
 
                                {
 
2106
      }
 
2107
      //rename layer
 
2108
      else if (selected != 0 && selected->text() == "Rename")
 
2109
      {
 
2110
        QString name = QInputDialog::getText(this, "Rename layer", "Name:");
 
2111
        if (name != "")
 
2112
        {
2051
2113
          getActiveCanvas()->setLayerName(layer, name);
2052
 
                                }
2053
 
                        }
2054
 
                        // flip layer up/downwards
2055
 
                        else if (selected != 0 && selected->text() == "Flip downwards (1D)")
2056
 
                        {
 
2114
        }
 
2115
      }
 
2116
      // flip layer up/downwards
 
2117
      else if (selected != 0 && selected->text() == "Flip downwards (1D)")
 
2118
      {
2057
2119
        getActive1DWidget()->canvas()->flipLayer(layer);
2058
2120
        getActive1DWidget()->canvas()->setMirrorModeActive(true);
2059
 
                        }
2060
 
                        else if (selected != 0 && selected->text() == "Flip upwards (1D)")
2061
 
                        {
 
2121
      }
 
2122
      else if (selected != 0 && selected->text() == "Flip upwards (1D)")
 
2123
      {
2062
2124
        getActive1DWidget()->canvas()->flipLayer(layer);
2063
2125
        bool b = getActive1DWidget()->canvas()->flippedLayersExist();
2064
2126
        getActive1DWidget()->canvas()->setMirrorModeActive(b);
2065
 
                        }
2066
 
                        else if (selected != 0 && selected->text() == "Preferences")
2067
 
                        {
 
2127
      }
 
2128
      else if (selected != 0 && selected->text() == "Preferences")
 
2129
      {
2068
2130
        getActiveCanvas()->showCurrentLayerPreferences();
2069
 
                        }
 
2131
      }
2070
2132
 
2071
 
                        //Update tab bar and window title
2072
 
      if (getActiveCanvas()->getLayerCount()!=0)
2073
 
                        {
 
2133
      //Update tab bar and window title
 
2134
      if (getActiveCanvas()->getLayerCount() != 0)
 
2135
      {
2074
2136
        tab_bar_->setTabText(tab_bar_->currentIndex(), getActiveCanvas()->getLayer(0).name.toQString());
2075
2137
        getActiveSpectrumWidget()->setWindowTitle(getActiveCanvas()->getLayer(0).name.toQString());
2076
 
                        }
2077
 
                        else
2078
 
                        {
2079
 
                                tab_bar_->setTabText(tab_bar_->currentIndex(),"empty");
 
2138
      }
 
2139
      else
 
2140
      {
 
2141
        tab_bar_->setTabText(tab_bar_->currentIndex(), "empty");
2080
2142
        getActiveSpectrumWidget()->setWindowTitle("empty");
2081
 
                        }
 
2143
      }
2082
2144
 
2083
 
                        //Update filter bar, spectrum bar and layer bar
2084
 
                        updateLayerBar();
 
2145
      //Update filter bar, spectrum bar and layer bar
 
2146
      updateLayerBar();
2085
2147
      updateViewBar();
2086
 
                        updateFilterBar();
2087
 
                        updateMenu();
2088
 
 
2089
 
                        delete (context_menu);
2090
 
                }
2091
 
        }
2092
 
 
2093
 
        void TOPPViewBase::logContextMenu(const QPoint & pos)
2094
 
        {
2095
 
                QMenu* context_menu = new QMenu(log_);
2096
 
                context_menu->addAction("Clear");
2097
 
 
2098
 
                QAction* selected = context_menu->exec(log_->mapToGlobal(pos));
2099
 
 
2100
 
                //clear text
2101
 
    if (selected != 0 && selected->text()== "Clear")
2102
 
                {
2103
 
                        log_->clear();
2104
 
                }
2105
 
                delete (context_menu);
2106
 
        }
2107
 
 
2108
 
        void TOPPViewBase::filterContextMenu(const QPoint & pos)
2109
 
        {
2110
 
                //do nothing if no window is open
2111
 
    if (getActiveCanvas()==0) return;
 
2148
      updateFilterBar();
 
2149
      updateMenu();
 
2150
 
 
2151
      delete (context_menu);
 
2152
    }
 
2153
  }
 
2154
 
 
2155
  void TOPPViewBase::logContextMenu(const QPoint& pos)
 
2156
  {
 
2157
    QMenu* context_menu = new QMenu(log_);
 
2158
    context_menu->addAction("Clear");
 
2159
 
 
2160
    QAction* selected = context_menu->exec(log_->mapToGlobal(pos));
 
2161
 
 
2162
    //clear text
 
2163
    if (selected != 0 && selected->text() == "Clear")
 
2164
    {
 
2165
      log_->clear();
 
2166
    }
 
2167
    delete (context_menu);
 
2168
  }
 
2169
 
 
2170
  void TOPPViewBase::filterContextMenu(const QPoint& pos)
 
2171
  {
 
2172
    //do nothing if no window is open
 
2173
    if (getActiveCanvas() == 0)
 
2174
      return;
2112
2175
 
2113
2176
    //do nothing if no layer is loaded into the canvas
2114
 
    if (getActiveCanvas()->getLayerCount() == 0) return;
2115
 
 
2116
 
                QMenu* context_menu = new QMenu(filters_);
2117
 
 
2118
 
                //warn if the current layer is not visible
 
2177
    if (getActiveCanvas()->getLayerCount() == 0)
 
2178
      return;
 
2179
 
 
2180
    QMenu* context_menu = new QMenu(filters_);
 
2181
 
 
2182
    //warn if the current layer is not visible
2119
2183
    String layer_name = String("Layer: ") + getActiveCanvas()->getCurrentLayer().name;
2120
2184
    if (!getActiveCanvas()->getCurrentLayer().visible)
2121
 
                {
2122
 
                        layer_name += " (invisible)";
2123
 
                }
2124
 
                context_menu->addAction(layer_name.toQString())->setEnabled(false);
2125
 
                context_menu->addSeparator();
 
2185
    {
 
2186
      layer_name += " (invisible)";
 
2187
    }
 
2188
    context_menu->addAction(layer_name.toQString())->setEnabled(false);
 
2189
    context_menu->addSeparator();
2126
2190
 
2127
 
                //add actions
2128
 
                QListWidgetItem* item = filters_->itemAt(pos);
2129
 
                if (item)
2130
 
                {
2131
 
                        context_menu->addAction("Edit");
2132
 
                        context_menu->addAction("Delete");
2133
 
                }
2134
 
                else
2135
 
                {
2136
 
                        context_menu->addAction("Add filter");
2137
 
                }
2138
 
                //results
2139
 
                QAction* selected = context_menu->exec(filters_->mapToGlobal(pos));
2140
 
                if (selected!=0)
2141
 
                {
2142
 
                        if(selected->text()=="Delete")
2143
 
                        {
 
2191
    //add actions
 
2192
    QListWidgetItem* item = filters_->itemAt(pos);
 
2193
    if (item)
 
2194
    {
 
2195
      context_menu->addAction("Edit");
 
2196
      context_menu->addAction("Delete");
 
2197
    }
 
2198
    else
 
2199
    {
 
2200
      context_menu->addAction("Add filter");
 
2201
    }
 
2202
    //results
 
2203
    QAction* selected = context_menu->exec(filters_->mapToGlobal(pos));
 
2204
    if (selected != 0)
 
2205
    {
 
2206
      if (selected->text() == "Delete")
 
2207
      {
2144
2208
        DataFilters filters = getActiveCanvas()->getCurrentLayer().filters;
2145
 
                                filters.remove(filters_->row(item));
 
2209
        filters.remove(filters_->row(item));
2146
2210
        getActiveCanvas()->setFilters(filters);
2147
 
                                updateFilterBar();
2148
 
                        }
2149
 
                        else if (selected->text()=="Edit")
2150
 
                        {
2151
 
                                filterEdit(item);
2152
 
                        }
2153
 
                        else if (selected->text()=="Add filter")
2154
 
                        {
 
2211
        updateFilterBar();
 
2212
      }
 
2213
      else if (selected->text() == "Edit")
 
2214
      {
 
2215
        filterEdit(item);
 
2216
      }
 
2217
      else if (selected->text() == "Add filter")
 
2218
      {
2155
2219
        DataFilters filters = getActiveCanvas()->getCurrentLayer().filters;
2156
 
                                DataFilters::DataFilter filter;
2157
 
                                DataFilterDialog dlg(filter, this);
2158
 
                                if (dlg.exec())
2159
 
                                {
2160
 
                                        filters.add(filter);
 
2220
        DataFilters::DataFilter filter;
 
2221
        DataFilterDialog dlg(filter, this);
 
2222
        if (dlg.exec())
 
2223
        {
 
2224
          filters.add(filter);
2161
2225
          getActiveCanvas()->setFilters(filters);
2162
 
                                        updateFilterBar();
2163
 
                                }
2164
 
                        }
2165
 
                }
2166
 
                delete (context_menu);
2167
 
        }
 
2226
          updateFilterBar();
 
2227
        }
 
2228
      }
 
2229
    }
 
2230
    delete (context_menu);
 
2231
  }
2168
2232
 
2169
 
        void TOPPViewBase::filterEdit(QListWidgetItem* item)
2170
 
        {
 
2233
  void TOPPViewBase::filterEdit(QListWidgetItem* item)
 
2234
  {
2171
2235
    DataFilters filters = getActiveCanvas()->getCurrentLayer().filters;
2172
 
                DataFilters::DataFilter filter = filters[filters_->row(item)];
2173
 
                DataFilterDialog dlg(filter, this);
2174
 
                if (dlg.exec())
2175
 
                {
2176
 
                        filters.replace(filters_->row(item),filter);
 
2236
    DataFilters::DataFilter filter = filters[filters_->row(item)];
 
2237
    DataFilterDialog dlg(filter, this);
 
2238
    if (dlg.exec())
 
2239
    {
 
2240
      filters.replace(filters_->row(item), filter);
2177
2241
      getActiveCanvas()->setFilters(filters);
2178
 
                        updateFilterBar();
2179
 
                }
2180
 
        }
 
2242
      updateFilterBar();
 
2243
    }
 
2244
  }
2181
2245
 
2182
 
        void TOPPViewBase::layerEdit(QListWidgetItem* /*item*/)
2183
 
        {
 
2246
  void TOPPViewBase::layerEdit(QListWidgetItem* /*item*/)
 
2247
  {
2184
2248
    getActiveCanvas()->showCurrentLayerPreferences();
2185
 
        }
 
2249
  }
2186
2250
 
2187
2251
  void TOPPViewBase::updateFilterBar()
2188
2252
  {
2189
 
        //update filters
2190
 
        filters_->clear();
 
2253
    //update filters
 
2254
    filters_->clear();
2191
2255
 
2192
2256
    SpectrumCanvas* canvas = getActiveCanvas();
2193
 
                if (canvas==0) return;
2194
 
                if (canvas->getLayerCount()==0) return;
 
2257
    if (canvas == 0)
 
2258
      return;
 
2259
 
 
2260
    if (canvas->getLayerCount() == 0)
 
2261
      return;
2195
2262
 
2196
2263
    const DataFilters& filters = getActiveCanvas()->getCurrentLayer().filters;
2197
 
                for (Size i=0; i<filters.size(); ++i)
2198
 
                {
2199
 
                        QListWidgetItem* item = new QListWidgetItem(filters_);
2200
 
                        item->setText(filters[i].toString().toQString());
2201
 
                }
 
2264
    for (Size i = 0; i < filters.size(); ++i)
 
2265
    {
 
2266
      QListWidgetItem* item = new QListWidgetItem(filters_);
 
2267
      item->setText(filters[i].toString().toQString());
 
2268
    }
2202
2269
 
2203
 
        //update check box
 
2270
    //update check box
2204
2271
    filters_check_box_->setChecked(getActiveCanvas()->getCurrentLayer().filters.isActive());
2205
2272
  }
2206
2273
 
2207
 
        void TOPPViewBase::layerFilterVisibilityChange(bool on)
2208
 
        {
 
2274
  void TOPPViewBase::layerFilterVisibilityChange(bool on)
 
2275
  {
2209
2276
    if (getActiveCanvas())
2210
 
                {
2211
 
      getActiveCanvas()->changeLayerFilterState(getActiveCanvas()->activeLayerIndex(),on);
2212
 
                }
2213
 
        }
 
2277
    {
 
2278
      getActiveCanvas()->changeLayerFilterState(getActiveCanvas()->activeLayerIndex(), on);
 
2279
    }
 
2280
  }
2214
2281
 
2215
 
        void TOPPViewBase::layerVisibilityChange(QListWidgetItem* item)
2216
 
        {
2217
 
                int layer;
2218
 
                bool visible;
2219
 
                layer = layer_manager_->row(item);
 
2282
  void TOPPViewBase::layerVisibilityChange(QListWidgetItem* item)
 
2283
  {
 
2284
    int layer;
 
2285
    bool visible;
 
2286
    layer = layer_manager_->row(item);
2220
2287
    visible = getActiveCanvas()->getLayer(layer).visible;
2221
2288
 
2222
 
                if (item->checkState()==Qt::Unchecked && visible)
2223
 
                {
 
2289
    if (item->checkState() == Qt::Unchecked && visible)
 
2290
    {
2224
2291
      getActiveCanvas()->changeVisibility(layer, false);
2225
 
                }
2226
 
                else if (item->checkState()==Qt::Checked && !visible)
2227
 
                {
 
2292
    }
 
2293
    else if (item->checkState() == Qt::Checked && !visible)
 
2294
    {
2228
2295
      getActiveCanvas()->changeVisibility(layer, true);
2229
 
                }
2230
 
        }
 
2296
    }
 
2297
  }
2231
2298
 
2232
2299
  void TOPPViewBase::updateTabBar(QWidget* w)
2233
2300
  {
2234
 
        if (w)
2235
 
        {
 
2301
    if (w)
 
2302
    {
2236
2303
      EnhancedTabBarWidgetInterface* tbw = dynamic_cast<EnhancedTabBarWidgetInterface*>(w);
2237
2304
      Int window_id = tbw->getWindowId();
2238
 
                tab_bar_->setCurrentId(window_id);
2239
 
        }
 
2305
      tab_bar_->setCurrentId(window_id);
 
2306
    }
2240
2307
  }
2241
2308
 
2242
2309
  void TOPPViewBase::tileVertical()
2243
2310
  {
2244
2311
    // primitive horizontal tiling
2245
2312
    QWidgetList windows = ws_->windowList();
2246
 
    if ( !windows.count() ) return;
 
2313
    if (!windows.count())
 
2314
      return;
2247
2315
 
2248
 
    if (getActive1DWidget()) getActive1DWidget()->showNormal();
2249
 
    if (getActive2DWidget()) getActive2DWidget()->showNormal();
 
2316
    if (getActive1DWidget())
 
2317
      getActive1DWidget()->showNormal();
 
2318
    if (getActive2DWidget())
 
2319
      getActive2DWidget()->showNormal();
2250
2320
 
2251
2321
    int heightForEach = ws_->height() / windows.count();
2252
2322
    int y = 0;
2253
 
    for ( int i = 0; i < int(windows.count()); ++i )
 
2323
    for (int i = 0; i < int(windows.count()); ++i)
2254
2324
    {
2255
 
      QWidget *window = windows.at(i);
2256
 
      if ( window->isMaximized() || window->isFullScreen() )
 
2325
      QWidget* window = windows.at(i);
 
2326
      if (window->isMaximized() || window->isFullScreen())
2257
2327
      {
2258
2328
        // prevent flicker
2259
2329
        window->hide();
2260
2330
        window->setWindowState(Qt::WindowNoState);
2261
2331
        window->show();
2262
2332
      }
2263
 
      int preferredHeight = window->minimumHeight()+window->parentWidget()->baseSize().height();
 
2333
      int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
2264
2334
      int actHeight = std::max(heightForEach, preferredHeight);
2265
2335
 
2266
 
      window->parentWidget()->setGeometry( 0, y, ws_->width(), actHeight );
 
2336
      window->parentWidget()->setGeometry(0, y, ws_->width(), actHeight);
2267
2337
      y += actHeight;
2268
2338
    }
2269
2339
  }
2272
2342
  {
2273
2343
    // primitive horizontal tiling
2274
2344
    QWidgetList windows = ws_->windowList();
2275
 
    if ( !windows.count() ) return;
 
2345
    if (!windows.count())
 
2346
      return;
2276
2347
 
2277
 
    if (getActive1DWidget()) getActive1DWidget()->showNormal();
2278
 
    if (getActive2DWidget()) getActive2DWidget()->showNormal();
 
2348
    if (getActive1DWidget())
 
2349
      getActive1DWidget()->showNormal();
 
2350
    if (getActive2DWidget())
 
2351
      getActive2DWidget()->showNormal();
2279
2352
 
2280
2353
    int widthForEach = ws_->width() / windows.count();
2281
2354
    int y = 0;
2282
 
    for ( int i = 0; i < int(windows.count()); ++i )
 
2355
    for (int i = 0; i < int(windows.count()); ++i)
2283
2356
    {
2284
 
      QWidget *window = windows.at(i);
2285
 
      if ( window->windowState() & Qt::WindowMaximized )
 
2357
      QWidget* window = windows.at(i);
 
2358
      if (window->windowState() & Qt::WindowMaximized)
2286
2359
      {
2287
2360
        // prevent flicker
2288
2361
        window->hide();
2289
2362
        window->showNormal();
2290
2363
      }
2291
 
      int preferredWidth = window->minimumWidth()+window->parentWidget()->baseSize().width();
 
2364
      int preferredWidth = window->minimumWidth() + window->parentWidget()->baseSize().width();
2292
2365
 
2293
2366
      int actWidth = std::max(widthForEach, preferredWidth);
2294
2367
 
2295
 
      window->parentWidget()->setGeometry( y, 0, actWidth , ws_->height() );
 
2368
      window->parentWidget()->setGeometry(y, 0, actWidth, ws_->height());
2296
2369
      y += actWidth;
2297
2370
    }
2298
2371
  }
2299
2372
 
 
2373
  void TOPPViewBase::linkZoom()
 
2374
  {
 
2375
    zoom_together_ = !zoom_together_;
 
2376
    if (!zoom_together_)
 
2377
    {
 
2378
      linkZoom_action_->setText("Link &Zoom");
 
2379
    }
 
2380
    else
 
2381
    {
 
2382
      linkZoom_action_->setText("Unlink &Zoom");
 
2383
    }
 
2384
  }
 
2385
 
2300
2386
  void TOPPViewBase::layerActivated()
2301
2387
  {
2302
2388
    updateToolBar();
2304
2390
    updateCurrentPath();
2305
2391
  }
2306
2392
 
 
2393
  void TOPPViewBase::layerZoomChanged()
 
2394
  {
 
2395
    QWidgetList windows = ws_->windowList();
 
2396
    if (!windows.count())
 
2397
      return;
 
2398
 
 
2399
    if (!zoom_together_)
 
2400
      return;
 
2401
 
 
2402
    SpectrumWidget* w = getActiveSpectrumWidget();
 
2403
 
 
2404
    // figure out which dimension the active widget has: 2D (MSExperiment) or 1D (Iontrace)
 
2405
    // and get the corresponding RT values.
 
2406
    Spectrum1DWidget* sw1 = qobject_cast<Spectrum1DWidget*>(w);
 
2407
    Spectrum2DWidget* sw2 = qobject_cast<Spectrum2DWidget*>(w);
 
2408
    Spectrum3DWidget* sw3 = qobject_cast<Spectrum3DWidget*>(w);
 
2409
    int widget_dimension = -1;
 
2410
    if (sw1 != 0)
 
2411
    {
 
2412
      widget_dimension = 1;
 
2413
    }
 
2414
    else if (sw2 != 0)
 
2415
    {
 
2416
      widget_dimension = 2;
 
2417
    }
 
2418
    else if (sw3 != 0)
 
2419
    {
 
2420
      // dont link 3D
 
2421
      widget_dimension = 3;
 
2422
      return;
 
2423
    }
 
2424
    else
 
2425
    {
 
2426
      // Could not cast into any widget.
 
2427
      return;
 
2428
    }
 
2429
 
 
2430
    // check if the calling layer is a chromatogram:
 
2431
    // - either its type is DT_CHROMATOGRAM
 
2432
    // - or its peak data has a metavalue called "is_chromatogram" that is set to true
 
2433
    if (getActiveCanvas()->getCurrentLayer().type == LayerData::DT_CHROMATOGRAM ||
 
2434
        (getActiveCanvas()->getCurrentLayer().getPeakData()->size() > 0 &&
 
2435
         getActiveCanvas()->getCurrentLayer().getPeakData()->metaValueExists("is_chromatogram") &&
 
2436
         getActiveCanvas()->getCurrentLayer().getPeakData()->getMetaValue("is_chromatogram").toBool()
 
2437
        ))
 
2438
    {
 
2439
      double minRT = -1, maxRT = -1;
 
2440
 
 
2441
      // Get the corresponding RT values depending on whether it is 2D (MSExperiment) or 1D (Iontrace).
 
2442
      if (widget_dimension == 1)
 
2443
      {
 
2444
        minRT = sw1->canvas()->getVisibleArea().minX();
 
2445
        maxRT = sw1->canvas()->getVisibleArea().maxX();
 
2446
      }
 
2447
      else if (widget_dimension == 2)
 
2448
      {
 
2449
        minRT = sw2->canvas()->getVisibleArea().minY();
 
2450
        maxRT = sw2->canvas()->getVisibleArea().maxY();
 
2451
      }
 
2452
 
 
2453
      // go through all windows, adjust the visible area where necessary
 
2454
      for (int i = 0; i < int(windows.count()); ++i)
 
2455
      {
 
2456
        QWidget* window = windows.at(i);
 
2457
        DRange<2> visible_area;
 
2458
        SpectrumWidget* specwidg = qobject_cast<SpectrumWidget*>(window);
 
2459
 
 
2460
        // Skip if its not a SpectrumWidget, if it is not a chromatogram or if the dimensions don't match.
 
2461
        if (!specwidg)
 
2462
          continue;
 
2463
        if (!(specwidg->canvas()->getCurrentLayer().type == LayerData::DT_CHROMATOGRAM) &&
 
2464
            !(specwidg->canvas()->getCurrentLayer().getPeakData()->size() > 0 &&
 
2465
              specwidg->canvas()->getCurrentLayer().getPeakData()->metaValueExists("is_chromatogram") &&
 
2466
              specwidg->canvas()->getCurrentLayer().getPeakData()->getMetaValue("is_chromatogram").toBool()
 
2467
              ))
 
2468
        {
 
2469
          continue;
 
2470
        }
 
2471
        if (!(widget_dimension == 1 && qobject_cast<Spectrum1DWidget*>(specwidg)) &&
 
2472
            !(widget_dimension == 2 && qobject_cast<Spectrum2DWidget*>(specwidg)))
 
2473
        {
 
2474
          continue;
 
2475
        }
 
2476
 
 
2477
        visible_area = specwidg->canvas()->getVisibleArea();
 
2478
 
 
2479
        // if we found a min/max RT, change all windows of 1 dimension
 
2480
        if (minRT != -1 && maxRT != -1 && qobject_cast<Spectrum1DWidget*>(window))
 
2481
        {
 
2482
          visible_area.setMinX(minRT);
 
2483
          visible_area.setMaxX(maxRT);
 
2484
        }
 
2485
        specwidg->canvas()->setVisibleArea(visible_area);
 
2486
      }
 
2487
    }
 
2488
    else
 
2489
    {
 
2490
      DRange<2> new_visible_area = w->canvas()->getVisibleArea();
 
2491
      // go through all windows, adjust the visible area where necessary
 
2492
      for (int i = 0; i < int(windows.count()); ++i)
 
2493
      {
 
2494
        QWidget* window = windows.at(i);
 
2495
        SpectrumWidget* specwidg = qobject_cast<SpectrumWidget*>(window);
 
2496
 
 
2497
        // Skip if its not a SpectrumWidget, if it is a chromatogram or if the dimensions don't match.
 
2498
        if (!specwidg)
 
2499
          continue;
 
2500
        if ((specwidg->canvas()->getCurrentLayer().type == LayerData::DT_CHROMATOGRAM) ||
 
2501
            (specwidg->canvas()->getCurrentLayer().getPeakData()->size() > 0 &&
 
2502
             specwidg->canvas()->getCurrentLayer().getPeakData()->metaValueExists("is_chromatogram") &&
 
2503
             specwidg->canvas()->getCurrentLayer().getPeakData()->getMetaValue("is_chromatogram").toBool()
 
2504
            ))
 
2505
        {
 
2506
          continue;
 
2507
        }
 
2508
        if (!(widget_dimension == 1 && qobject_cast<Spectrum1DWidget*>(specwidg)) &&
 
2509
            !(widget_dimension == 2 && qobject_cast<Spectrum2DWidget*>(specwidg)))
 
2510
        {
 
2511
          continue;
 
2512
        }
 
2513
        specwidg->canvas()->setVisibleArea(new_visible_area);
 
2514
      }
 
2515
      return;
 
2516
    }
 
2517
 
 
2518
  }
 
2519
 
2307
2520
  void TOPPViewBase::layerDeactivated()
2308
2521
  {
2309
2522
 
2311
2524
 
2312
2525
  void TOPPViewBase::showSpectrumWidgetInWindow(SpectrumWidget* sw, const String& caption)
2313
2526
  {
2314
 
        ws_->addWindow(sw);
2315
 
    connect(sw->canvas(),SIGNAL(preferencesChange()),this,SLOT(updateLayerBar()));
2316
 
    connect(sw->canvas(),SIGNAL(layerActivated(QWidget*)),this,SLOT(layerActivated()));
2317
 
    connect(sw->canvas(),SIGNAL(layerModficationChange(Size,bool)),this,SLOT(updateLayerBar()));
2318
 
    connect(sw,SIGNAL(sendStatusMessage(std::string,OpenMS::UInt)),this,SLOT(showStatusMessage(std::string,OpenMS::UInt)));
2319
 
    connect(sw,SIGNAL(sendCursorStatus(double,double)),this,SLOT(showCursorStatus(double,double)));
2320
 
    connect(sw,SIGNAL(dropReceived(const QMimeData*,QWidget*,int)),this,SLOT(copyLayer(const QMimeData*,QWidget*,int)));
 
2527
    ws_->addWindow(sw);
 
2528
    connect(sw->canvas(), SIGNAL(preferencesChange()), this, SLOT(updateLayerBar()));
 
2529
    connect(sw->canvas(), SIGNAL(layerActivated(QWidget*)), this, SLOT(layerActivated()));
 
2530
    connect(sw->canvas(), SIGNAL(layerModficationChange(Size, bool)), this, SLOT(updateLayerBar()));
 
2531
    connect(sw->canvas(), SIGNAL(layerZoomChanged(QWidget*)), this, SLOT(layerZoomChanged()));
 
2532
    connect(sw, SIGNAL(sendStatusMessage(std::string, OpenMS::UInt)), this, SLOT(showStatusMessage(std::string, OpenMS::UInt)));
 
2533
    connect(sw, SIGNAL(sendCursorStatus(double, double)), this, SLOT(showCursorStatus(double, double)));
 
2534
    connect(sw, SIGNAL(dropReceived(const QMimeData*, QWidget*, int)), this, SLOT(copyLayer(const QMimeData*, QWidget*, int)));
2321
2535
 
2322
2536
    // 1D spectrum specific signals
2323
2537
    Spectrum1DWidget* sw1 = qobject_cast<Spectrum1DWidget*>(sw);
2328
2542
    }
2329
2543
 
2330
2544
    // 2D spectrum specific signals
2331
 
        Spectrum2DWidget* sw2 = qobject_cast<Spectrum2DWidget*>(sw);
2332
 
        if (sw2 != 0)
2333
 
        {
2334
 
                connect(sw2->getHorizontalProjection(),SIGNAL(sendCursorStatus(double,double)),this,SLOT(showCursorStatus(double,double)));
2335
 
                connect(sw2->getVerticalProjection(),SIGNAL(sendCursorStatus(double,double)),this,SLOT(showCursorStatusInvert(double,double)));
 
2545
    Spectrum2DWidget* sw2 = qobject_cast<Spectrum2DWidget*>(sw);
 
2546
    if (sw2 != 0)
 
2547
    {
 
2548
      connect(sw2->getHorizontalProjection(), SIGNAL(sendCursorStatus(double, double)), this, SLOT(showCursorStatus(double, double)));
 
2549
      connect(sw2->getVerticalProjection(), SIGNAL(sendCursorStatus(double, double)), this, SLOT(showCursorStatusInvert(double, double)));
2336
2550
      connect(sw2, SIGNAL(showSpectrumAs1D(int)), this, SLOT(showSpectrumAs1D(int)));
 
2551
      connect(sw2, SIGNAL(showSpectrumAs1D(std::vector<int, std::allocator<int> >)), this, SLOT(showSpectrumAs1D(std::vector<int, std::allocator<int> >)));
2337
2552
      connect(sw2, SIGNAL(showCurrentPeaksAs3D()), this, SLOT(showCurrentPeaksAs3D()));
2338
 
        }
 
2553
    }
2339
2554
 
2340
2555
    // 3D spectrum specific signals
2341
2556
    Spectrum3DWidget* sw3 = qobject_cast<Spectrum3DWidget*>(sw);
2344
2559
      connect(sw3, SIGNAL(showCurrentPeaksAs2D()), this, SLOT(showCurrentPeaksAs2D()));
2345
2560
    }
2346
2561
 
2347
 
          sw->setWindowTitle(caption.toQString());
 
2562
    sw->setWindowTitle(caption.toQString());
2348
2563
 
2349
 
                //add tab with id
2350
 
        static int window_counter = 4711;
 
2564
    //add tab with id
 
2565
    static int window_counter = 4711;
2351
2566
 
2352
2567
    sw->setWindowId(window_counter++);
2353
2568
 
2357
2572
    //- through the menu entry
2358
2573
    //- through the tab bar
2359
2574
    //- thourgh the MDI close button
2360
 
    connect(sw,SIGNAL(aboutToBeDestroyed(int)),tab_bar_,SLOT(removeId(int)));
 
2575
    connect(sw, SIGNAL(aboutToBeDestroyed(int)), tab_bar_, SLOT(removeId(int)));
2361
2576
 
2362
2577
    tab_bar_->setCurrentId(sw->getWindowId());
2363
2578
 
2364
 
                //show first window maximized (only visible windows are in the list)
2365
 
                if (ws_->windowList().count()==0)
2366
 
                {
2367
 
                        sw->showMaximized();
2368
 
                }
2369
 
                else
2370
 
                {
2371
 
                        sw->show();
2372
 
                }
 
2579
    //show first window maximized (only visible windows are in the list)
 
2580
    if (ws_->windowList().count() == 0)
 
2581
    {
 
2582
      sw->showMaximized();
 
2583
    }
 
2584
    else
 
2585
    {
 
2586
      sw->show();
 
2587
    }
2373
2588
    enhancedWorkspaceWindowChanged(sw->getWindowId());
2374
2589
  }
2375
2590
 
2391
2606
    }
2392
2607
  }
2393
2608
 
 
2609
  void TOPPViewBase::activate1DSpectrum(std::vector<int, std::allocator<int> > indices)
 
2610
  {
 
2611
    Spectrum1DWidget* w = getActive1DWidget();
 
2612
    if (w)
 
2613
    {
 
2614
      view_behavior_->activate1DSpectrum(indices);
 
2615
    }
 
2616
  }
 
2617
 
2394
2618
  void TOPPViewBase::deactivate1DSpectrum(int index)
2395
2619
  {
2396
2620
    Spectrum1DWidget* w = getActive1DWidget();
2414
2638
    return qobject_cast<SpectrumWidget*>(ws_->activeWindow());
2415
2639
  }
2416
2640
 
2417
 
  SpectrumCanvas*  TOPPViewBase::getActiveCanvas() const
 
2641
  SpectrumCanvas* TOPPViewBase::getActiveCanvas() const
2418
2642
  {
2419
2643
    SpectrumWidget* sw = qobject_cast<SpectrumWidget*>(ws_->activeWindow());
2420
2644
    if (sw == 0)
2421
2645
    {
2422
 
        return 0;
 
2646
      return 0;
2423
2647
    }
2424
2648
    return sw->canvas();
2425
2649
  }
2426
2650
 
2427
 
 
2428
 
  TOPPASWidget* TOPPViewBase::getActiveTOPPASWidget() const
2429
 
  {
2430
 
    if (!ws_->activeWindow())
2431
 
    {
2432
 
      return 0;
2433
 
    }
2434
 
    return qobject_cast<TOPPASWidget*>(ws_->activeWindow());
2435
 
  }
2436
 
 
2437
2651
  Spectrum1DWidget* TOPPViewBase::getActive1DWidget() const
2438
2652
  {
2439
2653
    Spectrum1DWidget* w = qobject_cast<Spectrum1DWidget*>(getActiveSpectrumWidget());
2441
2655
    {
2442
2656
      return 0;
2443
2657
    }
2444
 
                return w;
 
2658
    return w;
2445
2659
  }
2446
2660
 
2447
2661
  Spectrum2DWidget* TOPPViewBase::getActive2DWidget() const
2451
2665
    {
2452
2666
      return 0;
2453
2667
    }
2454
 
                return w;
 
2668
    return w;
2455
2669
  }
2456
2670
 
2457
2671
  Spectrum3DWidget* TOPPViewBase::getActive3DWidget() const
2461
2675
    {
2462
2676
      return 0;
2463
2677
    }
2464
 
                return w;
 
2678
    return w;
2465
2679
  }
2466
2680
 
2467
2681
  void TOPPViewBase::loadPreferences(String filename)
2477
2691
    // load preferences, if file exists
2478
2692
    if (File::exists(filename))
2479
2693
    {
2480
 
        bool error = false;
2481
 
        Param tmp;
2482
 
      try
2483
 
      { // the file might be corrupt
2484
 
          tmp.load(filename);
 
2694
      bool error = false;
 
2695
      Param tmp;
 
2696
      ParamXMLFile paramFile;
 
2697
      try // the file might be corrupt
 
2698
      {
 
2699
        paramFile.load(filename, tmp);
2485
2700
      }
2486
2701
      catch (...)
2487
2702
      {
2489
2704
      }
2490
2705
 
2491
2706
      //apply preferences if they are of the current TOPPView version
2492
 
      if(!error && tmp.exists("preferences:version") &&
 
2707
      if (!error && tmp.exists("preferences:version") &&
2493
2708
          tmp.getValue("preferences:version").toString() == VersionInfo::getVersion())
2494
 
        {
2495
 
                try
2496
 
                {
2497
 
                setParameters(tmp);
2498
 
                }
2499
 
                catch (Exception::InvalidParameter& /*e*/)
2500
 
                {
2501
 
                        error = true;
2502
 
                }
2503
 
        }
2504
 
        else
2505
 
        {
2506
 
                                error = true;
2507
 
        }
2508
 
 
2509
 
                        //set parameters to defaults when something is fishy with the parameters file
2510
 
                        if (error)
2511
 
                        {
2512
 
                        //reset parameters (they will be stored again when TOPPView quits)
2513
 
                        setParameters(Param());
2514
 
 
2515
 
                                cerr << "The TOPPView preferences files '" << filename << "' was ignored. It is no longer compatible with this TOPPView version and will be replaced." << endl;
2516
 
                        }
 
2709
      {
 
2710
        try
 
2711
        {
 
2712
          setParameters(tmp);
 
2713
        }
 
2714
        catch (Exception::InvalidParameter& /*e*/)
 
2715
        {
 
2716
          error = true;
 
2717
        }
 
2718
      }
 
2719
      else
 
2720
      {
 
2721
        error = true;
 
2722
      }
 
2723
 
 
2724
      //set parameters to defaults when something is fishy with the parameters file
 
2725
      if (error)
 
2726
      {
 
2727
        //reset parameters (they will be stored again when TOPPView quits)
 
2728
        setParameters(Param());
 
2729
 
 
2730
        cerr << "The TOPPView preferences files '" << filename << "' was ignored. It is no longer compatible with this TOPPView version and will be replaced." << endl;
 
2731
      }
2517
2732
    }
2518
2733
    else if (filename != default_ini_file)
2519
2734
    {
2520
 
        cerr << "Unable to load INI File: '" << filename << "'" << endl;
 
2735
      cerr << "Unable to load INI File: '" << filename << "'" << endl;
2521
2736
    }
2522
 
    param_.setValue("PreferencesFile" , filename);
 
2737
    param_.setValue("PreferencesFile", filename);
2523
2738
 
2524
2739
    //set the recent files
2525
2740
    Param p = param_.copy("preferences:RecentFiles");
2526
 
    if (p.size()!=0)
 
2741
    if (p.size() != 0)
2527
2742
    {
2528
 
      for (Param::ParamIterator it=p.begin() ; it!=p.end() ; ++it)
 
2743
      for (Param::ParamIterator it = p.begin(); it != p.end(); ++it)
2529
2744
      {
2530
 
        QString filename = it->value.toQString();
2531
 
        if (File::exists(filename)) recent_files_.append(filename);
 
2745
        QString filename = it->value.toQString();
 
2746
        if (File::exists(filename))
 
2747
          recent_files_.append(filename);
2532
2748
      }
2533
2749
    }
2534
2750
 
2542
2758
 
2543
2759
    for (int i = 0; i < recent_files_.size(); ++i)
2544
2760
    {
2545
 
      param_.setValue("preferences:RecentFiles:"+String(i),recent_files_[i]);
 
2761
      param_.setValue("preferences:RecentFiles:" + String(i), recent_files_[i]);
2546
2762
    }
2547
2763
 
2548
 
                //set version
2549
 
                param_.setValue("preferences:version",VersionInfo::getVersion());
 
2764
    //set version
 
2765
    param_.setValue("preferences:version", VersionInfo::getVersion());
2550
2766
 
2551
2767
    //save only the subsection that begins with "preferences:"
 
2768
    ParamXMLFile paramFile;
2552
2769
    try
2553
2770
    {
2554
 
      param_.copy("preferences:").store(string(param_.getValue("PreferencesFile")));
 
2771
      paramFile.store(string(param_.getValue("PreferencesFile")), param_.copy("preferences:"));
2555
2772
    }
2556
 
    catch(Exception::UnableToCreateFile& /*e*/)
 
2773
    catch (Exception::UnableToCreateFile& /*e*/)
2557
2774
    {
2558
2775
      cerr << "Unable to create INI File: '" << string(param_.getValue("PreferencesFile")) << "'" << endl;
2559
2776
    }
2561
2778
 
2562
2779
  void TOPPViewBase::openRecentFile()
2563
2780
  {
2564
 
                QAction* action = qobject_cast<QAction *>(sender());
 
2781
    QAction* action = qobject_cast<QAction*>(sender());
2565
2782
    if (action)
2566
 
                {
 
2783
    {
2567
2784
      QString filename = action->text();
2568
 
      if (filename.endsWith(".toppas", Qt::CaseInsensitive))
2569
 
      {
2570
 
        addTOPPASFile(filename, true);
2571
 
      }
2572
 
      else
2573
 
      {
2574
 
        addDataFile(filename, true, true);
2575
 
      }
 
2785
      addDataFile(filename, true, true);
2576
2786
    }
2577
 
        }
 
2787
  }
2578
2788
 
2579
2789
  QStringList TOPPViewBase::getFileList_(const String& path_overwrite)
2580
2790
  {
2581
 
    String filter_all = "readable files (*.mzML *.mzXML *.mzData *.featureXML *.consensusXML *.idXML *.dta *.dta2d fid *.bz2 *.gz *.toppas);;";
2582
 
    String filter_single = "mzML files (*.mzML);;mzXML files (*.mzXML);;mzData files (*.mzData);;feature map (*.featureXML);;consensus feature map (*.consensusXML);;peptide identifications (*.idXML);;XML files (*.xml);;XMass Analysis (fid);;dta files (*.dta);;dta2d files (*.dta2d);;bzipped files (*.bz2);;gzipped files (*.gz);;TOPPAS files (*.toppas);;all files (*)";
 
2791
    String filter_all = "readable files (*.mzML *.mzXML *.mzData *.featureXML *.consensusXML *.idXML *.dta *.dta2d fid *.bz2 *.gz);;";
 
2792
    String filter_single = "mzML files (*.mzML);;mzXML files (*.mzXML);;mzData files (*.mzData);;feature map (*.featureXML);;consensus feature map (*.consensusXML);;peptide identifications (*.idXML);;XML files (*.xml);;XMass Analysis (fid);;dta files (*.dta);;dta2d files (*.dta2d);;bzipped files (*.bz2);;gzipped files (*.gz);;all files (*)";
2583
2793
 
2584
 
                QString open_path = current_path_.toQString();
2585
 
                if (path_overwrite!="")
2586
 
                {
 
2794
    QString open_path = current_path_.toQString();
 
2795
    if (path_overwrite != "")
 
2796
    {
2587
2797
      open_path = path_overwrite.toQString();
2588
 
                }
 
2798
    }
2589
2799
    // we use the QT file dialog instead of using QFileDialog::Names(...)
2590
 
                // On Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog,
2591
 
                // which prevents us from doing GUI testing on it.
 
2800
    // On Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog,
 
2801
    // which prevents us from doing GUI testing on it.
2592
2802
    QFileDialog dialog(this, "Open file(s)", open_path, (filter_all + filter_single).toQString());
2593
 
                dialog.setFileMode(QFileDialog::ExistingFiles);
2594
 
                QStringList file_names;
 
2803
    dialog.setFileMode(QFileDialog::ExistingFiles);
 
2804
    QStringList file_names;
2595
2805
 
2596
2806
    if (dialog.exec())
2597
2807
    {
2598
2808
      file_names = dialog.selectedFiles();
2599
2809
    }
2600
2810
 
2601
 
                return file_names;
 
2811
    return file_names;
2602
2812
  }
2603
2813
 
2604
2814
  void TOPPViewBase::openFileDialog()
2605
2815
  {
2606
 
                QStringList files = getFileList_();
2607
 
    for(QStringList::iterator it = files.begin(); it!=files.end(); ++it)
2608
 
                {
 
2816
    QStringList files = getFileList_();
 
2817
    for (QStringList::iterator it = files.begin(); it != files.end(); ++it)
 
2818
    {
2609
2819
      QString filename = *it;
2610
 
      if (filename.endsWith(".toppas", Qt::CaseInsensitive))
2611
 
      {
2612
 
        addTOPPASFile(filename, true);
2613
 
      }
2614
 
      else
2615
 
      {
2616
 
        addDataFile(filename, true, true);
2617
 
      }
2618
 
                }
2619
 
  }
2620
 
 
2621
 
  void TOPPViewBase::addTOPPASFile(const String& file_name, bool in_new_window)
2622
 
  {
2623
 
    TOPPASScene* scene = 0;
2624
 
    if (in_new_window) // open in new window
2625
 
    {
2626
 
      // create TOPPASWidget, load data and open in new window
2627
 
      TOPPASWidget* tw = new TOPPASWidget(Param(), ws_, toppas_tmp_path_);
2628
 
      showTOPPipelineInWindow_(tw, File::basename(file_name));
2629
 
      scene = tw->getScene();
2630
 
      scene->load(file_name);
2631
 
      addRecentFile_(file_name);
2632
 
    }
2633
 
    else  // merge into existing scene
2634
 
    {
2635
 
      TOPPASWidget* tw = getActiveTOPPASWidget();
2636
 
      if (!tw)
2637
 
      {
2638
 
        return;
2639
 
      }
2640
 
      // create TOPPASWidget, load data into temporary scene and include into existing one
2641
 
      TOPPASScene* tmp_scene = new TOPPASScene(0, File::getTempDirectory().toQString()+QDir::separator(), false);
2642
 
      tmp_scene->load(file_name);
2643
 
      scene = tw->getScene();
2644
 
      scene->include(tmp_scene);
2645
 
      delete tmp_scene;
2646
 
    }
2647
 
 
2648
 
    if (in_new_window)
2649
 
    {
2650
 
      // connect scene signals only if we created a new window (otherwise they already exist)
2651
 
      connect(scene, SIGNAL(saveMe()), this, SLOT(savePipeline()));
2652
 
      connect(scene, SIGNAL(selectionCopied(TOPPASScene*)), this, SLOT(saveToClipboard(TOPPASScene*)));
2653
 
      connect(scene, SIGNAL(requestClipboardContent()), this, SLOT(sendClipboardContent()));
2654
 
      connect(scene, SIGNAL(mainWindowNeedsUpdate()), this, SLOT(updateMenu()));
2655
 
      connect(scene, SIGNAL(openInTOPPView(QStringList)), this, SLOT(openFilesInTOPPView(QStringList)));
2656
 
    }
2657
 
 
2658
 
    //connect vertex signals/slots for log messages
2659
 
    for (TOPPASScene::VertexIterator it = scene->verticesBegin(); it != scene->verticesEnd(); ++it)
2660
 
    {
2661
 
      TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(*it);
2662
 
      if (tv)
2663
 
      {
2664
 
        connect(tv, SIGNAL(toolStarted()), this, SLOT(toolStarted()));
2665
 
        connect(tv, SIGNAL(toolFinished()), this, SLOT(toolFinished()));
2666
 
        connect(tv, SIGNAL(toolCrashed()), this, SLOT(toolCrashed()));
2667
 
        connect(tv, SIGNAL(toolFailed()), this, SLOT(toolFailed()));
2668
 
        connect(tv, SIGNAL(toppOutputReady(const QString&)), this, SLOT(updateTOPPOutputLog(const QString&)));
2669
 
        continue;
2670
 
      }
2671
 
      TOPPASOutputFileListVertex* oflv = qobject_cast<TOPPASOutputFileListVertex*>(*it);
2672
 
      if (oflv)
2673
 
      {
2674
 
        connect (oflv, SIGNAL(outputFileWritten(const String&)), this, SLOT(outputVertexFinished(const String&)));
2675
 
        continue;
2676
 
      }
2677
 
    }
2678
 
  }
2679
 
 
2680
 
  void TOPPViewBase::showTOPPipelineInWindow_(TOPPASWidget* tw, const String& caption)
2681
 
  {
2682
 
    ws_->addWindow(tw);
2683
 
 
2684
 
    connect(tw,SIGNAL(sendStatusMessage(std::string,OpenMS::UInt)),this,SLOT(showStatusMessage(std::string,OpenMS::UInt)));
2685
 
    connect(tw,SIGNAL(sendCursorStatus(double,double)),this,SLOT(showCursorStatus(double,double)));
2686
 
    connect(tw,SIGNAL(toolDroppedOnWidget(double,double)),this,SLOT(insertNewVertex_(double,double)));
2687
 
    connect(tw,SIGNAL(pipelineDroppedOnWidget(const String&, bool)),this,SLOT(addTOPPASFile(const String&, bool)));
2688
 
 
2689
 
    tw->setWindowTitle(caption.toQString());
2690
 
 
2691
 
    //add tab with id
2692
 
    static int window_counter = 1337;
2693
 
    tw->setWindowId(window_counter);
2694
 
    window_counter++;
2695
 
 
2696
 
    //connect slots and signals for removing the widget from the bar, when it is closed
2697
 
    //- through the menu entry
2698
 
    //- through the tab bar
2699
 
    //- through the MDI close button
2700
 
    connect(tw, SIGNAL(aboutToBeDestroyed(int)),tab_bar_,SLOT(removeId(int)));
2701
 
 
2702
 
    //show first window maximized (only visible windows are in the list)
2703
 
    if (ws_->windowList().count()==0)
2704
 
    {
2705
 
      tw->showMaximized();
2706
 
    }
2707
 
    else
2708
 
    {
2709
 
      tw->show();
2710
 
    }
2711
 
    TOPPASScene* ts = tw->getScene();
2712
 
 
2713
 
    connect (ts, SIGNAL(entirePipelineFinished()), this, SLOT(showPipelineFinishedLogMessage()));
2714
 
    connect (ts, SIGNAL(entirePipelineFinished()), this, SLOT(updateMenu()));
2715
 
    connect (ts, SIGNAL(pipelineExecutionFailed()), this, SLOT(updateMenu()));
2716
 
 
2717
 
    ts->setSceneRect((tw->mapToScene(tw->rect())).boundingRect());
2718
 
 
2719
 
    tab_bar_->addTab(caption.toQString(), tw->getWindowId());
2720
 
    tab_bar_->setCurrentId(tw->getWindowId());
2721
 
    enhancedWorkspaceWindowChanged(tw->getWindowId());
2722
 
  }
2723
 
 
2724
 
  void TOPPViewBase::insertNewVertex_(double x, double y, QTreeWidgetItem* item)
2725
 
  {
2726
 
    // get toppas tree view from tab widget 2
2727
 
    TOPPASTreeView* toppas_tree_view = qobject_cast<TOPPASTreeView*>(views_tabwidget_->widget(2));
2728
 
 
2729
 
    if (!getActiveTOPPASWidget() || !getActiveTOPPASWidget()->getScene() || !toppas_tree_view)
2730
 
    {
2731
 
      return;
2732
 
    }
2733
 
 
2734
 
    TOPPASScene* scene = getActiveTOPPASWidget()->getScene();
2735
 
    QTreeWidgetItem* current_tool = item ? item : toppas_tree_view->currentItem();
2736
 
    String tool_name = String(current_tool->text(0));
2737
 
    TOPPASVertex* tv = 0;
2738
 
 
2739
 
    if (tool_name == "<Input files>")
2740
 
    {
2741
 
      tv = new TOPPASInputFileListVertex();
2742
 
    }
2743
 
    else if (tool_name == "<Output files>")
2744
 
    {
2745
 
      tv = new TOPPASOutputFileListVertex();
2746
 
      TOPPASOutputFileListVertex* oflv = qobject_cast<TOPPASOutputFileListVertex*>(tv);
2747
 
      connect (oflv, SIGNAL(outputFileWritten(const String&)), this, SLOT(outputVertexFinished(const String&)));
2748
 
      scene->connectOutputVertexSignals(oflv);
2749
 
    }
2750
 
    else if (tool_name == "<Merger>")
2751
 
    {
2752
 
      tv = new TOPPASMergerVertex(true);
2753
 
    }
2754
 
    else if (tool_name == "<Collector>")
2755
 
    {
2756
 
      tv = new TOPPASMergerVertex(false);
2757
 
    }
2758
 
    else // node is a TOPP tool
2759
 
    {
2760
 
      if (current_tool->childCount() > 0)
2761
 
      {
2762
 
        // category or tool name with types is selected (instead of a concrete type)
2763
 
        return;
2764
 
      }
2765
 
      String tool_type;
2766
 
      if (current_tool->parent() != 0 && current_tool->parent()->parent() != 0)
2767
 
      {
2768
 
        // selected item is a type
2769
 
        tool_type = String(current_tool->text(0));
2770
 
        tool_name = String(current_tool->parent()->text(0));
2771
 
      }
2772
 
      else
2773
 
      {
2774
 
        // normal tool which does not have type selected
2775
 
        tool_name = String(current_tool->text(0));
2776
 
        tool_type = "";
2777
 
      }
2778
 
 
2779
 
      tv = new TOPPASToolVertex(tool_name, tool_type);
2780
 
      TOPPASToolVertex* ttv = qobject_cast<TOPPASToolVertex*>(tv);
2781
 
      connect (ttv, SIGNAL(toolStarted()), this, SLOT(toolStarted()));
2782
 
      connect (ttv, SIGNAL(toolFinished()), this, SLOT(toolFinished()));
2783
 
      connect (ttv, SIGNAL(toolCrashed()), this, SLOT(toolCrashed()));
2784
 
      connect (ttv, SIGNAL(toolFailed()), this, SLOT(toolFailed()));
2785
 
      connect (ttv, SIGNAL(toppOutputReady(const QString&)), this, SLOT(updateTOPPOutputLog(const QString&)));
2786
 
 
2787
 
      scene->connectToolVertexSignals(ttv);
2788
 
    }
2789
 
 
2790
 
    scene->connectVertexSignals(tv);
2791
 
    scene->addVertex(tv);
2792
 
    tv->setPos(x,y);
2793
 
    tv->setZValue(toppas_z_value_);
2794
 
    toppas_z_value_ += 0.000001;
2795
 
    scene->topoSort();
2796
 
    scene->setChanged(true);
2797
 
  }
2798
 
 
2799
 
  void TOPPViewBase::insertNewVertexInCenter_(QTreeWidgetItem* item)
2800
 
  {
2801
 
    TOPPASTreeView* toppas_tree_view = qobject_cast<TOPPASTreeView*>(views_tabwidget_->widget(2));
2802
 
 
2803
 
    if (!getActiveTOPPASWidget() || !getActiveTOPPASWidget()->getScene() || !toppas_tree_view || !toppas_tree_view->currentItem())
2804
 
    {
2805
 
      return;
2806
 
    }
2807
 
 
2808
 
    QPointF insert_pos = getActiveTOPPASWidget()->mapToScene(QPoint((getActiveTOPPASWidget()->width()/2.0)+(qreal)(5*toppas_node_offset_),(getActiveTOPPASWidget()->height()/2.0)+(qreal)(5*toppas_node_offset_)));
2809
 
    insertNewVertex_(insert_pos.x(), insert_pos.y(), item);
2810
 
    toppas_node_offset_ = (toppas_node_offset_+1) % 10;
 
2820
      addDataFile(filename, true, true);
 
2821
    }
2811
2822
  }
2812
2823
 
2813
2824
  void TOPPViewBase::openExampleDialog()
2814
2825
  {
2815
 
                QStringList files = getFileList_(File::getOpenMSDataPath() + "/examples/");
 
2826
    QStringList files = getFileList_(File::getOpenMSDataPath() + "/examples/");
2816
2827
 
2817
 
    for(QStringList::iterator it = files.begin(); it != files.end(); ++it)
2818
 
                {
 
2828
    for (QStringList::iterator it = files.begin(); it != files.end(); ++it)
 
2829
    {
2819
2830
      QString filename = *it;
2820
 
      if (filename.endsWith(".toppas", Qt::CaseInsensitive))
2821
 
      {
2822
 
        addTOPPASFile(filename, true);
2823
 
      }
2824
 
      else
2825
 
      {
2826
 
        addDataFile(filename, true, true);
2827
 
      }
2828
 
                }
2829
 
  }
2830
 
 
2831
 
        void TOPPViewBase::connectToDB_(DBConnection& db)
2832
 
        {
2833
 
                //get the password if unset
2834
 
                if (!param_.exists("DBPassword"))
2835
 
                {
2836
 
                        stringstream ss;
2837
 
                        ss << "Enter password for user '" << (String)param_.getValue("preferences:db:login") << "' at '"<< (String)param_.getValue("preferences:db:host")<<":"<<(String)param_.getValue("preferences:db:port")<<"' : ";
2838
 
                        bool ok;
2839
 
                        QString text = QInputDialog::getText(this, "TOPPView database password", ss.str().c_str(), QLineEdit::Password,QString::null, &ok);
2840
 
                        if ( ok )
2841
 
                        {
2842
 
                                param_.setValue("DBPassword",text);
2843
 
                        }
2844
 
                }
2845
 
 
2846
 
                if (param_.exists("DBPassword"))
2847
 
                {
2848
 
                        try
2849
 
                        {
2850
 
                                db.connect((String)param_.getValue("preferences:db:name"), (String)param_.getValue("preferences:db:login"),(String)param_.getValue("DBPassword"),(String)param_.getValue("preferences:db:host"),(UInt)param_.getValue("preferences:db:port"));
2851
 
                        }
2852
 
                        catch (DBConnection::InvalidQuery& er)
2853
 
                        {
2854
 
                                param_.remove("DBPassword");
2855
 
                                showLogMessage_(LS_ERROR,"Unable to log in to the database server",String("Check the login data in the preferences!\nDatabase error message: ") + er.what());
2856
 
                        }
2857
 
                }
2858
 
        }
 
2831
      addDataFile(filename, true, true);
 
2832
    }
 
2833
  }
 
2834
 
 
2835
  void TOPPViewBase::connectToDB_(DBConnection& db)
 
2836
  {
 
2837
    //get the password if unset
 
2838
    if (!param_.exists("DBPassword"))
 
2839
    {
 
2840
      stringstream ss;
 
2841
      ss << "Enter password for user '" << (String)param_.getValue("preferences:db:login") << "' at '" << (String)param_.getValue("preferences:db:host") << ":" << (String)param_.getValue("preferences:db:port") << "' : ";
 
2842
      bool ok;
 
2843
      QString text = QInputDialog::getText(this, "TOPPView database password", ss.str().c_str(), QLineEdit::Password, QString::null, &ok);
 
2844
      if (ok)
 
2845
      {
 
2846
        param_.setValue("DBPassword", text);
 
2847
      }
 
2848
    }
 
2849
 
 
2850
    if (param_.exists("DBPassword"))
 
2851
    {
 
2852
      try
 
2853
      {
 
2854
        db.connect((String)param_.getValue("preferences:db:name"), (String)param_.getValue("preferences:db:login"), (String)param_.getValue("DBPassword"), (String)param_.getValue("preferences:db:host"), (UInt)param_.getValue("preferences:db:port"));
 
2855
      }
 
2856
      catch (DBConnection::InvalidQuery& er)
 
2857
      {
 
2858
        param_.remove("DBPassword");
 
2859
        showLogMessage_(LS_ERROR, "Unable to log in to the database server", String("Check the login data in the preferences!\nDatabase error message: ") + er.what());
 
2860
      }
 
2861
    }
 
2862
  }
2859
2863
 
2860
2864
  void TOPPViewBase::openDatabaseDialog()
2861
2865
  {
2862
 
                DBConnection db;
2863
 
                connectToDB_(db);
2864
 
                if (db.isConnected())
2865
 
                {
2866
 
                        vector<UInt> result;
2867
 
                        DBOpenDialog db_dialog(db,result,this);
2868
 
                        if (db_dialog.exec())
2869
 
                        {
2870
 
                                db.disconnect();
2871
 
                                for (vector<UInt>::iterator it = result.begin();it!=result.end();++it)
2872
 
                                {
 
2866
    DBConnection db;
 
2867
    connectToDB_(db);
 
2868
    if (db.isConnected())
 
2869
    {
 
2870
      vector<UInt> result;
 
2871
      DBOpenDialog db_dialog(db, result, this);
 
2872
      if (db_dialog.exec())
 
2873
      {
 
2874
        db.disconnect();
 
2875
        for (vector<UInt>::iterator it = result.begin(); it != result.end(); ++it)
 
2876
        {
2873
2877
          addDataDB(*it, true);
2874
 
                                }
2875
 
                        }
2876
 
                }
2877
 
  }
2878
 
 
2879
 
        void TOPPViewBase::rerunTOPPTool()
2880
 
        {
2881
 
                //warn if hidden layer => wrong layer selected...
2882
 
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
2883
 
                if (!layer.visible)
2884
 
                {
2885
 
                showLogMessage_(LS_NOTICE,"The current layer is not visible","Have you selected the right layer for this action?");
2886
 
                }
2887
 
 
2888
 
                //delete old input and output file
2889
 
                File::remove(topp_.file_name + "_in");
2890
 
                File::remove(topp_.file_name + "_out");
2891
 
 
2892
 
                //run the tool
2893
 
                runTOPPTool_();
2894
 
        }
2895
 
 
2896
 
        void TOPPViewBase::showTOPPDialog()
2897
 
        {
2898
 
                QAction* action = qobject_cast<QAction*>(sender());
2899
 
                showTOPPDialog_(action->data().toBool());
2900
 
        }
2901
 
 
2902
 
        void TOPPViewBase::showTOPPDialog_(bool visible)
2903
 
        {
2904
 
                //warn if hidden layer => wrong layer selected...
2905
 
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
2906
 
                if (!layer.visible)
2907
 
                {
2908
 
                showLogMessage_(LS_NOTICE,"The current layer is not visible","Have you selected the right layer for this action?");
2909
 
                }
2910
 
 
2911
 
                //create and store unique file name prefix for files
2912
 
                topp_.file_name = param_.getValue("preferences:tmp_file_path").toString() + "/TOPPView_" + File::getUniqueName();
2913
 
                if (!File::writable(topp_.file_name+"_ini"))
2914
 
                {
2915
 
                        showLogMessage_(LS_ERROR,"Cannot create temporary file",String("Cannot write to '")+topp_.file_name+"'_ini!");
2916
 
                        return;
2917
 
                }
2918
 
                ToolsDialog tools_dialog(this,topp_.file_name+"_ini",current_path_,getCurrentLayer()->type);
2919
 
 
2920
 
                if(tools_dialog.exec()==QDialog::Accepted)
2921
 
                {
2922
 
                        //Store tool name, input parameter and output parameter
2923
 
                        topp_.tool = tools_dialog.getTool();
2924
 
                        topp_.in = tools_dialog.getInput();
2925
 
                        topp_.out = tools_dialog.getOutput();
2926
 
                        topp_.visible = visible;
2927
 
                        //run the tool
2928
 
                        runTOPPTool_();
2929
 
                }
2930
 
        }
2931
 
 
2932
 
        void TOPPViewBase::runTOPPTool_()
2933
 
        {
2934
 
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
2935
 
 
2936
 
                //test if files are writable
2937
 
                if (!File::writable(topp_.file_name+"_in"))
2938
 
                {
2939
 
                        showLogMessage_(LS_ERROR,"Cannot create temporary file",String("Cannot write to '")+topp_.file_name+"_in'!");
2940
 
                        return;
2941
 
                }
2942
 
                if (!File::writable(topp_.file_name+"_out"))
2943
 
                {
2944
 
                        showLogMessage_(LS_ERROR,"Cannot create temporary file",String("Cannot write to '")+topp_.file_name+"'_out!");
2945
 
                        return;
2946
 
                }
2947
 
 
2948
 
                //Store data
2949
 
                topp_.layer_name = layer.name;
 
2878
        }
 
2879
      }
 
2880
    }
 
2881
  }
 
2882
 
 
2883
  void TOPPViewBase::rerunTOPPTool()
 
2884
  {
 
2885
    //warn if hidden layer => wrong layer selected...
 
2886
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
 
2887
    if (!layer.visible)
 
2888
    {
 
2889
      showLogMessage_(LS_NOTICE, "The current layer is not visible", "Have you selected the right layer for this action?");
 
2890
    }
 
2891
 
 
2892
    //delete old input and output file
 
2893
    File::remove(topp_.file_name + "_in");
 
2894
    File::remove(topp_.file_name + "_out");
 
2895
 
 
2896
    //run the tool
 
2897
    runTOPPTool_();
 
2898
  }
 
2899
 
 
2900
  void TOPPViewBase::showTOPPDialog()
 
2901
  {
 
2902
    QAction* action = qobject_cast<QAction*>(sender());
 
2903
    showTOPPDialog_(action->data().toBool());
 
2904
  }
 
2905
 
 
2906
  void TOPPViewBase::showTOPPDialog_(bool visible)
 
2907
  {
 
2908
    //warn if hidden layer => wrong layer selected...
 
2909
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
 
2910
    if (!layer.visible)
 
2911
    {
 
2912
      showLogMessage_(LS_NOTICE, "The current layer is not visible", "Have you selected the right layer for this action?");
 
2913
    }
 
2914
 
 
2915
    //create and store unique file name prefix for files
 
2916
    topp_.file_name = param_.getValue("preferences:tmp_file_path").toString() + "/TOPPView_" + File::getUniqueName();
 
2917
    if (!File::writable(topp_.file_name + "_ini"))
 
2918
    {
 
2919
      showLogMessage_(LS_ERROR, "Cannot create temporary file", String("Cannot write to '") + topp_.file_name + "'_ini!");
 
2920
      return;
 
2921
    }
 
2922
    ToolsDialog tools_dialog(this, topp_.file_name + "_ini", current_path_, getCurrentLayer()->type);
 
2923
 
 
2924
    if (tools_dialog.exec() == QDialog::Accepted)
 
2925
    {
 
2926
      //Store tool name, input parameter and output parameter
 
2927
      topp_.tool = tools_dialog.getTool();
 
2928
      topp_.in = tools_dialog.getInput();
 
2929
      topp_.out = tools_dialog.getOutput();
 
2930
      topp_.visible = visible;
 
2931
      //run the tool
 
2932
      runTOPPTool_();
 
2933
    }
 
2934
  }
 
2935
 
 
2936
  void TOPPViewBase::runTOPPTool_()
 
2937
  {
 
2938
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
 
2939
 
 
2940
    //test if files are writable
 
2941
    if (!File::writable(topp_.file_name + "_in"))
 
2942
    {
 
2943
      showLogMessage_(LS_ERROR, "Cannot create temporary file", String("Cannot write to '") + topp_.file_name + "_in'!");
 
2944
      return;
 
2945
    }
 
2946
    if (!File::writable(topp_.file_name + "_out"))
 
2947
    {
 
2948
      showLogMessage_(LS_ERROR, "Cannot create temporary file", String("Cannot write to '") + topp_.file_name + "'_out!");
 
2949
      return;
 
2950
    }
 
2951
 
 
2952
    //Store data
 
2953
    topp_.layer_name = layer.name;
2950
2954
    topp_.window_id = getActiveSpectrumWidget()->getWindowId();
2951
2955
    topp_.spectrum_id = layer.getCurrentSpectrumIndex();
2952
 
                if (layer.type==LayerData::DT_PEAK)
2953
 
                {
2954
 
                        MzMLFile f;
2955
 
                        f.setLogType(ProgressLogger::GUI);
2956
 
                        if (topp_.visible)
2957
 
                        {
2958
 
                                ExperimentType exp;
2959
 
        getActiveCanvas()->getVisiblePeakData(exp);
2960
 
                                f.store(topp_.file_name+"_in",exp);
2961
 
                        }
2962
 
                        else
2963
 
                        {
2964
 
        f.store(topp_.file_name+"_in",*layer.getPeakData());
2965
 
                        }
2966
 
                }
2967
 
                else if (layer.type==LayerData::DT_FEATURE)
2968
 
                {
2969
 
                        if (topp_.visible)
2970
 
                        {
2971
 
                                FeatureMapType map;
 
2956
    if (layer.type == LayerData::DT_PEAK  && !(layer.chromatogram_flag_set()))
 
2957
    {
 
2958
      MzMLFile f;
 
2959
      f.setLogType(ProgressLogger::GUI);
 
2960
      if (topp_.visible)
 
2961
      {
 
2962
        ExperimentType exp;
 
2963
        getActiveCanvas()->getVisiblePeakData(exp);
 
2964
        f.store(topp_.file_name + "_in", exp);
 
2965
      }
 
2966
      else
 
2967
      {
 
2968
 
 
2969
        f.store(topp_.file_name + "_in", *layer.getPeakData());
 
2970
      }
 
2971
    }
 
2972
    else if (layer.type == LayerData::DT_CHROMATOGRAM || layer.chromatogram_flag_set())
 
2973
    {
 
2974
      MzMLFile f;
 
2975
      // This means we have chromatogram data, either as DT_CHROMATOGRAM or as
 
2976
      // DT_PEAK with the chromatogram flag set. To run the TOPPTool we need to
 
2977
      // remove the flag and add the newly generated layer as spectrum data
 
2978
      // (otherwise we run into problems with SpectraViewWidget::updateEntries
 
2979
      // which assumes that all chromatogram data has chromatograms).
 
2980
      getActiveCanvas()->getCurrentLayer().remove_chromatogram_flag(); // removing the flag is not constant
 
2981
      //getActiveCanvas()->getCurrentLayer().getPeakData()->setMetaValue("chromatogram_passed_through_TOPP", "true");
 
2982
 
 
2983
      f.setLogType(ProgressLogger::GUI);
 
2984
      if (topp_.visible)
 
2985
      {
 
2986
        ExperimentType exp;
 
2987
        getActiveCanvas()->getVisiblePeakData(exp);
 
2988
        f.store(topp_.file_name + "_in", exp);
 
2989
      }
 
2990
      else
 
2991
      {
 
2992
        f.store(topp_.file_name + "_in", *layer.getPeakData());
 
2993
      }
 
2994
    }
 
2995
    else if (layer.type == LayerData::DT_FEATURE)
 
2996
    {
 
2997
      if (topp_.visible)
 
2998
      {
 
2999
        FeatureMapType map;
2972
3000
        getActiveCanvas()->getVisibleFeatureData(map);
2973
 
                                FeatureXMLFile().store(topp_.file_name+"_in",map);
2974
 
                        }
2975
 
                        else
2976
 
                        {
2977
 
        FeatureXMLFile().store(topp_.file_name+"_in",*layer.getFeatureMap());
2978
 
                        }
2979
 
                }
2980
 
                else
2981
 
                {
2982
 
                        if (topp_.visible)
2983
 
                        {
2984
 
                                ConsensusMapType map;
 
3001
        FeatureXMLFile().store(topp_.file_name + "_in", map);
 
3002
      }
 
3003
      else
 
3004
      {
 
3005
        FeatureXMLFile().store(topp_.file_name + "_in", *layer.getFeatureMap());
 
3006
      }
 
3007
    }
 
3008
    else
 
3009
    {
 
3010
      if (topp_.visible)
 
3011
      {
 
3012
        ConsensusMapType map;
2985
3013
        getActiveCanvas()->getVisibleConsensusData(map);
2986
 
                                ConsensusXMLFile().store(topp_.file_name+"_in",map);
2987
 
                        }
2988
 
                        else
2989
 
                        {
2990
 
        ConsensusXMLFile().store(topp_.file_name+"_in",*layer.getConsensusMap());
2991
 
                        }
2992
 
                }
2993
 
 
2994
 
                //compose argument list
2995
 
                QStringList args;
2996
 
                args << "-ini"
2997
 
                                 << (topp_.file_name + "_ini").toQString()
2998
 
                                 << QString("-%1").arg(topp_.in.toQString())
2999
 
                                 << (topp_.file_name + "_in").toQString()
3000
 
                                 << "-no_progress";
3001
 
                if (topp_.out!="")
3002
 
                {
3003
 
                        args << QString("-%1").arg(topp_.out.toQString())
3004
 
                                         << (topp_.file_name+"_out").toQString();
3005
 
                }
3006
 
 
3007
 
                //start log and show it
3008
 
                showLogMessage_(LS_NOTICE,"Starting TOPP tool","");// tool + args.join(" "));
3009
 
 
3010
 
                //start process
3011
 
                topp_.process = new QProcess();
3012
 
                topp_.process->setProcessChannelMode(QProcess::MergedChannels);
3013
 
                connect(topp_.process,SIGNAL(readyReadStandardOutput()),this,SLOT(updateProcessLog()));
3014
 
                topp_.process->start(topp_.tool.toQString(),args);
3015
 
 
3016
 
                //connect the finished slot
3017
 
                connect(topp_.process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(finishTOPPToolExecution(int,QProcess::ExitStatus)));
3018
 
 
3019
 
                //start process
3020
 
                topp_.process->waitForStarted();
3021
 
                updateMenu();
3022
 
        }
 
3014
        ConsensusXMLFile().store(topp_.file_name + "_in", map);
 
3015
      }
 
3016
      else
 
3017
      {
 
3018
        ConsensusXMLFile().store(topp_.file_name + "_in", *layer.getConsensusMap());
 
3019
      }
 
3020
    }
 
3021
 
 
3022
    // compose argument list
 
3023
    QStringList args;
 
3024
    args << "-ini"
 
3025
         << (topp_.file_name + "_ini").toQString()
 
3026
         << QString("-%1").arg(topp_.in.toQString())
 
3027
         << (topp_.file_name + "_in").toQString()
 
3028
         << "-no_progress";
 
3029
    if (topp_.out != "")
 
3030
    {
 
3031
      args << QString("-%1").arg(topp_.out.toQString())
 
3032
           << (topp_.file_name + "_out").toQString();
 
3033
    }
 
3034
 
 
3035
    // start log and show it
 
3036
    showLogMessage_(LS_NOTICE, QString("Starting '%1'").arg(topp_.tool.toQString()), ""); // tool + args.join(" "));
 
3037
 
 
3038
    // initialize process
 
3039
    topp_.process = new QProcess();
 
3040
    topp_.process->setProcessChannelMode(QProcess::MergedChannels);
 
3041
 
 
3042
    // connect slots
 
3043
    connect(topp_.process, SIGNAL(readyReadStandardOutput()), this, SLOT(updateProcessLog()));
 
3044
    connect(topp_.process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishTOPPToolExecution(int, QProcess::ExitStatus)));
 
3045
 
 
3046
    QString tool_executable;
 
3047
    try
 
3048
    {
 
3049
      // find correct location of TOPP tool
 
3050
      tool_executable = File::findExecutable(topp_.tool).toQString();
 
3051
    }
 
3052
    catch (Exception::FileNotFound& /*ex*/)
 
3053
    {
 
3054
      showLogMessage_(LS_ERROR, "Could not locate executable!", QString("Finding executable of TOPP tool '%1' failed. Please check your TOPP/OpenMS installation. Workaround: Add the bin/ directory to your PATH").arg(topp_.tool.toQString()));
 
3055
      return;
 
3056
    }
 
3057
 
 
3058
    // update menu entries according to new state
 
3059
    updateMenu();
 
3060
 
 
3061
    // start the actual process
 
3062
    topp_.timer.restart();
 
3063
    topp_.process->start(tool_executable, args);
 
3064
    topp_.process->waitForStarted();
 
3065
 
 
3066
    if (topp_.process->error() == QProcess::FailedToStart)
 
3067
    {
 
3068
      showLogMessage_(LS_ERROR, QString("Failed to execute '%1'").arg(topp_.tool.toQString()), QString("Execution of TOPP tool '%1' failed with error: %2").arg(topp_.tool.toQString(), topp_.process->errorString()));
 
3069
 
 
3070
      // ensure that all tool output is emitted into log screen
 
3071
      updateProcessLog();
 
3072
 
 
3073
      // re-enable Apply TOPP tool menues
 
3074
      delete topp_.process;
 
3075
      topp_.process = 0;
 
3076
      updateMenu();
 
3077
 
 
3078
      return;
 
3079
    }
 
3080
  }
3023
3081
 
3024
3082
  void TOPPViewBase::finishTOPPToolExecution(int, QProcess::ExitStatus)
3025
3083
  {
3026
 
        //finish with new line
3027
 
        log_->append("");
3028
 
 
3029
 
        String tmp_dir = param_.getValue("preferences:tmp_file_path").toString();
3030
 
 
3031
 
                if (topp_.process->exitStatus()==QProcess::CrashExit)
3032
 
                {
3033
 
                        showLogMessage_(LS_ERROR,"Execution of TOPP tool not successful!",String("The tool crashed during execution. If you want to debug this crash, check the input files in '") + tmp_dir + "' or enable 'debug' mode in the TOPP ini file.");
3034
 
                }
3035
 
                else if(topp_.out!="")
3036
 
                {
3037
 
                        if (!File::readable(topp_.file_name+"_out"))
3038
 
                        {
3039
 
                                showLogMessage_(LS_ERROR,"Cannot read TOPP output",String("Cannot read '")+topp_.file_name+"_out'!");
3040
 
                        }
3041
 
                        else
3042
 
                        {
3043
 
                                addDataFile(topp_.file_name+"_out",true,false, topp_.layer_name + " (" + topp_.tool + ")", topp_.window_id, topp_.spectrum_id);
3044
 
                        }
3045
 
                }
3046
 
 
3047
 
                //clean up
3048
 
                delete topp_.process;
3049
 
                topp_.process = 0;
3050
 
                updateMenu();
3051
 
 
3052
 
                //clean up temporary files
3053
 
                if (param_.getValue("preferences:topp_cleanup")=="true")
3054
 
                {
3055
 
                        File::remove(topp_.file_name+"_ini");
3056
 
                        File::remove(topp_.file_name+"_in");
3057
 
                        File::remove(topp_.file_name+"_out");
3058
 
        }
 
3084
    //finish with new line
 
3085
    log_->append("");
 
3086
 
 
3087
    String tmp_dir = param_.getValue("preferences:tmp_file_path").toString();
 
3088
 
 
3089
    if (topp_.process->exitStatus() == QProcess::CrashExit)
 
3090
    {
 
3091
      showLogMessage_(LS_ERROR, QString("Execution of '%1' not successful!").arg(topp_.tool.toQString()),
 
3092
                      QString("The tool crashed during execution. If you want to debug this crash, check the input files in '%1'"
 
3093
                              " or enable 'debug' mode in the TOPP ini file.").arg(tmp_dir.toQString()));
 
3094
    }
 
3095
    else if (topp_.out != "")
 
3096
    {
 
3097
      showLogMessage_(LS_NOTICE, QString("'%1' finished successfully").arg(topp_.tool.toQString()),
 
3098
                      QString("Execution time: %1 ms").arg(topp_.timer.elapsed()));
 
3099
      if (!File::readable(topp_.file_name + "_out"))
 
3100
      {
 
3101
        showLogMessage_(LS_ERROR, "Cannot read TOPP output", String("Cannot read '") + topp_.file_name + "_out'!");
 
3102
      }
 
3103
      else
 
3104
      {
 
3105
        addDataFile(topp_.file_name + "_out", true, false, topp_.layer_name + " (" + topp_.tool + ")", topp_.window_id, topp_.spectrum_id);
 
3106
      }
 
3107
    }
 
3108
 
 
3109
    //clean up
 
3110
    delete topp_.process;
 
3111
    topp_.process = 0;
 
3112
    updateMenu();
 
3113
 
 
3114
    //clean up temporary files
 
3115
    if (param_.getValue("preferences:topp_cleanup") == "true")
 
3116
    {
 
3117
      File::remove(topp_.file_name + "_ini");
 
3118
      File::remove(topp_.file_name + "_in");
 
3119
      File::remove(topp_.file_name + "_out");
 
3120
    }
3059
3121
  }
3060
3122
 
3061
 
        const LayerData* TOPPViewBase::getCurrentLayer() const
3062
 
        {
 
3123
  const LayerData* TOPPViewBase::getCurrentLayer() const
 
3124
  {
3063
3125
    SpectrumCanvas* canvas = getActiveCanvas();
3064
 
                if (canvas==0)
3065
 
                {
3066
 
                        return 0;
3067
 
                }
3068
 
                return &(canvas->getCurrentLayer());
3069
 
        }
 
3126
    if (canvas == 0)
 
3127
    {
 
3128
      return 0;
 
3129
    }
 
3130
    return &(canvas->getCurrentLayer());
 
3131
  }
3070
3132
 
3071
3133
  void TOPPViewBase::toggleProjections()
3072
3134
  {
3073
3135
    Spectrum2DWidget* w = getActive2DWidget();
3074
3136
    if (w)
3075
3137
    {
3076
 
        //update minimum size before
3077
 
        if (!w->projectionsVisible())
3078
 
        {
3079
 
                setMinimumSize(700,700);
3080
 
        }
3081
 
        else
3082
 
        {
3083
 
                setMinimumSize(400,400);
3084
 
        }
3085
 
        w->toggleProjections();
 
3138
      //update minimum size before
 
3139
      if (!w->projectionsVisible())
 
3140
      {
 
3141
        setMinimumSize(700, 700);
 
3142
      }
 
3143
      else
 
3144
      {
 
3145
        setMinimumSize(400, 400);
 
3146
      }
 
3147
      w->toggleProjections();
3086
3148
    }
3087
3149
  }
3088
3150
 
3089
 
        void TOPPViewBase::annotateWithID()
3090
 
        {
 
3151
  void TOPPViewBase::loadFile(QString filename)
 
3152
  {
 
3153
    addDataFile(String(filename), true, false);
 
3154
  }
 
3155
 
 
3156
  void TOPPViewBase::annotateWithID()
 
3157
  {
3091
3158
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
3092
 
                //warn if hidden layer => wrong layer selected...
3093
 
                if (!layer.visible)
3094
 
                {
3095
 
                showLogMessage_(LS_NOTICE,"The current layer is not visible","Have you selected the right layer for this action?");
3096
 
                }
 
3159
    //warn if hidden layer => wrong layer selected...
 
3160
    if (!layer.visible)
 
3161
    {
 
3162
      showLogMessage_(LS_NOTICE, "The current layer is not visible", "Have you selected the right layer for this action? Aborting.");
 
3163
      return;
 
3164
    }
3097
3165
 
3098
 
                //load id data
 
3166
    //load id data
3099
3167
    QString name = QFileDialog::getOpenFileName(this,
3100
3168
                                                "Select protein identification data",
3101
3169
                                                current_path_.toQString(),
3102
3170
                                                "idXML files (*.idXML);; all files (*.*)");
3103
3171
 
3104
 
                if(name!="")
3105
 
                {
3106
 
                        vector<PeptideIdentification> identifications;
3107
 
                        vector<ProteinIdentification> protein_identifications;
3108
 
  
 
3172
    if (name != "")
 
3173
    {
 
3174
      vector<PeptideIdentification> identifications;
 
3175
      vector<ProteinIdentification> protein_identifications;
 
3176
 
3109
3177
      try
3110
3178
      {
3111
 
                        String document_id;
3112
 
                        IdXMLFile().load(name, protein_identifications, identifications, document_id);
 
3179
        String document_id;
 
3180
        IdXMLFile().load(name, protein_identifications, identifications, document_id);
3113
3181
      }
3114
3182
      catch (Exception::BaseException& e)
3115
3183
      {
3116
3184
        QMessageBox::warning(this, "Error", QString("Loading of idXML file failed! (") + e.what() + ")");
3117
 
                          return;
 
3185
        return;
3118
3186
      }
3119
3187
 
3120
3188
      IDMapper mapper;
3121
 
                        if (layer.type==LayerData::DT_PEAK)
3122
 
                        {
 
3189
      if (layer.type == LayerData::DT_PEAK)
 
3190
      {
 
3191
        // clear identifications
 
3192
        MSExperiment<>& exp = *layer.getPeakData();
 
3193
        for (MSExperiment<>::iterator it = exp.begin(); it != exp.end(); ++it)
 
3194
        {
 
3195
          vector<PeptideIdentification> empty_ids;
 
3196
          it->setPeptideIdentifications(empty_ids);
 
3197
        }
 
3198
 
3123
3199
        Param p = mapper.getDefaults();
3124
3200
        p.setValue("rt_tolerance", 0.1, "RT tolerance (in seconds) for the matching");
3125
3201
        p.setValue("mz_tolerance", 1.0, "m/z tolerance (in ppm or Da) for the matching");
3126
3202
        p.setValue("mz_measure", "Da", "unit of 'mz_tolerance' (ppm or Da)");
3127
3203
        mapper.setParameters(p);
3128
3204
        mapper.annotate(*layer.getPeakData(), identifications, protein_identifications);
3129
 
        views_tabwidget_->setTabEnabled(1, true);         // enable identification view
3130
 
                        }
3131
 
                        else if (layer.type==LayerData::DT_FEATURE)
3132
 
                        {
 
3205
        views_tabwidget_->setTabEnabled(1, true); // enable identification view
 
3206
      }
 
3207
      else if (layer.type == LayerData::DT_FEATURE)
 
3208
      {
3133
3209
        mapper.annotate(*layer.getFeatureMap(), identifications, protein_identifications);
3134
 
                        }
3135
 
                        else
3136
 
                        {
 
3210
      }
 
3211
      else
 
3212
      {
3137
3213
        mapper.annotate(*layer.getConsensusMap(), identifications, protein_identifications);
3138
 
                        }
3139
 
                }
 
3214
      }
 
3215
    }
 
3216
    showLogMessage_(LS_NOTICE, "Done", "Annotation of spectra finished. Open identification view to see results!");
3140
3217
    updateViewBar();
3141
 
        }
 
3218
  }
3142
3219
 
3143
3220
  void TOPPViewBase::showSpectrumGenerationDialog()
3144
 
        {
3145
 
                TheoreticalSpectrumGenerationDialog spec_gen_dialog;
3146
 
                if (spec_gen_dialog.exec())
3147
 
                {
3148
 
                        String seq_string(spec_gen_dialog.line_edit->text());
3149
 
                        if (seq_string == "")
3150
 
                        {
3151
 
                                QMessageBox::warning(this, "Error", "You must enter a peptide sequence!");
3152
 
                                return;
3153
 
                        }
 
3221
  {
 
3222
    TheoreticalSpectrumGenerationDialog spec_gen_dialog;
 
3223
    if (spec_gen_dialog.exec())
 
3224
    {
 
3225
      String seq_string(spec_gen_dialog.line_edit->text());
 
3226
      if (seq_string == "")
 
3227
      {
 
3228
        QMessageBox::warning(this, "Error", "You must enter a peptide sequence!");
 
3229
        return;
 
3230
      }
3154
3231
      AASequence aa_sequence;
3155
3232
      try
3156
3233
      {
3159
3236
      catch (Exception::BaseException& e)
3160
3237
      {
3161
3238
        QMessageBox::warning(this, "Error", QString("Spectrum generation failed! (") + e.what() + ")");
3162
 
                          return;
 
3239
        return;
3163
3240
      }
3164
 
                        Int charge = spec_gen_dialog.spin_box->value();
 
3241
      Int charge = spec_gen_dialog.spin_box->value();
3165
3242
 
3166
 
                        if (aa_sequence.isValid())
3167
 
                        {
3168
 
                                RichPeakSpectrum rich_spec;
3169
 
                                TheoreticalSpectrumGenerator generator;
3170
 
                                Param p;
 
3243
      if (aa_sequence.isValid())
 
3244
      {
 
3245
        RichPeakSpectrum rich_spec;
 
3246
        TheoreticalSpectrumGenerator generator;
 
3247
        Param p;
3171
3248
 
3172
3249
        p.setValue("add_metainfo", "true", "Adds the type of peaks as metainfo to the peaks, like y8+, [M-H2O+2H]++");
3173
3250
 
3174
 
                                bool losses = (spec_gen_dialog.list_widget->item(7)->checkState() == Qt::Checked); // "Neutral losses"
3175
 
                                String losses_str = losses ? "true" : "false";
3176
 
                                p.setValue("add_losses", losses_str, "Adds common losses to those ion expect to have them, only water and ammonia loss is considered");
 
3251
        bool losses = (spec_gen_dialog.list_widget->item(7)->checkState() == Qt::Checked); // "Neutral losses"
 
3252
        String losses_str = losses ? "true" : "false";
 
3253
        p.setValue("add_losses", losses_str, "Adds common losses to those ion expect to have them, only water and ammonia loss is considered");
3177
3254
 
3178
 
                                bool isotopes = (spec_gen_dialog.list_widget->item(8)->checkState() == Qt::Checked); // "Isotope clusters"
3179
 
                                String iso_str = isotopes ? "true" : "false";
3180
 
                                p.setValue("add_isotopes", iso_str, "If set to 1 isotope peaks of the product ion peaks are added");
 
3255
        bool isotopes = (spec_gen_dialog.list_widget->item(8)->checkState() == Qt::Checked); // "Isotope clusters"
 
3256
        String iso_str = isotopes ? "true" : "false";
 
3257
        p.setValue("add_isotopes", iso_str, "If set to 1 isotope peaks of the product ion peaks are added");
3181
3258
 
3182
3259
        bool abundant_immonium_ions = (spec_gen_dialog.list_widget->item(9)->checkState() == Qt::Checked); // "abundant immonium-ions"
3183
3260
        String abundant_immonium_ions_str = abundant_immonium_ions ? "true" : "false";
3185
3262
 
3186
3263
        Size max_iso_count = (Size)spec_gen_dialog.max_iso_spinbox->value();
3187
3264
        p.setValue("max_isotope", max_iso_count, "Number of isotopic peaks");
3188
 
                                p.setValue("a_intensity", spec_gen_dialog.a_intensity->value(), "Intensity of the a-ions");
3189
 
                                p.setValue("b_intensity", spec_gen_dialog.b_intensity->value(), "Intensity of the b-ions");
3190
 
                                p.setValue("c_intensity", spec_gen_dialog.c_intensity->value(), "Intensity of the c-ions");
3191
 
                                p.setValue("x_intensity", spec_gen_dialog.x_intensity->value(), "Intensity of the x-ions");
3192
 
                                p.setValue("y_intensity", spec_gen_dialog.y_intensity->value(), "Intensity of the y-ions");
3193
 
                                p.setValue("z_intensity", spec_gen_dialog.z_intensity->value(), "Intensity of the z-ions");
3194
 
                                DoubleReal rel_loss_int = (DoubleReal)(spec_gen_dialog.rel_loss_intensity->value()) / 100.0;
3195
 
                                p.setValue("relative_loss_intensity", rel_loss_int, "Intensity of loss ions, in relation to the intact ion intensity");
3196
 
                                generator.setParameters(p);
 
3265
        p.setValue("a_intensity", spec_gen_dialog.a_intensity->value(), "Intensity of the a-ions");
 
3266
        p.setValue("b_intensity", spec_gen_dialog.b_intensity->value(), "Intensity of the b-ions");
 
3267
        p.setValue("c_intensity", spec_gen_dialog.c_intensity->value(), "Intensity of the c-ions");
 
3268
        p.setValue("x_intensity", spec_gen_dialog.x_intensity->value(), "Intensity of the x-ions");
 
3269
        p.setValue("y_intensity", spec_gen_dialog.y_intensity->value(), "Intensity of the y-ions");
 
3270
        p.setValue("z_intensity", spec_gen_dialog.z_intensity->value(), "Intensity of the z-ions");
 
3271
        DoubleReal rel_loss_int = (DoubleReal)(spec_gen_dialog.rel_loss_intensity->value()) / 100.0;
 
3272
        p.setValue("relative_loss_intensity", rel_loss_int, "Intensity of loss ions, in relation to the intact ion intensity");
 
3273
        generator.setParameters(p);
3197
3274
 
3198
3275
        try
3199
3276
        {
3200
 
                                  if (spec_gen_dialog.list_widget->item(0)->checkState() == Qt::Checked) // "A-ions"
3201
 
                                  {
3202
 
                                          generator.addPeaks(rich_spec, aa_sequence, Residue::AIon, charge);
3203
 
                                  }
3204
 
                                  if (spec_gen_dialog.list_widget->item(1)->checkState() == Qt::Checked) // "B-ions"
3205
 
                                  {
3206
 
                                          generator.addPeaks(rich_spec, aa_sequence, Residue::BIon, charge);
3207
 
                                  }
3208
 
                                  if (spec_gen_dialog.list_widget->item(2)->checkState() == Qt::Checked) // "C-ions"
3209
 
                                  {
3210
 
                                          generator.addPeaks(rich_spec, aa_sequence, Residue::CIon, charge);
3211
 
                                  }
3212
 
                                  if (spec_gen_dialog.list_widget->item(3)->checkState() == Qt::Checked) // "X-ions"
3213
 
                                  {
3214
 
                                          generator.addPeaks(rich_spec, aa_sequence, Residue::XIon, charge);
3215
 
                                  }
3216
 
                                  if (spec_gen_dialog.list_widget->item(4)->checkState() == Qt::Checked) // "Y-ions"
3217
 
                                  {
3218
 
                                          generator.addPeaks(rich_spec, aa_sequence, Residue::YIon, charge);
3219
 
                                  }
3220
 
                                  if (spec_gen_dialog.list_widget->item(5)->checkState() == Qt::Checked) // "Z-ions"
3221
 
                                  {
3222
 
                                          generator.addPeaks(rich_spec, aa_sequence, Residue::ZIon, charge);
3223
 
                                  }
3224
 
                                  if (spec_gen_dialog.list_widget->item(6)->checkState() == Qt::Checked) // "Precursor"
3225
 
                                  {
3226
 
                                          generator.addPrecursorPeaks(rich_spec, aa_sequence, charge);
 
3277
          if (spec_gen_dialog.list_widget->item(0)->checkState() == Qt::Checked) // "A-ions"
 
3278
          {
 
3279
            generator.addPeaks(rich_spec, aa_sequence, Residue::AIon, charge);
 
3280
          }
 
3281
          if (spec_gen_dialog.list_widget->item(1)->checkState() == Qt::Checked) // "B-ions"
 
3282
          {
 
3283
            generator.addPeaks(rich_spec, aa_sequence, Residue::BIon, charge);
 
3284
          }
 
3285
          if (spec_gen_dialog.list_widget->item(2)->checkState() == Qt::Checked) // "C-ions"
 
3286
          {
 
3287
            generator.addPeaks(rich_spec, aa_sequence, Residue::CIon, charge);
 
3288
          }
 
3289
          if (spec_gen_dialog.list_widget->item(3)->checkState() == Qt::Checked) // "X-ions"
 
3290
          {
 
3291
            generator.addPeaks(rich_spec, aa_sequence, Residue::XIon, charge);
 
3292
          }
 
3293
          if (spec_gen_dialog.list_widget->item(4)->checkState() == Qt::Checked) // "Y-ions"
 
3294
          {
 
3295
            generator.addPeaks(rich_spec, aa_sequence, Residue::YIon, charge);
 
3296
          }
 
3297
          if (spec_gen_dialog.list_widget->item(5)->checkState() == Qt::Checked) // "Z-ions"
 
3298
          {
 
3299
            generator.addPeaks(rich_spec, aa_sequence, Residue::ZIon, charge);
 
3300
          }
 
3301
          if (spec_gen_dialog.list_widget->item(6)->checkState() == Qt::Checked) // "Precursor"
 
3302
          {
 
3303
            generator.addPrecursorPeaks(rich_spec, aa_sequence, charge);
3227
3304
          }
3228
3305
          if (spec_gen_dialog.list_widget->item(9)->checkState() == Qt::Checked) // "abundant Immonium-ions"
3229
3306
          {
3233
3310
        catch (Exception::BaseException& e)
3234
3311
        {
3235
3312
          QMessageBox::warning(this, "Error", QString("Spectrum generation failed! (") + e.what() + "). Please report this to the developers (specify what input you used)!");
3236
 
                                  return;
 
3313
          return;
3237
3314
        }
3238
3315
 
 
3316
        // set precursor information
 
3317
        PeakSpectrum new_spec;
 
3318
        vector<Precursor> precursors;
 
3319
        Precursor precursor;
 
3320
        precursor.setMZ(aa_sequence.getMonoWeight());
 
3321
        precursor.setCharge(charge);
 
3322
        precursors.push_back(precursor);
 
3323
        new_spec.setPrecursors(precursors);
 
3324
        new_spec.setMSLevel(2);
3239
3325
        // convert rich spectrum to simple spectrum
3240
 
                                PeakSpectrum new_spec;
3241
 
                                for (RichPeakSpectrum::Iterator it = rich_spec.begin(); it != rich_spec.end(); ++it)
3242
 
                                {
3243
 
                                        new_spec.push_back(static_cast<Peak1D>(*it));
3244
 
                                }
 
3326
        for (RichPeakSpectrum::Iterator it = rich_spec.begin(); it != rich_spec.end(); ++it)
 
3327
        {
 
3328
          new_spec.push_back(static_cast<Peak1D>(*it));
 
3329
        }
3245
3330
 
3246
 
                                PeakMap new_exp;
3247
 
                                new_exp.push_back(new_spec);
 
3331
        PeakMap new_exp;
 
3332
        new_exp.addSpectrum(new_spec);
3248
3333
        ExperimentSharedPtrType new_exp_sptr(new PeakMap(new_exp));
3249
3334
        FeatureMapSharedPtrType f_dummy(new FeatureMapType());
3250
3335
        ConsensusMapSharedPtrType c_dummy(new ConsensusMapType());
3251
 
                                vector<PeptideIdentification> p_dummy;
 
3336
        vector<PeptideIdentification> p_dummy;
3252
3337
        addData(f_dummy, c_dummy, p_dummy, new_exp_sptr, LayerData::DT_CHROMATOGRAM, false, true, true, "", seq_string + QString(" (theoretical)"));
3253
3338
 
3254
 
              // ensure spectrum is drawn as sticks
3255
 
              draw_group_1d_->button(Spectrum1DCanvas::DM_PEAKS)->setChecked(true);
3256
 
                                setDrawMode1D(Spectrum1DCanvas::DM_PEAKS);
3257
 
 
3258
 
                        }
3259
 
                        else
3260
 
                        {
3261
 
                                QMessageBox::warning(this, "Error", "The entered peptide sequence is invalid!");
3262
 
                        }
3263
 
                }
3264
 
        }
3265
 
 
3266
 
        void TOPPViewBase::showSpectrumAlignmentDialog()
3267
 
        {
 
3339
        // ensure spectrum is drawn as sticks
 
3340
        draw_group_1d_->button(Spectrum1DCanvas::DM_PEAKS)->setChecked(true);
 
3341
        setDrawMode1D(Spectrum1DCanvas::DM_PEAKS);
 
3342
      }
 
3343
      else
 
3344
      {
 
3345
        QMessageBox::warning(this, "Error", "The entered peptide sequence is invalid!");
 
3346
      }
 
3347
    }
 
3348
  }
 
3349
 
 
3350
  void TOPPViewBase::showSpectrumAlignmentDialog()
 
3351
  {
3268
3352
    Spectrum1DWidget* active_1d_window = getActive1DWidget();
3269
 
                if (!active_1d_window || !active_1d_window->canvas()->mirrorModeActive())
3270
 
                {
3271
 
                        return;
3272
 
                }
3273
 
                Spectrum1DCanvas* cc = active_1d_window->canvas();
3274
 
 
3275
 
                SpectrumAlignmentDialog spec_align_dialog(active_1d_window);
3276
 
                if (spec_align_dialog.exec())
3277
 
                {
3278
 
                        Int layer_index_1 = spec_align_dialog.get1stLayerIndex();
3279
 
                        Int layer_index_2 = spec_align_dialog.get2ndLayerIndex();
3280
 
 
3281
 
                        // two layers must be selected:
3282
 
                        if (layer_index_1 < 0 || layer_index_2 < 0)
3283
 
                        {
3284
 
                                QMessageBox::information(this, "Layer selection invalid", "You must select two layers for an alignment.");
3285
 
                                return;
3286
 
                        }
3287
 
 
3288
 
                        Param param;
3289
 
                        DoubleReal tolerance = spec_align_dialog.tolerance_spinbox->value();
3290
 
      param.setValue("tolerance", tolerance, "Defines the absolut (in Da) or relative (in ppm) mass tolerance");
3291
 
                        String unit_is_ppm = spec_align_dialog.ppm->isChecked() ? "true" : "false";
 
3353
    if (!active_1d_window || !active_1d_window->canvas()->mirrorModeActive())
 
3354
    {
 
3355
      return;
 
3356
    }
 
3357
    Spectrum1DCanvas* cc = active_1d_window->canvas();
 
3358
 
 
3359
    SpectrumAlignmentDialog spec_align_dialog(active_1d_window);
 
3360
    if (spec_align_dialog.exec())
 
3361
    {
 
3362
      Int layer_index_1 = spec_align_dialog.get1stLayerIndex();
 
3363
      Int layer_index_2 = spec_align_dialog.get2ndLayerIndex();
 
3364
 
 
3365
      // two layers must be selected:
 
3366
      if (layer_index_1 < 0 || layer_index_2 < 0)
 
3367
      {
 
3368
        QMessageBox::information(this, "Layer selection invalid", "You must select two layers for an alignment.");
 
3369
        return;
 
3370
      }
 
3371
 
 
3372
      Param param;
 
3373
      DoubleReal tolerance = spec_align_dialog.tolerance_spinbox->value();
 
3374
      param.setValue("tolerance", tolerance, "Defines the absolute (in Da) or relative (in ppm) mass tolerance");
 
3375
      String unit_is_ppm = spec_align_dialog.ppm->isChecked() ? "true" : "false";
3292
3376
      param.setValue("is_relative_tolerance", unit_is_ppm, "If true, the mass tolerance is interpreted as ppm value otherwise in Dalton");
3293
3377
 
3294
 
                        active_1d_window->performAlignment((UInt)layer_index_1, (UInt)layer_index_2, param);
3295
 
 
3296
 
                        DoubleReal al_score = cc->getAlignmentScore();
3297
 
                        Size al_size = cc->getAlignmentSize();
3298
 
 
3299
 
                        QMessageBox::information(this, "Alignment performed", QString("Aligned %1 pairs of peaks (Score: %2).").arg(al_size).arg(al_score));
3300
 
                }
3301
 
        }
3302
 
 
3303
 
        void TOPPViewBase::showSpectrumAs1D(int index)
3304
 
        {
3305
 
    Spectrum1DWidget* widget_1d = getActive1DWidget();
3306
 
    Spectrum2DWidget* widget_2d = getActive2DWidget();
3307
 
 
3308
 
    if (widget_1d)
3309
 
    {
3310
 
      if (spectra_view_widget_->isVisible())
3311
 
      {
3312
 
        spectraview_behavior_->showSpectrumAs1D(index);
3313
 
      }
3314
 
 
3315
 
      if (spectra_identification_view_widget_->isVisible())
3316
 
      {
3317
 
        identificationview_behavior_->showSpectrumAs1D(index);
3318
 
      }
3319
 
    } else if (widget_2d)
3320
 
    {
3321
 
      if (spectra_view_widget_->isVisible())
3322
 
      {
3323
 
        spectraview_behavior_->showSpectrumAs1D(index);
3324
 
      }
3325
 
 
3326
 
      if (spectra_identification_view_widget_->isVisible())
3327
 
      {
3328
 
        identificationview_behavior_->showSpectrumAs1D(index);
3329
 
      }
3330
 
    }
3331
 
 
3332
 
        }
 
3378
      active_1d_window->performAlignment((UInt)layer_index_1, (UInt)layer_index_2, param);
 
3379
 
 
3380
      DoubleReal al_score = cc->getAlignmentScore();
 
3381
      Size al_size = cc->getAlignmentSize();
 
3382
 
 
3383
      QMessageBox::information(this, "Alignment performed", QString("Aligned %1 pairs of peaks (Score: %2).").arg(al_size).arg(al_score));
 
3384
    }
 
3385
  }
 
3386
 
 
3387
  void TOPPViewBase::showSpectrumAs1D(int index)
 
3388
  {
 
3389
    Spectrum1DWidget* widget_1d = getActive1DWidget();
 
3390
    Spectrum2DWidget* widget_2d = getActive2DWidget();
 
3391
 
 
3392
    if (widget_1d)
 
3393
    {
 
3394
      if (spectra_view_widget_->isVisible())
 
3395
      {
 
3396
        spectraview_behavior_->showSpectrumAs1D(index);
 
3397
      }
 
3398
 
 
3399
      if (spectra_identification_view_widget_->isVisible())
 
3400
      {
 
3401
        identificationview_behavior_->showSpectrumAs1D(index);
 
3402
      }
 
3403
    }
 
3404
    else if (widget_2d)
 
3405
    {
 
3406
      if (spectra_view_widget_->isVisible())
 
3407
      {
 
3408
        spectraview_behavior_->showSpectrumAs1D(index);
 
3409
      }
 
3410
 
 
3411
      if (spectra_identification_view_widget_->isVisible())
 
3412
      {
 
3413
        identificationview_behavior_->showSpectrumAs1D(index);
 
3414
      }
 
3415
    }
 
3416
 
 
3417
  }
 
3418
 
 
3419
  void TOPPViewBase::showSpectrumAs1D(std::vector<int, std::allocator<int> > indices)
 
3420
  {
 
3421
    Spectrum1DWidget* widget_1d = getActive1DWidget();
 
3422
    Spectrum2DWidget* widget_2d = getActive2DWidget();
 
3423
 
 
3424
    if (widget_1d)
 
3425
    {
 
3426
      if (spectra_view_widget_->isVisible())
 
3427
      {
 
3428
        spectraview_behavior_->showSpectrumAs1D(indices);
 
3429
      }
 
3430
 
 
3431
 
 
3432
    }
 
3433
    else if (widget_2d)
 
3434
    {
 
3435
      if (spectra_view_widget_->isVisible())
 
3436
      {
 
3437
        spectraview_behavior_->showSpectrumAs1D(indices);
 
3438
      }
 
3439
 
 
3440
 
 
3441
    }
 
3442
 
 
3443
  }
3333
3444
 
3334
3445
  void TOPPViewBase::showCurrentPeaksAs2D()
3335
3446
  {
3346
3457
    }
3347
3458
 
3348
3459
    String caption = layer.name;
 
3460
    // remove 3D suffix added when opening data in 3D mode (see below showCurrentPeaksAs3D())
 
3461
    if (caption.hasSuffix(CAPTION_3D_SUFFIX_))
 
3462
    {
 
3463
      caption = caption.prefix(caption.rfind(CAPTION_3D_SUFFIX_));
 
3464
    }
3349
3465
    w->canvas()->setLayerName(w->canvas()->activeLayerIndex(), caption);
3350
3466
    showSpectrumWidgetInWindow(w, caption);
3351
3467
    updateLayerBar();
3356
3472
 
3357
3473
  void TOPPViewBase::showCurrentPeaksAs3D()
3358
3474
  {
3359
 
    const LayerData& layer = getActiveCanvas()->getCurrentLayer();
 
3475
 
 
3476
    // we first pick the layer with 3D support which is closest (or ideally identical) to the currently active layer
 
3477
    // we might find that there is no compatible layer though...
 
3478
    // if some day more than one type of data is supported, we need to adapt the code below accordingly
 
3479
 
 
3480
    const int BIGINDEX = 10000; // some large number which is never reached
 
3481
    const int target_layer = (int) getActiveCanvas()->getCurrentLayerIndex();
 
3482
    int best_candidate = BIGINDEX;
 
3483
    for (int i = 0; i < (int) getActiveCanvas()->getLayerCount(); ++i)
 
3484
    {
 
3485
      if ((LayerData::DT_PEAK == getActiveCanvas()->getLayer(i).type) && // supported type
 
3486
          (std::abs(i - target_layer) < std::abs(best_candidate - target_layer))) // & smallest distance to active layer
 
3487
      {
 
3488
        best_candidate = i;
 
3489
      }
 
3490
    }
 
3491
 
 
3492
    if (best_candidate == BIGINDEX)
 
3493
    {
 
3494
      showLogMessage_(LS_NOTICE, "No compatible layer", "No layer found which is supported by the 3D view.");
 
3495
      return;
 
3496
    }
 
3497
 
 
3498
 
 
3499
    if (best_candidate != target_layer)
 
3500
    {
 
3501
      showLogMessage_(LS_NOTICE, "Auto-selected compatible layer", "The currently active layer cannot be viewed in 3D view. The closest layer which is supported by the 3D view was selected!");
 
3502
    }
 
3503
 
 
3504
    const LayerData& layer = getActiveCanvas()->getLayer(best_candidate);
3360
3505
 
3361
3506
    if (layer.type == LayerData::DT_PEAK)
3362
3507
    {
3363
3508
      //open new 3D widget
3364
3509
      Spectrum3DWidget* w = new Spectrum3DWidget(getSpectrumParameters(3), ws_);
3365
3510
 
3366
 
      ExperimentSharedPtrType exp_sptr = getActiveCanvas()->getCurrentLayer().getPeakData();
 
3511
      ExperimentSharedPtrType exp_sptr = layer.getPeakData();
3367
3512
 
3368
3513
      if (!w->canvas()->addLayer(exp_sptr, layer.filename))
3369
3514
      {
3370
3515
        return;
3371
3516
      }
3372
3517
 
3373
 
     if (getActive1DWidget()) // switch from 1D to 3D
3374
 
     {
3375
 
       //TODO:
3376
 
       //- doesnt make sense for fragment scan
3377
 
       //- build new Area with mz range equal to 1D visible range
3378
 
       //- rt range either overall MS1 data range or some convenient window
 
3518
      if (getActive1DWidget()) // switch from 1D to 3D
 
3519
      {
 
3520
        //TODO:
 
3521
        //- doesnt make sense for fragment scan
 
3522
        //- build new Area with mz range equal to 1D visible range
 
3523
        //- rt range either overall MS1 data range or some convenient window
3379
3524
 
3380
 
     } else if (getActive2DWidget())  // switch from 2D to 3D
3381
 
     {
 
3525
      }
 
3526
      else if (getActive2DWidget()) // switch from 2D to 3D
 
3527
      {
3382
3528
        w->canvas()->setVisibleArea(getActiveCanvas()->getVisibleArea());
3383
 
     }
 
3529
      }
3384
3530
 
3385
3531
      // set layer name
3386
 
      String caption = layer.name + " (3D)";
 
3532
      String caption = layer.name + CAPTION_3D_SUFFIX_;
3387
3533
      w->canvas()->setLayerName(w->canvas()->activeLayerIndex(), caption);
3388
3534
      showSpectrumWidgetInWindow(w, caption);
3389
3535
 
3397
3543
    }
3398
3544
    else
3399
3545
    {
3400
 
      showLogMessage_(LS_NOTICE,"Wrong layer type","You cannot open feature data in 3D mode.");
 
3546
      showLogMessage_(LS_NOTICE, "Wrong layer type", "Something went wrong during layer selection. Please report this problem with a description of your current layers!");
3401
3547
    }
3402
3548
  }
3403
3549
 
3404
 
        void TOPPViewBase::showAboutDialog()
3405
 
        {
3406
 
                //dialog and grid layout
3407
 
                QDialog* dlg = new QDialog(this);
3408
 
                QGridLayout* grid = new QGridLayout(dlg);
3409
 
                dlg->setWindowTitle("About TOPPView");
3410
 
 
3411
 
                //image
3412
 
                QLabel* label = new QLabel(dlg);
3413
 
                label->setPixmap(QPixmap(":/TOPP_about.png"));
3414
 
                grid->addWidget(label,0,0);
3415
 
 
3416
 
                //text
3417
 
                QString text = QString("<BR>"
3418
 
                                                                                                         "<FONT size=+3>TOPPView</font><BR>"
3419
 
                                                                                                         "<BR>"
3420
 
                                                                                                         "Version: %1<BR>"
3421
 
                                                                                                         "<BR>"
3422
 
                                                                                                         "OpenMS and TOPP is free software available under the<BR>"
3423
 
                                                                                                         "Lesser GNU Public License (LGPL)<BR>"
3424
 
                                                                                                         "<BR>"
3425
 
                                                                                                         "<BR>"
3426
 
                                                                                                         "<BR>"
3427
 
                                                                                                         "<BR>"
3428
 
                                                                                                         "<BR>"
3429
 
                                                                                                         "Any published work based on TOPP and OpenMS shall cite these papers:<BR>"
3430
 
                                                                                                         "Sturm et al., BMC Bioinformatics (2008), 9, 163<BR>"
3431
 
                                                                                                         "Kohlbacher et al., Bioinformatics (2007), 23:e191-e197<BR>"
3432
 
                                                                                                         ).arg(VersionInfo::getVersion().toQString());
3433
 
                label = new QLabel(text,dlg);
3434
 
                grid->addWidget(label,0,1,Qt::AlignTop | Qt::AlignLeft);
3435
 
 
3436
 
                //close button
3437
 
                QPushButton* button = new QPushButton("Close",dlg);
3438
 
                grid->addWidget(button,1,1,Qt::AlignBottom | Qt::AlignRight);
3439
 
                connect(button,SIGNAL(clicked()),dlg,SLOT(close()));
3440
 
 
3441
 
                //execute
3442
 
                dlg->exec();
3443
 
        }
3444
 
 
3445
 
        void TOPPViewBase::updateProcessLog()
3446
 
        {
3447
 
                //show log if there is output
3448
 
                qobject_cast<QWidget *>(log_->parent())->show();
3449
 
 
3450
 
                //update log_
3451
 
                log_->append(topp_.process->readAllStandardOutput());
3452
 
        }
 
3550
  void TOPPViewBase::showAboutDialog()
 
3551
  {
 
3552
    //dialog and grid layout
 
3553
    QDialog* dlg = new QDialog(this);
 
3554
    QGridLayout* grid = new QGridLayout(dlg);
 
3555
    dlg->setWindowTitle("About TOPPView");
 
3556
 
 
3557
    //image
 
3558
    QLabel* label = new QLabel(dlg);
 
3559
    label->setPixmap(QPixmap(":/TOPP_about.png"));
 
3560
    grid->addWidget(label, 0, 0);
 
3561
 
 
3562
    //text
 
3563
    QString text = QString("<BR>"
 
3564
                           "<FONT size=+3>TOPPView</font><BR>"
 
3565
                           "<BR>"
 
3566
                           "Version: %1<BR>"
 
3567
                           "<BR>"
 
3568
                           "OpenMS and TOPP is free software available under the<BR>"
 
3569
                           "BSD 3-Clause Licence (BSD-new)<BR>"
 
3570
                           "<BR>"
 
3571
                           "<BR>"
 
3572
                           "<BR>"
 
3573
                           "<BR>"
 
3574
                           "<BR>"
 
3575
                           "Any published work based on TOPP and OpenMS shall cite these papers:<BR>"
 
3576
                           "Sturm et al., BMC Bioinformatics (2008), 9, 163<BR>"
 
3577
                           "Kohlbacher et al., Bioinformatics (2007), 23:e191-e197<BR>"
 
3578
                           ).arg(VersionInfo::getVersion().toQString());
 
3579
    label = new QLabel(text, dlg);
 
3580
    grid->addWidget(label, 0, 1, Qt::AlignTop | Qt::AlignLeft);
 
3581
 
 
3582
    //close button
 
3583
    QPushButton* button = new QPushButton("Close", dlg);
 
3584
    grid->addWidget(button, 1, 1, Qt::AlignBottom | Qt::AlignRight);
 
3585
    connect(button, SIGNAL(clicked()), dlg, SLOT(close()));
 
3586
 
 
3587
    //execute
 
3588
    dlg->exec();
 
3589
  }
 
3590
 
 
3591
  void TOPPViewBase::updateProcessLog()
 
3592
  {
 
3593
    //show log if there is output
 
3594
    qobject_cast<QWidget*>(log_->parent())->show();
 
3595
 
 
3596
    //update log_
 
3597
    log_->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); // move cursor to end, since text is inserted at cursor
 
3598
    log_->insertPlainText(topp_.process->readAllStandardOutput());
 
3599
 
 
3600
  }
3453
3601
 
3454
3602
  Param TOPPViewBase::getSpectrumParameters(UInt dim)
3455
 
        {
3456
 
                Param out = param_.copy(String("preferences:") + dim + "d:",true);
3457
 
                out.setValue("default_path",param_.getValue("preferences:default_path").toString());
3458
 
                return out;
3459
 
        }
 
3603
  {
 
3604
    Param out = param_.copy(String("preferences:") + dim + "d:", true);
 
3605
    out.setValue("default_path", param_.getValue("preferences:default_path").toString());
 
3606
    return out;
 
3607
  }
3460
3608
 
3461
3609
  void TOPPViewBase::abortTOPPTool()
3462
3610
  {
3463
 
        if (topp_.process)
3464
 
        {
3465
 
                //block signals to avoid error message from finished() signal
3466
 
                topp_.process->blockSignals(true);
3467
 
                //kill and delete the process
3468
 
                topp_.process->terminate();
3469
 
                delete topp_.process;
3470
 
                topp_.process = 0;
3471
 
 
3472
 
                        //finish log with new line
3473
 
                log_->append("");
3474
 
 
3475
 
                updateMenu();
3476
 
        }
 
3611
    if (topp_.process)
 
3612
    {
 
3613
      //block signals to avoid error message from finished() signal
 
3614
      topp_.process->blockSignals(true);
 
3615
      //kill and delete the process
 
3616
      topp_.process->terminate();
 
3617
      delete topp_.process;
 
3618
      topp_.process = 0;
 
3619
 
 
3620
      //finish log with new line
 
3621
      log_->append("");
 
3622
 
 
3623
      updateMenu();
 
3624
    }
3477
3625
  }
3478
3626
 
3479
3627
  void TOPPViewBase::updateMenu()
3480
3628
  {
3481
 
        //is there a canvas?
3482
 
        bool canvas_exists = false;
3483
 
    if (getActiveCanvas()!=0)
3484
 
        {
3485
 
                canvas_exists = true;
3486
 
        }
3487
 
        //is there a layer?
3488
 
        bool layer_exists = false;
3489
 
    if (canvas_exists && getActiveCanvas()->getLayerCount()!=0)
3490
 
        {
3491
 
                layer_exists = true;
3492
 
        }
3493
 
                //is there a TOPP tool running
3494
 
                bool topp_running = false;
3495
 
                if (topp_.process!=0)
3496
 
                {
3497
 
                        topp_running = true;
3498
 
                }
3499
 
 
3500
 
    TOPPASWidget* tw = getActiveTOPPASWidget();
3501
 
    TOPPASScene* ts = 0;
3502
 
    if (tw)
3503
 
    {
3504
 
      ts = tw->getScene();
3505
 
    } else // active widget is no TOPPAS widget
3506
 
    {
3507
 
 
 
3629
    //is there a canvas?
 
3630
    bool canvas_exists = false;
 
3631
    if (getActiveCanvas() != 0)
 
3632
    {
 
3633
      canvas_exists = true;
 
3634
    }
 
3635
    //is there a layer?
 
3636
    bool layer_exists = false;
 
3637
    if (canvas_exists && getActiveCanvas()->getLayerCount() != 0)
 
3638
    {
 
3639
      layer_exists = true;
 
3640
    }
 
3641
    //is there a TOPP tool running
 
3642
    bool topp_running = false;
 
3643
    if (topp_.process != 0)
 
3644
    {
 
3645
      topp_running = true;
3508
3646
    }
3509
3647
 
3510
3648
    bool mirror_mode = getActive1DWidget() && getActive1DWidget()->canvas()->mirrorModeActive();
3511
 
                QList<QAction*> actions = this->findChildren<QAction*>("");
3512
 
                for (int i=0; i<actions.count(); ++i)
3513
 
                {
3514
 
                        QString text = actions[i]->text();
3515
 
                        if (text=="&Close" || text=="Show/hide grid lines" || text=="Show/hide axis legends")
3516
 
                        {
3517
 
                                actions[i]->setEnabled(false);
3518
 
                                if (canvas_exists)
3519
 
                                {
3520
 
                                        actions[i]->setEnabled(true);
3521
 
                                }
3522
 
                        }
3523
 
                        else if (text.left(15)=="Apply TOPP tool")
3524
 
                        {
3525
 
                                actions[i]->setEnabled(false);
3526
 
                                if (canvas_exists && layer_exists && !topp_running)
3527
 
                                {
3528
 
                                        actions[i]->setEnabled(true);
3529
 
                                }
3530
 
                        }
3531
 
                        else if (text=="Abort running TOPP tool")
3532
 
                        {
3533
 
                                actions[i]->setEnabled(false);
3534
 
                                if (topp_running)
3535
 
                                {
3536
 
                                        actions[i]->setEnabled(true);
3537
 
                                }
3538
 
                        }
3539
 
                        else if (text=="Rerun TOPP tool")
3540
 
                        {
3541
 
                                actions[i]->setEnabled(false);
3542
 
                                if (canvas_exists && layer_exists && !topp_running && topp_.tool!="")
3543
 
                                {
3544
 
                                        actions[i]->setEnabled(true);
3545
 
                                }
3546
 
                        }
3547
 
      else if (text=="&Go to" || text=="&Edit meta data" || text=="&Statistics" || text=="&Annotate with identification"  || text=="Save all data"  || text=="Save visible data"  || text=="Preferences")
3548
 
                        {
3549
 
                                actions[i]->setEnabled(false);
3550
 
                                if (canvas_exists && layer_exists)
3551
 
                                {
3552
 
                                        actions[i]->setEnabled(true);
3553
 
                                }
3554
 
                        }
3555
 
                        else if (text=="Align spectra")
3556
 
                        {
3557
 
                                actions[i]->setEnabled(false);
3558
 
                                if (mirror_mode)
3559
 
                                {
3560
 
                                        actions[i]->setEnabled(true);
3561
 
                                }
3562
 
                        }
3563
 
      else if (text=="&Run (F5)")  // pipeline menu
3564
 
      {
3565
 
        bool show = false;
3566
 
        if (ts && !(ts->isPipelineRunning()))
3567
 
        {
3568
 
          show = true;
3569
 
        }
3570
 
        actions[i]->setEnabled(show);
3571
 
      }
3572
 
      else if (text=="&Abort") // pipeline menu
3573
 
      {
3574
 
        bool show = false;
3575
 
        if (ts && ts->isPipelineRunning())
3576
 
        {
3577
 
          show = true;
3578
 
        }
3579
 
        actions[i]->setEnabled(show);
3580
 
      }
3581
 
      else if (text=="&Include TOPPAS pipeline") // pipeline menu
3582
 
      {
3583
 
        bool show = ts;
3584
 
        actions[i]->setEnabled(show);
3585
 
      }
3586
 
      else if (text=="&Load TOPPAS resource file") // pipeline menu
3587
 
      {
3588
 
        bool show = ts;
3589
 
        actions[i]->setEnabled(show);
3590
 
      }
3591
 
      else if (text=="Save TOPPAS &resource file") // pipeline menu
3592
 
      {
3593
 
        bool show = ts;
3594
 
        actions[i]->setEnabled(show);
3595
 
      }
3596
 
      else if (text=="&Save TOPPAS pipeline")
3597
 
      {
3598
 
        bool show = ts && ts->wasChanged();
3599
 
        actions[i]->setEnabled(show);
3600
 
      }
3601
 
      else if (text=="Save TOPPAS pipeline &As")
3602
 
      {
3603
 
        bool show = ts && ts->wasChanged();
3604
 
        actions[i]->setEnabled(show);
3605
 
      }
3606
 
      else if (text=="Refresh TOPPAS &parameters") // pipeline menu
3607
 
      {
3608
 
        bool show = ts && !(ts->isPipelineRunning());
3609
 
        actions[i]->setEnabled(show);
3610
 
      }
3611
 
                        else if (text=="")
3612
 
                        {
3613
 
                                actions[i]->setEnabled(false);
3614
 
                                if (canvas_exists && layer_exists)
3615
 
                                {
3616
 
                                        actions[i]->setEnabled(true);
3617
 
                                }
3618
 
                        }
3619
 
                }
 
3649
    QList<QAction*> actions = this->findChildren<QAction*>("");
 
3650
    for (int i = 0; i < actions.count(); ++i)
 
3651
    {
 
3652
      QString text = actions[i]->text();
 
3653
      if (text == "&Close" || text == "Show/hide grid lines" || text == "Show/hide axis legends")
 
3654
      {
 
3655
        actions[i]->setEnabled(false);
 
3656
        if (canvas_exists)
 
3657
        {
 
3658
          actions[i]->setEnabled(true);
 
3659
        }
 
3660
      }
 
3661
      else if (text.left(15) == "Apply TOPP tool")
 
3662
      {
 
3663
        actions[i]->setEnabled(false);
 
3664
        if (canvas_exists && layer_exists && !topp_running)
 
3665
        {
 
3666
          actions[i]->setEnabled(true);
 
3667
        }
 
3668
      }
 
3669
      else if (text == "Abort running TOPP tool")
 
3670
      {
 
3671
        actions[i]->setEnabled(false);
 
3672
        if (topp_running)
 
3673
        {
 
3674
          actions[i]->setEnabled(true);
 
3675
        }
 
3676
      }
 
3677
      else if (text == "Rerun TOPP tool")
 
3678
      {
 
3679
        actions[i]->setEnabled(false);
 
3680
        if (canvas_exists && layer_exists && !topp_running && topp_.tool != "")
 
3681
        {
 
3682
          actions[i]->setEnabled(true);
 
3683
        }
 
3684
      }
 
3685
      else if (text == "&Go to" || text == "&Edit meta data" || text == "&Statistics" || text == "&Annotate with identification"  || text == "Save all data"  || text == "Save visible data"  || text == "Preferences")
 
3686
      {
 
3687
        actions[i]->setEnabled(false);
 
3688
        if (canvas_exists && layer_exists)
 
3689
        {
 
3690
          actions[i]->setEnabled(true);
 
3691
        }
 
3692
      }
 
3693
      else if (text == "Align spectra")
 
3694
      {
 
3695
        actions[i]->setEnabled(false);
 
3696
        if (mirror_mode)
 
3697
        {
 
3698
          actions[i]->setEnabled(true);
 
3699
        }
 
3700
      }
 
3701
      else if (text == "")
 
3702
      {
 
3703
        actions[i]->setEnabled(false);
 
3704
        if (canvas_exists && layer_exists)
 
3705
        {
 
3706
          actions[i]->setEnabled(true);
 
3707
        }
 
3708
      }
 
3709
    }
3620
3710
  }
3621
3711
 
3622
3712
  void TOPPViewBase::loadFiles(const StringList& list, QSplashScreen* splash_screen)
3623
3713
  {
3624
 
                bool last_was_plus = false;
3625
 
    for (StringList::const_iterator it=list.begin(); it!=list.end(); ++it)
 
3714
    bool last_was_plus = false;
 
3715
    for (StringList::const_iterator it = list.begin(); it != list.end(); ++it)
3626
3716
    {
3627
 
      if (*it=="+")
3628
 
      {
3629
 
        last_was_plus = true;
3630
 
        continue;
3631
 
        }
3632
 
        else if (*it=="@bw")
3633
 
        {
3634
 
        if ( (getActive2DWidget()!=0 || getActive3DWidget()!=0) && getActiveCanvas()!=0 )
3635
 
                {
3636
 
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
3637
 
                        tmp.setValue("dot:gradient", "Linear|0,#ffffff;100,#000000");
3638
 
          getActiveCanvas()->setCurrentLayerParameters(tmp);
3639
 
                }
3640
 
        }
3641
 
        else if (*it=="@bg")
3642
 
        {
3643
 
        if ( (getActive2DWidget()!=0 || getActive3DWidget()!=0) && getActiveCanvas()!=0 )
3644
 
                {
3645
 
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
3646
 
                        tmp.setValue("dot:gradient", "Linear|0,#dddddd;100,#000000");
3647
 
          getActiveCanvas()->setCurrentLayerParameters(tmp);
3648
 
                }
3649
 
        }
3650
 
        else if (*it=="@b")
3651
 
        {
3652
 
        if ( (getActive2DWidget()!=0 || getActive3DWidget()!=0) && getActiveCanvas()!=0 )
3653
 
                {
3654
 
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
3655
 
                        tmp.setValue("dot:gradient", "Linear|0,#000000;100,#000000");
3656
 
          getActiveCanvas()->setCurrentLayerParameters(tmp);
3657
 
                }
3658
 
        }
3659
 
        else if (*it=="@r")
3660
 
        {
3661
 
        if ( (getActive2DWidget()!=0 || getActive3DWidget()!=0) && getActiveCanvas()!=0 )
3662
 
                {
3663
 
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
3664
 
                        tmp.setValue("dot:gradient", "Linear|0,#ff0000;100,#ff0000");
3665
 
          getActiveCanvas()->setCurrentLayerParameters(tmp);
3666
 
                }
3667
 
        }
3668
 
        else if (*it=="@g")
3669
 
        {
3670
 
        if ( (getActive2DWidget()!=0 || getActive3DWidget()!=0) && getActiveCanvas()!=0 )
3671
 
                {
3672
 
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
3673
 
                        tmp.setValue("dot:gradient", "Linear|0,#00ff00;100,#00ff00");
3674
 
          getActiveCanvas()->setCurrentLayerParameters(tmp);
3675
 
                }
3676
 
        }
3677
 
        else if (*it=="@m")
3678
 
        {
3679
 
        if ( (getActive2DWidget()!=0 || getActive3DWidget()!=0) && getActiveCanvas()!=0 )
3680
 
                {
3681
 
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
3682
 
                        tmp.setValue("dot:gradient", "Linear|0,#ff00ff;100,#ff00ff");
3683
 
          getActiveCanvas()->setCurrentLayerParameters(tmp);
3684
 
                }
3685
 
        }
 
3717
      if (*it == "+")
 
3718
      {
 
3719
        last_was_plus = true;
 
3720
        continue;
 
3721
      }
 
3722
      else if (*it == "@bw")
 
3723
      {
 
3724
        if ((getActive2DWidget() != 0 || getActive3DWidget() != 0) && getActiveCanvas() != 0)
 
3725
        {
 
3726
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
 
3727
          tmp.setValue("dot:gradient", "Linear|0,#ffffff;100,#000000");
 
3728
          getActiveCanvas()->setCurrentLayerParameters(tmp);
 
3729
        }
 
3730
      }
 
3731
      else if (*it == "@bg")
 
3732
      {
 
3733
        if ((getActive2DWidget() != 0 || getActive3DWidget() != 0) && getActiveCanvas() != 0)
 
3734
        {
 
3735
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
 
3736
          tmp.setValue("dot:gradient", "Linear|0,#dddddd;100,#000000");
 
3737
          getActiveCanvas()->setCurrentLayerParameters(tmp);
 
3738
        }
 
3739
      }
 
3740
      else if (*it == "@b")
 
3741
      {
 
3742
        if ((getActive2DWidget() != 0 || getActive3DWidget() != 0) && getActiveCanvas() != 0)
 
3743
        {
 
3744
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
 
3745
          tmp.setValue("dot:gradient", "Linear|0,#000000;100,#000000");
 
3746
          getActiveCanvas()->setCurrentLayerParameters(tmp);
 
3747
        }
 
3748
      }
 
3749
      else if (*it == "@r")
 
3750
      {
 
3751
        if ((getActive2DWidget() != 0 || getActive3DWidget() != 0) && getActiveCanvas() != 0)
 
3752
        {
 
3753
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
 
3754
          tmp.setValue("dot:gradient", "Linear|0,#ff0000;100,#ff0000");
 
3755
          getActiveCanvas()->setCurrentLayerParameters(tmp);
 
3756
        }
 
3757
      }
 
3758
      else if (*it == "@g")
 
3759
      {
 
3760
        if ((getActive2DWidget() != 0 || getActive3DWidget() != 0) && getActiveCanvas() != 0)
 
3761
        {
 
3762
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
 
3763
          tmp.setValue("dot:gradient", "Linear|0,#00ff00;100,#00ff00");
 
3764
          getActiveCanvas()->setCurrentLayerParameters(tmp);
 
3765
        }
 
3766
      }
 
3767
      else if (*it == "@m")
 
3768
      {
 
3769
        if ((getActive2DWidget() != 0 || getActive3DWidget() != 0) && getActiveCanvas() != 0)
 
3770
        {
 
3771
          Param tmp = getActiveCanvas()->getCurrentLayer().param;
 
3772
          tmp.setValue("dot:gradient", "Linear|0,#ff00ff;100,#ff00ff");
 
3773
          getActiveCanvas()->setCurrentLayerParameters(tmp);
 
3774
        }
 
3775
      }
3686
3776
      else if (!last_was_plus || !getActiveSpectrumWidget())
3687
 
        {
3688
 
                splash_screen->showMessage((String("Loading file: ") + *it).toQString());
3689
 
                splash_screen->repaint();
3690
 
                QApplication::processEvents();
3691
 
        addDataFile(*it, false, true);  // add data file but don't show options
3692
 
        }
3693
 
        else
3694
 
        {
3695
 
                splash_screen->showMessage((String("Loading file: ") + *it).toQString());
3696
 
                splash_screen->repaint();
3697
 
                QApplication::processEvents();
3698
 
                last_was_plus = false;
3699
 
        addDataFile(*it, false, true,"",getActiveSpectrumWidget()->getWindowId());
3700
 
        }
 
3777
      {
 
3778
        splash_screen->showMessage((String("Loading file: ") + *it).toQString());
 
3779
        splash_screen->repaint();
 
3780
        QApplication::processEvents();
 
3781
        addDataFile(*it, false, true); // add data file but don't show options
 
3782
      }
 
3783
      else
 
3784
      {
 
3785
        splash_screen->showMessage((String("Loading file: ") + *it).toQString());
 
3786
        splash_screen->repaint();
 
3787
        QApplication::processEvents();
 
3788
        last_was_plus = false;
 
3789
        addDataFile(*it, false, true, "", getActiveSpectrumWidget()->getWindowId());
 
3790
      }
3701
3791
    }
3702
3792
  }
3703
3793
 
3704
3794
  void TOPPViewBase::showLogMessage_(TOPPViewBase::LogState state, const String& heading, const String& body)
3705
3795
  {
3706
 
                //Compose current time string
3707
 
                DateTime d = DateTime::now();
3708
 
 
3709
 
                String state_string;
3710
 
                switch(state)
3711
 
                {
3712
 
                        case LS_NOTICE: state_string = "NOTICE"; break;
3713
 
                        case LS_WARNING: state_string = "WARNING"; break;
3714
 
                        case LS_ERROR: state_string = "ERROR"; break;
3715
 
                }
3716
 
 
3717
 
                //update log
3718
 
                log_->append("==============================================================================");
3719
 
                log_->append((d.getTime() + " " + state_string + ": " + heading).toQString());
3720
 
                log_->append(body.toQString());
3721
 
 
3722
 
        //show log tool window
3723
 
                qobject_cast<QWidget *>(log_->parent())->show();
 
3796
    //Compose current time string
 
3797
    DateTime d = DateTime::now();
 
3798
 
 
3799
    String state_string;
 
3800
    switch (state)
 
3801
    {
 
3802
    case LS_NOTICE: state_string = "NOTICE"; break;
 
3803
 
 
3804
    case LS_WARNING: state_string = "WARNING"; break;
 
3805
 
 
3806
    case LS_ERROR: state_string = "ERROR"; break;
 
3807
    }
 
3808
 
 
3809
    //update log
 
3810
    log_->append("==============================================================================");
 
3811
    log_->append((d.getTime() + " " + state_string + ": " + heading).toQString());
 
3812
    log_->append(body.toQString());
 
3813
 
 
3814
    //show log tool window
 
3815
    qobject_cast<QWidget*>(log_->parent())->show();
3724
3816
  }
3725
3817
 
3726
 
        void TOPPViewBase::saveLayerAll()
3727
 
        {
 
3818
  void TOPPViewBase::saveLayerAll()
 
3819
  {
3728
3820
    getActiveCanvas()->saveCurrentLayer(false);
3729
 
        }
 
3821
  }
3730
3822
 
3731
 
        void TOPPViewBase::saveLayerVisible()
3732
 
        {
 
3823
  void TOPPViewBase::saveLayerVisible()
 
3824
  {
3733
3825
    getActiveCanvas()->saveCurrentLayer(true);
3734
 
        }
 
3826
  }
3735
3827
 
3736
 
        void TOPPViewBase::toggleGridLines()
3737
 
        {
 
3828
  void TOPPViewBase::toggleGridLines()
 
3829
  {
3738
3830
    getActiveCanvas()->showGridLines(!getActiveCanvas()->gridLinesShown());
3739
 
        }
 
3831
  }
3740
3832
 
3741
 
        void TOPPViewBase::toggleAxisLegends()
3742
 
        {
 
3833
  void TOPPViewBase::toggleAxisLegends()
 
3834
  {
3743
3835
    getActiveSpectrumWidget()->showLegend(!getActiveSpectrumWidget()->isLegendShown());
3744
 
        }
 
3836
  }
3745
3837
 
3746
 
        void TOPPViewBase::showPreferences()
3747
 
        {
 
3838
  void TOPPViewBase::showPreferences()
 
3839
  {
3748
3840
    getActiveCanvas()->showCurrentLayerPreferences();
3749
 
        }
3750
 
 
3751
 
        void TOPPViewBase::metadataFileDialog()
3752
 
        {
3753
 
                QStringList files = getFileList_();
3754
 
                FileHandler fh;
3755
 
                fh.getOptions().setMetadataOnly(true);
3756
 
                for (QStringList::iterator it = files.begin(); it!=files.end(); ++it)
3757
 
                {
3758
 
                        ExperimentType exp;
3759
 
                        try
3760
 
                        {
3761
 
                                fh.loadExperiment(*it,exp);
3762
 
                        }
3763
 
                        catch (Exception::BaseException& e)
3764
 
                        {
3765
 
                                QMessageBox::critical(this,"Error",(String("Error while reading data: ")+e.what()).c_str());
3766
 
              return;
3767
 
                        }
3768
 
                        MetaDataBrowser dlg(false, this);
3769
 
                        dlg.add(exp);
3770
 
                        dlg.exec();
3771
 
                }
3772
 
        }
3773
 
 
3774
 
        void TOPPViewBase::metadataDatabaseDialog()
3775
 
        {
3776
 
                DBConnection con;
3777
 
                connectToDB_(con);
3778
 
                if (con.isConnected())
3779
 
                {
3780
 
                        vector<UInt> ids;
3781
 
                        DBOpenDialog db_dialog(con,ids,ws_);
3782
 
                        if (db_dialog.exec())
3783
 
                        {
3784
 
                                DBAdapter db(con);
3785
 
                                db.getOptions().setMetadataOnly(true);
3786
 
                                for (vector<UInt>::iterator it = ids.begin();it!=ids.end();++it)
3787
 
                                {
3788
 
                                        ExperimentType exp;
3789
 
                                        try
3790
 
                                        {
3791
 
                                                db.loadExperiment(*it, exp);
3792
 
                                        }
3793
 
                                        catch (Exception::BaseException& e)
3794
 
                                        {
3795
 
                                                QMessageBox::critical(this,"Error",(String("Error while reading data: ")+e.what()).c_str());
3796
 
                              return;
3797
 
                                        }
3798
 
                                        MetaDataBrowser dlg(false, this);
3799
 
                                        dlg.add(exp);
3800
 
                                        dlg.exec();
3801
 
                                }
3802
 
                        }
3803
 
                }
3804
 
        }
 
3841
  }
 
3842
 
 
3843
  void TOPPViewBase::metadataFileDialog()
 
3844
  {
 
3845
    QStringList files = getFileList_();
 
3846
    FileHandler fh;
 
3847
    fh.getOptions().setMetadataOnly(true);
 
3848
    for (QStringList::iterator it = files.begin(); it != files.end(); ++it)
 
3849
    {
 
3850
      ExperimentType exp;
 
3851
      try
 
3852
      {
 
3853
        fh.loadExperiment(*it, exp);
 
3854
      }
 
3855
      catch (Exception::BaseException& e)
 
3856
      {
 
3857
        QMessageBox::critical(this, "Error", (String("Error while reading data: ") + e.what()).c_str());
 
3858
        return;
 
3859
      }
 
3860
      MetaDataBrowser dlg(false, this);
 
3861
      dlg.add(exp);
 
3862
      dlg.exec();
 
3863
    }
 
3864
  }
 
3865
 
 
3866
  void TOPPViewBase::metadataDatabaseDialog()
 
3867
  {
 
3868
    DBConnection con;
 
3869
    connectToDB_(con);
 
3870
    if (con.isConnected())
 
3871
    {
 
3872
      vector<UInt> ids;
 
3873
      DBOpenDialog db_dialog(con, ids, ws_);
 
3874
      if (db_dialog.exec())
 
3875
      {
 
3876
        DBAdapter db(con);
 
3877
        db.getOptions().setMetadataOnly(true);
 
3878
        for (vector<UInt>::iterator it = ids.begin(); it != ids.end(); ++it)
 
3879
        {
 
3880
          ExperimentType exp;
 
3881
          try
 
3882
          {
 
3883
            db.loadExperiment(*it, exp);
 
3884
          }
 
3885
          catch (Exception::BaseException& e)
 
3886
          {
 
3887
            QMessageBox::critical(this, "Error", (String("Error while reading data: ") + e.what()).c_str());
 
3888
            return;
 
3889
          }
 
3890
          MetaDataBrowser dlg(false, this);
 
3891
          dlg.add(exp);
 
3892
          dlg.exec();
 
3893
        }
 
3894
      }
 
3895
    }
 
3896
  }
3805
3897
 
3806
3898
  SpectraIdentificationViewWidget* TOPPViewBase::getSpectraIdentificationViewWidget()
3807
3899
  {
3814
3906
  }
3815
3907
 
3816
3908
  void TOPPViewBase::copyLayer(const QMimeData* data, QWidget* source, int id)
3817
 
        {
 
3909
  {
3818
3910
    QTreeWidget* spectra_view_treewidget = spectra_view_widget_->getTreeWidget();
3819
 
                try
3820
 
                {
3821
 
                        //NOT USED RIGHT NOW, BUT KEEP THIS CODE (it was hard to find out how this is done)
3822
 
                        //decode data to get the row
3823
 
                        //QByteArray encoded_data = data->data(data->formats()[0]);
3824
 
                        //QDataStream stream(&encoded_data, QIODevice::ReadOnly);
3825
 
                        //int row, col;
3826
 
                        //stream >> row >> col;
3827
 
 
3828
 
                //set wait cursor
3829
 
                setCursor(Qt::WaitCursor);
3830
 
 
3831
 
                        //determine where to copy the data
3832
 
                        UInt new_id = 0;
3833
 
      if (id != -1) new_id = id;
3834
 
 
3835
 
                        if (source == layer_manager_)
3836
 
                        {
3837
 
                                //only the selected row can be dragged => the source layer is the selected layer
 
3911
    try
 
3912
    {
 
3913
      //NOT USED RIGHT NOW, BUT KEEP THIS CODE (it was hard to find out how this is done)
 
3914
      //decode data to get the row
 
3915
      //QByteArray encoded_data = data->data(data->formats()[0]);
 
3916
      //QDataStream stream(&encoded_data, QIODevice::ReadOnly);
 
3917
      //int row, col;
 
3918
      //stream >> row >> col;
 
3919
 
 
3920
      //set wait cursor
 
3921
      setCursor(Qt::WaitCursor);
 
3922
 
 
3923
      //determine where to copy the data
 
3924
      UInt new_id = 0;
 
3925
      if (id != -1)
 
3926
        new_id = id;
 
3927
 
 
3928
      if (source == layer_manager_)
 
3929
      {
 
3930
        //only the selected row can be dragged => the source layer is the selected layer
3838
3931
        const LayerData& layer = getActiveCanvas()->getCurrentLayer();
3839
3932
 
3840
 
         //attach feature, consensus and peak data
 
3933
        //attach feature, consensus and peak data
3841
3934
        FeatureMapSharedPtrType features = layer.getFeatureMap();
3842
3935
        ExperimentSharedPtrType peaks = layer.getPeakData();
3843
3936
        ConsensusMapSharedPtrType consensus = layer.getConsensusMap();
3844
 
                                vector<PeptideIdentification> peptides = layer.peptides;
 
3937
        vector<PeptideIdentification> peptides = layer.peptides;
3845
3938
 
3846
 
                                //add the data
 
3939
        //add the data
3847
3940
        addData(features, consensus, peptides, peaks, layer.type, false, false, true, layer.filename, layer.name, new_id);
3848
 
                        }
 
3941
      }
3849
3942
      else if (source == spectra_view_treewidget)
3850
 
                        {
 
3943
      {
3851
3944
        const LayerData& layer = getActiveCanvas()->getCurrentLayer();
3852
3945
        QTreeWidgetItem* item = spectra_view_treewidget->currentItem();
3853
 
                                if (item != 0)
3854
 
                                {
3855
 
                                        Size index = (Size)(item->text(3).toInt());
 
3946
        if (item != 0)
 
3947
        {
 
3948
          Size index = (Size)(item->text(3).toInt());
3856
3949
          const ExperimentType::SpectrumType spectrum = (*layer.getPeakData())[index];
3857
 
                                        ExperimentType new_exp;
3858
 
                                        new_exp.push_back(spectrum);
 
3950
          ExperimentType new_exp;
 
3951
          new_exp.addSpectrum(spectrum);
3859
3952
          ExperimentSharedPtrType new_exp_sptr(new ExperimentType(new_exp));
3860
3953
          FeatureMapSharedPtrType f_dummy(new FeatureMapType());
3861
3954
          ConsensusMapSharedPtrType c_dummy(new ConsensusMapType());
3862
 
                                        vector<PeptideIdentification> p_dummy;
 
3955
          vector<PeptideIdentification> p_dummy;
3863
3956
          addData(f_dummy, c_dummy, p_dummy, new_exp_sptr, LayerData::DT_CHROMATOGRAM, false, false, true, layer.filename, layer.name, new_id);
3864
 
                                }
3865
 
                        }
3866
 
                        else if (source == 0)
3867
 
                        {
3868
 
                                // drag source is external
3869
 
                                if (data->hasUrls())
3870
 
                                {
3871
 
                                        QList<QUrl> urls = data->urls();
3872
 
                                        for (QList<QUrl>::const_iterator it = urls.begin(); it != urls.end(); ++it)
3873
 
                                        {
3874
 
                                                addDataFile(it->toLocalFile(), false, true, "", new_id);
3875
 
                                        }
3876
 
                                }
3877
 
                        }
3878
 
 
3879
 
                }
3880
 
    catch(Exception::BaseException& e)
3881
 
    {
3882
 
        showLogMessage_(LS_ERROR,"Error while creating layer",e.what());
3883
 
    }
3884
 
 
3885
 
                //reset cursor
3886
 
        setCursor(Qt::ArrowCursor);
3887
 
        }
3888
 
 
3889
 
 
3890
 
        void TOPPViewBase::updateCurrentPath()
3891
 
        {
3892
 
                //do not update if the user disabled this feature.
3893
 
                if (param_.getValue("preferences:default_path_current")!="true") return;
3894
 
 
3895
 
                //reset
3896
 
                current_path_ = param_.getValue("preferences:default_path");
3897
 
 
3898
 
                //update if the current layer has a path associated
3899
 
    if (getActiveCanvas() && getActiveCanvas()->getLayerCount()!=0 && getActiveCanvas()->getCurrentLayer().filename!="")
3900
 
                {
 
3957
        }
 
3958
      }
 
3959
      else if (source == 0)
 
3960
      {
 
3961
        // drag source is external
 
3962
        if (data->hasUrls())
 
3963
        {
 
3964
          QList<QUrl> urls = data->urls();
 
3965
          for (QList<QUrl>::const_iterator it = urls.begin(); it != urls.end(); ++it)
 
3966
          {
 
3967
            addDataFile(it->toLocalFile(), false, true, "", new_id);
 
3968
          }
 
3969
        }
 
3970
      }
 
3971
 
 
3972
    }
 
3973
    catch (Exception::BaseException& e)
 
3974
    {
 
3975
      showLogMessage_(LS_ERROR, "Error while creating layer", e.what());
 
3976
    }
 
3977
 
 
3978
    //reset cursor
 
3979
    setCursor(Qt::ArrowCursor);
 
3980
  }
 
3981
 
 
3982
  void TOPPViewBase::updateCurrentPath()
 
3983
  {
 
3984
    //do not update if the user disabled this feature.
 
3985
    if (param_.getValue("preferences:default_path_current") != "true")
 
3986
      return;
 
3987
 
 
3988
    //reset
 
3989
    current_path_ = param_.getValue("preferences:default_path");
 
3990
 
 
3991
    //update if the current layer has a path associated
 
3992
    if (getActiveCanvas() && getActiveCanvas()->getLayerCount() != 0 && getActiveCanvas()->getCurrentLayer().filename != "")
 
3993
    {
3901
3994
      current_path_ = File::path(getActiveCanvas()->getCurrentLayer().filename);
3902
 
                }
3903
 
        }
 
3995
    }
 
3996
  }
3904
3997
 
3905
 
        void TOPPViewBase::showSpectrumBrowser()
3906
 
        {
 
3998
  void TOPPViewBase::showSpectrumBrowser()
 
3999
  {
3907
4000
    views_dockwidget_->show();
3908
4001
    updateViewBar();
3909
 
        }
 
4002
  }
3910
4003
 
3911
4004
  void TOPPViewBase::fileChanged_(const String& filename)
3912
4005
  {
3920
4013
    QWidgetList wl = ws_->windowList();
3921
4014
 
3922
4015
    // iterate over all windows and determine which need an update
3923
 
    std::vector<std::pair<const SpectrumWidget *, Size> > needs_update;
3924
 
    for(int i=0; i!=ws_->windowList().count(); ++i)
 
4016
    std::vector<std::pair<const SpectrumWidget*, Size> > needs_update;
 
4017
    for (int i = 0; i != ws_->windowList().count(); ++i)
3925
4018
    {
3926
4019
      //std::cout << "Number of windows: " << ws_->windowList().count() << std::endl;
3927
4020
      QWidget* w = wl[i];
3928
4021
      const SpectrumWidget* sw = qobject_cast<const SpectrumWidget*>(w);
3929
 
      if (sw!=0)
 
4022
      if (sw != 0)
3930
4023
      {
3931
4024
        Size lc = sw->canvas()->getLayerCount();
3932
4025
 
3933
4026
        // determine if widget stores one or more layers for the given filename (->needs update)
3934
 
        for (Size j=0; j!= lc; ++j)
 
4027
        for (Size j = 0; j != lc; ++j)
3935
4028
        {
3936
4029
          //std::cout << "Layer filename: " << sw->canvas()->getLayer(j).filename << std::endl;
3937
4030
          const LayerData& ld = sw->canvas()->getLayer(j);
3938
4031
          if (ld.filename == filename)
3939
4032
          {
3940
 
            needs_update.push_back(std::pair<const SpectrumWidget *, Size>(sw,j));
 
4033
            needs_update.push_back(std::pair<const SpectrumWidget*, Size>(sw, j));
3941
4034
          }
3942
4035
        }
3943
4036
      }
3945
4038
 
3946
4039
    if (needs_update.empty()) // no layer references data of filename
3947
4040
    {
3948
 
      watcher_->removeFile(filename);  // remove watcher
 
4041
      watcher_->removeFile(filename); // remove watcher
3949
4042
      return;
3950
 
    } else if ( !needs_update.empty() )  // at least one layer references data of filename
 
4043
    }
 
4044
    else if (!needs_update.empty()) // at least one layer references data of filename
3951
4045
    {
3952
4046
      //std::cout << "Number of Layers that need update: " << needs_update.size() << std::endl;
3953
 
      pair<const SpectrumWidget *, Size>& slp = needs_update[0];
3954
 
      const SpectrumWidget * sw = slp.first;
 
4047
      pair<const SpectrumWidget*, Size>& slp = needs_update[0];
 
4048
      const SpectrumWidget* sw = slp.first;
3955
4049
      Size layer_index = slp.second;
3956
4050
 
3957
4051
      bool user_wants_update = false;
3958
 
      if ((String)(param_.getValue("preferences:on_file_change"))=="update automatically") //automatically update
 
4052
      if ((String)(param_.getValue("preferences:on_file_change")) == "update automatically") //automatically update
3959
4053
      {
3960
4054
        user_wants_update = true;
3961
4055
      }
3962
 
      else if ((String)(param_.getValue("preferences:on_file_change"))=="ask") //ask the user if the layer should be updated
 
4056
      else if ((String)(param_.getValue("preferences:on_file_change")) == "ask") //ask the user if the layer should be updated
3963
4057
      {
3964
 
        if (watcher_msgbox_==true)
3965
 
        { // we already have a dialog for that opened... do not ask again
 
4058
        if (watcher_msgbox_ == true) // we already have a dialog for that opened... do not ask again
 
4059
        {
3966
4060
          return;
3967
4061
        }
3968
4062
        // track that we will show the msgbox and we do not need to show it again if file changes once more and the dialog is still open
3969
 
        watcher_msgbox_=true;
 
4063
        watcher_msgbox_ = true;
3970
4064
        QMessageBox msg_box;
3971
4065
        QAbstractButton* ok = msg_box.addButton(QMessageBox::Ok);
3972
4066
        msg_box.addButton(QMessageBox::Cancel);
3973
4067
        msg_box.setWindowTitle("Layer data changed");
3974
4068
        msg_box.setText((String("The data of file '") + filename + "' has changed.<BR>Update layers?").toQString());
3975
4069
        msg_box.exec();
3976
 
        watcher_msgbox_=false;
 
4070
        watcher_msgbox_ = false;
3977
4071
        if (msg_box.clickedButton() == ok)
3978
4072
        {
3979
4073
          user_wants_update = true;
3988
4082
      {
3989
4083
        const LayerData& layer = sw->canvas()->getLayer(layer_index);
3990
4084
        // reload data
3991
 
        if (layer.type==LayerData::DT_PEAK) //peak data
 
4085
        if (layer.type == LayerData::DT_PEAK) //peak data
3992
4086
        {
3993
4087
          try
3994
4088
          {
3995
 
            FileHandler().loadExperiment(layer.filename,*layer.getPeakData());
 
4089
            FileHandler().loadExperiment(layer.filename, *layer.getPeakData());
3996
4090
          }
3997
 
          catch(Exception::BaseException& e)
 
4091
          catch (Exception::BaseException& e)
3998
4092
          {
3999
 
            QMessageBox::critical(this,"Error",(String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
 
4093
            QMessageBox::critical(this, "Error", (String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
4000
4094
            layer.getPeakData()->clear(true);
4001
4095
          }
4002
4096
          layer.getPeakData()->sortSpectra(true);
4003
4097
          layer.getPeakData()->updateRanges(1);
4004
4098
        }
4005
 
        else if (layer.type==LayerData::DT_FEATURE) //feature data
 
4099
        else if (layer.type == LayerData::DT_FEATURE) //feature data
4006
4100
        {
4007
4101
          try
4008
4102
          {
4009
 
            FileHandler().loadFeatures(layer.filename,*layer.getFeatureMap());
 
4103
            FileHandler().loadFeatures(layer.filename, *layer.getFeatureMap());
4010
4104
          }
4011
 
          catch(Exception::BaseException& e)
 
4105
          catch (Exception::BaseException& e)
4012
4106
          {
4013
 
            QMessageBox::critical(this,"Error",(String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
 
4107
            QMessageBox::critical(this, "Error", (String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
4014
4108
            layer.getFeatureMap()->clear(true);
4015
4109
          }
4016
4110
          layer.getFeatureMap()->updateRanges();
4017
4111
        }
4018
 
        else if (layer.type==LayerData::DT_CONSENSUS)  //consensus feature data
 
4112
        else if (layer.type == LayerData::DT_CONSENSUS) //consensus feature data
4019
4113
        {
4020
4114
          try
4021
4115
          {
4022
 
            ConsensusXMLFile().load(layer.filename,*layer.getConsensusMap());
 
4116
            ConsensusXMLFile().load(layer.filename, *layer.getConsensusMap());
4023
4117
          }
4024
 
          catch(Exception::BaseException& e)
 
4118
          catch (Exception::BaseException& e)
4025
4119
          {
4026
 
            QMessageBox::critical(this,"Error",(String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
 
4120
            QMessageBox::critical(this, "Error", (String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
4027
4121
            layer.getConsensusMap()->clear(true);
4028
4122
          }
4029
4123
          layer.getConsensusMap()->updateRanges();
4030
4124
        }
4031
 
        else if (layer.type==LayerData::DT_CHROMATOGRAM) //chromatgram
 
4125
        else if (layer.type == LayerData::DT_CHROMATOGRAM) //chromatgram
4032
4126
        {
4033
4127
          //TODO CHROM
4034
4128
          try
4035
4129
          {
4036
 
            FileHandler().loadExperiment(layer.filename,*layer.getPeakData());
 
4130
            FileHandler().loadExperiment(layer.filename, *layer.getPeakData());
4037
4131
          }
4038
 
          catch(Exception::BaseException& e)
 
4132
          catch (Exception::BaseException& e)
4039
4133
          {
4040
 
            QMessageBox::critical(this,"Error",(String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
 
4134
            QMessageBox::critical(this, "Error", (String("Error while loading file") + layer.filename + "\nError message: " + e.what()).toQString());
4041
4135
            layer.getPeakData()->clear(true);
4042
4136
          }
4043
4137
          layer.getPeakData()->sortChromatograms(true);
4061
4155
      }
4062
4156
 
4063
4157
      // update all layers that need an update
4064
 
      for (Size i=0; i!= needs_update.size(); ++i)
 
4158
      for (Size i = 0; i != needs_update.size(); ++i)
4065
4159
      {
4066
 
        pair<const SpectrumWidget *, Size>& slp = needs_update[i];
4067
 
        const SpectrumWidget * sw = slp.first;
 
4160
        pair<const SpectrumWidget*, Size>& slp = needs_update[i];
 
4161
        const SpectrumWidget* sw = slp.first;
4068
4162
        Size layer_index = slp.second;
4069
4163
        sw->canvas()->updateLayer(layer_index);
4070
4164
      }
4090
4184
    watcher_->addFile(filename);
4091
4185
  }
4092
4186
 
4093
 
  void TOPPViewBase::setTOPPASTabEnabled(bool enabled)
4094
 
  {
4095
 
    if (views_tabwidget_->isTabEnabled(2) != enabled)
4096
 
    {
4097
 
      views_tabwidget_->setTabEnabled(2, enabled);
4098
 
    }
4099
 
  }
4100
 
 
4101
 
  // ******************************************TOPPAS events**********************************
4102
 
  void TOPPViewBase::newPipeline()
4103
 
  {
4104
 
    TOPPASWidget* tw = new TOPPASWidget(Param(), ws_, toppas_tmp_path_);
4105
 
    TOPPASScene* ts = tw->getScene();
4106
 
    connect (ts, SIGNAL(selectionCopied(TOPPASScene*)), this, SLOT(saveToClipboard(TOPPASScene*)));
4107
 
    connect (ts, SIGNAL(requestClipboardContent()), this, SLOT(sendClipboardContent()));
4108
 
    connect (ts, SIGNAL(saveMe()), this, SLOT(savePipeline()));
4109
 
    connect (ts, SIGNAL(mainWindowNeedsUpdate()), this, SLOT(updateMenu()));
4110
 
    showTOPPipelineInWindow_(tw, "(Untitled)");
4111
 
  }
4112
 
 
4113
 
  void TOPPViewBase::includePipeline()
4114
 
  {
4115
 
    QString file_name = QFileDialog::getOpenFileName(this, tr("Include workflow"), current_path_.toQString(), tr("TOPPAS pipelines (*.toppas)"));
4116
 
    addTOPPASFile(file_name, false);
4117
 
  }
4118
 
 
4119
 
  void TOPPViewBase::savePipeline()
4120
 
  {
4121
 
    TOPPASWidget* w = 0;
4122
 
    QObject* sendr = QObject::sender();
4123
 
    QAction* save_button_clicked = qobject_cast<QAction*>(sendr);
4124
 
 
4125
 
    if (!save_button_clicked)
4126
 
    {
4127
 
      // scene has requested to be saved
4128
 
      TOPPASScene* ts = qobject_cast<TOPPASScene*>(sendr);
4129
 
      if (ts && ts->views().size() > 0)
4130
 
      {
4131
 
        w = qobject_cast<TOPPASWidget*>(ts->views().first());
4132
 
      }
4133
 
    }
4134
 
    else
4135
 
    {
4136
 
      w = getActiveTOPPASWidget();
4137
 
    }
4138
 
 
4139
 
    if (!w)
4140
 
    {
4141
 
      return;
4142
 
    }
4143
 
 
4144
 
    String file_name = w->getScene()->getSaveFileName();
4145
 
    if (file_name != "")
4146
 
    {
4147
 
      if (!file_name.hasSuffix(".toppas"))
4148
 
      {
4149
 
        file_name += ".toppas";
4150
 
      }
4151
 
      w->getScene()->store(file_name);
4152
 
    }
4153
 
    else
4154
 
    {
4155
 
      TOPPASBase::savePipelineAs(w, current_path_.toQString());
4156
 
    }
4157
 
  }
4158
 
 
4159
 
  void TOPPViewBase::saveCurrentPipelineAs()
4160
 
  {
4161
 
    TOPPASWidget* w = getActiveTOPPASWidget();
4162
 
    QString file_name = TOPPASBase::savePipelineAs(w, current_path_.toQString());
4163
 
    if (file_name != "")
4164
 
    {
4165
 
      QString caption = File::basename(file_name).toQString();
4166
 
      tab_bar_->setTabText(tab_bar_->currentIndex(), caption);
4167
 
    }
4168
 
  }
4169
 
 
4170
 
  void TOPPViewBase::loadPipelineResourceFile()
4171
 
  {
4172
 
    TOPPASWidget* w = getActiveTOPPASWidget();
4173
 
    TOPPASBase::loadPipelineResourceFile(w, current_path_.toQString());
4174
 
  }
4175
 
 
4176
 
  void TOPPViewBase::savePipelineResourceFile()
4177
 
  {
4178
 
    TOPPASWidget* w = getActiveTOPPASWidget();
4179
 
    TOPPASBase::savePipelineResourceFile(w, current_path_.toQString());
4180
 
  }
4181
 
 
4182
 
  void TOPPViewBase::refreshPipelineParameters()
4183
 
  {
4184
 
    TOPPASWidget* w = getActiveTOPPASWidget();
4185
 
    QString file_name = TOPPASBase::refreshPipelineParameters(w, current_path_.toQString());
4186
 
    if (file_name != "")
4187
 
    {
4188
 
      QString caption = File::basename(file_name).toQString();
4189
 
      tab_bar_->setTabText(tab_bar_->currentIndex(), caption);
4190
 
    }
4191
 
  }
4192
 
 
4193
 
  void TOPPViewBase::runPipeline()
4194
 
  {
4195
 
    TOPPASWidget* w = getActiveTOPPASWidget();
4196
 
    if (w)
4197
 
    {
4198
 
      w->getScene()->runPipeline();
4199
 
    }
4200
 
  }
4201
 
 
4202
 
  void TOPPViewBase::abortPipeline()
4203
 
  {
4204
 
    TOPPASWidget* w = getActiveTOPPASWidget();
4205
 
    if (w)
4206
 
    {
4207
 
      w->getScene()->abortPipeline();
4208
 
    }
4209
 
    updateMenu();
4210
 
  }
4211
 
 
4212
 
  void TOPPViewBase::showPipelineFinishedLogMessage()
4213
 
  {
4214
 
    showLogMessage_(LS_NOTICE, "Entire pipeline execution finished!", "");
4215
 
  }
4216
 
 
4217
 
  void TOPPViewBase::saveToClipboard(TOPPASScene* scene)
4218
 
  {
4219
 
    if (toppas_clipboard_scene_ != 0)
4220
 
    {
4221
 
      delete toppas_clipboard_scene_;
4222
 
      toppas_clipboard_scene_ = 0;
4223
 
    }
4224
 
    toppas_clipboard_scene_ = scene;
4225
 
  }
4226
 
 
4227
 
  void TOPPViewBase::sendClipboardContent()
4228
 
  {
4229
 
    TOPPASScene* sndr = qobject_cast<TOPPASScene*>(QObject::sender());
4230
 
    if (sndr != 0)
4231
 
    {
4232
 
      sndr->setClipboard(toppas_clipboard_scene_);
4233
 
    }
4234
 
  }
4235
 
 
4236
 
  void TOPPViewBase::toolStarted()
4237
 
  {
4238
 
    TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
4239
 
    if (tv)
4240
 
    {
4241
 
      String text = tv->getName();
4242
 
      String type = tv->getType();
4243
 
      if (type != "")
4244
 
      {
4245
 
        text += " ("+type+")";
4246
 
      }
4247
 
      text += " started. Processing ...";
4248
 
 
4249
 
      showLogMessage_(LS_NOTICE, text, "");
4250
 
    }
4251
 
    updateMenu();
4252
 
  }
4253
 
 
4254
 
  void TOPPViewBase::toolFinished()
4255
 
  {
4256
 
    TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
4257
 
    if (tv)
4258
 
    {
4259
 
      String text = tv->getName();
4260
 
      String type = tv->getType();
4261
 
      if (type != "")
4262
 
      {
4263
 
        text += " ("+type+")";
4264
 
      }
4265
 
      text += " finished!";
4266
 
 
4267
 
      showLogMessage_(LS_NOTICE, text, "");
4268
 
    }
4269
 
    updateMenu();
4270
 
  }
4271
 
 
4272
 
  void TOPPViewBase::toolCrashed()
4273
 
  {
4274
 
    TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
4275
 
    if (tv)
4276
 
    {
4277
 
      String text = tv->getName();
4278
 
      String type = tv->getType();
4279
 
      if (type != "")
4280
 
      {
4281
 
        text += " ("+type+")";
4282
 
      }
4283
 
      text += " crashed!";
4284
 
 
4285
 
      showLogMessage_(LS_ERROR, text, "");
4286
 
    }
4287
 
    updateMenu();
4288
 
  }
4289
 
 
4290
 
  void TOPPViewBase::toolFailed()
4291
 
  {
4292
 
    TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
4293
 
    if (tv)
4294
 
    {
4295
 
      String text = tv->getName();
4296
 
      String type = tv->getType();
4297
 
      if (type != "")
4298
 
      {
4299
 
        text += " ("+type+")";
4300
 
      }
4301
 
      text += " failed!";
4302
 
 
4303
 
      showLogMessage_(LS_ERROR, text, "");
4304
 
    }
4305
 
    updateMenu();
4306
 
  }
4307
 
 
4308
 
  void TOPPViewBase::outputVertexFinished(const String& file)
4309
 
  {
4310
 
    String text = "Output file '" + file + "' written.";
4311
 
    showLogMessage_(LS_NOTICE, text, "");
4312
 
  }
4313
 
 
4314
 
  void TOPPViewBase::updateTOPPOutputLog(const QString& out)
4315
 
  {
4316
 
    QString text = out; // shortened version for now (if we reintroduce simultaneous tool execution,
4317
 
                        // we need to rethink this (probably only trigger this slot when tool 100% finished)
4318
 
 
4319
 
    //show log if there is output
4320
 
    qobject_cast<QWidget*>(log_->parent())->show();
4321
 
 
4322
 
    //update log_
4323
 
    log_->append(text);
4324
 
  }
4325
 
 
4326
 
  void TOPPViewBase::openFilesInTOPPView(QStringList files)
4327
 
  {
4328
 
    foreach(QString s, files)
4329
 
    {
4330
 
      addDataFile(s, false, false, s);
4331
 
    }
4332
 
  }
4333
 
 
4334
 
  //
4335
 
 
4336
4187
  TOPPViewBase::~TOPPViewBase()
4337
4188
  {
4338
4189
    savePreferences();
4339
4190
    abortTOPPTool();
4340
4191
 
4341
4192
    // dispose behavior
4342
 
    if(identificationview_behavior_ != 0)
 
4193
    if (identificationview_behavior_ != 0)
4343
4194
    {
4344
4195
      delete(identificationview_behavior_);
4345
4196
    }
4346
4197
 
4347
 
    if(spectraview_behavior_ != 0)
 
4198
    if (spectraview_behavior_ != 0)
4348
4199
    {
4349
4200
      delete(spectraview_behavior_);
4350
4201
    }