1
/***************************************************************************
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
6
Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
7
Description : Fast Fourier transform options dialog
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
29
#include "FFTDialog.h"
32
#include "ApplicationWindow.h"
33
#include "MultiLayer.h"
38
#include <QRadioButton>
41
#include <QMessageBox>
42
#include <QPushButton>
48
FFTDialog::FFTDialog(int type, QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
49
: QDialog( parent, name, modal, fl )
51
setWindowTitle(tr("QtiPlot - FFT Options"));
57
forwardBtn = new QRadioButton(tr("&Forward"));
58
forwardBtn->setChecked( true );
59
backwardBtn = new QRadioButton(tr("&Inverse"));
61
QHBoxLayout *hbox1 = new QHBoxLayout();
62
hbox1->addWidget(forwardBtn);
63
hbox1->addWidget(backwardBtn);
65
QGroupBox *gb1 = new QGroupBox();
66
gb1->setLayout(hbox1);
68
QGridLayout *gl1 = new QGridLayout();
69
if (d_type == onGraph)
70
gl1->addWidget(new QLabel(tr("Curve")), 0, 0);
72
gl1->addWidget(new QLabel(tr("Sampling")), 0, 0);
74
boxName = new QComboBox();
75
gl1->addWidget(boxName, 0, 1);
77
boxSampling = new QLineEdit();
78
if (d_type == onTable)
80
gl1->addWidget(new QLabel(tr("Real")), 1, 0);
81
boxReal = new QComboBox();
82
gl1->addWidget(boxReal, 1, 1);
84
gl1->addWidget(new QLabel(tr("Imaginary")), 2, 0);
85
boxImaginary = new QComboBox();
86
gl1->addWidget(boxImaginary, 2, 1);
88
gl1->addWidget(new QLabel(tr("Sampling Interval")), 3, 0);
89
gl1->addWidget(boxSampling, 3, 1);
93
gl1->addWidget(new QLabel(tr("Sampling Interval")), 1, 0);
94
gl1->addWidget(boxSampling, 1, 1);
96
QGroupBox *gb2 = new QGroupBox();
99
boxNormalize = new QCheckBox(tr( "&Normalize Amplitude" ));
100
boxNormalize->setChecked(true);
102
boxOrder = new QCheckBox(tr( "&Shift Results" ));
103
boxOrder->setChecked(true);
105
QVBoxLayout *vbox1 = new QVBoxLayout();
106
vbox1->addWidget(gb1);
107
vbox1->addWidget(gb2);
108
vbox1->addWidget(boxNormalize);
109
vbox1->addWidget(boxOrder);
112
buttonOK = new QPushButton(tr("&OK"));
113
buttonOK->setDefault( true );
114
buttonCancel = new QPushButton(tr("&Close"));
116
QVBoxLayout *vbox2 = new QVBoxLayout();
117
vbox2->addWidget(buttonOK);
118
vbox2->addWidget(buttonCancel);
121
QHBoxLayout *hbox2 = new QHBoxLayout(this);
122
hbox2->addLayout(vbox1);
123
hbox2->addLayout(vbox2);
125
setFocusProxy(boxName);
127
// signals and slots connections
128
connect( boxName, SIGNAL( activated(const QString&) ), this, SLOT( activateCurve(const QString&) ) );
129
connect( buttonOK, SIGNAL( clicked() ), this, SLOT( accept() ) );
130
connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
133
void FFTDialog::accept()
139
parser.SetExpr(boxSampling->text().ascii());
140
sampling=parser.Eval();
142
catch(mu::ParserError &e)
144
QMessageBox::critical(this, tr("QtiPlot - Sampling value error"), QString::fromStdString(e.GetMsg()));
145
boxSampling->setFocus();
149
ApplicationWindow *app = (ApplicationWindow *)parent();
153
fft = new FFT(app, graph, boxName->currentText());
157
if (boxReal->currentText().isEmpty())
159
QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please choose a column for the real part of the data!"));
163
fft = new FFT(app, d_table, boxReal->currentText(), boxImaginary->currentText());
165
fft->setInverseFFT(backwardBtn->isChecked());
166
fft->setSampling(sampling);
167
fft->normalizeAmplitudes(boxNormalize->isChecked());
168
fft->shiftFrequencies(boxOrder->isChecked());
174
void FFTDialog::setGraph(Graph *g)
177
boxName->insertStringList (g->analysableCurvesList());
178
activateCurve(boxName->currentText());
181
void FFTDialog::activateCurve(const QString& curveName)
185
QwtPlotCurve *c = graph->curve(curveName);
189
boxSampling->setText(QString::number(c->x(1) - c->x(0)));
193
int col = d_table->colIndex(curveName);
194
double x0 = d_table->text(0, col).toDouble();
195
double x1 = d_table->text(1, col).toDouble();
196
boxSampling->setText(QString::number(x1 - x0));
200
void FFTDialog::setTable(Table *t)
203
QStringList l = t->columnsList();
204
boxName->insertStringList (l);
205
boxReal->insertStringList (l);
206
boxImaginary->insertStringList (l);
208
int xcol = t->firstXCol();
211
boxName->setCurrentItem(xcol);
213
double x0 = t->text(0, xcol).toDouble();
214
double x1 = t->text(1, xcol).toDouble();
215
boxSampling->setText(QString::number(x1 - x0));
218
l = t->selectedColumns();
219
int selected = (int)l.size();
222
boxReal->setCurrentText(QString());
223
boxImaginary->setCurrentText(QString());
225
else if (selected == 1)
227
boxReal->setCurrentItem(t->colIndex(l[0]));
228
boxImaginary->setCurrentText(QString());
232
boxReal->setCurrentItem(t->colIndex(l[0]));
233
boxImaginary->setCurrentItem(t->colIndex(l[1]));