mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-04 22:17:31 +00:00
TraceWidget: support dropping files for importing measurements
This commit is contained in:
parent
0b8e1a7b50
commit
6ea8869f7f
9 changed files with 174 additions and 131 deletions
|
|
@ -8,7 +8,7 @@
|
|||
#include <QFileDialog>
|
||||
|
||||
TraceWidgetSA::TraceWidgetSA(TraceModel &model, QWidget *parent)
|
||||
: TraceWidget(model, parent)
|
||||
: TraceWidget(model, nullptr, nullptr, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -20,32 +20,3 @@ void TraceWidgetSA::exportDialog()
|
|||
csv->show();
|
||||
}
|
||||
}
|
||||
|
||||
void TraceWidgetSA::importDialog()
|
||||
{
|
||||
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "CSV files (*.csv)", nullptr, Preferences::QFileDialogOptions());
|
||||
if (!filename.isEmpty()) {
|
||||
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);
|
||||
if(AppWindow::showGUI()) {
|
||||
i->show();
|
||||
}
|
||||
} catch(const std::exception &e) {
|
||||
InformationBox::ShowError("Failed to import file", QString("Attempt to import file ended with error: \"") + e.what()+"\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public:
|
|||
TraceWidgetSA(TraceModel &model, QWidget *parent = nullptr);
|
||||
public slots:
|
||||
virtual void exportDialog() override;
|
||||
virtual void importDialog() override;
|
||||
virtual QStringList supportsImportFileFormats() override {return {"csv"};}
|
||||
|
||||
protected:
|
||||
virtual QString defaultParameter() override {return "PORT1";}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue