libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
xicwidget.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/widget/xicwidget/xicwidget.h
3 * \date 12/1/2018
4 * \author Olivier Langella
5 * \brief plot a 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 "xicwidget.h"
34#include <QDebug>
35#include <QHBoxLayout>
36#include "qcpxic.h"
38
39using namespace pappso;
40
41XicWidget::XicWidget(QWidget *parent) : GraphicDeviceWidget(parent)
42{
43 qDebug() << "XicWidget::XicWidget begin";
44
45
46 this->setLayout(new QHBoxLayout(this));
47
48 setMinimumSize(200, 160);
49 this->layout()->setContentsMargins(0, 0, 0, 0);
50
51 _qcp_xic = new QCPXic(this);
52 this->layout()->addWidget(_qcp_xic);
53 qDebug() << "XicWidget::XicWidget end";
54}
58
59void
61{
62 XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
63 _qcp_xic->addMsMsEvent(xic_p, rt);
64 _map_xic_msms_event[xic_p] = rt;
65}
66QCPGraph *
68{
69 _xic_sp_list.push_back(xic_sp);
70 return _qcp_xic->addXicP(xic_sp.get());
71}
72
73const QString &
74XicWidget::getName(const Xic *xic_p) const
75{
76 XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
77 return _map_xic_name.at(xic_p);
78}
79
80void
81XicWidget::setName(const Xic *xic_p, const QString &name)
82{
83 XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
84 _qcp_xic->legend->setVisible(true);
85 _qcp_xic->setName(xic_p, name);
86 _map_xic_name[xic_p] = name;
87}
88
89void
91{
92 _qcp_xic->replot();
93}
94void
96{
97 _qcp_xic->xAxis->rescale(true);
98 _qcp_xic->yAxis->rescale(true);
99 _qcp_xic->rescale();
100}
101
102QCPAxis *
104{
105 return _qcp_xic->xAxis;
106}
107
108QCPAxis *
110{
111 return _qcp_xic->yAxis;
112}
113
114void
115XicWidget::rescaleOneRange(QString axis_name, QCPRange new_range)
116{
117 if(axis_name == "xAxis")
118 {
119 _qcp_xic->xAxis->setRange(new_range);
120 }
121 else // axis_name == "yAxis"
122 {
123 _qcp_xic->yAxis->setRange(new_range);
124 }
125 _qcp_xic->replot();
126}
127
128void
130{
131 _map_xic_name.clear();
132 _xic_sp_list.clear();
133 _xic_peak_sp_list.clear();
134 _qcp_xic->clear();
135 _map_xic_msms_event.clear();
136}
137
139XicWidget::getXicCstSPtr(const Xic *xic_p) const
140{
141 std::vector<XicCstSPtr>::const_iterator it =
142 std::find_if(_xic_sp_list.begin(), _xic_sp_list.end(), [xic_p](XicCstSPtr xic_sp) {
143 return xic_sp.get() == xic_p;
144 });
145 if(it == _xic_sp_list.end())
146 {
147 throw pappso::ExceptionNotFound(tr("ERROR : xic pointer not found"));
148 }
149 return *it;
150}
151
152void
154 const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
155{
156 XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
157 _qcp_xic->addXicPeakList(xic_p, xic_peak_list);
158 for(const pappso::TracePeakCstSPtr &xic_peak : xic_peak_list)
159 {
160 _xic_peak_sp_list.push_back(std::pair<XicCstSPtr, TracePeakCstSPtr>(xic_sp, xic_peak));
161 }
162}
163void
165{
166 emit rtChanged(rt);
167
168 std::vector<std::pair<XicCstSPtr, TracePeakCstSPtr>> over_xic_peak_list;
169 for(std::pair<XicCstSPtr, TracePeakCstSPtr> pair_xic_peak : _xic_peak_sp_list)
170 {
171 if(pair_xic_peak.second.get()->containsRt(rt))
172 {
173 over_xic_peak_list.push_back(pair_xic_peak);
174 }
175 }
176
177 // if (over_xic_peak_list.size() > 0) {
178 emit xicPeakListChanged(over_xic_peak_list);
179 //}
180}
181
182void
183XicWidget::toQPaintDevice(QPaintDevice *device, const QSize &size)
184{
185
186 if(_qcp_xic != nullptr)
187 {
188 QCPPainter painter;
189 painter.begin(device);
190 _qcp_xic->toPainter(&painter, size.width(), size.height());
191 painter.end();
192 }
193}
194
195
196void
198{
199 _rt_in_seconds = true;
200 _qcp_xic->xAxis->setLabel("retention time (sec)");
201 replotAll();
202}
203void
205{
206 _rt_in_seconds = false;
207 _qcp_xic->xAxis->setLabel("retention time (min)");
208 replotAll();
209}
210
211void
213{
214 _qcp_xic->clear();
215
216 for(XicCstSPtr xic_sp : _xic_sp_list)
217 {
218 _qcp_xic->addXicP(xic_sp.get());
219
220 std::vector<TracePeakCstSPtr> xic_peak_list;
221 for(auto xic_map_peak_list : _xic_peak_sp_list)
222 {
223 if(xic_map_peak_list.first.get() == xic_sp.get())
224 xic_peak_list.push_back(xic_map_peak_list.second);
225 }
226 _qcp_xic->addXicPeakList(xic_sp.get(), xic_peak_list);
227 }
228 for(auto xic_name : _map_xic_name)
229 {
230 setName(xic_name.first, xic_name.second);
231 }
232 for(auto xic_msms : _map_xic_msms_event)
233 {
234 _qcp_xic->addMsMsEvent(xic_msms.first, xic_msms.second);
235 }
236
237 rescale();
238 _qcp_xic->replot();
239}
240
241void
243{
244 emit clicked(rt, intensity);
245}
246
247
248void
250{
251 XicCstSPtr xic_sp;
252 for(std::pair<XicCstSPtr, TracePeakCstSPtr> pair_xic_peak : _xic_peak_sp_list)
253 {
254 if(pair_xic_peak.second.get() == xic_peak.get())
255 {
256 xic_sp = pair_xic_peak.first;
257 break;
258 }
259 }
260
261 if(xic_sp.get() != nullptr)
262 {
263
264 unsigned int i = 0;
265 for(XicCstSPtr xic_in_list : _xic_sp_list)
266 {
267 if(xic_in_list.get() == xic_sp.get())
268 {
269 break;
270 }
271 i++;
272 }
273 _qcp_xic->drawXicPeakBorders(i, xic_sp.get(), xic_peak.get());
274 }
275}
276
277
278void
280{
281 _qcp_xic->clearXicPeakBorders();
282}
GraphicDeviceWidget(QWidget *parent)
friend class QCPXic
Definition xicwidget.h:89
void toQPaintDevice(QPaintDevice *device, const QSize &size) override
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
void rtChanged(double rt) const
announce the current retention time (under mouse) in seconds
QCPAxis * getIntensityAxisP()
std::vector< XicCstSPtr > _xic_sp_list
Definition xicwidget.h:102
void clearXicPeakBorders()
XicCstSPtr getXicCstSPtr(const Xic *xic_p) const
XicXicPeakPairList _xic_peak_sp_list
Definition xicwidget.h:103
std::map< const Xic *, QString > _map_xic_name
Definition xicwidget.h:100
XicWidget(QWidget *parent=0)
Definition xicwidget.cpp:41
void setRetentionTimeInMinutes()
const QString & getName(const Xic *xic_p) const
Definition xicwidget.cpp:74
void rtChangeEvent(pappso::pappso_double rt) const
QCPGraph * addXicSp(XicCstSPtr xic_sp)
Definition xicwidget.cpp:67
std::map< const Xic *, pappso::pappso_double > _map_xic_msms_event
Definition xicwidget.h:101
QCPAxis * getRtAxisP()
get the plots axis and rescale one axis with the given range
void xicPeakListChanged(pappso::XicXicPeakPairList xic_peak_list) const
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition xicwidget.cpp:60
void setName(const Xic *xic_p, const QString &name)
Definition xicwidget.cpp:81
void clicked(double rt, double intensity) const
announce mouse position on click (rt in seconds, intensity)
void rescaleOneRange(QString axis_name, QCPRange new_range)
void drawXicPeakBorders(pappso::TracePeakCstSPtr xic_peak)
void xicClickEvent(pappso::pappso_double rt, pappso::pappso_double intensity) const
QCPXic * _qcp_xic
Definition xicwidget.h:104
void setRetentionTimeInSeconds()
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const Xic > XicCstSPtr
Definition xic.h:38
double pappso_double
A type definition for doubles.
Definition types.h:60
std::shared_ptr< const TracePeak > TracePeakCstSPtr
Definition tracepeak.h:35