2 #include "ui_toolbox_FFT.h"
4 #include <QDialogButtonBox>
8 #include <QDragEnterEvent>
18 ui =
new Ui::toolbox_fft;
22 connect(
ui->buttonBox, &QDialogButtonBox::rejected,
this, &ToolboxPlugin::closed);
24 connect(
ui->pushButtonCalculate, &QPushButton::clicked,
this,
45 auto preview_layout_A =
new QHBoxLayout(
ui->framePlotPreviewA);
46 preview_layout_A->setMargin(6);
49 auto preview_layout_B =
new QHBoxLayout(
ui->framePlotPreviewB);
50 preview_layout_B->setMargin(6);
71 QString theme = settings.value(
"StyleSheet::theme",
"light").toString();
73 ui->pushButtonClear->setIcon(
LoadSvg(
":/resources/svg/clear.svg", theme));
90 if (curve_data.
size() == 0)
96 size_t max_index = curve_data.
size() - 1;
98 if (
ui->radioZoomed->isChecked())
104 size_t N = 1 + max_index - min_index;
117 double dT = (curve_data.
at(max_index).x - curve_data.
at(min_index).x) /
double(N - 1);
119 std::vector<kiss_fft_scalar> input;
120 input.reserve(curve_data.
size());
123 if (
ui->checkAverage->isChecked())
125 for (
size_t i = 0; i < N; i++)
127 sum += curve_data[i + min_index].y;
130 double average = sum / double(N);
132 for (
size_t i = 0; i < N; i++)
134 size_t index = i + min_index;
135 const auto& p = curve_data[index];
140 double dTi = (p.x - curve_data[index - 1].x);
141 double diff = dTi - dT;
147 std::vector<kiss_fft_cpx> out(N / 2 + 1);
151 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
152 kiss_fftr(config, input.data(), out.data());
153 QApplication::restoreOverrideCursor();
157 for (
size_t i = 0; i < N / 2; i++)
161 curver_fft.pushBack({ Hz, amplitude });
164 QColor
color = Qt::transparent;
166 if (colorHint.isValid())
168 color = colorHint.value<QColor>();
187 ui->pushButtonSave->setEnabled(
false);
188 ui->pushButtonCalculate->setEnabled(
false);
190 ui->lineEditSuffix->setEnabled(
false);
191 ui->lineEditSuffix->setText(
"_FFT");
198 const QMimeData* mimeData =
event->mimeData();
199 QStringList mimeFormats = mimeData->formats();
201 for (
const QString&
format : mimeFormats)
203 QByteArray encoded = mimeData->data(
format);
204 QDataStream stream(&encoded, QIODevice::ReadOnly);
206 if (
format !=
"curveslist/add_curve")
212 while (!stream.atEnd())
215 stream >> curve_name;
216 if (!curve_name.isEmpty())
218 curves.push_back(curve_name);
233 std::string curve_id = curve.toStdString();
242 ui->pushButtonSave->setEnabled(
true);
243 ui->pushButtonCalculate->setEnabled(
true);
244 ui->lineEditSuffix->setEnabled(
true);
258 auto suffix =
ui->lineEditSuffix->text().toStdString();
261 ui->lineEditSuffix->setText(
"_FFT");