diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx index 1f6c09eda3659460d223a0a6daedb8355dc2f92f..cb7ca8418d81961a6cb92503bc5289a1cdaa5c4b 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.cxx @@ -30,11 +30,15 @@ QtWidgetProgressReport::QtWidgetProgressReport(QtWidgetModel * model) : m_IsProg m_Model = model; connect(model, SIGNAL(SetProgressReportBegin()), this, SLOT(ReportProgress()) ); connect(model, SIGNAL(SetProgressReportDone()), this, SLOT(close()) ); + connect(model, SIGNAL(SetProgressReportDone()), this, SLOT(RemoveLayout()) ); + + m_Layout = new QVBoxLayout; + this->setLayout(m_Layout); } QtWidgetProgressReport::~QtWidgetProgressReport() { - + delete m_Layout; } void QtWidgetProgressReport::SetApplication(Application::Pointer app) @@ -44,73 +48,81 @@ void QtWidgetProgressReport::SetApplication(Application::Pointer app) void QtWidgetProgressReport::ReportProgress() { + // clear previous progress bar added + m_BarListIntern.clear(); + m_BarListWriter.clear(); + m_LabelListIntern.clear(); + m_LabelListWriter.clear(); + // show the widget if closed due to a previous execution this->show(); + + if( m_Application->GetInternalProcessList().size() != m_Application->GetInternalProcessListName().size()) + { + itkGenericExceptionMacro ("Internal process list and list name size mismatch..."); + } - if(!m_IsProgressReportGuiAlreadyBuilt) + // Build the window : First internal process + for (unsigned int ii=0; ii < m_Application->GetInternalProcessList().size(); ii++) { - QVBoxLayout *layout = new QVBoxLayout; - this->setLayout(layout); + // Create a itk::QtProgressBar, observing the event ProgressEvent + itk::QtProgressBar * bar = new itk::QtProgressBar(this); + connect( bar, SIGNAL(SetValueChanged(int)), bar, SLOT(setValue(int)) ); + connect( m_Model, SIGNAL(SetProgressReportDone()), bar, SLOT(reset()) ); + bar->Observe(m_Application->GetInternalProcessList()[ii]); + + // label + QLabel *label = new QLabel(QString(m_Application->GetInternalProcessListName()[ii].c_str())); - if( m_Application->GetInternalProcessList().size() != m_Application->GetInternalProcessListName().size()) + // Build the layout and store the pointers + m_Layout->addWidget(label); + m_Layout->addWidget(bar); + m_BarListIntern.push_back(bar); + m_LabelListIntern.push_back(label); + } + + // Build the window : then writers + 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) { - itkGenericExceptionMacro ("Internal process list and list name size mismatch..."); - } + Parameter* param = m_Application->GetParameterByKey(*it); + OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); + + // create the label including the output description + itk::OStringStream oss; + oss << "Writer "<< nbOutput << ": "; + oss << outputParam->GetName() <<"."; + QLabel *label = new QLabel(QString(oss.str().c_str())); - // Build the window : First internal process - for (unsigned int ii=0; ii < m_Application->GetInternalProcessList().size(); ii++) - { // Create a itk::QtProgressBar, observing the event ProgressEvent itk::QtProgressBar * bar = new itk::QtProgressBar(this); connect( bar, SIGNAL(SetValueChanged(int)), bar, SLOT(setValue(int)) ); connect( m_Model, SIGNAL(SetProgressReportDone()), bar, SLOT(reset()) ); - bar->Observe(m_Application->GetInternalProcessList()[ii]); + bar->Observe(outputParam->GetWriter()); - // label - QLabel *label = new QLabel(QString(m_Application->GetInternalProcessListName()[ii].c_str())); - // Build the layout and store the pointers - layout->addWidget(label); - layout->addWidget(bar); - m_BarListIntern.push_back(bar); - m_LabelListIntern.push_back(label); + bar->setToolTip( QString( outputParam->GetDescription()) ); + m_Layout->addWidget(label); + m_Layout->addWidget(bar); + m_BarListWriter.push_back(bar); + m_LabelListWriter.push_back(label); } - - // Build the window : then writers - 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) - { - Parameter* param = m_Application->GetParameterByKey(*it); - OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); - - // create the label including the output description - itk::OStringStream oss; - oss << "Writer "<< nbOutput << ": "; - oss << outputParam->GetName() <<"."; - QLabel *label = new QLabel(QString(oss.str().c_str())); - - // Create a itk::QtProgressBar, observing the event ProgressEvent - itk::QtProgressBar * bar = new itk::QtProgressBar(this); - connect( bar, SIGNAL(SetValueChanged(int)), bar, SLOT(setValue(int)) ); - connect( m_Model, SIGNAL(SetProgressReportDone()), bar, SLOT(reset()) ); - - bar->Observe(outputParam->GetWriter()); - - // Build the layout and store the pointers - bar->setToolTip( QString( outputParam->GetDescription()) ); - layout->addWidget(label); - layout->addWidget(bar); - m_BarListWriter.push_back(bar); - m_LabelListWriter.push_back(label); - } - } - - m_IsProgressReportGuiAlreadyBuilt = true; + } +} + +void QtWidgetProgressReport::RemoveLayout() +{ + // Remove the children of the layout (progress bar widgets) + QLayoutItem *child; + while ((child = this->layout()->takeAt(0)) != 0) + { + delete child->widget(); + delete child; } } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h index 996ff932f936d73f195a65b8d28657d237a6df91..4eb93861fbf8af726ef9caa0a474ae5fc1c70a74 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetProgressReport.h @@ -43,6 +43,7 @@ public: public slots: void ReportProgress(); + void RemoveLayout(); private: QtWidgetProgressReport(const QtWidgetProgressReport&); //purposely not implemented @@ -57,6 +58,7 @@ private: std::vector< QLabel * > m_LabelListWriter; bool m_IsProgressReportGuiAlreadyBuilt; + QVBoxLayout * m_Layout; };