better handling of fitting process
This commit is contained in:
@ -29,6 +29,8 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <qtimer.h>
|
||||||
|
|
||||||
#include "PFitOutputHandler.h"
|
#include "PFitOutputHandler.h"
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -41,31 +43,30 @@ PFitOutputHandler::PFitOutputHandler(QString workingDirectory, QValueVector<QStr
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
vbox = new QVBox( this );
|
fVbox = new QVBox( this );
|
||||||
vbox->resize(800, 500);
|
fVbox->resize(800, 500);
|
||||||
output = new QTextEdit( vbox );
|
fOutput = new QTextEdit( fVbox );
|
||||||
output->setMinimumSize(800, 455);
|
fOutput->setMinimumSize(800, 455);
|
||||||
output->setReadOnly(true);
|
fOutput->setReadOnly(true);
|
||||||
quitButton = new QPushButton( tr("Done"), vbox );
|
fQuitButton = new QPushButton( tr("Fitting..."), fVbox );
|
||||||
connect( quitButton, SIGNAL(clicked()),
|
connect( fQuitButton, SIGNAL( clicked() ), this, SLOT( quitButtonPressed() ) );
|
||||||
this, SLOT(accept()) );
|
|
||||||
resize( 800, 500 );
|
resize( 800, 500 );
|
||||||
quitButton->setFocus();
|
fQuitButton->setFocus();
|
||||||
|
|
||||||
// QProcess related code
|
// QProcess related code
|
||||||
proc = new QProcess( this );
|
fProc = new QProcess( this );
|
||||||
|
|
||||||
proc->setWorkingDirectory(workingDirectory);
|
fProc->setWorkingDirectory(workingDirectory);
|
||||||
|
|
||||||
// Set up the command and arguments.
|
// Set up the command and arguments.
|
||||||
for (unsigned int i=0; i<cmd.size(); i++)
|
for (unsigned int i=0; i<cmd.size(); i++)
|
||||||
proc->addArgument(cmd[i]);
|
fProc->addArgument(cmd[i]);
|
||||||
|
|
||||||
connect( proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdOut()) );
|
connect( fProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdOut() ) );
|
||||||
connect( proc, SIGNAL(readyReadStderr()), this, SLOT(readFromStdErr()) );
|
connect( fProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStdErr() ) );
|
||||||
// connect( proc, SIGNAL(processExited()), this, SLOT(scrollToTop()) );
|
connect( fProc, SIGNAL( processExited() ), this, SLOT( processDone() ) );
|
||||||
|
|
||||||
if ( !proc->start() ) {
|
if ( !fProc->start() ) {
|
||||||
// error handling
|
// error handling
|
||||||
QMessageBox::critical( 0,
|
QMessageBox::critical( 0,
|
||||||
tr("Fatal error"),
|
tr("Fatal error"),
|
||||||
@ -83,7 +84,7 @@ void PFitOutputHandler::readFromStdOut()
|
|||||||
{
|
{
|
||||||
// Read and process the data.
|
// Read and process the data.
|
||||||
// Bear in mind that the data might be output in chunks.
|
// Bear in mind that the data might be output in chunks.
|
||||||
output->append( proc->readStdout() );
|
fOutput->append( fProc->readStdout() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -94,7 +95,31 @@ void PFitOutputHandler::readFromStdErr()
|
|||||||
{
|
{
|
||||||
// Read and process the data.
|
// Read and process the data.
|
||||||
// Bear in mind that the data might be output in chunks.
|
// Bear in mind that the data might be output in chunks.
|
||||||
output->append( proc->readStderr() );
|
fOutput->append( fProc->readStderr() );
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
void PFitOutputHandler::processDone()
|
||||||
|
{
|
||||||
|
fQuitButton->setText("Done");
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
void PFitOutputHandler::quitButtonPressed()
|
||||||
|
{
|
||||||
|
// if the fitting is still taking place, kill it
|
||||||
|
if (fProc->isRunning()) {
|
||||||
|
fProc->tryTerminate();
|
||||||
|
QTimer::singleShot( 100, fProc, SLOT( kill() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
@ -51,15 +51,17 @@ public:
|
|||||||
PFitOutputHandler(QString workingDirectory, QValueVector<QString> &cmd);
|
PFitOutputHandler(QString workingDirectory, QValueVector<QString> &cmd);
|
||||||
~PFitOutputHandler() {}
|
~PFitOutputHandler() {}
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void readFromStdOut();
|
void readFromStdOut();
|
||||||
void readFromStdErr();
|
void readFromStdErr();
|
||||||
|
void quitButtonPressed();
|
||||||
|
void processDone();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QProcess *proc;
|
QProcess *fProc;
|
||||||
QVBox *vbox;
|
QVBox *fVbox;
|
||||||
QTextEdit *output;
|
QTextEdit *fOutput;
|
||||||
QPushButton *quitButton;
|
QPushButton *fQuitButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PFITOUTPUTHANDLER_H_
|
#endif // _PFITOUTPUTHANDLER_H_
|
||||||
|
Reference in New Issue
Block a user