From 373b2144c19e25f37f3c7448e716290b45a69024 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Wed, 30 May 2018 16:25:14 +0200
Subject: [PATCH] edit detection parameter dialog box

---
 src/CMakeLists.txt                          |  1 +
 src/gui/xic_view/xic_box/xicbox.h           |  2 +-
 src/gui/xic_view/xic_widgets/zivy_widget.ui | 76 +++++++++------------
 src/gui/xic_view/xic_widgets/zivydialog.cpp | 61 +++++++++++++++++
 src/gui/xic_view/xic_widgets/zivydialog.h   | 53 ++++++++++++++
 src/gui/xic_view/xic_widgets/zivywidget.cpp |  8 ++-
 src/gui/xic_view/xic_widgets/zivywidget.h   |  9 ++-
 src/gui/xic_view/xic_window.ui              | 26 ++++++-
 src/gui/xic_view/xicwindow.cpp              | 32 +++++++--
 src/gui/xic_view/xicwindow.h                |  8 +++
 10 files changed, 221 insertions(+), 55 deletions(-)
 create mode 100644 src/gui/xic_view/xic_widgets/zivydialog.cpp
 create mode 100644 src/gui/xic_view/xic_widgets/zivydialog.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b28de307f..76b83adf5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -193,6 +193,7 @@ SET(XTPCPP_SRCS
   ./gui/widgets/contaminant_widget/contaminantwidget.cpp
   ./gui/widgets/massitemdelegate.cpp
   ./gui/xic_view/xic_box/xicbox.cpp
+  ./gui/xic_view/xic_widgets/zivydialog.cpp
   ./gui/xic_view/xic_widgets/zivywidget.cpp
   ./gui/xic_view/xicwindow.cpp
   ./gui/xic_view/xicworkerthread.cpp
diff --git a/src/gui/xic_view/xic_box/xicbox.h b/src/gui/xic_view/xic_box/xicbox.h
index 62a83aec4..32bb20933 100644
--- a/src/gui/xic_view/xic_box/xicbox.h
+++ b/src/gui/xic_view/xic_box/xicbox.h
@@ -60,7 +60,7 @@ class XicBox: public QWidget
 public:
 
     explicit XicBox(XicWindow * parent = 0);
-    ~XicBox();
+    virtual ~XicBox();
     void setPeptideEvidence(const PeptideEvidence * p_peptide_evidence) ;
     void setPeptideEvidenceInMsRun(const PeptideEvidence * p_peptide_evidence, MsRunSp msrun_sp);
     
diff --git a/src/gui/xic_view/xic_widgets/zivy_widget.ui b/src/gui/xic_view/xic_widgets/zivy_widget.ui
index 34d312fbc..df0847484 100644
--- a/src/gui/xic_view/xic_widgets/zivy_widget.ui
+++ b/src/gui/xic_view/xic_widgets/zivy_widget.ui
@@ -27,9 +27,6 @@
      </property>
     </widget>
    </item>
-   <item row="0" column="1">
-    <widget class="QSpinBox" name="smoothing_spinbox"/>
-   </item>
    <item row="1" column="0">
     <widget class="QLabel" name="label_2">
      <property name="text">
@@ -57,9 +54,6 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="1">
-    <widget class="QSpinBox" name="minmax_threshold_spinbox"/>
-   </item>
    <item row="4" column="0">
     <widget class="QLabel" name="label_5">
      <property name="text">
@@ -67,29 +61,39 @@
      </property>
     </widget>
    </item>
+   <item row="3" column="1">
+    <widget class="QDoubleSpinBox" name="minmax_threshold_spinbox">
+     <property name="decimals">
+      <number>0</number>
+     </property>
+     <property name="maximum">
+      <double>1000000.000000000000000</double>
+     </property>
+     <property name="singleStep">
+      <double>10000.000000000000000</double>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QSpinBox" name="smoothing_spinbox"/>
+   </item>
    <item row="4" column="1">
-    <widget class="QSpinBox" name="maxmin_threshold_spinbox"/>
+    <widget class="QDoubleSpinBox" name="maxmin_threshold_spinbox">
+     <property name="decimals">
+      <number>0</number>
+     </property>
+     <property name="maximum">
+      <double>1000000.000000000000000</double>
+     </property>
+     <property name="singleStep">
+      <double>10000.000000000000000</double>
+     </property>
+    </widget>
    </item>
   </layout>
  </widget>
  <resources/>
  <connections>
-  <connection>
-   <sender>smoothing_spinbox</sender>
-   <signal>valueChanged(int)</signal>
-   <receiver>ZivyWidget</receiver>
-   <slot>doSpinboxChanged(int)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>339</x>
-     <y>31</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>615</x>
-     <y>47</y>
-    </hint>
-   </hints>
-  </connection>
   <connection>
    <sender>minmax_spinbox</sender>
    <signal>valueChanged(int)</signal>
@@ -123,34 +127,18 @@
    </hints>
   </connection>
   <connection>
-   <sender>minmax_threshold_spinbox</sender>
-   <signal>valueChanged(int)</signal>
-   <receiver>ZivyWidget</receiver>
-   <slot>doSpinboxChanged(int)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>254</x>
-     <y>129</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>683</x>
-     <y>194</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>maxmin_threshold_spinbox</sender>
+   <sender>smoothing_spinbox</sender>
    <signal>valueChanged(int)</signal>
    <receiver>ZivyWidget</receiver>
    <slot>doSpinboxChanged(int)</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>215</x>
-     <y>160</y>
+     <x>339</x>
+     <y>31</y>
     </hint>
     <hint type="destinationlabel">
-     <x>574</x>
-     <y>220</y>
+     <x>615</x>
+     <y>47</y>
     </hint>
    </hints>
   </connection>
diff --git a/src/gui/xic_view/xic_widgets/zivydialog.cpp b/src/gui/xic_view/xic_widgets/zivydialog.cpp
new file mode 100644
index 000000000..5f4244c55
--- /dev/null
+++ b/src/gui/xic_view/xic_widgets/zivydialog.cpp
@@ -0,0 +1,61 @@
+/**
+ * \file src/gui/xic_view/xic_widgets/zivydialog.h
+ * \date 30/5/2018
+ * \author Olivier Langella
+ * \brief dialog window to edit Zivy quantification method
+ */
+/*******************************************************************************
+* 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 "zivydialog.h"
+#include <QVBoxLayout>
+#include <QDebug>
+
+ZivyDialog::ZivyDialog(QWidget *parent) {
+    _p_zivy_widget = new ZivyWidget(this);
+    _p_button_box = new QDialogButtonBox(QDialogButtonBox::Ok
+                                         | QDialogButtonBox::Cancel);
+
+    connect(_p_button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
+    connect(_p_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
+
+    QVBoxLayout *mainLayout = new QVBoxLayout;
+    mainLayout->addWidget(_p_zivy_widget);
+    mainLayout->addWidget(_p_button_box);
+    setLayout(mainLayout);
+
+    setWindowTitle(tr("Edit parameters"));
+}
+
+
+ZivyDialog::~ZivyDialog()
+{
+    qDebug() << "ZivyDialog::~ZivyDialog";
+}
+
+void ZivyDialog::setZivyParams(const ZivyParams & params) {
+    _p_zivy_widget->setZivyParams(params);
+}
+
+const ZivyParams ZivyDialog::getZivyParams() const {
+    return _p_zivy_widget->getZivyParams();
+}
diff --git a/src/gui/xic_view/xic_widgets/zivydialog.h b/src/gui/xic_view/xic_widgets/zivydialog.h
new file mode 100644
index 000000000..25c1625b4
--- /dev/null
+++ b/src/gui/xic_view/xic_widgets/zivydialog.h
@@ -0,0 +1,53 @@
+/**
+ * \file src/gui/xic_view/xic_widgets/zivydialog.h
+ * \date 30/5/2018
+ * \author Olivier Langella
+ * \brief dialog window to edit Zivy quantification method
+ */
+/*******************************************************************************
+* 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 ZIVYDIALOG_H
+#define ZIVYDIALOG_H
+
+#include <QDialogButtonBox>
+#include <QDialog>
+#include "zivywidget.h"
+
+class ZivyDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit ZivyDialog(QWidget *parent = 0);
+    virtual ~ZivyDialog();
+    
+    
+    void setZivyParams(const ZivyParams & params);
+    const ZivyParams getZivyParams() const;
+
+private:
+    ZivyWidget * _p_zivy_widget;
+    QDialogButtonBox * _p_button_box;
+};
+
+#endif // ZIVYDIALOG_H
diff --git a/src/gui/xic_view/xic_widgets/zivywidget.cpp b/src/gui/xic_view/xic_widgets/zivywidget.cpp
index 55d21c5ea..9755c10ba 100644
--- a/src/gui/xic_view/xic_widgets/zivywidget.cpp
+++ b/src/gui/xic_view/xic_widgets/zivywidget.cpp
@@ -30,7 +30,13 @@
 #include "ui_zivy_widget.h"
 #include <QDebug>
 
-
+void ZivyParams::setDetectionParameters(pappso::XicDetectionZivy * detect_zivy) const {
+    detect_zivy->setSmoothingHalfEdgeWindows(_smoothing_half_window);
+    detect_zivy->setMinMaxHalfEdgeWindows(_minmax_half_window);
+    detect_zivy->setMaxMinHalfEdgeWindows(_maxmin_half_window);
+    detect_zivy->setDetectionThresholdOnMinmax(_minmax_threshold);
+    detect_zivy->setDetectionThresholdOnMaxmin(_maxmin_threshold);
+}
 
 ZivyWidget::ZivyWidget(QWidget *parent):
     QWidget(parent),
diff --git a/src/gui/xic_view/xic_widgets/zivywidget.h b/src/gui/xic_view/xic_widgets/zivywidget.h
index 77c32ba07..c6bc0ca93 100644
--- a/src/gui/xic_view/xic_widgets/zivywidget.h
+++ b/src/gui/xic_view/xic_widgets/zivywidget.h
@@ -30,6 +30,7 @@
 #define ZIVYWIDGET_H
 
 #include <QWidget>
+#include <pappsomspp/xic/detection/xicdetectionzivy.h>
 
 namespace Ui {
 class ZivyWidget;
@@ -37,10 +38,12 @@ class ZivyWidget;
 
 
 struct ZivyParams {
+    void setDetectionParameters(pappso::XicDetectionZivy * detect_zivy) const;
+    
     unsigned int _maxmin_half_window = 3;
     unsigned int _minmax_half_window = 2;
-    unsigned int _maxmin_threshold = 3000;
-    unsigned int _minmax_threshold = 5000;
+    double _maxmin_threshold = 3000;
+    double _minmax_threshold = 5000;
     unsigned int _smoothing_half_window = 1;
 };
 
@@ -50,7 +53,7 @@ class ZivyWidget: public QWidget
 public:
 
     explicit ZivyWidget(QWidget * parent = 0);
-    ~ZivyWidget();
+    virtual ~ZivyWidget();
     
     void setZivyParams(const ZivyParams & params);
     
diff --git a/src/gui/xic_view/xic_window.ui b/src/gui/xic_view/xic_window.ui
index 6f01750e3..725bbd06d 100644
--- a/src/gui/xic_view/xic_window.ui
+++ b/src/gui/xic_view/xic_window.ui
@@ -66,6 +66,13 @@
          </attribute>
         </widget>
        </item>
+       <item>
+        <widget class="QPushButton" name="edit_zivy_params_pushbutton">
+         <property name="text">
+          <string>Edit</string>
+         </property>
+        </widget>
+       </item>
        <item>
         <spacer name="horizontalSpacer">
          <property name="orientation">
@@ -93,7 +100,7 @@
          <x>0</x>
          <y>0</y>
          <width>780</width>
-         <height>498</height>
+         <height>496</height>
         </rect>
        </property>
        <layout class="QVBoxLayout" name="verticalLayout"/>
@@ -159,10 +166,27 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>edit_zivy_params_pushbutton</sender>
+   <signal>clicked()</signal>
+   <receiver>XicWindow</receiver>
+   <slot>doEditZivyParams()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>351</x>
+     <y>38</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>918</x>
+     <y>77</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>xicPrecisionChanged(pappso::PrecisionP)</slot>
   <slot>rtUnitChanged(QAbstractButton*)</slot>
+  <slot>doEditZivyParams()</slot>
  </slots>
  <buttongroups>
   <buttongroup name="rt_unit_buttongroup"/>
diff --git a/src/gui/xic_view/xicwindow.cpp b/src/gui/xic_view/xicwindow.cpp
index 1a4046aaa..e19f78de5 100644
--- a/src/gui/xic_view/xicwindow.cpp
+++ b/src/gui/xic_view/xicwindow.cpp
@@ -45,12 +45,23 @@ XicWindow::XicWindow(ProjectWindow *parent):
 
     ui->xic_precision->setPrecision(pappso::Precision::fromString(precision_str));
 
-    _detect_zivy.setSmoothingHalfEdgeWindows(settings.value("xic/zivy_smoothing", "1").toInt());
-    _detect_zivy.setMinMaxHalfEdgeWindows(settings.value("xic/zivy_minmax_half_window", "4").toInt());
-    _detect_zivy.setMaxMinHalfEdgeWindows(settings.value("xic/zivy_maxmin_half_window", "2").toInt());
-    _detect_zivy.setDetectionThresholdOnMinmax(settings.value("xic/zivy_minmax_threshold", "50000").toDouble());
-    _detect_zivy.setDetectionThresholdOnMaxmin(settings.value("xic/zivy_maxmin_threshold", "30000").toDouble());
 
+    ZivyParams zivy_params;
+    zivy_params._maxmin_threshold  = settings.value("xic/zivy_maxmin_threshold", "30000").toDouble();
+    zivy_params._minmax_threshold = settings.value("xic/zivy_minmax_threshold", "50000").toDouble();
+    zivy_params._maxmin_half_window = settings.value("xic/zivy_maxmin_half_window", "2").toInt();
+    zivy_params._minmax_half_window = settings.value("xic/zivy_minmax_half_window", "4").toInt();
+    zivy_params._smoothing_half_window = settings.value("xic/zivy_smoothing", "1").toInt();
+
+
+    zivy_params.setDetectionParameters(&_detect_zivy);
+
+    _p_zivy_dialog = new ZivyDialog(this);
+    _p_zivy_dialog->setZivyParams(zivy_params);
+
+
+
+    connect(_p_zivy_dialog, &ZivyDialog::accepted, this, &XicWindow::doAcceptedZivyDialog);
 
 #if QT_VERSION >= 0x050000
     // Qt5 code
@@ -65,6 +76,11 @@ XicWindow::XicWindow(ProjectWindow *parent):
 XicWindow::~XicWindow()
 {
     qDebug() << "XicWindow::~XicWindow";
+    delete _p_zivy_dialog;
+}
+
+void XicWindow::doEditZivyParams() {
+    _p_zivy_dialog->show();
 }
 
 void XicWindow::clear() {
@@ -124,3 +140,9 @@ bool XicWindow::isRetentionTimeSeconds() const {
     }
     return false;
 }
+
+void XicWindow::doAcceptedZivyDialog() {
+    _p_zivy_dialog->getZivyParams().setDetectionParameters(&_detect_zivy);
+    emit reExtractXicNeeded();
+    
+}
diff --git a/src/gui/xic_view/xicwindow.h b/src/gui/xic_view/xicwindow.h
index 6d0bd3d76..47e306796 100644
--- a/src/gui/xic_view/xicwindow.h
+++ b/src/gui/xic_view/xicwindow.h
@@ -35,6 +35,7 @@
 #include <pappsomspp/xic/detection/xicdetectionzivy.h>
 
 #include "../../core/peptideevidence.h"
+#include "xic_widgets/zivydialog.h"
 
 class ProjectWindow;
 
@@ -66,6 +67,10 @@ public slots:
     void xicPrecisionChanged(pappso::PrecisionP precision);
     void rtUnitChanged(QAbstractButton* button);
     
+    protected slots :
+    void doEditZivyParams();
+    void doAcceptedZivyDialog();
+    
 signals :
     void reExtractXicNeeded();
     void rtUnitChangeNeeded();
@@ -82,6 +87,9 @@ private:
     Ui::XicWindow *ui;
     
     pappso::XicDetectionZivy _detect_zivy;
+    
+    
+    ZivyDialog * _p_zivy_dialog;
 };
 
 #endif // XICWINDOW_H
-- 
GitLab