From b6f7ebac6f03c8616d5dc3f5f43de4758605e8f7 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Sun, 26 Jan 2020 17:51:56 -0500 Subject: [PATCH] Move Viatom filename pattern matching into loader. --- oscar/SleepLib/loader_plugins/viatom_loader.cpp | 5 +++++ oscar/SleepLib/loader_plugins/viatom_loader.h | 2 ++ oscar/mainwindow.cpp | 8 ++++---- oscar/tests/viatomtests.cpp | 8 ++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/oscar/SleepLib/loader_plugins/viatom_loader.cpp b/oscar/SleepLib/loader_plugins/viatom_loader.cpp index 997c836c..52be4f15 100644 --- a/oscar/SleepLib/loader_plugins/viatom_loader.cpp +++ b/oscar/SleepLib/loader_plugins/viatom_loader.cpp @@ -172,6 +172,11 @@ void ViatomLoader::EndEventList(ChannelID channel, qint64 /*t*/) } } +QStringList ViatomLoader::getNameFilter() +{ + return QStringList("20[0-5][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9][0-5][0-9]"); +} + static bool viatom_initialized = false; void diff --git a/oscar/SleepLib/loader_plugins/viatom_loader.h b/oscar/SleepLib/loader_plugins/viatom_loader.h index 37b294aa..b63b4e54 100644 --- a/oscar/SleepLib/loader_plugins/viatom_loader.h +++ b/oscar/SleepLib/loader_plugins/viatom_loader.h @@ -39,6 +39,8 @@ class ViatomLoader : public MachineLoader virtual MachineInfo newInfo() { return MachineInfo(MT_OXIMETER, 0, viatom_class_name, QObject::tr("Viatom"), QString(), QString(), QString(), QObject::tr("Viatom Software"), QDateTime::currentDateTime(), viatom_data_version); } + + QStringList getNameFilter(); //Machine *CreateMachine(); diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 966313e8..ac049790 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -2399,13 +2399,13 @@ void MainWindow::on_actionImport_Somnopose_Data_triggered() void MainWindow::on_actionImport_Viatom_Data_triggered() { + ViatomLoader viatom; + QFileDialog w; - w.setFileMode(QFileDialog::ExistingFiles); + w.setFileMode(QFileDialog::AnyFile); w.setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); w.setOption(QFileDialog::ShowDirsOnly, false); - w.setNameFilters(QStringList("Viatom Data File (20[0-5][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9][0-5][0-9])")); - - ViatomLoader viatom; + w.setNameFilters(viatom.getNameFilter()); if (w.exec() == QFileDialog::Accepted) { QString filename = w.selectedFiles()[0]; diff --git a/oscar/tests/viatomtests.cpp b/oscar/tests/viatomtests.cpp index 7294d1f8..90e1da21 100644 --- a/oscar/tests/viatomtests.cpp +++ b/oscar/tests/viatomtests.cpp @@ -8,7 +8,6 @@ #include "viatomtests.h" #include "sessiontests.h" -#include #define TESTDATA_PATH "./testdata/" @@ -47,17 +46,14 @@ static void parseAndEmitSessionYaml(const QString & path) void ViatomTests::testSessionsToYaml() { static const QString root = TESTDATA_PATH "viatom/input/"; - static const QRegularExpression re("(20[0-5][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9][0-5][0-9])"); QDir dir(root); dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks); + dir.setNameFilters(s_loader->getNameFilter()); dir.setSorting(QDir::Name); for (auto & fi : dir.entryInfoList()) { - QRegularExpressionMatch match = re.match(fi.fileName()); - if (match.hasMatch()) { - parseAndEmitSessionYaml(fi.canonicalFilePath()); - } + parseAndEmitSessionYaml(fi.canonicalFilePath()); } }