2020-11-25 01:08:00 +08:00
|
|
|
#include "tracewidgetsa.h"
|
2021-10-21 19:00:34 +08:00
|
|
|
|
2020-12-12 03:28:40 +08:00
|
|
|
#include "Traces/tracecsvexport.h"
|
2020-12-13 05:51:38 +08:00
|
|
|
#include "Traces/traceimportdialog.h"
|
2021-05-13 04:05:50 +08:00
|
|
|
#include "CustomWidgets/informationbox.h"
|
2022-03-03 19:28:59 +08:00
|
|
|
#include "appwindow.h"
|
2020-12-12 03:28:40 +08:00
|
|
|
|
2021-10-21 19:00:34 +08:00
|
|
|
#include <QFileDialog>
|
|
|
|
|
2020-11-25 01:08:00 +08:00
|
|
|
TraceWidgetSA::TraceWidgetSA(TraceModel &model, QWidget *parent)
|
|
|
|
: TraceWidget(model, parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2020-12-12 03:28:40 +08:00
|
|
|
|
|
|
|
void TraceWidgetSA::exportDialog()
|
|
|
|
{
|
|
|
|
auto csv = new TraceCSVExport(model);
|
2022-03-03 19:28:59 +08:00
|
|
|
if(AppWindow::showGUI()) {
|
|
|
|
csv->show();
|
|
|
|
}
|
2020-12-12 03:28:40 +08:00
|
|
|
}
|
2020-12-13 05:51:38 +08:00
|
|
|
|
|
|
|
void TraceWidgetSA::importDialog()
|
|
|
|
{
|
|
|
|
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "CSV files (*.csv)", nullptr, QFileDialog::DontUseNativeDialog);
|
|
|
|
if (!filename.isEmpty()) {
|
2021-05-13 04:05:50 +08:00
|
|
|
try {
|
|
|
|
std::vector<Trace*> traces;
|
|
|
|
QString prefix = QString();
|
|
|
|
auto csv = CSV::fromFile(filename);
|
|
|
|
traces = Trace::createFromCSV(csv);
|
|
|
|
// contruct prefix from filename
|
|
|
|
prefix = filename;
|
|
|
|
// remove any directory names (keep only the filename itself)
|
|
|
|
int lastSlash = qMax(prefix.lastIndexOf('/'), prefix.lastIndexOf('\\'));
|
|
|
|
if(lastSlash != -1) {
|
|
|
|
prefix.remove(0, lastSlash + 1);
|
|
|
|
}
|
|
|
|
// remove file type
|
|
|
|
prefix.truncate(prefix.indexOf('.'));
|
|
|
|
prefix.append("_");
|
|
|
|
auto i = new TraceImportDialog(model, traces, prefix);
|
2022-03-03 19:28:59 +08:00
|
|
|
if(AppWindow::showGUI()) {
|
|
|
|
i->show();
|
|
|
|
}
|
2022-03-17 19:53:13 +08:00
|
|
|
} catch(const std::exception &e) {
|
2021-05-13 04:05:50 +08:00
|
|
|
InformationBox::ShowError("Failed to import file", QString("Attempt to import file ended with error: \"") + e.what()+"\"");
|
2020-12-13 05:51:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|