From 2fa0e54c75c6c26ab180829010586289b374e73e Mon Sep 17 00:00:00 2001 From: Olivier Langella <olivier.langella@u-psud.fr> Date: Fri, 23 Mar 2018 17:05:40 +0100 Subject: [PATCH] new item delegate to display percent and mass correctly --- src/CMakeLists.txt | 1 + .../peptide_list_view/peptidelistwindow.cpp | 7 +- src/gui/peptide_list_view/peptidelistwindow.h | 10 +-- .../peptide_list_view/peptidetablemodel.cpp | 4 +- .../protein_list_view/proteinlistwindow.cpp | 4 ++ src/gui/widgets/massitemdelegate.cpp | 31 +++++++++ src/gui/widgets/massitemdelegate.h | 66 +++++++++++++++++++ src/output/mcqrspectralcount.cpp | 2 +- 8 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 src/gui/widgets/massitemdelegate.cpp create mode 100644 src/gui/widgets/massitemdelegate.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc235eb4..6e9c67b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -226,6 +226,7 @@ SET(XTPCPP_MOC_HDRS ./gui/waiting_message_dialog/waitingmessagedialog.h ./gui/widgets/automatic_filter_widget/automaticfilterwidget.h ./gui/widgets/contaminant_widget/contaminantwidget.h + ./gui/widgets/massitemdelegate.h ./gui/xic_view/xic_box/xicbox.h ./gui/xic_view/xicwindow.h ./gui/xic_view/xicworkerthread.h diff --git a/src/gui/peptide_list_view/peptidelistwindow.cpp b/src/gui/peptide_list_view/peptidelistwindow.cpp index f313fe52..fd89c31c 100644 --- a/src/gui/peptide_list_view/peptidelistwindow.cpp +++ b/src/gui/peptide_list_view/peptidelistwindow.cpp @@ -22,12 +22,12 @@ ******************************************************************************/ #include <QSettings> +#include "../widgets/massitemdelegate.h" #include "peptidelistwindow.h" #include "../project_view/projectwindow.h" #include "ui_peptide_view.h" - PeptideListQactionColumn::PeptideListQactionColumn(PeptideListWindow * parent, PeptideListColumn column):QAction(parent) { this->setText(PeptideTableModel::getTitle(column)); @@ -82,6 +82,11 @@ PeptideListWindow::PeptideListWindow(ProjectWindow *parent): ui->tableView->setSortingEnabled(true); ui->tableView->setAlternatingRowColors(true); + MassItemDelegate * item_delegate = new MassItemDelegate(ui->tableView); + ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::experimental_mhplus, item_delegate); + ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::theoretical_mhplus, item_delegate); + ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::experimental_mz, item_delegate); + //connect(ui->tableView, SIGNAL(clicked(const QModelIndex &)), _p_proxy_model, SLOT(onTableClicked(const QModelIndex &))); diff --git a/src/gui/peptide_list_view/peptidelistwindow.h b/src/gui/peptide_list_view/peptidelistwindow.h index 7188d3eb..0ed4a713 100644 --- a/src/gui/peptide_list_view/peptidelistwindow.h +++ b/src/gui/peptide_list_view/peptidelistwindow.h @@ -45,7 +45,7 @@ public: explicit PeptideListQactionColumn(PeptideListWindow * parent, PeptideListColumn column); ~PeptideListQactionColumn(); - + public slots: void doToggled(bool toggled); @@ -76,16 +76,16 @@ public slots: // void setColor(const QColor &color); // void setShape(Shape shape); void doIdentificationGroupGrouped(IdentificationGroup * p_identification_group); - + protected slots: void showContextMenu(const QPoint & pos); - + signals: void identificationGroupEdited(IdentificationGroup * p_identification_group); void peptideDataChanged(); //void peptideChanged(pappso::PeptideSp peptide); - + protected : void askPeptideDetailView(PeptideEvidence * p_peptide_evidence); @@ -99,7 +99,7 @@ protected slots: void doScanNumberSearch(int scan_num); void doSearchOn(QString search_on); void updateStatusBar(); - + private: Ui::PeptideView *ui; PeptideTableModel * _peptide_table_model_p = nullptr; diff --git a/src/gui/peptide_list_view/peptidetablemodel.cpp b/src/gui/peptide_list_view/peptidetablemodel.cpp index 3fb37add..fb93131e 100644 --- a/src/gui/peptide_list_view/peptidetablemodel.cpp +++ b/src/gui/peptide_list_view/peptidetablemodel.cpp @@ -149,7 +149,7 @@ QVariant PeptideTableModel::data(const QModelIndex &index, int role ) const { return QVariant ((quint32) _p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getCharge()); break; case (std::int8_t)PeptideListColumn::experimental_mz: - return QVariant ((qreal) _p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getExperimentalMz()); + return QVariant (_p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getExperimentalMz()); break; case (std::int8_t)PeptideListColumn::sequence: return _p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getPeptideXtpSp().get()->getSequence(); @@ -186,7 +186,7 @@ QVariant PeptideTableModel::data(const QModelIndex &index, int role ) const { return QVariant((qreal) _p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getEvalue()); break; case (std::int8_t)PeptideListColumn::experimental_mhplus: - return QVariant((qreal) (_p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getExperimentalMass()+pappso::MHPLUS)); + return QVariant((_p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getExperimentalMass()+pappso::MHPLUS)); break; case (std::int8_t)PeptideListColumn::theoretical_mhplus: return QVariant(_p_protein_match->getPeptideMatchList().at(row).getPeptideEvidence()->getPeptideXtpSp().get()->getMz(1)); diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp index 2255a7b6..1a1db5a3 100644 --- a/src/gui/protein_list_view/proteinlistwindow.cpp +++ b/src/gui/protein_list_view/proteinlistwindow.cpp @@ -25,6 +25,7 @@ #include "ui_protein_view.h" #include "../mainwindow.h" +#include "../widgets/massitemdelegate.h" #include <QSettings> ProteinListQactionColumn::ProteinListQactionColumn(ProteinListWindow * parent, ProteinListColumn column):QAction(parent) { @@ -80,6 +81,9 @@ ProteinListWindow::ProteinListWindow(ProjectWindow *parent): ui->tableView->setModel( _p_proxy_model ); ui->tableView->setSortingEnabled(true); ui->tableView->setAlternatingRowColors(true); + + PercentItemDelegate * item_delegate = new PercentItemDelegate(ui->tableView); + ui->tableView->setItemDelegateForColumn((std::int8_t) ProteinListColumn::coverage, item_delegate); QSettings settings; bool hide = settings.value("proteinview/hidenotvalid", "true").toBool(); diff --git a/src/gui/widgets/massitemdelegate.cpp b/src/gui/widgets/massitemdelegate.cpp new file mode 100644 index 00000000..fd11881e --- /dev/null +++ b/src/gui/widgets/massitemdelegate.cpp @@ -0,0 +1,31 @@ +/** + * \file /gui/widgets/massitemdelegate.cpp + * \date 23/3/2018 + * \author Olivier Langella + * \brief writes mass in table columns with convenient precision + */ + +/******************************************************************************* +* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>. +* +* This file is part of XTPcpp. +* +* XTPcpp 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. +* +* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation +******************************************************************************/ + + +#include "massitemdelegate.h" diff --git a/src/gui/widgets/massitemdelegate.h b/src/gui/widgets/massitemdelegate.h new file mode 100644 index 00000000..4d941f86 --- /dev/null +++ b/src/gui/widgets/massitemdelegate.h @@ -0,0 +1,66 @@ +/** + * \file /gui/widgets/massitemdelegate.h + * \date 23/3/2018 + * \author Olivier Langella + * \brief writes mass in table columns with convenient precision + */ + +/******************************************************************************* +* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>. +* +* This file is part of XTPcpp. +* +* XTPcpp 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. +* +* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation +******************************************************************************/ +#ifndef MASSITEMDELEGATE_H +#define MASSITEMDELEGATE_H + +#include <QStyledItemDelegate> + +class PercentItemDelegate : public QStyledItemDelegate +{ + + Q_OBJECT + +public: + + PercentItemDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} + + QString displayText(const QVariant & value, const QLocale & locale) const override + { + QString str = QString("%1 %").arg(QString::number(value.toDouble()*100.0, 'f', 2)); + return str; + } +}; + +class MassItemDelegate : public QStyledItemDelegate +{ + + Q_OBJECT + +public: + + MassItemDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} + + QString displayText(const QVariant & value, const QLocale & locale) const override + { + QString str = QString::number(value.toDouble(), 'f', 5); + return str; + } +}; + +#endif // MASSITEMDELEGATE_H diff --git a/src/output/mcqrspectralcount.cpp b/src/output/mcqrspectralcount.cpp index 3e5b1377..960d4cb3 100644 --- a/src/output/mcqrspectralcount.cpp +++ b/src/output/mcqrspectralcount.cpp @@ -1,5 +1,5 @@ /** - * \file /output/mcqrspectralcount.h + * \file /output/mcqrspectralcount.cpp * \date 23/3/2018 * \author Olivier Langella * \brief write simple TSV file for MassChroqR spectral count studies -- GitLab