libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
qcpxic.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/widget/xicwidget/qcpxic.cpp
3 * \date 12/1/2018
4 * \author Olivier Langella
5 * \brief custom plot XIC
6 */
7
8
9/*******************************************************************************
10 * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
11 *
12 * This file is part of the PAPPSOms++ library.
13 *
14 * PAPPSOms++ is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * PAPPSOms++ is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * Contributors:
28 * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
29 *implementation
30 ******************************************************************************/
31
32
33#include "qcpxic.h"
35
36using namespace pappso;
37
38QCPXic::QCPXic(XicWidget *parent) : QCustomPlot(parent)
39{
40 qDebug() << "QCPXic::QCPXic begin";
41 _parent = parent;
42 setFocusPolicy(Qt::ClickFocus);
43
44 if(_parent->_rt_in_seconds)
45 {
46 xAxis->setLabel("retention time (sec)");
47 }
48 else
49 {
50 xAxis->setLabel("retention time (min)");
51 }
52
53 yAxis->setLabel("intensity");
54 setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
55 axisRect()->setRangeDrag(Qt::Horizontal);
56 axisRect()->setRangeZoom(Qt::Horizontal);
57
58 connect(this->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(setRtRangeChanged(QCPRange)));
59
60 //
61 // http://tools.medialab.sciences-po.fr/iwanthue/
62 _colours = {QColor(197, 89, 110),
63 QColor(94, 185, 86),
64 QColor(132, 95, 203),
65 QColor(176, 175, 69),
66 QColor(202, 72, 160),
67 QColor(91, 126, 59),
68 QColor(193, 126, 189),
69 QColor(81, 183, 159),
70 QColor(210, 77, 58),
71 QColor(99, 137, 203),
72 QColor(223, 147, 71),
73 QColor(156, 105, 52)};
74
75 qDebug() << "QCPXic::QCPXic end";
76}
80void
81QCPXic::keyPressEvent(QKeyEvent *event)
82{
83 if(event->key() == Qt::Key_Control)
84 {
85 _control_key = true;
86 }
87 qDebug() << "QCPXic::keyPressEvent end";
88}
89
90void
91QCPXic::keyReleaseEvent(QKeyEvent *event)
92{
93 if(event->key() == Qt::Key_Control)
94 {
95 _control_key = false;
96 }
97 qDebug() << "QCPXic::keyReleaseEvent end";
98}
99
100void
101QCPXic::mousePressEvent(QMouseEvent *event)
102{
103 qDebug() << " begin ";
104 _mouse_move = false;
105 _click = true;
106
107#if QT_VERSION < 0x060000
108 _old_x = event->x();
109 _old_y = yAxis->pixelToCoord(event->y());
110#else
111 _old_x = event->position().x();
112 _old_y = yAxis->pixelToCoord(event->position().y());
113#endif
114 if(_old_y < 0)
115 {
116 _old_y = 0;
117 }
118 else
119 {
120 }
121 qDebug() << "QCPXic::mousePressEvent end";
122}
123void
124QCPXic::mouseReleaseEvent(QMouseEvent *event)
125{
126
127#if QT_VERSION < 0x060000
128 qDebug() << "QCPXic::mouseReleaseEvent begin " << xAxis->pixelToCoord(event->x()) << " "
129 << yAxis->pixelToCoord(event->y());
130#else
131 qDebug() << "QCPXic::mouseReleaseEvent begin " << xAxis->pixelToCoord(event->position().x())
132 << " " << yAxis->pixelToCoord(event->position().y());
133#endif
134
135 _click = false;
136 if(_mouse_move)
137 {
138 _mouse_move = false;
139 }
140 else
141 {
142 _parent->xicClickEvent(xAxisToSeconds(_old_x), _old_y);
143 }
144 qDebug() << "QCPXic::mouseReleaseEvent end";
145}
146void
147QCPXic::mouseMoveEvent(QMouseEvent *event)
148{
149 _mouse_move = true;
150
151#if QT_VERSION < 0x060000
152 pappso::pappso_double x = xAxis->pixelToCoord(event->x());
153#else
154 pappso::pappso_double x = xAxis->pixelToCoord(event->position().x());
155#endif
156 if(_click)
157 {
158
159#if QT_VERSION < 0x060000
160 qDebug() << "QCPXic::mouseMoveEvent begin " << xAxis->pixelToCoord(event->x()) << " "
161 << yAxis->pixelToCoord(event->y());
162 pappso::pappso_double y = yAxis->pixelToCoord(event->y());
163#else
164 qDebug() << "QCPXic::mouseMoveEvent begin " << xAxis->pixelToCoord(event->position().x())
165 << " " << yAxis->pixelToCoord(event->position().y());
166 pappso::pappso_double y = yAxis->pixelToCoord(event->position().y());
167#endif
168 if(y < 0)
169 {
170 y = 0;
171 }
172 if(_control_key)
173 {
174 if(y > 0)
175 {
176 this->yAxis->scaleRange(_old_y / y, 0);
177 }
178 }
179 else
180 {
181
182#if QT_VERSION < 0x060000
183 this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) - xAxis->pixelToCoord(event->x()));
184#else
185 this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) -
186 xAxis->pixelToCoord(event->position().x()));
187#endif
188 }
189
190#if QT_VERSION < 0x060000
191 _old_x = event->x();
192#else
193 _old_x = event->position().x();
194#endif
195 _old_y = y;
196 replot();
197 qDebug() << "QCPXic::mouseMoveEvent end";
198 }
199 else
200 {
201 if(_map_xic_graph.size() > 0)
202 {
203 // pappso::pappso_double mouse_mz_range = xAxis->pixelToCoord(10) -
204 // xAxis->pixelToCoord(5); getNearestPeakBetween(x, mouse_mz_range);
205 _parent->rtChangeEvent(xAxisToSeconds(x));
206 }
207 }
208}
209
210QCPGraph *
211QCPXic::addXicP(const Xic *xic_p)
212{
213
214 _graph_color = _colours[(int)(_map_xic_graph.size() % _colours.size())];
215
216 QCPGraph *graph_xic = addGraph();
217 graph_xic->setPen(QPen(_graph_color));
218 _map_xic_graph.insert(std::pair<const Xic *, QCPGraph *>(xic_p, graph_xic));
219 graph_xic->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 2.0));
220
221 if(xic_p->size() > 0)
222 {
223 for(const DataPoint &element : *xic_p)
224 {
225 graph_xic->addData(getRetentionTimeFromSecondsToLocal(element.x), element.y);
226 }
227 if(_rt_range.lower > getRetentionTimeFromSecondsToLocal(xic_p->front().x))
228 _rt_range.lower = getRetentionTimeFromSecondsToLocal(xic_p->front().x) - 1;
229 if(_rt_range.upper < getRetentionTimeFromSecondsToLocal(xic_p->back().x))
230 _rt_range.upper = getRetentionTimeFromSecondsToLocal(xic_p->back().x) + 1;
231 _intensity_range.lower = 0;
232 if(_intensity_range.upper < xic_p->maxYDataPoint().y)
233 _intensity_range.upper = xic_p->maxYDataPoint().y;
234 }
235
236 return graph_xic;
237}
238
239
240void
242{
243}
244
245
246void
248{
249 qDebug() << "QCPXic::setMzRangeChanged _rt_range.lower" << _rt_range.lower;
250 if(range.lower < _rt_range.lower)
251 {
252 range.lower = _rt_range.lower;
253 }
254 if(range.upper > _rt_range.upper)
255 {
256 range.upper = _rt_range.upper;
257 }
258
259 xAxis->setRange(range);
260}
261
262
263void
265{
266 _current_ms2_event = new QCPItemTracer(this);
267 // itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
268 // bracketDataSlot for animation
269
270 _current_ms2_event->setGraph(_map_xic_graph.at(xic_p));
272 _current_ms2_event->setInterpolating(true);
273 _current_ms2_event->setStyle(QCPItemTracer::tsCircle);
274 _current_ms2_event->setPen(QPen(Qt::red));
275 _current_ms2_event->setBrush(Qt::red);
276 _current_ms2_event->setSize(7);
277
278 // addItem(_current_ms2_event);
279}
280
281void
282QCPXic::setName(const Xic *xic_p, const QString &name)
283{
284 _map_xic_graph.at(xic_p)->addToLegend();
285 _map_xic_graph.at(xic_p)->setName(name);
286}
287
288
289void
291{
292 legend->clearItems();
293 _map_xic_graph.clear();
294 this->clearGraphs();
295 this->clearItems();
296 this->clearPlottables();
297}
298
299
300void
301QCPXic::addXicPeakList(const Xic *xic_p, const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
302{
303 for(const pappso::TracePeakCstSPtr &peak : xic_peak_list)
304 {
305 _graph_peak_surface_list.push_back(addGraph());
306 for(auto &xic_element : *(xic_p))
307 {
308 if(peak.get()->containsRt(xic_element.x))
309 {
310 _graph_peak_surface_list.back()->addData(
311 getRetentionTimeFromSecondsToLocal(xic_element.x), xic_element.y);
312 }
313 }
314 // graph()->setData(rt_peak, intensity_peak);
315 _graph_peak_surface_list.back()->removeFromLegend();
316 _graph_peak_surface_list.back()->setChannelFillGraph(0);
317 _graph_peak_surface_list.back()->setLineStyle(QCPGraph::LineStyle::lsLine);
318 QColor color = _colours[_graph_peak_surface_list.size() % 12];
319 color.setAlpha(0);
320 // QColor(0, 110, 110, 30)
321 _graph_peak_surface_list.back()->setPen(QPen(color));
322 color.setAlpha(40);
323 //_graph_peak_surface_list.back()->setScatterStyle(QCPScatterStyle::ssDot);
324 _graph_peak_surface_list.back()->setBrush(QBrush(color));
325 }
326}
327
330{
331 if(_parent->_rt_in_seconds)
332 {
333 return rt;
334 }
335 else
336 {
337 return (rt / (pappso::pappso_double)60);
338 }
339}
340
343{
344 if(_parent->_rt_in_seconds)
345 {
346 return rt;
347 }
348 else
349 {
350 return (rt * (pappso::pappso_double)60);
351 }
352}
353
354void
355QCPXic::drawXicPeakBorders(unsigned int i, const Xic *xic_p, const pappso::TracePeak *p_xic_peak)
356{
357 QCPGraph *p_graph = _map_xic_graph.at(xic_p);
358 QColor color = _colours[i % 12];
359 // color.setAlpha(95);
360
361 QCPItemTracer *p_peak_border_left = new QCPItemTracer(this);
362 // itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
363 // bracketDataSlot for animation
364 QPen border_pen(color);
365 border_pen.setWidth(3);
366
367 p_peak_border_left->setGraph(p_graph);
368 p_peak_border_left->setGraphKey(
370 p_peak_border_left->setInterpolating(true);
371 p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
372 p_peak_border_left->setPen(border_pen);
373 p_peak_border_left->setBrush(color);
374 p_peak_border_left->setSize(30);
375
376 _graph_peak_border_list.push_back(p_peak_border_left);
377
378 // addItem(p_peak_border_left);
379
380 QPen apex_pen(color);
381 apex_pen.setWidth(2);
382 p_peak_border_left = new QCPItemTracer(this);
383 p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
384 p_peak_border_left->setGraphKey(
386 p_peak_border_left->setInterpolating(true);
387 p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
388 p_peak_border_left->setPen(apex_pen);
389 p_peak_border_left->setBrush(color);
390 p_peak_border_left->setSize(8);
391
392 _graph_peak_border_list.push_back(p_peak_border_left);
393
394 // addItem(p_peak_border_left);
395
396
397 p_peak_border_left = new QCPItemTracer(this);
398 p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
399 p_peak_border_left->setGraphKey(
401 p_peak_border_left->setInterpolating(true);
402 p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
403 p_peak_border_left->setPen(border_pen);
404 p_peak_border_left->setBrush(color);
405 p_peak_border_left->setSize(30);
406
407 _graph_peak_border_list.push_back(p_peak_border_left);
408
409 // addItem(p_peak_border_left);
410
411 replot();
412}
413
414void
416{
417 for(QCPItemTracer *p_tracer : _graph_peak_border_list)
418 {
419 removeItem(p_tracer);
420 // delete p_tracer;
421 }
423 replot();
424}
bool _click
Definition qcpxic.h:80
virtual void keyPressEvent(QKeyEvent *event) override
Definition qcpxic.cpp:81
bool _mouse_move
Definition qcpxic.h:81
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition qcpxic.cpp:264
void clearXicPeakBorders()
Definition qcpxic.cpp:415
std::vector< QColor > _colours
Definition qcpxic.h:88
std::vector< QCPItemTracer * > _graph_peak_border_list
Definition qcpxic.h:90
bool _control_key
Definition qcpxic.h:82
pappso::pappso_double _old_y
Definition qcpxic.h:84
QCPRange _rt_range
Definition qcpxic.h:78
pappso::pappso_double xAxisToSeconds(pappso::pappso_double rt) const
Definition qcpxic.cpp:342
void setName(const Xic *xic_p, const QString &name)
Definition qcpxic.cpp:282
QCPRange _intensity_range
Definition qcpxic.h:79
pappso::pappso_double _old_x
Definition qcpxic.h:83
std::vector< QCPGraph * > _graph_peak_surface_list
Definition qcpxic.h:89
friend class XicWidget
Definition qcpxic.h:44
std::map< const Xic *, QCPGraph * > _map_xic_graph
Definition qcpxic.h:86
Q_SLOT void setRtRangeChanged(QCPRange range)
Definition qcpxic.cpp:247
pappso::pappso_double getRetentionTimeFromSecondsToLocal(pappso::pappso_double rt) const
Definition qcpxic.cpp:329
virtual void mousePressEvent(QMouseEvent *event) override
Definition qcpxic.cpp:101
void drawXicPeakBorders(unsigned int i, const Xic *xic_p, const pappso::TracePeak *p_xic_peak)
Definition qcpxic.cpp:355
QCPItemTracer * _current_ms2_event
Definition qcpxic.h:85
virtual void mouseMoveEvent(QMouseEvent *event) override
Definition qcpxic.cpp:147
virtual void keyReleaseEvent(QKeyEvent *event) override
Definition qcpxic.cpp:91
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition qcpxic.cpp:301
void rescale()
Definition qcpxic.cpp:241
QColor _graph_color
Definition qcpxic.h:87
virtual void mouseReleaseEvent(QMouseEvent *event) override
Definition qcpxic.cpp:124
QCPXic(XicWidget *parent)
Definition qcpxic.cpp:38
XicWidget * _parent
Definition qcpxic.h:77
QCPGraph * addXicP(const Xic *xic_p)
Definition qcpxic.cpp:211
DataPoint & getLeftBoundary()
Definition tracepeak.cpp:93
DataPoint & getMaxXicElement()
Definition tracepeak.cpp:83
DataPoint & getRightBoundary()
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
double pappso_double
A type definition for doubles.
Definition types.h:60
std::shared_ptr< const TracePeak > TracePeakCstSPtr
Definition tracepeak.h:35
pappso_double x
Definition datapoint.h:24