Commit 34f69c29 authored by Bruno Colombet's avatar Bruno Colombet

in progress

parent a3fdfbae
......@@ -3,52 +3,27 @@
#include <qfileiconprovider.h>
#include "AwBIDSItem.h"
//AwBIDSGUI::AwBIDSGUI(AwBIDSManager *bids, const QString& rootDir, QWidget *parent)
// : QWidget(parent)
//{
// m_ui.setupUi(this);
// m_ui.leDIR->setText(rootDir);
// m_bids = bids;
//// connect(m_ui.comboSource, SIGNAL(currentIndexChanged(int)), this, SLOT(changeSourceFolder(int)));
// m_ui.treeView->header()->setSectionResizeMode(QHeaderView::Stretch);
// connect(m_ui.treeView, &QTreeView::doubleClicked, this, &AwBIDSGUI::handleDoubleClick);
// m_ui.treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
//}
AwBIDSGUI::AwBIDSGUI(QWidget *parent) : QWidget(parent)
{
m_ui.setupUi(this);
m_bids = AwBIDSManager::instance();
m_ui.leDIR->setText(m_bids->rootDir());
m_ui.treeView->header()->setSectionResizeMode(QHeaderView::Stretch);
m_ui.treeView->setHeaderHidden(true);
connect(m_ui.treeView, &QTreeView::doubleClicked, this, &AwBIDSGUI::handleDoubleClick);
m_ui.treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_model = new QStandardItemModel(this);
m_ui.treeView->setModel(m_model);
}
//void AwBIDSGUI::setRootDir(const QString& path)
//{
// m_ui.leDIR->setText(path);
//}
AwBIDSGUI::~AwBIDSGUI()
{
//clear();
}
//void AwBIDSGUI::clear()
//{
// //for (auto m : m_models.values())
// // delete m;
// //m_models.clear();
//}
void AwBIDSGUI::handleDoubleClick(const QModelIndex& index)
{
// get the item
//auto item = m_currentModel->itemFromIndex(index);
auto item = m_model->itemFromIndex(index);
if (item == 0)
......@@ -69,51 +44,11 @@ void AwBIDSGUI::handleDoubleClick(const QModelIndex& index)
void AwBIDSGUI::refresh()
{
//clear();
//// check for available source directories and subjects
//AwBIDSSubjectList raw = m_bids->getSubjectsFromSourceDir(AwBIDSManager::raw);
//AwBIDSSubjectList sourcedata = m_bids->getSubjectsFromSourceDir(AwBIDSManager::source);
//bool isRaw = !raw.isEmpty();
//bool isSource = !sourcedata.isEmpty();
//QStandardItemModel *model = NULL;
//if (isRaw) {
// m_ui.comboSource->addItem("raw data", QVariant(AwBIDSManager::raw));
// model = new QStandardItemModel;
// initModel(model, raw);
// m_models.insert(AwBIDSManager::raw, model);
//}
//if (isSource) {
// m_ui.comboSource->addItem("source data", QVariant(AwBIDSManager::source));
// model = new QStandardItemModel;
// initModel(model, sourcedata);
// m_models.insert(AwBIDSManager::source, model);
//}
//model->setHeaderData(0, Qt::Horizontal, "Subjects");
//m_ui.comboSource->setCurrentIndex(0);
//changeSourceFolder(0);
//clear();
// m_model->clear();
// auto subjects = m_bids->subjects();
m_model->clear();
initModel(m_bids->subjects(), nullptr);
initModel(m_bids->subjects(), m_model->invisibleRootItem());
}
//void AwBIDSGUI::changeSourceFolder(int index)
//{
// if (m_models.isEmpty())
// return;
// int type = m_ui.comboSource->itemData(index, Qt::EditRole).toInt();
//
// auto model = m_models.value(type);
// if (model) {
// m_ui.treeView->setModel(model);
// m_currentModel = model;
// }
//}
void AwBIDSGUI::initModel(const AwBIDSNodes& nodes, QStandardItem *parent)
{
if (nodes.isEmpty())
......@@ -133,7 +68,7 @@ void AwBIDSGUI::initModel(const AwBIDSNodes& nodes, QStandardItem *parent)
item->setData(AwBIDSGUI::Subject, AwBIDSGUI::TypeRole);
item->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// subject are always root items =>
m_model->appendRow(item);
parent->appendRow(item);
initModel(node->children(), item);
break;
case AwBIDSNode::session:
......@@ -209,125 +144,3 @@ void AwBIDSGUI::initModel(const AwBIDSNodes& nodes, QStandardItem *parent)
}
}
}
//void AwBIDSGUI::initModel(QStandardItemModel *model, const AwBIDSSubjectList& subjects)
//{
// model->clear();
// QFileIconProvider fi;
//
// for (auto s : subjects) {
// // first item is a AwBIDSItem to hold the reference to the subject object.
// auto subItem = new AwBIDSItem(s->ID(), s);
// subItem->setToolTip(tr("subject"));
// // set custom data
// subItem->setData(s->fullPath(), AwBIDSGUI::PathRole);
// subItem->setData(AwBIDSGUI::Subject, AwBIDSGUI::TypeRole);
// subItem->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// QList<QStandardItem *> subChildren;
// if (s->hasSessions()) {
// for (auto session : s->sessions()) {
// auto sessionItem = new QStandardItem(session->label());
// sessionItem->setToolTip(tr("session"));
// sessionItem->setData(session->fullPath(), AwBIDSGUI::PathRole);
// sessionItem->setData(AwBIDSGUI::Session, AwBIDSGUI::TypeRole);
// sessionItem->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// subChildren.append(sessionItem);
// QList<QStandardItem *> sesChildren;
// for (auto fileItem : session->fileItems()) {
// switch (fileItem->type()) {
// case AwFileItem::eeg:
// break;
// case AwFileItem::ieeg:
// {
// auto ieegItem = new QStandardItem("ieeg");
// ieegItem->setData(AwBIDSGUI::ieeg, AwBIDSGUI::TypeRole);
// ieegItem->setData(fileItem->fullPath(), AwBIDSGUI::PathRole);
// ieegItem->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// sesChildren.append(ieegItem);
// QList<QStandardItem *> ieegChildren;
// for (auto file : fileItem->files()) {
// auto item = new QStandardItem(file);
// item->setToolTip("SEEG data file");
// item->setData(QString("%1/%2").arg(fileItem->fullPath()).arg(file), AwBIDSGUI::PathRole);
// item->setData(AwBIDSGUI::DataFile, AwBIDSGUI::TypeRole);
// item->setData(fi.icon(QFileIconProvider::File), Qt::DecorationRole);
// ieegChildren.append(item);
// }
// ieegItem->insertColumn(0, ieegChildren);
// }
// break;
// case AwFileItem::meg:
// {
// auto megItem = new QStandardItem("meg");
// megItem->setData(AwBIDSGUI::ieeg, AwBIDSGUI::TypeRole);
// megItem->setData(fileItem->fullPath(), AwBIDSGUI::PathRole);
// megItem->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// sesChildren.append(megItem);
// QList<QStandardItem *> megChildren;
// for (auto file : fileItem->files()) {
// auto item = new QStandardItem(file);
// item->setToolTip("MEG data file");
// item->setData(QString("%1/%2").arg(fileItem->fullPath()).arg(file), AwBIDSGUI::PathRole);
// item->setData(AwBIDSGUI::DataFile, AwBIDSGUI::TypeRole);
// item->setData(fi.icon(QFileIconProvider::File), Qt::DecorationRole);
// megChildren.append(item);
// }
// megItem->insertColumn(0, megChildren);
// }
// break;
// }
// }
// sessionItem->insertColumn(0, sesChildren);
// }
// subItem->insertColumn(0, subChildren);
// }
// else {
// for (auto fileItem : s->fileItems()) {
// switch (fileItem->type()) {
// case AwFileItem::eeg:
// break;
// case AwFileItem::ieeg:
// {
// auto ieegItem = new QStandardItem("ieeg");
// ieegItem->setData(AwBIDSGUI::ieeg, AwBIDSGUI::TypeRole);
// ieegItem->setData(fileItem->fullPath(), AwBIDSGUI::PathRole);
// ieegItem->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// subChildren.append(ieegItem);
// QList<QStandardItem *> ieegChildren;
// for (auto file : fileItem->files()) {
// auto item = new QStandardItem(file);
// item->setToolTip("SEEG data file");
// item->setData(QString("%1/%2").arg(fileItem->fullPath()).arg(file), AwBIDSGUI::PathRole);
// item->setData(AwBIDSGUI::DataFile, AwBIDSGUI::TypeRole);
// item->setData(fi.icon(QFileIconProvider::File), Qt::DecorationRole);
// ieegChildren.append(item);
// }
// ieegItem->insertColumn(0, ieegChildren);
// }
// break;
// case AwFileItem::meg:
// {
// auto megItem = new QStandardItem("meg");
// megItem->setData(AwBIDSGUI::ieeg, AwBIDSGUI::TypeRole);
// megItem->setData(fileItem->fullPath(), AwBIDSGUI::PathRole);
// megItem->setData(fi.icon(QFileIconProvider::Folder), Qt::DecorationRole);
// subChildren.append(megItem);
// QList<QStandardItem *> megChildren;
// for (auto file : fileItem->files()) {
// auto item = new QStandardItem(file);
// item->setToolTip("MEG data file");
// item->setData(QString("%1/%2").arg(fileItem->fullPath()).arg(file), AwBIDSGUI::PathRole);
// item->setData(AwBIDSGUI::DataFile, AwBIDSGUI::TypeRole);
// item->setData(fi.icon(QFileIconProvider::File), Qt::DecorationRole);
// megChildren.append(item);
// }
// megItem->insertColumn(0, megChildren);
// }
// break;
// }
// }
// subItem->insertColumn(0, subChildren);
// }
// model->appendRow(subItem);
// }
//}
\ No newline at end of file
......@@ -53,13 +53,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Available data files:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="treeView">
<property name="layoutDirection">
......
......@@ -19,7 +19,9 @@
// statics
AwBIDSManager *AwBIDSManager::m_instance = 0;
//QString AwBIDSManager::m_parsingPath = QString("derivatives/parsing");
QStringList AwBIDSManager::m_dataFileSuffixes = { "_eeg", "_meg", "_ieeg" };
void AwBIDSManager::toBIDS(const AwArguments& args)
{
......@@ -632,15 +634,6 @@ int AwBIDSManager::convertToEDF(const QString& file, AwFileIO *reader)
}
//AwBIDSManager *AwBIDSManager::instance(const QString& rootDir)
//{
// if (!m_instance)
// m_instance = new AwBIDSManager(rootDir);
// else
// m_instance->setRootDir(rootDir);
// return m_instance;
//}
AwBIDSManager *AwBIDSManager::instance()
{
if (!m_instance)
......@@ -651,21 +644,8 @@ AwBIDSManager *AwBIDSManager::instance()
AwBIDSManager::AwBIDSManager()
{
m_ui = NULL;
//m_currentSubject = Q_NULLPTR;
//// Get extensions readers can handle.
//auto pm = AwPluginManager::getInstance();
//for (auto r : pm->readers())
// m_fileExtensions += r->fileExtensions;
// setRootDir(rootDir);
m_ui = nullptr;
m_mustValidateModifications = false;
// init settings
//m_settings["parsing_path"] = QString("derivatives/parsing");
//m_settings["aw_derivatives"] = QString("derivatives/anywave");
//m_knownDerivativesPaths[AwBIDSManager::AnyWave] = QString("%1/derivatives/anywave").arg(rootDir);
//m_knownDerivativesPaths[AwBIDSManager::EpiTools] = QString("%1/derivatives/epitools").arg(rootDir);
}
AwBIDSManager::~AwBIDSManager()
......@@ -678,7 +658,6 @@ QString AwBIDSManager::getParsingPath()
if (!isBIDSActive())
return QString();
return m_settings["parsing_path"].toString();
//return QString("%1/%2").arg(m_rootDir).arg(m_parsingPath);
}
void AwBIDSManager::setRootDir(const QString& path)
......@@ -704,26 +683,6 @@ void AwBIDSManager::setRootDir(const QString& path)
closeBIDS();
m_rootDir = path;
//// check that the root dir contains subjects
//getSubjects();
//// check for source_data dir
//bool source = false, derivatives = false;
//QDirIterator it(m_rootDir, QDir::Dirs);
//while (it.hasNext()) {
// it.next();
// QString name = it.fileName();
// if (name == "sourcedata")
// source = true;
// else if (name == "derivatives")
// derivatives = true;
// if (source && derivatives)
// break;
//}
//if (source)
// getSubjects(AwBIDSManager::source);
//if (derivatives)
// getSubjects(AwBIDSManager::derivatives);
AwBIDSParser parser;
parser.parse();
m_nodes = parser.nodes();
......@@ -731,128 +690,21 @@ void AwBIDSManager::setRootDir(const QString& path)
for (auto n : m_nodes)
m_IDToSubject[n->ID()] = n;
// instantiate UI if needed
if (m_ui == NULL)
if (m_ui == nullptr)
m_ui = new AwBIDSGUI;
m_ui->refresh();
}
//AwBIDSSubjectList& AwBIDSManager::getSubjectsFromSourceDir(int sourceDir)
//{
// return m_subjects[sourceDir];
//}
//AwFileItem *AwBIDSManager::parseDir(const QString& fullPath, const QString& dir)
//{
// QStringList items = { "ieeg", "eeg", "meg" };
// QVector<int> types = { AwFileItem::ieeg, AwFileItem::eeg, AwFileItem::meg };
// int index = items.indexOf(dir);
// if (index == -1)
// return NULL;
// // parse files
// QString fullPathItem = QString("%1/%2").arg(fullPath).arg(dir);
// QDir directory(fullPathItem);
// QStringList files = directory.entryList(m_fileExtensions, QDir::Files);
// if (files.isEmpty())
// return NULL;
// AwFileItem *item = new AwFileItem(types.value(index));
// item->setFullPath(fullPathItem);
// item->setFiles(files);
// return item;
//}
//void AwBIDSManager::parseSubject(AwBIDSSubject *subject)
//{
// // check for subdirs that AnyWave could handle (iEEG, MEG, SES-)
//
// QDir dir(subject->fullPath());
// QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
// if (dirs.isEmpty())
// return;
//
// // check for session directories (optional)
// for (auto d : dirs) {
// if (d.startsWith("ses-")) {
// // get session label
// auto label = AwBIDS::getSessionLabel(d);
// subject->addSession(label);
// }
// }
//
// // have we got sessions?
// if (subject->hasSessions()) {
// // remove sessions from dirs
// for (auto session : subject->sessions()) {
// QDir sessionDir = QDir(session->fullPath());
// QStringList entries = sessionDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
// for (auto d : entries) {
// auto item = parseDir(sessionDir.absolutePath(), d);
// if (item)
// session->addItem(item);
// }
// }
// }
//
// // parse non ses- folders
// for (auto d : dirs) {
// if (d.startsWith("ses-"))
// continue;
// auto item = parseDir(dir.absolutePath(), d);
// if (item)
// subject->addItem(item);
// }
//}
///// Parse root dir to get all the subjects present in the structure.
///// Create subject objects
///// Can result in an empty list if no subject is found.
//void AwBIDSManager::getSubjects(int sourceDir)
//{
// QString directory;
// switch (sourceDir) {
// case AwBIDSManager::raw:
// directory = m_rootDir;
// break;
// case AwBIDSManager::source:
// directory = QString("%1/sourcedata").arg(m_rootDir);
// break;
// case AwBIDSManager::derivatives:
// directory = QString("%1/derivatives").arg(m_rootDir);
// break;
// }
//
// clearSubjects(sourceDir);
//
// QDirIterator it(directory, QDir::Dirs);
// QRegularExpression re("^(?<subject>sub-)(?<ID>\\w+)$");
// QRegularExpressionMatch match;
// while (it.hasNext()) {
// it.next();
// QString name = it.fileName();
// match = re.match(name);
// if (match.hasMatch()) {
// name = match.captured("ID");
// m_subjects[sourceDir].append(new AwBIDSSubject(directory, name));
// }
// }
//
// for (auto s : m_subjects[sourceDir]) {
// parseSubject(s);
// }
//}
void AwBIDSManager::closeBIDS()
{
if (!isBIDSActive())
return;
//for (int i = 0; i < AWBIDS_SOURCE_DIRS; i++)
// clearSubjects(i);
while (!m_nodes.isEmpty())
delete m_nodes.takeFirst();
m_rootDir.clear();
m_modifications.clear();
m_mustValidateModifications = false;
// m_currentSubject = Q_NULLPTR;
m_currentSubject = nullptr;
emit BIDSClosed();
}
......@@ -1023,19 +875,6 @@ void AwBIDSManager::updateChannelsTsv(const QString& itemPath)
QFile::remove(bak);
}
//void AwBIDSManager::clearSubjects(int sourceDir)
//{
// while (!m_subjects[sourceDir].isEmpty())
// delete m_subjects[sourceDir].takeFirst();
// m_subjectsIDs[sourceDir].clear();
//}
//AwBIDSSubject *AwBIDSManager::getSubject(const QString& ID, int sourceDir)
//{
// if (m_subjectsIDs[sourceDir].contains(ID))
// return m_subjectsIDs[sourceDir].value(ID);
// return Q_NULLPTR;
//}
int AwBIDSManager::convertFile(AwFileIO *reader, AwFileIOPlugin *plugin, const QString& file)
{
......@@ -1072,18 +911,57 @@ int AwBIDSManager::convertFile(AwFileIO *reader, AwFileIOPlugin *plugin, const Q
}
//QString AwBIDSManager::getDerivativesPath(int type, AwBIDSSubject *sub)
//{
// switch (type) {
// case AwBIDSManager::EPITOOLS:
// break;
// case AwBIDSManager::EI:
// break;
// case AwBIDSManager::ICA:
// break;
// }
// return QString();
//}
QString AwBIDSManager::getTSVFile(const QString& dataFilePath, int type)
{
if (m_currentSubject == nullptr || !isBIDSActive())
return QString();
QString suffix;
if (type == AwBIDSManager::EventsTsv)
suffix = "_events.tsv";
else if (type == AwBIDSManager::ChannelsTsv)
suffix = "_channels.tsv";
else
return QString();
// find the child node in current subject which contains the file
auto node = m_currentSubject->findNode(QFileInfo(dataFilePath).fileName(), m_currentSubject);
if (node == nullptr)
return QString();
// remove the extension
auto base = QFileInfo(dataFilePath).baseName();
for (auto e : m_dataFileSuffixes) {
if (base.contains(e)) {
base.remove(e);
break;
}
}
QString res = QString("%1/%2%3").arg(node->fullPath()).arg(base).arg(suffix);
if (QFile::exists(res))
return res;
return QString();
}
AwBIDSNode *AwBIDSManager::findSubject(const QString& dataFilePath)
{
m_currentSubject = nullptr;
if (!isBIDSActive())
return nullptr;
QFileInfo fi(dataFilePath);
if (!fi.exists())
return nullptr;
auto fileName = fi.fileName();
for (auto s : m_nodes) {
auto files = s->gatherFiles();
if (files.contains(fileName)) {
m_currentSubject = s;
return s;
}
}
return m_currentSubject;
}
void AwBIDSManager::newFile(AwFileIO *reader)
{
......@@ -1095,40 +973,10 @@ void AwBIDSManager::newFile(AwFileIO *reader)
closeBIDS(); // close current BIDS
return;
}
auto subj = guessSubject(reader->infos.fileName());
if (subj)
m_currentSubject = subj;
// find the corresponding subject node
m_currentSubject = findSubject(reader->infos.fileName());
}
//AwBIDSSubject *AwBIDSManager::guessSubject(const QString& path)
//{
// m_currentSubject = Q_NULLPTR;
// if (!isBIDSActive())
// return Q_NULLPTR;
// QFileInfo fi(path);
// if (!fi.exists())
// return Q_NULLPTR;
//
// // using the full path we should be able to guess the BIDS base directory between (raw, sourcedata, derivatives).
// int sourceDir = AwBIDSManager::raw;
// if (path.contains("sourcedata"))
// sourceDir = AwBIDSManager::source;
// if (path.contains("derivatives"))
// sourceDir = AwBIDSManager::derivatives;
// auto subjects = m_subjects[sourceDir];
// if (subjects.isEmpty())
// return Q_NULLPTR;
// for (auto subj : subjects) {
// auto files = subj->findFile(fi.fileName());
// if (!files.isEmpty()) {
// m_currentSubject = subj;
// return subj;
// }
// }
// // failed to find a subject
// return Q_NULLPTR;
//}
void AwBIDSManager::saveTsvFile(const QString& path, const QMap<QString, QStringList>& dict, const QStringList& orderedColumns)
{
QFile file(path);
......
......@@ -25,14 +25,10 @@
//////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <qobject.h>
#include "AwBIDSSubject.h"
#include "AwBIDSNode.h"
#include "AwBIDSGUI.h"
#include <AwFileIO.h>
#include <AwCommandLine.h>
class AwFileItem;
#define AWBIDS_SOURCE_DIRS 3
class AwFileIO;
// command line parsing
......@@ -51,7 +47,6 @@ public:
// destructor
~AwBIDSManager();
// utilities static methods
//static AwBIDSManager *instance(const QString& rootDir = QString());
static AwBIDSManager *instance();
static bool isInstantiated() { return m_instance != NULL; }
......@@ -59,6 +54,7 @@ public:
/** check if a path is a BIDS directory or not. **/
static bool isBIDS(const QString& path);
static QString detectBIDSFolderFromPath(const QString& path);
void newFile(AwFileIO *reader);
void setRootDir(const QString& path);
......@@ -66,7 +62,6 @@ public:
inline bool isBIDSActive() { return !m_rootDir.isEmpty(); }
inline bool mustValidateMods() { return !m_modifications.isEmpty(); }
void closeBIDS();
// inline AwBIDSSubject *getSubject() { return m_currentSubject; }
AwBIDSNodes& subjects() { return m_nodes; }
void toBIDS(const AwArguments& args);
......@@ -78,10 +73,6 @@ public:
// BIDS GUI Specific
QWidget *ui() { return m_ui; }
AwBIDSSubjectList& getSubjectsFromSourceDir(int sourceDir = raw);
/** guess subject from a file. Set the subject as the current subject if success. **/
// AwBIDSSubject *guessSubject(const QString& path);
// Access to some tsv files
AwChannelList getMontageFromChannelsTsv(const QString& path);
AwMarkerList getMarkersFromEventsTsv(const QString& path);
......@@ -93,33 +84,32 @@ public:
void saveTsvFile(const QString& path, const AwTSVDict& dict, const QStringList& orderedColumns);
void updateChannelsTsv(const QString& path);
void updateEventsTsv(const QString& path);
/** try to find the subject in which the data file is stored. **/
AwBIDSNode *findSubject(const QString& dataFilePath);
/** Get the companion tsv file of a data file. Returns empty string if the file does not exist **/
QString getTSVFile(const QString& dataFilePath, int tsvType);
signals:
void log(const QString& message);
void BIDSClosed();
protected:
AwBIDSManager();
static AwBIDSManager *m_instance;
static QStringList m_dataFileSuffixes; // list of suffix for known data file (_ieeg, _eeg, ...)
QHash<QString, QVariant> m_settings;
//int convert4DNI(const AwArguments& args, AwFileIO *reader, const QString& dataFile);
int convertFile(AwFileIO *reader, AwFileIOPlugin *plugin, const QString& file);
//void getSubjects(int sourceDir = raw);
//void clearSubjects(int sourceDir = raw);
//AwFileItem *parseDir(const QString& fullPath, const QString& path);
//void parseSubject(AwBIDSSubject *subject);
//AwBIDSSubject *getSubject(const QString& ID, int sourceDir = raw);
QString getParsingPath();
void modifyUpdateJson(const QStringList& branches);
QMap<int, QString> m_modifications;
AwBIDSGUI *m_ui;
QString m_rootDir;
AwBIDSSubjectList m_subjects[AWBIDS_SOURCE_DIRS];
QMap<QString, AwBIDSSubject *> m_subjectsIDs[AWBIDS_SOURCE_DIRS];
QMap<int, QString> m_knownDerivativesPaths;
QStringList m_fileExtensions; // contains all file extensions that reader plugins can handle.
// keep the subject associated with the current open file in AnyWave
AwBIDSSubject *m_currentSubject;
AwBIDSNode *m_currentSubject;
AwBIDSNodes m_nodes;
QHash<QString, AwBIDSNode *> m_IDToSubject;
bool m_mustValidateModifications;
......
......@@ -37,4 +37,35 @@ AwBIDSNode::~AwBIDSNode()
{
while (!m_children.isEmpty())
delete m_children.takeFirst();
}
///
/// findNode:
/// given a subject node, browse though children nodes to find the data file.
/// filePath must be the filename only not the full path.
AwBIDSNode *AwBIDSNode::findNode(const QString& filePath, AwBIDSNode *node)
{
if (node->m_files.contains(filePath))
return node;
for (auto child : node->m_children)
return findNode(filePath, child);
return nullptr;
}
QStringList AwBIDSNode::findFiles(AwBIDSNode *node)
{
QStringList res;
if (node->m_children.isEmpty()) {
res += node->files();
return res;
}
for (auto child : node->m_children)
return findFiles(child);
return res;
}
QStringList AwBIDSNode::gatherFiles()
{
return findFiles(this);
}
\ No newline at end of file
......@@ -43,11 +43,16 @@ public:
inline QString& ID() { return m_ID; }
inline QList<AwBIDSNode *>& children() { return m_children; }
inline QStringList& files() { return m_files; }
/** return all the files contained in the node and the child nodes. **/
QStringList gatherFiles();
AwBIDSNode * addChild(AwBIDSNode *node) { m_children.append(node); return node; }
void addFiles(const QStringList& files) { m_files.append(files); }
/** Find child node which contains the file. **/
AwBIDSNode *findNode(const QString& fileName, AwBIDSNode *node);
protected:
QStringList findFiles(AwBIDSNode *node);
QString m_parentDir, m_ID, m_fullPath;
// a node may contain files
QStringList m_files;
......
......@@ -353,18 +353,11 @@ void AwMarkerManager::updateMarkersFromEventsTsv(const QString& filePath)
if (!BM->isBIDSActive())