scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

FilterDialog.cpp
Go to the documentation of this file.
1 
11 
29 #include "FilterDialog.h"
30 #include "Graph.h"
31 #include "MyParser.h"
32 #include "ColorButton.h"
33 #include "FFTFilter.h"
34 
35 #include <QGroupBox>
36 #include <QCheckBox>
37 #include <QMessageBox>
38 #include <QLayout>
39 #include <QPushButton>
40 #include <QLabel>
41 #include <QLineEdit>
42 #include <QComboBox>
43 
44 FilterDialog::FilterDialog(int type, QWidget* parent, Qt::WindowFlags fl )
45  : QDialog( parent, fl )
46 {
47  setWindowTitle(tr("Filter options"));
48  filter_type = type;
49 
50  QGroupBox *gb1 = new QGroupBox();
51  QGridLayout *gl1 = new QGridLayout(gb1);
52  gl1->addWidget(new QLabel(tr("Filter curve: ")), 0, 0);
53 
54  boxName = new QComboBox();
55  gl1->addWidget(boxName, 0, 1);
56 
57  if (type <= FFTFilter::HighPass)
58  gl1->addWidget(new QLabel(tr("Frequency cutoff (Hz)")), 1, 0);
59  else
60  gl1->addWidget(new QLabel(tr("Low Frequency (Hz)")), 1, 0);
61 
62  boxStart = new QLineEdit();
63  boxStart->setText(tr("0"));
64  gl1->addWidget(boxStart, 1, 1);
65 
66  btnColor = new ColorButton();
67  btnColor->setColor(QColor(Qt::red));
68  if (type >= FFTFilter::BandPass)
69  {
70  gl1->addWidget(new QLabel(tr("High Frequency (Hz)")), 2, 0);
71 
72  boxEnd = new QLineEdit();
73  boxEnd->setText(tr("0"));
74  gl1->addWidget(boxEnd, 2, 1);
75 
76  if (type == FFTFilter::BandPass)
77  gl1->addWidget(new QLabel(tr("Add DC Offset")), 3, 0);
78  else
79  gl1->addWidget(new QLabel(tr("Substract DC Offset")), 3, 0);
80 
81  boxOffset = new QCheckBox();
82  gl1->addWidget(boxOffset, 3, 1);
83 
84  gl1->addWidget(new QLabel(tr("Color")), 4, 0);
85  gl1->addWidget(btnColor, 4, 1);
86  gl1->setRowStretch(5, 1);
87  }
88  else
89  {
90  gl1->addWidget(new QLabel(tr("Color")), 2, 0);
91  gl1->addWidget(btnColor, 2, 1);
92  gl1->setRowStretch(3, 1);
93  }
94 
95  buttonFilter = new QPushButton(tr( "&Filter" ));
96  buttonFilter->setDefault( true );
97  buttonCancel = new QPushButton(tr( "&Close" ));
98 
99  QVBoxLayout *vl = new QVBoxLayout();
100  vl->addWidget(buttonFilter);
101  vl->addWidget(buttonCancel);
102  vl->addStretch();
103 
104  QHBoxLayout *hb = new QHBoxLayout(this);
105  hb->addWidget(gb1);
106  hb->addLayout(vl);
107 
108  connect( buttonFilter, SIGNAL( clicked() ), this, SLOT( filter() ) );
109  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
110 }
111 
113 {
114 double from = 0.0, to = 0.0;
115 try
116  {
117  MyParser parser;
118  parser.SetExpr(boxStart->text().replace(",", "."));
119  from = parser.Eval();
120  }
121 catch(mu::ParserError &e)
122  {
123  QMessageBox::critical(this, tr("Frequency input error"), QStringFromString(e.GetMsg()));
124  boxStart->setFocus();
125  return;
126  }
127 
128 if (from < 0)
129  {
130  QMessageBox::critical(this, tr("Frequency input error"),
131  tr("Please enter positive frequency values!"));
132  boxStart->setFocus();
133  return;
134  }
135 
137  {
138  try
139  {
140  MyParser parser;
141  parser.SetExpr(boxEnd->text().replace(",", "."));
142  to=parser.Eval();
143  }
144  catch(mu::ParserError &e)
145  {
146  QMessageBox::critical(this, tr("High Frequency input error"), QStringFromString(e.GetMsg()));
147  boxEnd->setFocus();
148  return;
149  }
150 
151  if (to < 0)
152  {
153  QMessageBox::critical(this, tr("High Frequency input error"),
154  tr("Please enter positive frequency values!"));
155  boxEnd->setFocus();
156  return;
157  }
158 
159  if (from>=to)
160  {
161  QMessageBox::critical(this, tr("Frequency input error"),
162  tr("Please enter frequency limits that satisfy: Low < High !"));
163  boxEnd->setFocus();
164  return;
165  }
166  }
167 
168 FFTFilter *f = new FFTFilter((ApplicationWindow *)this->parent(), graph, boxName->currentText(), filter_type);
170  {
171  f->setBand(from, to);
172  f->enableOffset(boxOffset->isChecked());
173  }
175  {
176  f->setBand(from, to);
177  f->enableOffset(!boxOffset->isChecked());
178  }
179 else
180  f->setCutoff(from);
181 
182 f->setColor(btnColor->color());
183 f->run();
184 delete f;
185 }
186 
188 {
189 graph = g;
190 boxName->addItems (g->analysableCurvesList());
191 };
FilterDialog::filter
void filter()
Definition: FilterDialog.cpp:112
FilterDialog::FilterDialog
FilterDialog(int type, QWidget *parent=0, Qt::WindowFlags fl=0)
Definition: FilterDialog.cpp:44
MyParser.h
FilterDialog::setGraph
void setGraph(Graph *g)
Definition: FilterDialog.cpp:187
Filter::setColor
void setColor(QColor colorId)
Sets the color of the output fit curve.
Definition: Filter.h:64
FilterDialog::boxStart
QLineEdit * boxStart
Definition: FilterDialog.h:54
ColorButton
A button used for color selection.
Definition: ColorButton.h:54
FilterDialog::buttonFilter
QPushButton * buttonFilter
Definition: FilterDialog.h:48
QStringFromString
QString QStringFromString(const std::string &x)
Definition: QStringStdString.h:15
FFTFilter::BandBlock
@ BandBlock
Definition: FFTFilter.h:42
Graph::analysableCurvesList
QStringList analysableCurvesList()
Returns the names of all the curves suitable for data analysis, as a string list. The list excludes e...
Definition: Graph.cpp:1311
FilterDialog.h
FilterDialog::boxOffset
QCheckBox * boxOffset
Definition: FilterDialog.h:53
FFTFilter::setBand
void setBand(double lowFreq, double highFreq)
Sets the cutoff frequencies. To be used only for the Band Pass and Band block filters.
Definition: FFTFilter.cpp:84
FilterDialog::graph
Graph * graph
Definition: FilterDialog.h:63
ColorButton.h
MyParser
Mathematical parser class based on muParser.
Definition: MyParser.h:52
MyParser::SetExpr
void SetExpr(const QString &x)
Definition: MyParser.h:56
FFTFilter::enableOffset
void enableOffset(bool offset=true)
Enables/Disables the DC offset when applying a Band Pass/Band block filter.
Definition: FFTFilter.h:54
ColorButton::color
QColor color() const
Get the color of the display part.
Definition: ColorButton.cpp:140
FFTFilter.h
FilterDialog::boxEnd
QLineEdit * boxEnd
Definition: FilterDialog.h:55
FFTFilter::setCutoff
void setCutoff(double f)
Sets the cutoff frequency. To be used only for Low Pass and High Pass filters.
Definition: FFTFilter.cpp:76
FFTFilter
Definition: FFTFilter.h:35
FilterDialog::boxName
QComboBox * boxName
Definition: FilterDialog.h:52
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
Graph.h
Filter::run
virtual bool run()
Actually does the job. Should be reimplemented in derived classes.
Definition: Filter.cpp:208
Graph
A 2D-plotting widget.
Definition: Graph.h:119
FFTFilter::HighPass
@ HighPass
Definition: FFTFilter.h:42
FFTFilter::BandPass
@ BandPass
Definition: FFTFilter.h:42
FilterDialog::btnColor
ColorButton * btnColor
Definition: FilterDialog.h:56
FilterDialog::buttonCancel
QPushButton * buttonCancel
Definition: FilterDialog.h:51
FilterDialog::filter_type
int filter_type
Definition: FilterDialog.h:64
ColorButton::setColor
void setColor(const QColor &c)
Set the color of the display part.
Definition: ColorButton.cpp:132