From c44ad0d6bf822ff2638bdb41d1807e55cc24ebc4 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sat, 25 Feb 2017 15:53:02 +0100 Subject: [PATCH] full implementation of musrStep functionality. --- src/musredit_qt5/PTextEdit.cpp | 76 +++++++++++++++++++++++++++++++++- src/musredit_qt5/PTextEdit.h | 3 ++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/musredit_qt5/PTextEdit.cpp b/src/musredit_qt5/PTextEdit.cpp index ff256bed..e29ee699 100644 --- a/src/musredit_qt5/PTextEdit.cpp +++ b/src/musredit_qt5/PTextEdit.cpp @@ -2266,7 +2266,55 @@ void PTextEdit::musrSetSteps() if ( !currentEditor() ) return; - QMessageBox::information(this, "**INFO**", "Eventually this will allow to set the\nstep values of the current msr-file."); + // make sure I have a saved msr-file to work on + QString tabLabel = fTabWidget->tabText(fTabWidget->currentIndex()); + if (tabLabel == "noname") { + QMessageBox::critical(this, "**ERROR**", "For musrStep a real mlog/msr-file is needed."); + return; + } else if (tabLabel == "noname*") { + fileSaveAs(); + } else if (tabLabel.indexOf("*") > 0) { + fileSave(); + } + + // fill the command queue + QString cmd = fAdmin->getExecPath() + "/musrStep"; + QString workDir = QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(); + QStringList arg; + QString str; + + // get file name and feed it to the command queue + str = *fFilenames.find( currentEditor() ); + int pos = str.lastIndexOf("/"); + if (pos != -1) + str.remove(0, pos+1); + arg << str; + + QProcess *proc = new QProcess(this); + if (proc == nullptr) { + QMessageBox::critical(0, "**ERROR**", "Couldn't invoke QProcess!"); + return; + } + + // handle return status of musrStep + connect(proc, static_cast(&QProcess::finished), + [=](int exitCode, QProcess::ExitStatus exitStatus){ exitStatusMusrSetSteps(exitCode, exitStatus); }); + + // make sure that the system environment variables are properly set + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("LD_LIBRARY_PATH", env.value("ROOTSYS") + "/lib:" + env.value("LD_LIBRARY_PATH")); + proc->setProcessEnvironment(env); + proc->setWorkingDirectory(workDir); + proc->start(cmd, arg); + if (!proc->waitForStarted()) { + // error handling + QString msg(tr("Could not execute the output command: ")+cmd[0]); + QMessageBox::critical( 0, + tr("Fatal error"), + msg, + tr("Quit") ); + return; + } } //---------------------------------------------------------------------------------------------------- @@ -2424,6 +2472,32 @@ void PTextEdit::helpAboutQt() QMessageBox::aboutQt(this); } + +//---------------------------------------------------------------------------------------------------- +/** + * @brief PTextEdit::existStatusMusrSetSteps + * @param exitCode + * @param exitStatus + */ +void PTextEdit::exitStatusMusrSetSteps(int exitCode, QProcess::ExitStatus exitStatus) +{ + if (exitStatus == QProcess::CrashExit) { + QMessageBox::critical(0, "**FATAL**", "musrStep returned CrashExit."); + return; + } + + // dialog finished with reject + if (exitCode == 0) + return; + + // dialog finished with save and quite, i.e. accept, hence reload + QString fln = *fFilenames.find( currentEditor() ); + int idx = fTabWidget->currentIndex(); + + fileClose(); + load(fln, idx); +} + //---------------------------------------------------------------------------------------------------- /** *

SLOT: called when the font shall be changed. diff --git a/src/musredit_qt5/PTextEdit.h b/src/musredit_qt5/PTextEdit.h index 7235cbd7..9e1863d5 100644 --- a/src/musredit_qt5/PTextEdit.h +++ b/src/musredit_qt5/PTextEdit.h @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -141,6 +142,8 @@ private slots: void helpAboutQt(); void helpAbout(); + void exitStatusMusrSetSteps(int exitCode, QProcess::ExitStatus exitStatus); + void fontChanged( const QFont &f ); void textChanged(const bool forced = false); void currentCursorPosition();