Logo Search packages:      
Sourcecode: edfbrowser version File versions  Download package

filter_dialog.cpp

/*
***************************************************************************
*
* Author: Teunis van Beelen
*
* Copyright (C) 2007, 2008 Teunis van Beelen
*
* teuniz@gmail.com
*
***************************************************************************
*
* This program 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 version 2 of the License.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
***************************************************************************
*
* The current version of GPL is at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*
***************************************************************************
*/



#include "filter_dialog.h"



UI_FilterDialog::UI_FilterDialog(QWidget *parent)
{
  int i;

  mainwindow = (UI_Mainwindow *)parent;

  filterdialog = new QDialog;

  filterdialog->setMinimumSize(QSize(620, 365));
  filterdialog->setMaximumSize(QSize(620, 365));
  filterdialog->setWindowTitle("Add a filter");
  filterdialog->setModal(TRUE);
  filterdialog->setAttribute(Qt::WA_DeleteOnClose, TRUE);

  box1label = new QLabel(filterdialog);
  box1label->setGeometry(QRect(20, 20, 120, 20));
  box1label->setText("Type");

  box2label = new QLabel(filterdialog);
  box2label->setGeometry(QRect(160, 20, 120, 20));
  box2label->setText("Frequency");

  box3label = new QLabel(filterdialog);
  box3label->setGeometry(QRect(300, 20, 120, 20));
  box3label->setText("Time Constant");

  box1 = new QComboBox(filterdialog);
  box1->setGeometry(QRect(20, 45, 120, 20));
  box1->addItem("HighPass");
  box1->addItem("LowPass");

  box2 = new QDoubleSpinBox(filterdialog);
  box2->setGeometry(QRect(160, 45, 120, 20));
  box2->setDecimals(6);
  box2->setSuffix(" Hz");
  box2->setMinimum(0.001);
  box2->setMaximum(10000.0);
  box2->setValue(1.0);

  box3 = new QDoubleSpinBox(filterdialog);
  box3->setGeometry(QRect(300, 45, 120, 20));
  box3->setDecimals(6);
  box3->setSuffix(" sec");
  box3->setMinimum(0.00000159);
  box3->setMaximum(159.154944);
  box3->setValue(0.159154943);

  listlabel = new QLabel(filterdialog);
  listlabel->setGeometry(QRect(440, 20, 100, 20));
  listlabel->setText("Signals");

  list = new QListWidget(filterdialog);
  list->setGeometry(QRect(440, 45, 160, 300));
  list->setSelectionBehavior(QAbstractItemView::SelectRows);
  list->setSelectionMode(QAbstractItemView::ExtendedSelection);

  CancelButton = new QPushButton(filterdialog);
  CancelButton->setGeometry(QRect(300, 320, 100, 25));
  CancelButton->setText("Cancel");

  ApplyButton = new QPushButton(filterdialog);
  ApplyButton->setGeometry(QRect(20, 320, 100, 25));
  ApplyButton->setText("Apply");

  for(i=0; i<mainwindow->signalcomps; i++)
  {
    list->addItem(mainwindow->signalcomp[i]->signallabel);
  }

  list->setCurrentRow(0);

  QObject::connect(ApplyButton,  SIGNAL(clicked()),                this,         SLOT(ApplyButtonClicked()));
  QObject::connect(CancelButton, SIGNAL(clicked()),                filterdialog, SLOT(close()));
  QObject::connect(box2,         SIGNAL(valueChanged(double)),     this,         SLOT(frequencyboxvaluechanged(double)));
  QObject::connect(box3,         SIGNAL(valueChanged(double)),     this,         SLOT(timeconstantboxvaluechanged(double)));

  filterdialog->exec();
}



void UI_FilterDialog::frequencyboxvaluechanged(double value)
{
  QObject::disconnect(box3, SIGNAL(valueChanged(double)), this, SLOT(timeconstantboxvaluechanged(double)));

  box3->setValue(0.15915494309189534197301692504302015416 / value);

  QObject::connect(box3, SIGNAL(valueChanged(double)), this, SLOT(timeconstantboxvaluechanged(double)));
}



void UI_FilterDialog::timeconstantboxvaluechanged(double value)
{
  QObject::disconnect(box2, SIGNAL(valueChanged(double)), this, SLOT(frequencyboxvaluechanged(double)));

  box2->setValue(0.15915494309189534197301692504302015416 / value);

  QObject::connect(box2, SIGNAL(valueChanged(double)), this, SLOT(frequencyboxvaluechanged(double)));
}



void UI_FilterDialog::ApplyButtonClicked()
{
  int i, s, n;

  double frequency;

  QListWidgetItem *item;

  QList<QListWidgetItem *> selectedlist;

  selectedlist = list->selectedItems();

  n = selectedlist.size();

  if(!n)
  {
    filterdialog->close();
    return;
  }

  for(i=0; i<n; i++)
  {
    item = selectedlist.at(i);
    s = list->row(item);

    if(mainwindow->signalcomp[s]->filter_cnt > (MAXFILTERS - 1))
    {
      UI_Messagewindow errormessage("Error", "The maximum amount of filters per signal has been reached.\n"
                                    "Remove some filters first.");
      return;
    }
  }

  frequency = box2->value();

  for(i=0; i<n; i++)
  {
    item = selectedlist.at(i);
    s = list->row(item);

    mainwindow->signalcomp[s]->filter[mainwindow->signalcomp[s]->filter_cnt]
    = create_filter(box1->currentIndex(),
                    frequency,
                    (double)(mainwindow->signalcomp[s]->edfhdr->edfparam[0].smp_per_record) / mainwindow->signalcomp[s]->edfhdr->data_record_duration);

    if(mainwindow->signalcomp[s]->filter[mainwindow->signalcomp[s]->filter_cnt]==NULL)
    {
      UI_Messagewindow errormessage("Error", "Memory allocation error. (struct filtersettings)");
      filterdialog->close();
      return;
    }

    mainwindow->signalcomp[s]->filter_cnt++;
  }

  filterdialog->close();

  mainwindow->setup_viewbuf();
}











Generated by  Doxygen 1.6.0   Back to index