1- #include " mainwindow.h"
1+ #include " mainwindow.h"
22#include " ui_mainwindow.h"
33
44#include < QDateTime>
@@ -41,8 +41,8 @@ MainWindow::MainWindow(QWidget *parent, const char *config_file)
4141 QMessageBox::about (this , " About LabRecorder" , infostr);
4242 });
4343
44- // Wheenver locationEdit is changed, print the final result.
45- connect (ui->locationEdit , &QLineEdit::textChanged, this , &MainWindow::printReplacedFilename);
44+ // Wheenver lineEdit_template is changed, print the final result.
45+ connect (ui->lineEdit_template , &QLineEdit::textChanged, this , &MainWindow::printReplacedFilename);
4646 auto spinchanged = static_cast <void (QSpinBox::*)(int )>(&QSpinBox::valueChanged);
4747 connect (ui->experimentNumberSpin , spinchanged, this , &MainWindow::printReplacedFilename);
4848 connect (ui->spinBox_run , spinchanged, this , &MainWindow::printReplacedFilename);
@@ -56,6 +56,18 @@ MainWindow::MainWindow(QWidget *parent, const char *config_file)
5656 connect (ui->lineEdit_participant , &QLineEdit::editingFinished, this , &MainWindow::buildFilename);
5757 connect (ui->lineEdit_session , &QLineEdit::editingFinished, this , &MainWindow::buildFilename);
5858 connect (ui->lineEdit_acq , &QLineEdit::editingFinished, this , &MainWindow::buildFilename);
59+ connect (ui->input_blocktask , &QComboBox::currentTextChanged, this , &MainWindow::buildFilename);
60+ connect (ui->check_bids , &QCheckBox::toggled, [this ](bool checked){
61+ auto & box = *ui->lineEdit_template ;
62+ box.setReadOnly (checked);
63+ if (checked) {
64+ legacyTemplate = box.text ();
65+ box.setText (
66+ QStringLiteral (" sub-%p/ses-%s/eeg/sub-%p_ses-%s_task-%b[_acq-%a]_run-%r_eeg.xdf" ));
67+ } else {
68+ box.setText (legacyTemplate);
69+ }
70+ });
5971
6072 load_config (config_file);
6173
@@ -70,7 +82,7 @@ MainWindow::~MainWindow() noexcept = default;
7082void MainWindow::statusUpdate () const {
7183 if (currentRecording) {
7284 auto elapsed = static_cast <unsigned int >(lsl::local_clock () - startTime);
73- QString recFilename = replaceFilename (ui->locationEdit ->text ());
85+ QString recFilename = replaceFilename (ui->lineEdit_template ->text ());
7486 auto fileinfo = QFileInfo (recFilename);
7587 fileinfo.refresh ();
7688 auto size = fileinfo.size ();
@@ -136,38 +148,28 @@ void MainWindow::load_config(QString filename) {
136148 // ----------------------------
137149 // Block/Task Names
138150 // ----------------------------
139- // Clear out any widgets where block/task name goes.
140- QLayoutItem *child = ui->horizontalLayout_blockTask ->takeAt (1 );
141- if (child != 0 ) { delete child; }
142151 QStringList taskNames;
143152 if (pt.contains (" SessionBlocks" )) { taskNames = pt.value (" SessionBlocks" ).toStringList (); }
144- hasTasks = !taskNames.empty ();
145- if (hasTasks) {
146- taskBox = new QComboBox ();
147- taskBox->addItems (taskNames);
148- connect (taskBox,
149- static_cast <void (QComboBox::*)(const QString &)>(&QComboBox::activated), this ,
150- &MainWindow::blockSelected);
151- ui->horizontalLayout_blockTask ->addWidget (taskBox);
153+ ui->input_blocktask ->clear ();
154+ ui->input_blocktask ->insertItems (0 , taskNames);
152155
156+ // StudyRoot
157+ if (pt.contains (" StudyRoot" )) {
158+ ui->rootEdit ->setText (pt.value (" StudyRoot" ).toString ());
153159 } else {
154- taskEdit = new QLineEdit ();
155- connect (taskEdit, &QLineEdit::editingFinished, this , &MainWindow::printReplacedFilename);
156- ui->horizontalLayout_blockTask ->addWidget (taskEdit);
160+ ui->rootEdit ->setText (
161+ QStandardPaths::writableLocation (QStandardPaths::DocumentsLocation));
157162 }
158163
159- // StudyRoot
160- if (pt.contains (" StudyRoot" )) { ui->rootEdit ->setText (pt.value (" StudyRoot" ).toString ()); }
161-
162164 // StorageLocation
163165 QString str_path = pt.value (" StorageLocation" , " " ).toString ();
164- ui->locationEdit ->setText (str_path);
166+ ui->lineEdit_template ->setText (str_path);
165167 if (str_path.length () == 0 ) { buildFilename (); }
166168
167169 // Check the wild-card-replaced filename to see if it exists already.
168170 // If it does then increment the exp number.
169171 // We only do this on settings-load because manual spin changes might indicate purposeful overwriting.
170- QString recFilename = ui->locationEdit ->text ();
172+ QString recFilename = ui->lineEdit_template ->text ();
171173 // Spin Number
172174 if (recFilename.contains (QStringLiteral (" %n" ))) {
173175 for (int i = 1 ; i < 1001 ; i++) {
@@ -183,7 +185,7 @@ void MainWindow::load_config(QString filename) {
183185
184186void MainWindow::save_config (QString filename) {
185187 QSettings settings (filename, QSettings::Format::IniFormat);
186- settings.setValue (" StorageLocation" , ui->locationEdit ->text ());
188+ settings.setValue (" StorageLocation" , ui->lineEdit_template ->text ());
187189 qInfo () << requiredStreams;
188190 settings.setValue (" RequiredStreams" , requiredStreams);
189191 // Stub.
@@ -259,7 +261,7 @@ void MainWindow::startRecording() {
259261 }
260262
261263 // Handle wildcards in filename.
262- QString recFilename = replaceFilename (ui->locationEdit ->text ());
264+ QString recFilename = replaceFilename (ui->lineEdit_template ->text ());
263265 if (recFilename.isEmpty ()) {
264266 QMessageBox::critical (this , " Filename empty" , " Can not record without a file name" );
265267 return ;
@@ -361,18 +363,17 @@ void MainWindow::buildFilename() {
361363
362364 // Build the file location in parts, starting with the root folder.
363365 QStringList fileparts = QStringList (ui->rootEdit ->text ());
366+ bool hasTasks = ui->input_blocktask ->currentText ().isEmpty ();
364367
365- bool use_bids = (!ui->lineEdit_participant ->text ().isEmpty ()) ||
366- (!ui->lineEdit_session ->text ().isEmpty ()) ||
367- (!ui->lineEdit_acq ->text ().isEmpty ());
368+ bool use_bids = ui->check_bids ->isChecked ();
368369 if (use_bids) {
369370 // path/to/CurrentStudy/sub-%p/ses-%s/eeg/sub-%p_ses-%s_task-%b[_acq-%a]_run-%r_eeg.xdf
370371
371372 // Make sure the BIDS required fields are full.
372373 if (ui->lineEdit_participant ->text ().isEmpty ()) { ui->lineEdit_participant ->setText (" P001" ); }
373374 if (ui->lineEdit_session ->text ().isEmpty ()) { ui->lineEdit_session ->setText (" S001" ); }
374- if (!hasTasks && taskEdit-> text ().isEmpty ()) { taskEdit-> setText (" Default" ); }
375-
375+ if (ui-> input_blocktask -> currentText ().isEmpty ()) { ui-> input_blocktask -> setCurrentText (" Default" ); }
376+
376377 // Folder hierarchy
377378 fileparts << " sub-%p"
378379 << " ses-%s"
@@ -411,10 +412,10 @@ void MainWindow::buildFilename() {
411412 if (!QDir (replaceFilename (recFilename)).exists ()) { break ; }
412413 }
413414 }
414- // Sometimes locationEdit doesn't change so printReplacedFilename isn't triggered.
415+ // Sometimes lineEdit_template doesn't change so printReplacedFilename isn't triggered.
415416 // So trigger manually.
416- if (ui->locationEdit ->text () == recFilename) { printReplacedFilename (); }
417- ui->locationEdit ->setText (recFilename);
417+ if (ui->lineEdit_template ->text () == recFilename) { printReplacedFilename (); }
418+ ui->lineEdit_template ->setText (recFilename);
418419}
419420
420421QString MainWindow::replaceFilename (QString fullfile) const {
@@ -425,11 +426,7 @@ QString MainWindow::replaceFilename(QString fullfile) const {
425426 // Where %n will be replaced by the contents of the experimentNumberSpin widget
426427 // and %b will be replaced by the contents of the blockList widget.
427428 fullfile.replace (" %n" , QString (" %1" ).arg (ui->experimentNumberSpin ->value (), 3 , 10 , QChar (' 0' )));
428- if (hasTasks) {
429- fullfile.replace (" %b" , taskBox->currentText ());
430- } else {
431- fullfile.replace (" %b" , taskEdit->text ());
432- }
429+ fullfile.replace (" %b" , ui->input_blocktask ->currentText ());
433430
434431 // BIDS
435432 // See https://docs.google.com/document/d/1ArMZ9Y_quTKXC-jNXZksnedK2VHHoKP3HCeO5HPcgLE/
@@ -445,5 +442,5 @@ QString MainWindow::replaceFilename(QString fullfile) const {
445442}
446443
447444void MainWindow::printReplacedFilename () {
448- ui->locationLabel ->setText (replaceFilename (ui->locationEdit ->text ()));
445+ ui->locationLabel ->setText (replaceFilename (ui->lineEdit_template ->text ()));
449446}
0 commit comments