Loading...
Searching...
No Matches
xicwidget.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/widget/xicwidget/xicwidget.h
* \date 12/1/2018
* \author Olivier Langella
* \brief plot a XIC
*/
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
*implementation
******************************************************************************/
#include "xicwidget.h"
#include <QDebug>
#include <QHBoxLayout>
#include "qcpxic.h"
#include "../../exception/exceptionnotfound.h"
using namespace pappso;
XicWidget::XicWidget(QWidget *parent) : GraphicDeviceWidget(parent)
{
qDebug() << "XicWidget::XicWidget begin";
this->setLayout(new QHBoxLayout(this));
setMinimumSize(200, 160);
this->layout()->setContentsMargins(0, 0, 0, 0);
_qcp_xic = new QCPXic(this);
this->layout()->addWidget(_qcp_xic);
qDebug() << "XicWidget::XicWidget end";
}
XicWidget::~XicWidget()
{
}
void
XicWidget::addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
{
XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
_qcp_xic->addMsMsEvent(xic_p, rt);
_map_xic_msms_event[xic_p] = rt;
}
QCPGraph *
XicWidget::addXicSp(XicCstSPtr xic_sp)
{
_xic_sp_list.push_back(xic_sp);
return _qcp_xic->addXicP(xic_sp.get());
}
const QString &
XicWidget::getName(const Xic *xic_p) const
{
XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
return _map_xic_name.at(xic_p);
}
void
XicWidget::setName(const Xic *xic_p, const QString &name)
{
XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
_qcp_xic->legend->setVisible(true);
_qcp_xic->setName(xic_p, name);
_map_xic_name[xic_p] = name;
}
void
XicWidget::plot()
{
_qcp_xic->replot();
}
void
XicWidget::rescale()
{
_qcp_xic->xAxis->rescale(true);
_qcp_xic->yAxis->rescale(true);
_qcp_xic->rescale();
}
QCPAxis *
XicWidget::getRtAxisP()
{
return _qcp_xic->xAxis;
}
QCPAxis *
XicWidget::getIntensityAxisP()
{
return _qcp_xic->yAxis;
}
void
XicWidget::rescaleOneRange(QString axis_name, QCPRange new_range)
{
if(axis_name == "xAxis")
{
_qcp_xic->xAxis->setRange(new_range);
}
else // axis_name == "yAxis"
{
_qcp_xic->yAxis->setRange(new_range);
}
_qcp_xic->replot();
}
void
XicWidget::clear()
{
_map_xic_name.clear();
_xic_sp_list.clear();
_xic_peak_sp_list.clear();
_qcp_xic->clear();
_map_xic_msms_event.clear();
}
XicCstSPtr
XicWidget::getXicCstSPtr(const Xic *xic_p) const
{
std::vector<XicCstSPtr>::const_iterator it =
std::find_if(_xic_sp_list.begin(),
_xic_sp_list.end(),
[xic_p](XicCstSPtr xic_sp) { return xic_sp.get() == xic_p; });
if(it == _xic_sp_list.end())
{
throw pappso::ExceptionNotFound(tr("ERROR : xic pointer not found"));
}
return *it;
}
void
XicWidget::addXicPeakList(
const Xic *xic_p, const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
{
XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
_qcp_xic->addXicPeakList(xic_p, xic_peak_list);
for(const pappso::TracePeakCstSPtr &xic_peak : xic_peak_list)
{
_xic_peak_sp_list.push_back(
std::pair<XicCstSPtr, TracePeakCstSPtr>(xic_sp, xic_peak));
}
}
void
XicWidget::rtChangeEvent(pappso::pappso_double rt) const
{
emit rtChanged(rt);
std::vector<std::pair<XicCstSPtr, TracePeakCstSPtr>> over_xic_peak_list;
for(std::pair<XicCstSPtr, TracePeakCstSPtr> pair_xic_peak : _xic_peak_sp_list)
{
if(pair_xic_peak.second.get()->containsRt(rt))
{
over_xic_peak_list.push_back(pair_xic_peak);
}
}
// if (over_xic_peak_list.size() > 0) {
emit xicPeakListChanged(over_xic_peak_list);
//}
}
void
XicWidget::toQPaintDevice(QPaintDevice *device, const QSize &size)
{
if(_qcp_xic != nullptr)
{
QCPPainter painter;
painter.begin(device);
_qcp_xic->toPainter(&painter, size.width(), size.height());
painter.end();
}
}
void
XicWidget::setRetentionTimeInSeconds()
{
_rt_in_seconds = true;
_qcp_xic->xAxis->setLabel("retention time (sec)");
replotAll();
}
void
XicWidget::setRetentionTimeInMinutes()
{
_rt_in_seconds = false;
_qcp_xic->xAxis->setLabel("retention time (min)");
replotAll();
}
void
XicWidget::replotAll()
{
_qcp_xic->clear();
for(XicCstSPtr xic_sp : _xic_sp_list)
{
_qcp_xic->addXicP(xic_sp.get());
std::vector<TracePeakCstSPtr> xic_peak_list;
for(auto xic_map_peak_list : _xic_peak_sp_list)
{
if(xic_map_peak_list.first.get() == xic_sp.get())
xic_peak_list.push_back(xic_map_peak_list.second);
}
_qcp_xic->addXicPeakList(xic_sp.get(), xic_peak_list);
}
for(auto xic_name : _map_xic_name)
{
setName(xic_name.first, xic_name.second);
}
for(auto xic_msms : _map_xic_msms_event)
{
_qcp_xic->addMsMsEvent(xic_msms.first, xic_msms.second);
}
rescale();
_qcp_xic->replot();
}
void
XicWidget::xicClickEvent(pappso::pappso_double rt,
pappso::pappso_double intensity) const
{
emit clicked(rt, intensity);
}
void
XicWidget::drawXicPeakBorders(pappso::TracePeakCstSPtr xic_peak)
{
XicCstSPtr xic_sp;
for(std::pair<XicCstSPtr, TracePeakCstSPtr> pair_xic_peak : _xic_peak_sp_list)
{
if(pair_xic_peak.second.get() == xic_peak.get())
{
xic_sp = pair_xic_peak.first;
break;
}
}
if(xic_sp.get() != nullptr)
{
unsigned int i = 0;
for(XicCstSPtr xic_in_list : _xic_sp_list)
{
if(xic_in_list.get() == xic_sp.get())
{
break;
}
i++;
}
_qcp_xic->drawXicPeakBorders(i, xic_sp.get(), xic_peak.get());
}
}
void
XicWidget::clearXicPeakBorders()
{
_qcp_xic->clearXicPeakBorders();
}
GraphicDeviceWidget
Definition graphicdevicewidget.h:37
pappso::ExceptionNotFound
Definition exceptionnotfound.h:32
pappso::QCPXic::addMsMsEvent
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition qcpxic.cpp:275
pappso::QCPXic::clearXicPeakBorders
void clearXicPeakBorders()
Definition qcpxic.cpp:431
pappso::QCPXic::clear
void clear()
Definition qcpxic.cpp:301
pappso::QCPXic::setName
void setName(const Xic *xic_p, const QString &name)
Definition qcpxic.cpp:293
pappso::QCPXic::drawXicPeakBorders
void drawXicPeakBorders(unsigned int i, const Xic *xic_p, const pappso::TracePeak *p_xic_peak)
Definition qcpxic.cpp:369
pappso::QCPXic::addXicPeakList
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition qcpxic.cpp:312
pappso::QCPXic::rescale
void rescale()
Definition qcpxic.cpp:252
pappso::QCPXic::addXicP
QCPGraph * addXicP(const Xic *xic_p)
Definition qcpxic.cpp:219
pappso::XicWidget::QCPXic
friend class QCPXic
Definition xicwidget.h:89
pappso::XicWidget::rescale
void rescale()
Definition xicwidget.cpp:95
pappso::XicWidget::toQPaintDevice
void toQPaintDevice(QPaintDevice *device, const QSize &size) override
Definition xicwidget.cpp:184
pappso::XicWidget::addXicPeakList
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition xicwidget.cpp:153
pappso::XicWidget::rtChanged
void rtChanged(double rt) const
announce the current retention time (under mouse) in seconds
pappso::XicWidget::getIntensityAxisP
QCPAxis * getIntensityAxisP()
Definition xicwidget.cpp:109
pappso::XicWidget::_xic_sp_list
std::vector< XicCstSPtr > _xic_sp_list
Definition xicwidget.h:102
pappso::XicWidget::clearXicPeakBorders
void clearXicPeakBorders()
Definition xicwidget.cpp:281
pappso::XicWidget::~XicWidget
~XicWidget()
Definition xicwidget.cpp:55
pappso::XicWidget::getXicCstSPtr
XicCstSPtr getXicCstSPtr(const Xic *xic_p) const
Definition xicwidget.cpp:139
pappso::XicWidget::plot
void plot()
Definition xicwidget.cpp:90
pappso::XicWidget::_xic_peak_sp_list
XicXicPeakPairList _xic_peak_sp_list
Definition xicwidget.h:103
pappso::XicWidget::_map_xic_name
std::map< const Xic *, QString > _map_xic_name
Definition xicwidget.h:100
pappso::XicWidget::replotAll
void replotAll()
Definition xicwidget.cpp:213
pappso::XicWidget::XicWidget
XicWidget(QWidget *parent=0)
Definition xicwidget.cpp:41
pappso::XicWidget::setRetentionTimeInMinutes
void setRetentionTimeInMinutes()
Definition xicwidget.cpp:205
pappso::XicWidget::getName
const QString & getName(const Xic *xic_p) const
Definition xicwidget.cpp:74
pappso::XicWidget::rtChangeEvent
void rtChangeEvent(pappso::pappso_double rt) const
Definition xicwidget.cpp:165
pappso::XicWidget::addXicSp
QCPGraph * addXicSp(XicCstSPtr xic_sp)
Definition xicwidget.cpp:67
pappso::XicWidget::_rt_in_seconds
bool _rt_in_seconds
Definition xicwidget.h:97
pappso::XicWidget::_map_xic_msms_event
std::map< const Xic *, pappso::pappso_double > _map_xic_msms_event
Definition xicwidget.h:101
pappso::XicWidget::getRtAxisP
QCPAxis * getRtAxisP()
get the plots axis and rescale one axis with the given range
Definition xicwidget.cpp:103
pappso::XicWidget::xicPeakListChanged
void xicPeakListChanged(pappso::XicXicPeakPairList xic_peak_list) const
pappso::XicWidget::addMsMsEvent
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition xicwidget.cpp:60
pappso::XicWidget::setName
void setName(const Xic *xic_p, const QString &name)
Definition xicwidget.cpp:81
pappso::XicWidget::clicked
void clicked(double rt, double intensity) const
announce mouse position on click (rt in seconds, intensity)
pappso::XicWidget::rescaleOneRange
void rescaleOneRange(QString axis_name, QCPRange new_range)
Definition xicwidget.cpp:115
pappso::XicWidget::drawXicPeakBorders
void drawXicPeakBorders(pappso::TracePeakCstSPtr xic_peak)
Definition xicwidget.cpp:251
pappso::XicWidget::xicClickEvent
void xicClickEvent(pappso::pappso_double rt, pappso::pappso_double intensity) const
Definition xicwidget.cpp:243
pappso::XicWidget::clear
void clear()
Definition xicwidget.cpp:129
pappso::XicWidget::_qcp_xic
QCPXic * _qcp_xic
Definition xicwidget.h:104
pappso::XicWidget::setRetentionTimeInSeconds
void setRetentionTimeInSeconds()
Definition xicwidget.cpp:198
pappso::Xic
Definition xic.h:44
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::XicCstSPtr
std::shared_ptr< const Xic > XicCstSPtr
Definition xic.h:38
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition types.h:50
pappso::DataKind::rt
@ rt
Retention time.
pappso::TracePeakCstSPtr
std::shared_ptr< const TracePeak > TracePeakCstSPtr
Definition tracepeak.h:35
qcpxic.h
custom plot XIC
xicwidget.h
plot a XIC