From 4110fbad3d566002615fe2ca999d85fe73927236 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Mon, 26 Mar 2018 09:13:47 +0200
Subject: [PATCH] delegates ok for protein list

---
 .../peptidetableproxymodel.cpp                | 21 ++++++++++++-------
 .../peptidetableproxymodel.h                  |  1 +
 .../protein_list_view/proteinlistwindow.cpp   |  8 ++-----
 .../proteintableproxymodel.cpp                | 21 +++++++++++++++++++
 .../proteintableproxymodel.h                  |  6 ++++++
 5 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/src/gui/peptide_list_view/peptidetableproxymodel.cpp b/src/gui/peptide_list_view/peptidetableproxymodel.cpp
index 7d03215a..b43cbb2f 100644
--- a/src/gui/peptide_list_view/peptidetableproxymodel.cpp
+++ b/src/gui/peptide_list_view/peptidetableproxymodel.cpp
@@ -44,6 +44,13 @@ PeptideTableProxyModel::PeptideTableProxyModel(PeptideListWindow * p_peptide_lis
     _second_delegate = new SecondItemDelegate(_p_peptide_list_window);
 }
 
+PeptideTableProxyModel::~PeptideTableProxyModel()
+{
+   // delete _mass_delegate ;
+   // delete _minute_delegate ;
+   // delete _second_delegate ;
+}
+
 bool PeptideTableProxyModel::filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const {
     if (_peptide_table_model_p->getPeptideListColumn(source_column) == PeptideListColumn::label) {
         if (_p_peptide_list_window->getProjectWindow()->getProjectP()->getLabelingMethodSp().get() == nullptr) {
@@ -257,7 +264,7 @@ void PeptideTableProxyModel::setPeptideListColumnDisplay(PeptideListColumn colum
 
 
 void PeptideTableProxyModel::resteItemDelegates() const {
-    
+
     for (int i = 0; i < columnCount(); ++i) {
         _p_peptide_list_window->ui->tableView->setItemDelegateForColumn(i, _p_peptide_list_window->ui->tableView->itemDelegate());
         if (mapToSource(index(0, i)).column() == (std::int8_t) PeptideListColumn::experimental_mhplus) {
@@ -276,10 +283,10 @@ void PeptideTableProxyModel::resteItemDelegates() const {
             _p_peptide_list_window->ui->tableView->setItemDelegateForColumn(i, _second_delegate);
         }
     }
-   /*
-    MinuteItemDelegate * minute_delegate = new MinuteItemDelegate(ui->tableView);
-    ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::rtmin, minute_delegate);
-    SecondItemDelegate * second_delegate = new SecondItemDelegate(ui->tableView);
-    ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::rt, second_delegate);
-*/
+    /*
+     MinuteItemDelegate * minute_delegate = new MinuteItemDelegate(ui->tableView);
+     ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::rtmin, minute_delegate);
+     SecondItemDelegate * second_delegate = new SecondItemDelegate(ui->tableView);
+     ui->tableView->setItemDelegateForColumn((std::int8_t) PeptideListColumn::rt, second_delegate);
+    */
 }
diff --git a/src/gui/peptide_list_view/peptidetableproxymodel.h b/src/gui/peptide_list_view/peptidetableproxymodel.h
index 866ea9ed..d8bd6865 100644
--- a/src/gui/peptide_list_view/peptidetableproxymodel.h
+++ b/src/gui/peptide_list_view/peptidetableproxymodel.h
@@ -39,6 +39,7 @@ class PeptideTableProxyModel : public QSortFilterProxyModel
     Q_OBJECT
 public:
     PeptideTableProxyModel(PeptideListWindow * p_peptide_list_window, PeptideTableModel* peptide_table_model_p);
+    virtual ~PeptideTableProxyModel();
     bool filterAcceptsRow(int source_row,
                           const QModelIndex &source_parent) const override;
     bool filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const override;
diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp
index ff7b1be9..e71b9ecd 100644
--- a/src/gui/protein_list_view/proteinlistwindow.cpp
+++ b/src/gui/protein_list_view/proteinlistwindow.cpp
@@ -25,7 +25,6 @@
 
 #include "ui_protein_view.h"
 #include "../mainwindow.h"
-#include "../widgets/massitemdelegate.h"
 #include <QSettings>
 
 ProteinListQactionColumn::ProteinListQactionColumn(ProteinListWindow * parent, ProteinListColumn column):QAction(parent) {
@@ -81,10 +80,7 @@ ProteinListWindow::ProteinListWindow(ProjectWindow *parent):
     ui->tableView->setModel( _p_proxy_model );
     ui->tableView->setSortingEnabled(true);
     ui->tableView->setAlternatingRowColors(true);
-    
-    PercentItemDelegate * percent_delegate = new PercentItemDelegate(ui->tableView);
-    ui->tableView->setItemDelegateForColumn((std::int8_t) ProteinListColumn::coverage, percent_delegate);
-
+ 
     QSettings settings;
     bool hide = settings.value("proteinview/hidenotvalid", "true").toBool();
     if (hide) {
@@ -321,7 +317,7 @@ void ProteinListWindow::setIdentificationGroup(IdentificationGroup * p_identific
         completer->setFilterMode(Qt::MatchContains);
         ui->mod_auto_completion->setCompleter(completer);
 
-
+        _p_proxy_model->resteItemDelegates();
     }
     else {
         qDebug() << "ProteinListWindow::setIdentificationGroup  null";
diff --git a/src/gui/protein_list_view/proteintableproxymodel.cpp b/src/gui/protein_list_view/proteintableproxymodel.cpp
index ee4ffc0d..08806350 100644
--- a/src/gui/protein_list_view/proteintableproxymodel.cpp
+++ b/src/gui/protein_list_view/proteintableproxymodel.cpp
@@ -40,8 +40,15 @@ ProteinTableProxyModel::ProteinTableProxyModel(ProteinListWindow * p_protein_lis
 
         _column_display[i] = settings.value(QString("protein_list_columns/%1").arg(_protein_table_model_p->getTitle((ProteinListColumn)i)), "true").toBool();
     }
+       
+    _percent_delegate = new PercentItemDelegate(p_protein_list_window->ui->tableView);
+
 }
 
+ProteinTableProxyModel::~ProteinTableProxyModel()
+{
+    //delete _percent_delegate;
+}
 bool ProteinTableProxyModel::filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const {
     return _column_display[source_column];
 }
@@ -271,7 +278,21 @@ void ProteinTableProxyModel::setProteinListColumnDisplay(ProteinListColumn colum
 
     _column_display[(std::int8_t) column] = toggled;
     endResetModel();
+    
+    resteItemDelegates();
 }
 bool ProteinTableProxyModel::getProteinListColumnDisplay(ProteinListColumn column) const {
     return _column_display[(std::int8_t) column];
 }
+
+
+
+void ProteinTableProxyModel::resteItemDelegates() const {
+
+    for (int i = 0; i < columnCount(); ++i) {
+        _p_protein_list_window->ui->tableView->setItemDelegateForColumn(i, _p_protein_list_window->ui->tableView->itemDelegate());
+        if (mapToSource(index(0, i)).column() == (std::int8_t) ProteinListColumn::coverage) {
+            _p_protein_list_window->ui->tableView->setItemDelegateForColumn(i, _percent_delegate);
+        }
+    }
+}
diff --git a/src/gui/protein_list_view/proteintableproxymodel.h b/src/gui/protein_list_view/proteintableproxymodel.h
index a71cf0a2..13fe073b 100644
--- a/src/gui/protein_list_view/proteintableproxymodel.h
+++ b/src/gui/protein_list_view/proteintableproxymodel.h
@@ -28,6 +28,7 @@
 #include <QSortFilterProxyModel>
 #include "../../core/project.h"
 #include "proteintablemodel.h"
+#include "../widgets/massitemdelegate.h"
 
 class ProteinListWindow;
 
@@ -38,6 +39,8 @@ class ProteinTableProxyModel : public QSortFilterProxyModel
     Q_OBJECT
 public:
     ProteinTableProxyModel(ProteinListWindow * p_protein_list_window, ProteinTableModel* protein_table_model_p);
+    virtual ~ProteinTableProxyModel();
+    
     bool filterAcceptsRow(int source_row,
                           const QModelIndex &source_parent) const override;
     bool filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const override;
@@ -54,9 +57,11 @@ public:
     void setSearchOn(QString search_on);
     void setProteinListColumnDisplay(ProteinListColumn column, bool toggled);
     bool getProteinListColumnDisplay(ProteinListColumn column) const;
+    void resteItemDelegates() const;
 
 public slots:
     void onTableClicked(const QModelIndex &index);
+    
 
 private:
     ProteinTableModel* _protein_table_model_p;
@@ -67,6 +72,7 @@ private:
     bool _hide_not_checked = true;
     bool _hide_not_grouped = true;
     std::vector<bool> _column_display;
+    PercentItemDelegate * _percent_delegate;
 };
 
 #endif // PROTEINTABLEPROXYMODEL_H
-- 
GitLab