libpappsomspp
Library for mass spectrometry
obolistmodel.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/widget/obo/obolistwidget/obolistmodel.h
3  * \date 19/04/2021
4  * \author Olivier Langella
5  * \brief MVC model of OBO term list
6  */
7 
8 
9 /*******************************************************************************
10  * Copyright (c) 2021 Olivier Langella
11  *<Olivier.Langella@universite-paris-saclay.fr>.
12  *
13  * This file is part of the PAPPSOms++ library.
14  *
15  * PAPPSOms++ is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * PAPPSOms++ is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
27  *
28  ******************************************************************************/
29 
30 #include "obolistmodel.h"
31 #include "../../../obo/obopsimod.h"
32 #include "obolistwidget.h"
33 #include "../../../exception/exceptionnotfound.h"
34 
35 #include <QColor>
36 #include <QDebug>
37 
38 using namespace pappso;
39 
40 OboListModel::OboListModel(QObject *parent) : QStringListModel(parent)
41 {
42 }
43 
45 {
46 }
47 
49  pappso::OboListModel *parent)
50 {
51  mp_parent = parent;
52 }
53 
55 {
56 }
57 
58 void
60  const pappso::OboPsiModTerm &term)
61 {
62  mp_parent->m_oboPsiModTermList.push_back(term);
63 }
64 
65 
66 void
68 {
69  OboPsiModHandler handler(this);
70  OboPsiMod reader(handler);
71 
72  qDebug() << m_oboPsiModTermList.size();
73 }
74 
75 QVariant
76 pappso::OboListModel::data(const QModelIndex &index, int role) const
77 {
78 
79  // generate a log message when this method gets called
80  std::size_t row = index.row();
81  // int col = index.column();
82  // qDebug() << QString("row %1, col%2, role %3")
83  // .arg(row).arg(col).arg(role);
84  if(row < m_oboPsiModTermList.size())
85  {
86 
87  switch(role)
88  {
89  case Qt::CheckStateRole:
90 
91  break;
92  case Qt::BackgroundRole:
93  // return QVariant(QColor("grey"));
94  break;
95  case Qt::SizeHintRole:
96  // qDebug() << "ProteinTableModel::headerData " <<
97  // ProteinTableModel::getColumnWidth(section);
98  // return QSize(PeptideTableModel::getColumnWidth(col), 30);
99  break;
100  case Qt::ToolTipRole:
101  break;
102  case Qt::DisplayRole:
103  return QVariant(QString("%1 %2 %3")
104  .arg(m_oboPsiModTermList[row].m_accession)
105  .arg(m_oboPsiModTermList[row].m_diffMono)
106  .arg(m_oboPsiModTermList[row].m_name));
107  break;
108  case Qt::UserRole:
109  QVariant value;
110  value.setValue(m_oboPsiModTermList[row]);
111  return value;
112  break;
113  }
114  }
115  return QVariant();
116 }
117 
118 int
119 pappso::OboListModel::rowCount(const QModelIndex &parent [[maybe_unused]]) const
120 {
121  return (int)m_oboPsiModTermList.size();
122 }
123 
124 const pappso::OboPsiModTerm &
126 {
127  if(row < (int) m_oboPsiModTermList.size())
128  {
129  return m_oboPsiModTermList[row];
130  }
131  else
132  {
133  throw pappso::ExceptionNotFound(tr("OBO term not found"));
134  }
135 }
OboPsiModHandler(OboListModel *parent)
void setOboPsiModTerm(const OboPsiModTerm &term) override
triggered function on each obo term when parsing obo file
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
const OboPsiModTerm & getOboPsiModTerm(int row) const
OboListModel(QObject *parent=nullptr)
std::vector< OboPsiModTerm > m_oboPsiModTermList
Definition: obolistmodel.h:83
int rowCount(const QModelIndex &parent=QModelIndex()) const override
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
MVC model of OBO term list.
handles a list of obo term, select and click