From acf0c54c305d3eb3db9cce93def3938072cafd65 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Fri, 9 Jun 2017 20:21:40 +0200
Subject: [PATCH] button layout

---
 src/core/proteinxtp.cpp                     | 21 ++++++++++-------
 src/core/proteinxtp.h                       | 10 ++++++--
 src/gui/protein_view/protein_detail_view.ui | 20 ++++++++++++++++
 src/gui/protein_view/proteinwindow.cpp      | 22 +++++++++++++++--
 src/gui/protein_view/proteinwindow.h        |  1 +
 src/output/proticdbml.cpp                   |  6 ++---
 src/utils/types.h                           | 26 ++++++++++-----------
 7 files changed, 77 insertions(+), 29 deletions(-)

diff --git a/src/core/proteinxtp.cpp b/src/core/proteinxtp.cpp
index 947eb4149..4dfa3f37a 100644
--- a/src/core/proteinxtp.cpp
+++ b/src/core/proteinxtp.cpp
@@ -137,31 +137,34 @@ void ProteinXtp::parseAccession2dbxref() {
         qDebug() << "ProteinXtp::parseAccession2dbxref accession " << accession;
         if (atg.indexIn(accession, 0) != -1) {
             QStringList temp = accession.split("\\.");
-            _dbxref_list.push_back(std::make_pair(ExternalDatabase::AGI_LocusCode, temp.at(0)));
+            _dbxref_list.push_back(DbXref(ExternalDatabase::AGI_LocusCode, temp.at(0)));
         }
         if (ncbi_gi.indexIn(accession, 0) != -1) {
-            _dbxref_list.push_back(std::make_pair(ExternalDatabase::NCBI_gi, accession));
+            _dbxref_list.push_back(DbXref(ExternalDatabase::NCBI_gi, accession));
         }
 
         if (swiss_prot.indexIn(accession, 0) != -1) {
             qDebug() << "ProteinXtp::parseAccession2dbxref accession SwissProt " << accession;
-            _dbxref_list.push_back(std::make_pair(ExternalDatabase::SwissProt, accession));
+            _dbxref_list.push_back(DbXref(ExternalDatabase::SwissProt, accession));
         }
 
         if (trembl.indexIn(accession, 0) != -1) {
             qDebug() << "ProteinXtp::parseAccession2dbxref accession TrEMBL " << accession;
-            _dbxref_list.push_back(std::make_pair(ExternalDatabase::TrEMBL, accession));
+            _dbxref_list.push_back(DbXref(ExternalDatabase::TrEMBL, accession));
         }
         if (ref.indexIn(accession, 0) != -1) {
-            _dbxref_list.push_back(std::make_pair(ExternalDatabase::ref, accession));
+            _dbxref_list.push_back(DbXref(ExternalDatabase::ref, accession));
         }
     }
     
     if (_dbxref_list.size() > 1) {
-        _dbxref_list.sort();
-        _dbxref_list.unique([] (const std::pair<ExternalDatabase, QString> & first, const std::pair<ExternalDatabase, QString> & second)
+        _dbxref_list.sort([] (const DbXref & first, const DbXref & second)
         {
-            return ( first.first == second.first ) && (first.second == second.second);
+            return std::tie(first.database, first.accession) < std::tie(second.database, second.accession);
+        });
+        _dbxref_list.unique([] (const DbXref & first, const DbXref & second)
+        {
+            return ( first.database == second.database ) && (first.accession == second.accession);
         });
     }
 
@@ -169,6 +172,6 @@ void ProteinXtp::parseAccession2dbxref() {
 
 }
 
-const std::list<std::pair<ExternalDatabase, QString>> & ProteinXtp::getDbxrefList() const {
+const std::list<DbXref> & ProteinXtp::getDbxrefList() const {
     return _dbxref_list;
 }
diff --git a/src/core/proteinxtp.h b/src/core/proteinxtp.h
index 947ebb593..2bde8ff7b 100644
--- a/src/core/proteinxtp.h
+++ b/src/core/proteinxtp.h
@@ -30,6 +30,12 @@
 #ifndef PROTEIN_XTP_H
 #define PROTEIN_XTP_H
 
+struct DbXref {
+    DbXref(ExternalDatabase database_in, const QString & accession_in):database(database), accession(accession_in) {
+    };
+    ExternalDatabase database;
+    QString accession;
+};
 
 class ProteinXtp;
 
@@ -68,13 +74,13 @@ public:
      */
     void parseAccession2dbxref();
     
-    const std::list<std::pair<ExternalDatabase, QString>> & getDbxrefList() const;
+    const std::list<DbXref> & getDbxrefList() const;
 
 private:
     SequenceDatabase * _p_sequence_database;
     bool _is_decoy=false;
     bool _is_contaminant=false;
-    std::list<std::pair<ExternalDatabase, QString>> _dbxref_list;
+    std::list<DbXref> _dbxref_list;
 };
 
 #endif // PROTEIN_XTP_H
diff --git a/src/gui/protein_view/protein_detail_view.ui b/src/gui/protein_view/protein_detail_view.ui
index 9281f5c04..e695d9f50 100644
--- a/src/gui/protein_view/protein_detail_view.ui
+++ b/src/gui/protein_view/protein_detail_view.ui
@@ -47,6 +47,26 @@
             </property>
            </widget>
           </item>
+          <item>
+           <layout class="QHBoxLayout" name="button_space_layout">
+            <item>
+             <layout class="QHBoxLayout" name="dbxref_list_layout"/>
+            </item>
+            <item>
+             <spacer name="horizontalSpacer_2">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+           </layout>
+          </item>
           <item>
            <widget class="QLabel" name="description_label">
             <property name="text">
diff --git a/src/gui/protein_view/proteinwindow.cpp b/src/gui/protein_view/proteinwindow.cpp
index cb8698c24..1bf378cca 100644
--- a/src/gui/protein_view/proteinwindow.cpp
+++ b/src/gui/protein_view/proteinwindow.cpp
@@ -27,6 +27,7 @@
 #include <pappsomspp/pappsoexception.h>
 #include <QMessageBox>
 #include <cmath>
+#include <QPushButton>
 
 ProteinWindow::ProteinWindow(ProjectWindow *parent):
     QMainWindow(parent),
@@ -56,6 +57,7 @@ ProteinWindow::ProteinWindow(ProjectWindow *parent):
 
 ProteinWindow::~ProteinWindow()
 {
+    clearDbXrefLayout();
     delete ui;
 }
 void ProteinWindow::doIdentificationGroupGrouped(IdentificationGroup * p_identification_group) {
@@ -68,18 +70,34 @@ void ProteinWindow::doPeptideMatchSelected(PeptideMatch * peptide_match) {
 
     }
 }
+void ProteinWindow::clearDbXrefLayout() {
+    for (int i = 0; i < ui->dbxref_list_layout->count(); ++i)
+{
+   delete ui->dbxref_list_layout->itemAt(i)->widget();
+}
+}
 
 void ProteinWindow::updateDisplay() {
     try {
+        clearDbXrefLayout();
         ui->valid_checkbox->setCheckState(Qt::Unchecked);
         if (_p_protein_match->isValid()) ui->valid_checkbox->setCheckState(Qt::Checked);
         ui->decoy_checkbox->setCheckState(Qt::Unchecked);
         if (_p_protein_match->getProteinXtpSp().get()->isDecoy()) ui->decoy_checkbox->setCheckState(Qt::Checked);
         ui->accession_label->setText(_p_protein_match->getProteinXtpSp().get()->getAccession());
-        for (std::pair<ExternalDatabase, QString> dbxref:_p_protein_match->getProteinXtpSp().get()->getDbxrefList()) {
-            QString accession = ui->accession_label->text().replace(dbxref.second, QString("<a href=\"\" style=\"color:%2;\">%1</a>").arg(dbxref.second).arg("blue"));
+        for (const DbXref & dbxref:_p_protein_match->getProteinXtpSp().get()->getDbxrefList()) {
+            QString accession = ui->accession_label->text().replace(dbxref.accession, QString("<span style=\"color:%2;\">%1</span>").arg(dbxref.accession).arg("blue"));
             ui->accession_label->setText(accession);
             qDebug() << "ProteinWindow::updateDisplay " << accession;
+            
+            QPushButton * dbxref_button = new QPushButton(this);
+            dbxref_button->setText(dbxref.accession);
+            ui->dbxref_list_layout->addWidget(dbxref_button);
+        }
+        
+            ui->button_space_layout->setEnabled(true);
+        if (ui->dbxref_list_layout->count() == 0) {
+            ui->button_space_layout->setEnabled(false);
         }
         ui->description_label->setText(_p_protein_match->getProteinXtpSp().get()->getDescription());
         ui->sequenceTextEdit->setText(_p_protein_match->getHtmlSequence());
diff --git a/src/gui/protein_view/proteinwindow.h b/src/gui/protein_view/proteinwindow.h
index a9a147088..ff6d92e5c 100644
--- a/src/gui/protein_view/proteinwindow.h
+++ b/src/gui/protein_view/proteinwindow.h
@@ -49,6 +49,7 @@ public slots:
     
 protected :
     void updateDisplay();
+    void clearDbXrefLayout();
 
 private:
     Ui::ProteinDetailView *ui;
diff --git a/src/output/proticdbml.cpp b/src/output/proticdbml.cpp
index b72b08ab0..159bf1612 100644
--- a/src/output/proticdbml.cpp
+++ b/src/output/proticdbml.cpp
@@ -128,11 +128,11 @@ void ProticdbMl::writeSequence(ProteinMatch * p_protein_match) {
         // <dbxref key="AT5G16390"
         // dbname="AGI_LocusCode"></dbxref>
         //if (prot.get_dbxref_type().equals("no") == false) {
-        for (const std::pair<ExternalDatabase, QString> & dbxref :p_protein_match->getProteinXtpSp().get()->getDbxrefList()) {
+        for (const DbXref & dbxref :p_protein_match->getProteinXtpSp().get()->getDbxrefList()) {
             _output_stream->writeStartElement("dbxref");
-            _output_stream->writeAttribute("dbname", Utils::getDatabaseName(dbxref.first));
+            _output_stream->writeAttribute("dbname", Utils::getDatabaseName(dbxref.database));
             _output_stream->writeAttribute("key",
-                                           dbxref.second);
+                                           dbxref.accession);
             _output_stream->writeEndElement();// dbxref
         }
         _output_stream->writeStartElement("description");
diff --git a/src/utils/types.h b/src/utils/types.h
index 6c6800a1a..e1a894909 100644
--- a/src/utils/types.h
+++ b/src/utils/types.h
@@ -31,12 +31,12 @@
 /** \def ExternalDatabase external database references
  *
  */
-enum class ExternalDatabase {
-    AGI_LocusCode, ///< AGI_LocusCode
-    NCBI_gi, ///< NCBI_gi
-    SwissProt, ///< Swiss-Prot
-    TrEMBL, ///< TrEMBL
-    ref ///< ref
+enum class ExternalDatabase: std::int8_t {
+    SwissProt =1, ///< Swiss-Prot
+    TrEMBL=2, ///< TrEMBL
+    AGI_LocusCode=3, ///< AGI_LocusCode
+    NCBI_gi=4, ///< NCBI_gi
+    ref=5 ///< ref
 };
 
 /** \def IdentificationEngine identification engine
@@ -77,10 +77,10 @@ enum class GroupingType {
  */
 
 enum class MzFormat {
-     unknown, ///< unknown format
-     mzML, ///< mzML
-     mzXML, ///< mzXML
-     MGF, ///< Mascot format
+    unknown, ///< unknown format
+    mzML, ///< mzML
+    mzXML, ///< mzXML
+    MGF, ///< Mascot format
 };
 
 /** \def ValidationState
@@ -89,9 +89,9 @@ enum class MzFormat {
 
 enum class ValidationState: std::int8_t {
     notValid = 0,///< notValid : automatic filter validation failed
-     valid =1, ///< valid : automatic filter validation passed
-     validAndChecked=2, ///< validAndChecked : automatic filter validation passed + manual checking
-     grouped=3 ///< grouped : automatic filter validation passed + manual checking + grouped
+    valid =1, ///< valid : automatic filter validation passed
+    validAndChecked=2, ///< validAndChecked : automatic filter validation passed + manual checking
+    grouped=3 ///< grouped : automatic filter validation passed + manual checking + grouped
 };
 
 
-- 
GitLab