From 0609f6a1eb658aa98d4c04929ce0e174a5cd4dd5 Mon Sep 17 00:00:00 2001
From: Bert <bertrand.provot@insa-rennes.fr>
Date: Tue, 26 Jun 2018 14:16:19 +0200
Subject: [PATCH] update filter part2: user can now take filters wherever he
 wants

---
 app/Widgets/FilterChoice.cpp | 40 ++++++++++++++++++------------------
 app/Widgets/FilterChoice.h   |  3 +++
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/app/Widgets/FilterChoice.cpp b/app/Widgets/FilterChoice.cpp
index 531d486..7521923 100644
--- a/app/Widgets/FilterChoice.cpp
+++ b/app/Widgets/FilterChoice.cpp
@@ -84,30 +84,29 @@ void FilterChoice::initUI()
     QGroupBox* stdOrCustomBox = new QGroupBox(tr("Select custom or standard filter"));
     _stdButton = new QRadioButton(tr("Standard filter"));
     _customButton = new QRadioButton(tr("Custom filter"));
-    QHBoxLayout* hbox = new QHBoxLayout();
+    QHBoxLayout* hbox = new QHBoxLayout(stdOrCustomBox);
 
     _stdButton->setChecked(true);
 
     hbox->addWidget(_stdButton);
     hbox->addWidget(_customButton);
-    stdOrCustomBox->setLayout(hbox);
 
     QGroupBox* confBox = new QGroupBox(tr("Filter configuration"));
     QFormLayout* confLayout = new QFormLayout(confBox);
 
     /* CUSTOM FILTER */
 
-    //gère l'appel du custom filter
-    //TODO
-
     _labelCustom = new QLabel(this);
     _labelCustom->setText(tr("Path to custom filter:"));
     _filterPath = new QTextEdit("/");
-    _filterPath->setMaximumWidth(200);
+  //  _filterPath->setMaximumWidth(200);
     _filterPath->setReadOnly(true);
+  //  _filterPath->setMaximumHeight(25);
+
+    _filterPath->setLineWrapMode(QTextEdit::FixedColumnWidth);
+    _filterPath->setLineWrapColumnOrWidth(190);
     _filterPathSelect = new QPushButton("...");
     _filterPathSelect->setFixedWidth(40);
-    _filterPath->setMaximumHeight(25);
     _pathLayout = new QHBoxLayout();
     _pathLayout->addWidget(_filterPath);
     _pathLayout->addWidget(_filterPathSelect);
@@ -173,6 +172,8 @@ void FilterChoice::initUI()
     QObject::connect(_customButton, SIGNAL(toggled(bool)), this, SLOT(showCustom(bool)));
     QObject::connect(_number, SIGNAL(valueChanged(const QString&)), this, SLOT(dataChanged(const QString&)));
     QObject::connect(_stdDevBox, SIGNAL(valueChanged(const QString&)), this, SLOT(dataChanged(const QString&)));
+    QObject::connect(_filterPathSelect, SIGNAL(clicked()), this, SLOT(openFile()));
+    QObject::connect(_filterPath, SIGNAL(textChanged()), this, SLOT(updatePath()));
 
 
     QWidget* rightWidget = new QWidget();
@@ -239,9 +240,8 @@ QStringList FilterChoice::initFilters() {
       std::cout << "filters size : " << _filters.size() << "\n";
   }
   else{
-      std::cout << "definitely checked\n";
       //Personal filters
-      QFile file("filters.xml");
+      QFile file(_path.toUtf8());
       if(file.exists())
       {
         QDomDocument doc("");
@@ -310,17 +310,6 @@ void FilterChoice::updateBlur(bool){
     _filters.clear();
     std::cout << "filters size after clearance:" << _filters.size() << "\n";
     std::cout << "blur choices count:" << _blurChoices->count() <<"\n";
- /*   while(_blurChoices->count()!=0){
-        std::cout << "inwhile\n";
-        _blurChoices->removeItem((_blurChoices->count()));
-        std::cout << "blur choice count:" << _blurChoices->count() << "\n";
-        std::cout << "outwhile\n";
-
-
-}*/
-  /*  if(_blurChoices->count()!=0){
-       _blurChoices = new QComboBox(this);
-   }*/
     if(_blurChoices->count()!=0){
         _blurChoices->clear();
     }
@@ -591,3 +580,14 @@ void FilterChoice::updateDisplay()
   _filterView->resizeColumnsToContents();
   _filterView->resizeRowsToContents();
 }
+
+void FilterChoice::openFile() {
+    QString file = QFileDialog::getOpenFileName(this, tr("Open a file"), QString(), tr("XML Documents (*.xml)"));
+    if(file.size()==0) return;
+    _filterPath->setText(file);
+}
+
+void FilterChoice::updatePath(){
+    _path = _filterPath->toPlainText();
+    updateBlur(true);
+}
diff --git a/app/Widgets/FilterChoice.h b/app/Widgets/FilterChoice.h
index ada33ff..bca3942 100644
--- a/app/Widgets/FilterChoice.h
+++ b/app/Widgets/FilterChoice.h
@@ -66,6 +66,8 @@ namespace filtrme
     void deleteFilter();
     void showCustom(bool);
     void updateBlur(bool);
+    void openFile();
+    void updatePath();
 
   private:
     bool _a = true;
@@ -85,6 +87,7 @@ namespace filtrme
     QRadioButton* _stdButton;
     QRadioButton* _customButton;
     QHBoxLayout* _pathLayout;
+    QString _path;
     
     QLabel* _labelNumber;
     QSpinBox* _number;
-- 
GitLab