Skip to content
Snippets Groups Projects
Commit 7e3313da authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: improve Qt process reporter

parent c22cc528
No related branches found
No related tags found
No related merge requests found
......@@ -85,7 +85,7 @@ int main(int argc, char* argv[])
// Create GUI based on module
QtWidgetView* gui = new QtWidgetView(app);
gui->CreateGui();
gui->show();
gui->GetMainWindow()->show();
// Start event processing loop
return qtApp.exec();
......
......@@ -18,6 +18,9 @@
#include "otbWrapperQtWidgetModel.h"
#include "otbWrapperOutputImageParameter.h"
//#include <stdio.h>
#include <time.h>
namespace otb
{
namespace Wrapper
......@@ -28,6 +31,7 @@ QtWidgetModel::QtWidgetModel(Application* app)
{
m_Application->Init();
m_ProgressWindow = new QWidget();
//m_Application->RegisterListener( this );
}
......@@ -45,8 +49,15 @@ void QtWidgetModel::ExecuteAndWriteOutput()
std::cout<<"********************************* ExecuteAndWriteOutput launched *********************************"<<std::endl;
AppliThread * taskAppli = new AppliThread( m_Application );
taskAppli->start();
WatchThread * taskWatch = new WatchThread( m_Application );
taskWatch->start();
//WatchThread * taskWatch = new WatchThread( m_Application, m_ProgressWindow );
//taskWatch->start();
std::cout<<"********************************* ExecuteAndWriteOutput reporting *********************************"<<std::endl;
// Prepare the progressbar window
std::cout<<"********************************** end ExecuteAndWriteOutput thread"<<std::endl;
//m_Application->ExecuteAndWriteOutput();
}
......
......@@ -49,22 +49,23 @@ private:
void operator=(const AppliThread&); //purposely not implemented
Application::Pointer m_Application;
QWidget * m_ProgressWindow;
};
class WatchThread : public QThread
{
Q_OBJECT
public:
WatchThread(Application* app)
WatchThread(Application* app, QWidget * pWin)
{
m_Application = app;
m_ProgressWindow = pWin;
}
virtual ~WatchThread(){};
void run()
{
// Prepare the progressbar window
QWidget * progWin = new QWidget();
//QWidget * progWin = new QWidget();
QVBoxLayout *layout = new QVBoxLayout;
std::vector< QProgressBar * > barListIntern, barListWriter;
......@@ -104,8 +105,8 @@ virtual ~WatchThread(){};
}
}
progWin->setLayout(layout);
progWin->show();
m_ProgressWindow->setLayout(layout);
//m_ProgressWindow->show();
double curWriterProgress = 0;
unsigned int curWriter = 0;
......@@ -120,7 +121,7 @@ virtual ~WatchThread(){};
{
//oss<< "doexe "<<i<<": "<<m_Application->GetDoExecuteProgress()[i] <<std::flush;
barListIntern[i]->setValue( static_cast<int>(progCount[i]*100 ));
progWin->update();
//m_ProgressWindow->update();
}
// Writer watcher
......@@ -136,14 +137,14 @@ virtual ~WatchThread(){};
//std::cout<<"progress writer: "<<curProg<<"."<<std::flush;
barListWriter[curWriter]->setValue( static_cast<int>(curProg*100) );
curWriterProgress = curProg;
progWin->update();
//m_ProgressWindow->update();
}
}
this->msleep(500);
}
progWin->close();
std::cout<<"waaaaaaatch done"<<std::endl;
//m_ProgressWindow->close();
}
private:
......@@ -151,14 +152,14 @@ private:
void operator=(const WatchThread&); //purposely not implemented
Application::Pointer m_Application;
QWidget * m_ProgressWindow;
};
/** \class
* \brief
*/
class QtWidgetModel : public QObject/*, public EventsListener<std::string>*/
class QtWidgetModel : public QObject /*, public EventsListener<std::string>*/
{
Q_OBJECT
public:
......@@ -171,13 +172,13 @@ public:
return m_Application;
}
// slot called when execution is requested
void ExecuteAndWriteOutput();
protected slots:
// slot called everytime one of the widget is updated
void NotifyUpdate();
// slot called when execution is requested
void ExecuteAndWriteOutput();
//void Notify();
private:
......@@ -185,9 +186,11 @@ private:
void operator=(const QtWidgetModel&); //purposely not implemented
Application::Pointer m_Application;
QWidget * m_ProgressWindow;
};
}
}
......
......@@ -29,6 +29,9 @@ QtWidgetView::QtWidgetView(Application* app)
{
m_Model = new QtWidgetModel(app);
m_Application = app;
m_MainWindow = new QWidget();
m_ProgressWindow = new QWidget();
//m_Application->RegisterListener( this );
}
......@@ -41,13 +44,13 @@ QtWidgetView::~QtWidgetView()
void QtWidgetView::CreateGui()
{
// Create a VBoxLayout with the header, the input widgets, and the footer
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QVBoxLayout *mainLayout = new QVBoxLayout(m_MainWindow);//this);
mainLayout->addWidget(CreateHeader());
mainLayout->addWidget(CreateInputWidgets());
mainLayout->addWidget(CreateFooter());
QGroupBox *mainGroup = new QGroupBox(this);
QGroupBox *mainGroup = new QGroupBox(m_MainWindow);//this);
mainGroup->setLayout(mainLayout);
// Put the main group inside a scroll area
......@@ -56,16 +59,17 @@ void QtWidgetView::CreateGui()
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QVBoxLayout *scrollLayout = new QVBoxLayout(this);
QVBoxLayout *scrollLayout = new QVBoxLayout(m_MainWindow);//this);
scrollLayout->addWidget(scrollArea);
// Make the scroll layout the main layout
this->setLayout(scrollLayout);
this->setWindowIcon(QIcon( ":/otb_small.png" ));
this->setWindowTitle(QString(m_Model->GetApplication()->GetName()).append(" - version ").append(OTB_VERSION_STRING));
m_MainWindow->setLayout(scrollLayout);
m_MainWindow->setWindowIcon(QIcon( ":/otb_small.png" ));
m_MainWindow->setWindowTitle(QString(m_Model->GetApplication()->GetName()).append(" - version ").append(OTB_VERSION_STRING));
// Tweak the window size so that it looks ok (TODO : find the way to make it perfectly symmetric)
this->resize(mainGroup->sizeHint() + scrollArea->verticalScrollBar()->size());
m_MainWindow->resize(mainGroup->sizeHint() + scrollArea->verticalScrollBar()->size());
//m_ProgressWindow->show();
}
QWidget* QtWidgetView::CreateHeader()
......@@ -128,11 +132,12 @@ QWidget* QtWidgetView::CreateFooter()
//m_ExecButton->setStyleSheet("border-style: none");
m_ExecButton->setDefault(true);
m_ExecButton->setText(QObject::tr("Execute"));
connect( m_ExecButton, SIGNAL(clicked()), m_Model, SLOT(ExecuteAndWriteOutput() ) );
//connect( m_ExecButton, SIGNAL(clicked()), m_Model, SLOT(ExecuteAndWriteOutput() ) );
connect( m_ExecButton, SIGNAL(clicked()), this, SLOT(ExecuteAndWriteOutputSlot() ) );
m_QuitButton = new QPushButton(footerGroup);
m_QuitButton->setText(QObject::tr("Quit"));
connect( m_QuitButton, SIGNAL(clicked()), this, SLOT(close()) );
connect( m_QuitButton, SIGNAL(clicked()), this, SLOT(m_MainWindow->close()) );
// Put the buttons on the right
//footerLayout->addWidget(m_ProgressLabel);
......@@ -144,6 +149,117 @@ QWidget* QtWidgetView::CreateFooter()
return footerGroup;
}
void QtWidgetView::ExecuteAndWriteOutputSlot()
{
m_Model->ExecuteAndWriteOutput();
//QWidget * progWin = new QWidget();
//QTextEdit * progWin = new QTextEdit();
//progWin->setWindowTitle( "Progress reporting..." );
//progWin->resize(700, 700);
m_ProgressWindow->setWindowTitle( "Progress reporting..." );
//m_ProgressWindow->resize(700, 700);
QVBoxLayout *layout = new QVBoxLayout;
std::vector< QProgressBar * > barListIntern, barListWriter;
std::vector< QLabel * > labelListIntern, labelListWriter;
if( m_Application->GetInternalProcessList().size() != m_Application->GetInternalProcessListName().size())
{
itkGenericExceptionMacro ("Internal process list and list name size mismatch...");
}
for(unsigned int ii=0; ii<m_Application->GetInternalProcessList().size(); ii++)
{
QLabel *label = new QLabel(QString(m_Application->GetInternalProcessListName()[ii].c_str()));
QProgressBar * bar = new QProgressBar();
layout->addWidget(label);
layout->addWidget(bar);
barListIntern.push_back(bar);
labelListIntern.push_back(label);
std::cout<<"********************************* progress added "<<std::endl;
}
unsigned int nbOutput = 0;
std::vector<std::string> paramList = m_Application->GetParametersKeys(true);
for (std::vector<std::string>::const_iterator it = paramList.begin();
it != paramList.end();
++it)
{
if ( m_Application->GetParameterType(*it) == ParameterType_OutputImage)
{
itk::OStringStream oss;
oss << "Writer "<<nbOutput;
QLabel *label = new QLabel(QString(oss.str().c_str()));
QProgressBar * bar = new QProgressBar();
layout->addWidget(label);
layout->addWidget(bar);
barListWriter.push_back(bar);
labelListWriter.push_back(label);
nbOutput++;
std::cout<<"********************************* wrietr added "<<std::endl;
}
}
//progWin->setLayout(layout);
//progWin->update();
//progWin->show();
m_ProgressWindow->setLayout(layout);
m_ProgressWindow->update();
std::cout<<"********************************* ExecuteAndWriteOutput window will be displayed *********************************"<<std::endl;
m_ProgressWindow->show();
QCoreApplication::processEvents();
std::cout<<"********************************* ExecuteAndWriteOutput window displayed *********************************"<<std::endl;
double curWriterProgress = 0;
unsigned int curWriter = 0;
unsigned int countt = 0;
while( m_Application->GetExecuteAndWriteOutputDone() == false )
{
//progWin->setText( QString(countt) );
//progWin->repaint();
itk::OStringStream oss;
oss.str("");
// Internal DoExecute process watcher
std::vector<double> progCount = m_Application->GetDoExecuteProgress();
for(unsigned int i=0; i<progCount.size(); i++)
{
//oss<< "doexe "<<i<<": "<<m_Application->GetDoExecuteProgress()[i] <<std::flush;
barListIntern[i]->setValue( static_cast<int>(progCount[i]*100 ));
//progWin->update();
m_ProgressWindow->update();
QCoreApplication::processEvents();
}
// Writer watcher
if( nbOutput > 0)
{
double curProg = m_Application->GetExecuteProgress();
if( curProg > -1 )
{
if( curWriterProgress > curProg )
{
curWriter++;
}
std::cout<<curProg<<"."<<std::flush;
barListWriter[curWriter]->setValue( static_cast<int>(curProg*100) );
curWriterProgress = curProg;
//progWin->update();
m_ProgressWindow->update();
QCoreApplication::processEvents();
}
}
sleep(1);
}
//progWin->close();
m_ProgressWindow->close();
}
}
}
......@@ -32,7 +32,7 @@ namespace Wrapper
/** \class
* \brief
*/
class QtWidgetView : public QWidget/*, public EventsListener<std::string>*/
class QtWidgetView : public QObject /* QWidget*/ /*, public EventsListener<std::string>*/
{
Q_OBJECT
public:
......@@ -41,6 +41,14 @@ public:
void CreateGui();
QWidget * GetMainWindow()
{
return m_MainWindow;
}
public slots:
void ExecuteAndWriteOutputSlot();
private:
QtWidgetView(const QtWidgetView&); //purposely not implemented
void operator=(const QtWidgetView&); //purposely not implemented
......@@ -55,8 +63,11 @@ private:
QtWidgetModel* m_Model;
QWidget * m_MainWindow;
QPushButton* m_ExecButton;
QPushButton* m_QuitButton;
QWidget * m_ProgressWindow;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment