diff --git a/mainwindow.cpp b/mainwindow.cpp index 1c897f0..10aa940 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1674,6 +1674,7 @@ void MainWindow::SetupNewExpPanel(){ QPushButton *bnChangeBranch = new QPushButton("Change", &dialog); layout->addWidget(bnChangeBranch, rowID, 3); + bnChangeBranch->setAutoDefault(false); connect(bnChangeBranch, &QPushButton::clicked, this, [=](){ this->ChangeExperiment(cb->currentText()); }); connect(bnChangeBranch, &QPushButton::clicked, &dialog, &QDialog::accept); @@ -1684,9 +1685,11 @@ void MainWindow::SetupNewExpPanel(){ }else{ for( int i = 0; i < branches.size(); i++){ if( i == bID ) continue; + if( branches[i].contains("HEAD")) continue; + if( branches[i].contains(presentBranch)) continue; cb->addItem(branches[i].remove(" ")); } - if ( branches.size() == 1) { + if ( cb->count() == 0) { cb->setEnabled(false); cb->addItem("no other branch"); bnChangeBranch->setEnabled(false); @@ -1694,11 +1697,11 @@ void MainWindow::SetupNewExpPanel(){ } connect(cbUseGit, &QCheckBox::clicked, this, [=](){ - if( branches.size() > 1 ) cb->setEnabled(cbUseGit->isChecked()); - }); - connect(cbUseGit, &QCheckBox::clicked, this, [=](){ - if(branches.size() > 1 ) bnChangeBranch->setEnabled(cbUseGit->isChecked()); - }); + if( cb->count() > 1 ) { + cb->setEnabled(cbUseGit->isChecked()); + bnChangeBranch->setEnabled(cbUseGit->isChecked()); + } + }); //------- type existing or new experiment rowID ++; @@ -1708,15 +1711,28 @@ void MainWindow::SetupNewExpPanel(){ QLineEdit * newExp = new QLineEdit("type and Enter", &dialog); layout->addWidget(newExp, rowID, 1, 1, 2); + //newExp->setFocus(); - QPushButton *button1 = new QPushButton("Create", &dialog); - layout->addWidget(button1, rowID, 3); - button1->setEnabled(false); + QPushButton *bnCreateNewExp = new QPushButton("Create", &dialog); + layout->addWidget(bnCreateNewExp, rowID, 3); + bnCreateNewExp->setEnabled(false); + bnCreateNewExp->setAutoDefault(false); - connect(newExp, &QLineEdit::textChanged, this, [=](){ newExp->setStyleSheet("color : green;");}); - connect(newExp, &QLineEdit::returnPressed, this, [=](){ if( newExp->text() != "") { newExp->setStyleSheet(""); button1->setEnabled(true);}}); - connect(button1, &QPushButton::clicked, this, [=](){ this->CreateNewExperiment(newExp->text());}); - connect(button1, &QPushButton::clicked, &dialog, &QDialog::accept); + connect(newExp, &QLineEdit::textChanged, this, [=](){ + newExp->setStyleSheet("color : blue;"); + if( newExp->text() == "") bnCreateNewExp->setEnabled(false); + }); + + connect(newExp, &QLineEdit::returnPressed, this, [=](){ + if( newExp->text() != "") { + newExp->setStyleSheet(""); + bnCreateNewExp->setEnabled(true); + } + + }); + + connect(bnCreateNewExp, &QPushButton::clicked, this, [=](){ this->CreateNewExperiment(newExp->text());}); + connect(bnCreateNewExp, &QPushButton::clicked, &dialog, &QDialog::accept); //----- diable all possible actions //?---- don't know why isGitExist && !isCleanGit does not work @@ -1726,12 +1742,13 @@ void MainWindow::SetupNewExpPanel(){ cb->setEnabled(false); bnChangeBranch->setEnabled(false); newExp->setEnabled(false); - button1->setEnabled(false); + bnCreateNewExp->setEnabled(false); } } //--------- cancel rowID ++; QPushButton *bnCancel = new QPushButton("Cancel", &dialog); + bnCancel->setAutoDefault(false); layout->addWidget(bnCancel, rowID, 0, 1, 4); connect(bnCancel, &QPushButton::clicked, this, [=](){this->LogMsg("Cancel New/Change/Reload Exp");}); connect(bnCancel, &QPushButton::clicked, &dialog, &QDialog::reject); @@ -1804,6 +1821,7 @@ bool MainWindow::LoadExpSettings(){ void MainWindow::CreateNewExperiment(const QString newExpName){ + LogMsg("======================================"); LogMsg("Creating new Exp. : " + newExpName + ""); expName = newExpName; @@ -1841,10 +1859,27 @@ void MainWindow::CreateNewExperiment(const QString newExpName){ git.start("git", QStringList() << "commit" << "-m" << "initial commit."); git.waitForFinished(); - LogMsg("Commit branch : " + newExpName + " as \"initial commit\""); + LogMsg("Commit branch : " + expName + " as \"initial commit\""); + + //check if remote exist, if exist, push to remote + git.start("git", QStringList() << "remote" ); + git.waitForFinished(); + + QString haha = QString::fromLocal8Bit(git.readAllStandardOutput()); + + if( haha != ""){ + git.start("git", QStringList() << "push" << "--set-upstream" << haha.remove('\n') << expName); + git.waitForFinished(); + + qDebug() << QString::fromLocal8Bit(git.readAllStandardOutput()); + LogMsg("Pushed new branch : " + expName + " to remote repositiory."); + } + } - CheckElog(); + //CheckElog(); + logMsgHTMLMode = true; + LogMsg(" !!!! Please Create a new Elog with name " + newExpName + ". "); leRawDataPath->setText(rawDataFolder); leExpName->setText(expName); @@ -1861,21 +1896,26 @@ void MainWindow::CreateNewExperiment(const QString newExpName){ influx->WriteData(DatabaseName.toStdString()); } - } void MainWindow::ChangeExperiment(const QString newExpName){ - //@---- git must exist. + expName = newExpName; + if( newExpName.contains("remotes")){ + QStringList haha = newExpName.split('/'); + expName = haha.last(); + } + //@---- git must exist. QProcess git; git.setWorkingDirectory(analysisPath); - git.start("git", QStringList() << "checkout" << newExpName); + git.start("git", QStringList() << "checkout" << expName); git.waitForFinished(); - LogMsg("Swicted to branch : " + newExpName + ""); - expName = newExpName; + LogMsg("============================================="); + LogMsg("Swicted to branch : " + expName + ""); + CreateRawDataFolderAndLink(); LoadExpSettings(); @@ -1915,7 +1955,7 @@ void MainWindow::CreateRawDataFolderAndLink(){ QDir dir; if( !dir.exists(rawDataFolder)){ if( dir.mkdir(rawDataFolder)){ - LogMsg("" + rawDataFolder + " created." ); + LogMsg("Created folder " + rawDataFolder + " for storing raw data." ); }else{ LogMsg("" + rawDataFolder + " cannot be created. Access right problem? " ); } @@ -1924,11 +1964,11 @@ void MainWindow::CreateRawDataFolderAndLink(){ } //----- create root data folder - rootDataFolder = rootDataFolder + "/" + expName; + rootDataFolder = rootDataPath + "/" + expName; QDir rootDir; if( !rootDir.exists(rootDataFolder)) { if( rootDir.mkdir(rootDataFolder) ){ - LogMsg("Created folder " + rootDataFolder + " for storing root files"); + LogMsg("Created folder " + rootDataFolder + " for storing root files."); }else{ LogMsg("" + rootDataFolder + " cannot be created. Access right problem? " ); } @@ -1954,6 +1994,7 @@ void MainWindow::CreateRawDataFolderAndLink(){ if( file.exists(linkName)) { file.remove(linkName); + LogMsg("removing existing Link"); } if (file.link(rawDataFolder, linkName)) { @@ -1962,9 +2003,10 @@ void MainWindow::CreateRawDataFolderAndLink(){ LogMsg("Symbolic link " + linkName +" -> " + rawDataFolder + " cannot be created. "); } - linkName = analysisPath + "root_data"; + linkName = analysisPath + "/root_data"; if( file.exists(linkName)) { file.remove(linkName); + LogMsg("removing existing Link"); } if (file.link(rawDataFolder, linkName)) {