From 587a6f17b25bc8bfc507a973970f0c41462ecf0b Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Fri, 31 Mar 2017 23:05:35 +0200
Subject: [PATCH] search protein string ok

---
 .../protein_list_view/proteinlistwindow.cpp   | 11 ++-
 src/gui/protein_list_view/proteinlistwindow.h |  2 +
 .../protein_list_view/proteintablemodel.cpp   | 68 ++++++++-----------
 src/gui/protein_list_view/proteintablemodel.h |  3 +-
 src/gui/protein_view/protein_detail_view.ui   |  9 ++-
 5 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp
index 17b642ed..1b313d2c 100644
--- a/src/gui/protein_list_view/proteinlistwindow.cpp
+++ b/src/gui/protein_list_view/proteinlistwindow.cpp
@@ -75,7 +75,7 @@ ProteinListWindow::ProteinListWindow(ProjectWindow *parent):
     connect (this, SIGNAL(proteinDataChanged()), _protein_table_model_p, SLOT(onProteinDataChanged())); 
     connect(ui->tableView, SIGNAL(clicked(const QModelIndex &)), _p_proxy_model, SLOT(onTableClicked(const QModelIndex &)));
     //connect(ui->tableView, SIGNAL(doubleClicked(const QModelIndex &)), _p_proxy_model, SLOT(onTableDoubleClicked(const QModelIndex &)));
-    connect(ui->proteinSearchEdit, SIGNAL(textChanged(QString)), _p_proxy_model, SLOT(onProteinSearchEdit(QString)));
+    connect(ui->proteinSearchEdit, SIGNAL(textChanged(QString)), this, SLOT(onProteinSearchEdit(QString)));
 
 
     //connect( this, SIGNAL( focusReceived(bool) ),this, SLOT(doFocusReceived(bool)) );
@@ -184,6 +184,15 @@ void ProteinListWindow::doNotGroupedHide(bool hide) {
     emit proteinDataChanged();
     qDebug() << "ProteinListWindow::doNotGroupedHide end";
 }
+
+
+void ProteinListWindow::onProteinSearchEdit(QString protein_search_string) {
+    qDebug() << "ProteinTableProxyModel::onProteinSearchEdit begin " << protein_search_string;
+    _p_proxy_model->setProteinSearchString( protein_search_string);
+    emit proteinDataChanged();
+}
+
+
 void ProteinListWindow::doIdentificationGroupGrouped(IdentificationGroup * p_identification_group) {
     qDebug() << "ProteinListWindow::doIdentificationGroupGrouped begin";
     if (_p_identification_group == p_identification_group) {
diff --git a/src/gui/protein_list_view/proteinlistwindow.h b/src/gui/protein_list_view/proteinlistwindow.h
index 3c070ee0..f8984131 100644
--- a/src/gui/protein_list_view/proteinlistwindow.h
+++ b/src/gui/protein_list_view/proteinlistwindow.h
@@ -68,6 +68,8 @@ protected slots:
     void showEvalueColumn(bool show);
     void showAccessionColumn(bool show);
     void updateStatusBar();
+    void onProteinSearchEdit(QString protein_search_string);
+    
 protected :
     void askProteinDetailView(ProteinMatch * p_protein_match);
     void askPeptideListView(ProteinMatch * p_protein_match);
diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp
index b71d4cc8..1512beb5 100644
--- a/src/gui/protein_list_view/proteintablemodel.cpp
+++ b/src/gui/protein_list_view/proteintablemodel.cpp
@@ -42,13 +42,13 @@ bool ProteinTableProxyModel::filterAcceptsRow(int source_row,
         qDebug() << "ProteinTableProxyModel::filterAcceptsRow begin " << source_row;
         ProteinMatch * protein_match = _protein_table_model_p->getIdentificationGroup()->getProteinMatchList().at(source_row);
         qDebug() << "ProteinTableProxyModel::filterAcceptsRow protein_match " << source_row;
-        /*
-                if (!_protein_search_string.isEmpty()) {
-                    if (!protein_match->getProteinXtpSp().get()->getDescription().contains(_protein_search_string)) {
-                        return false;
-                    }
-                }
-        */
+
+        if (!_protein_search_string.isEmpty()) {
+            if (!protein_match->getProteinXtpSp().get()->getDescription().contains(_protein_search_string)) {
+                return false;
+            }
+        }
+
         qDebug() << "ProteinTableProxyModel::filterAcceptsRow valid ";
         if (_hide_not_valid) {
             if (! protein_match->isValid()) {
@@ -176,13 +176,11 @@ void ProteinTableProxyModel::hideNotChecked(bool hide) {
 void ProteinTableProxyModel::hideNotGrouped(bool hide) {
     _hide_not_grouped = hide;
 }
-void ProteinTableProxyModel::onProteinSearchEdit(QString protein_search_string) {
-    qDebug() << "ProteinTableProxyModel::onProteinSearchEdit begin " << protein_search_string;
+
+void ProteinTableProxyModel::setProteinSearchString(QString protein_search_string) {
     _protein_search_string = protein_search_string;
-    //emit layoutChanged();
 }
 
-
 IdentificationGroup * ProteinTableModel::getIdentificationGroup() {
     return _p_identification_group;
 }
@@ -191,6 +189,8 @@ ProteinTableModel::ProteinTableModel(ProteinListWindow * p_protein_list_window)
 {
     _p_protein_list_window = p_protein_list_window;
     _p_identification_group = nullptr;
+
+    _columns << "checked" << "group" << "accession" << "protein description" << "Evalue" << "spectrum" << "specific" << "sequence" << "specific sequence" << "coverage" << "PAI";
 }
 
 void ProteinTableModel::setIdentificationGroup(IdentificationGroup * p_identification_group) {
@@ -216,40 +216,30 @@ int ProteinTableModel::rowCount(const QModelIndex &parent ) const {
 int ProteinTableModel::columnCount(const QModelIndex &parent ) const {
     qDebug() << "ProteinTableModel::columnCount begin ";
     if (_p_identification_group != nullptr) {
-        return 11;
+        return _columns.size();
     }
     return 0;
 }
 QVariant ProteinTableModel::headerData(int section, Qt::Orientation orientation, int role) const
 {
     if (_p_identification_group == nullptr) return QVariant();
-    if (role == Qt::DisplayRole)
+    if (orientation == Qt::Horizontal)
     {
-        if (orientation == Qt::Horizontal) {
-            switch (section)
+        if (section < _columns.size())
+        {
+            if (role == Qt::DisplayRole)
             {
-            case 0:
-                return QString("checked");
-            case 1:
-                return QString("group");
-            case 2:
-                return QString("accession");
-            case 3:
-                return QString("protein description");
-            case 4:
-                return QString("Evalue");
-            case 5:
-                return QString("spectrum");
-            case 6:
-                return QString("specific");
-            case 7:
-                return QString("sequence");
-            case 8:
-                return QString("specific sequence");
-            case 9:
-                return QString("coverage");
-            case 10:
-                return QString("PAI");
+                return QVariant(_columns.at(section));
+            }
+            else if(role == Qt::SizeHintRole)
+            {
+                QSize size(1000, 50);
+                if (section == 2)
+                {
+                    size.setWidth(400);
+                }
+
+                return QVariant(size);
             }
         }
     }
@@ -349,6 +339,6 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const {
 
 void ProteinTableModel::onProteinDataChanged() {
     qDebug() << "ProteinTableModel::onProteinDataChanged begin " << rowCount();
-     emit layoutAboutToBeChanged();
-     emit layoutChanged();
+    emit layoutAboutToBeChanged();
+    emit layoutChanged();
 }
diff --git a/src/gui/protein_list_view/proteintablemodel.h b/src/gui/protein_list_view/proteintablemodel.h
index 829a3dfe..cdff8192 100644
--- a/src/gui/protein_list_view/proteintablemodel.h
+++ b/src/gui/protein_list_view/proteintablemodel.h
@@ -46,10 +46,10 @@ public:
     void hideNotValid(bool hide);
     void hideNotChecked(bool hide);
     void hideNotGrouped(bool hide);
+    void setProteinSearchString(QString protein_search_string);
 
 public slots:
     void onTableClicked(const QModelIndex &index);
-    void onProteinSearchEdit(QString protein_search_string);
 
 private:
     ProteinTableModel* _protein_table_model_p;
@@ -80,6 +80,7 @@ private :
 private :
     IdentificationGroup * _p_identification_group = nullptr;
     ProteinListWindow * _p_protein_list_window;
+    QStringList _columns;
 };
 
 #endif // PROTEINTABLEMODEL_H
diff --git a/src/gui/protein_view/protein_detail_view.ui b/src/gui/protein_view/protein_detail_view.ui
index cd5a93d4..eb49e155 100644
--- a/src/gui/protein_view/protein_detail_view.ui
+++ b/src/gui/protein_view/protein_detail_view.ui
@@ -37,6 +37,9 @@
         <property name="wordWrap">
          <bool>true</bool>
         </property>
+        <property name="textInteractionFlags">
+         <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+        </property>
        </widget>
       </item>
       <item>
@@ -44,9 +47,11 @@
         <property name="lineWrapMode">
          <enum>QTextEdit::WidgetWidth</enum>
         </property>
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
        </widget>
       </item>
-
       <item>
        <layout class="QFormLayout" name="formLayout">
         <item row="0" column="0">
@@ -92,7 +97,7 @@
          </widget>
         </item>
        </layout>
-      </item>     
+      </item>
      </layout>
     </item>
    </layout>
-- 
GitLab