diff --git a/Modules/Radiometry/Indices/include/otbRadiometricIndex.h b/Modules/Radiometry/Indices/include/otbRadiometricIndex.h index d65213a2ec63b3a6d40e575b01b5f29b5847e53c..15cdba6cade2b34deeda96c9ac8df401d7652992 100644 --- a/Modules/Radiometry/Indices/include/otbRadiometricIndex.h +++ b/Modules/Radiometry/Indices/include/otbRadiometricIndex.h @@ -194,7 +194,7 @@ protected: */ double Value(BandNameType band, const itk::VariableLengthVector<TInput>& input) const { - assert(m_RequiredBands[band] && "Retrieving value for a band that is not in the required bands list"); + assert(m_RequiredBands[static_cast<size_t>(band)] && "Retrieving value for a band that is not in the required bands list"); return static_cast<double>(input[UncheckedBandIndex(band) - 1]); } diff --git a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx index bc26e07f5895a108c5fe37dfa81407d5f3fd2190..35070d00b1d89ea7befc6c61d6253681905d1c8b 100644 --- a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx +++ b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx @@ -1372,56 +1372,6 @@ MainWindow { assert( e!=NULL ); - { - // - // List OTB-application widgets. - typedef QList< mvd::Wrapper::QtWidgetView * > QtWidgetViewList; - - QtWidgetViewList c( findChildren< mvd::Wrapper::QtWidgetView * >() ); - - QStringList names; - - // - // Find out which OTB-applications are running. - for( QtWidgetViewList::iterator it( c.begin() ); - it!=c.end(); - ++ it ) - { - assert( *it ); - - if( !( *it )->IsClosable() ) - { - assert( ( *it )->GetModel()->GetApplication() ); - - // qDebug() << "OTB-application:" << ( *it )->GetApplication()->GetDocName(); - - names.push_back( ( *it )->GetModel()->GetApplication()->GetDocName() ); - } - } - - // - // If some OTB-application is running, display warning, names and - // prevent to close. - if( !names.isEmpty() ) - { - QMessageBox::warning( - this, - tr( "Warning!" ), - tr( - PROJECT_NAME - " cannot exit while some OTB-application is running!\n\n" - "Please wait for following OTB-applicatio(s) to exit:\n- %1" - ) - .arg( names.join( "\n- " ) ) - ); - - e->ignore(); - - return; - } - } - - { assert( I18nCoreApplication::Instance()!=NULL ); assert( I18nCoreApplication::Instance()->GetModel()== diff --git a/Modules/Visualization/MonteverdiGui/include/mvdApplicationLauncher.h b/Modules/Visualization/MonteverdiGui/include/mvdApplicationLauncher.h index 378e76108c3abb7f40d031bf23bef5fd2f94fcb4..2d58061ed4eb36ab42cc460e65d639898badb32a 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdApplicationLauncher.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdApplicationLauncher.h @@ -62,7 +62,7 @@ public: otb::Wrapper::Application::Pointer PrepareApplication(const QString& appName, bool isStandalone = false) const; - otb::Wrapper::QtMainWindow* NewOtbApplicationWindow(const QString& appName, bool isStandalone = false, QWidget* p = nullptr, Qt::WindowFlags = 0) const; + otb::Wrapper::QtMainWindow* NewOtbApplicationWindow(const QString& appName, bool isStandalone = false, QWidget* p = nullptr) const; }; } // namespace mvd diff --git a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h index 313f8f1537af75ef500d0bff91a93d1b94bd204f..1be6f7514f2db902f0194de47ce26f78e8ac99a2 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h @@ -90,7 +90,7 @@ namespace Wrapper */ template< typename W > void -SetupForFilenameDrop( W* widget, const char* text =NULL ); +SetupForFilenameDrop( W* widget ); /** */ @@ -376,7 +376,7 @@ FileSelectionInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); } /*****************************************************************************/ @@ -387,7 +387,7 @@ InputImageInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); } /*****************************************************************************/ @@ -409,7 +409,7 @@ InputFilenameInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); } /*****************************************************************************/ @@ -431,7 +431,7 @@ InputVectorDataInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); } /*****************************************************************************/ @@ -453,7 +453,7 @@ InputProcessXMLInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); } /*****************************************************************************/ @@ -494,7 +494,7 @@ OutputImageInitializer if( m_Prefix.isEmpty() ) { - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); assert( qApp!=NULL ); assert( !qApp->arguments().empty() ); @@ -518,7 +518,7 @@ OutputVectorDataInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); assert( qApp!=NULL ); assert( !qApp->arguments().empty() ); @@ -534,7 +534,7 @@ OutputFilenameInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); assert( qApp!=NULL ); assert( !qApp->arguments().empty() ); @@ -550,7 +550,7 @@ OutputProcessXMLInitializer { assert( widget!=NULL ); - SetupForFilenameDrop( widget, "You can drop filename here." ); + SetupForFilenameDrop( widget ); assert( qApp!=NULL ); assert( !qApp->arguments().empty() ); @@ -592,7 +592,7 @@ ParameterListInitializer /*****************************************************************************/ template< typename W > void -SetupForFilenameDrop( W* widget, const char* text ) +SetupForFilenameDrop( W* widget ) { assert( widget!=NULL ); @@ -602,15 +602,12 @@ SetupForFilenameDrop( W* widget, const char* text ) // Setup widget. bool signalsBlocked = lineEdit->blockSignals( true ); { - if( text!=NULL ) - { lineEdit->setPlaceholderText( QCoreApplication::translate( "mvd::Wrapper::QtWidgetView", - text + "You can drop a file here" ) ); - } // lineEdit->setReadOnly( true ); diff --git a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetView.h b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetView.h index 146c4c250d0682939f48d03327d329cde971f7e6..931a561b2d9c358e6e6ecea635bcde0d8d78dad5 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetView.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetView.h @@ -64,18 +64,10 @@ namespace Wrapper class OTBMonteverdiGUI_EXPORT QtWidgetView : public otb::Wrapper::QtWidgetView { - /*-[ QOBJECT SECTION ]-----------------------------------------------------*/ - Q_OBJECT - /*-[ PUBLIC SECTION ]------------------------------------------------------*/ - -// -// Public methods. public: - /** - */ static char const * const OBJECT_NAME; /** \brief Constructor. */ @@ -86,30 +78,18 @@ public: /** \brief Destructor. */ ~QtWidgetView() override; -protected: + bool BeforeExecuteButtonClicked() override; +protected: QWidget* CreateInputWidgets() override; -protected slots: - - /** extend the behaviour of base class OnExecButtonClicked */ - void OnExecButtonClicked() override; - - /** modify the behaviour of base class OnExceptionRaised - */ - void OnExceptionRaised( QString what ) override; - private: QtWidgetView(const QtWidgetView&) = delete; void operator=(const QtWidgetView&) = delete; - /** - */ void SetupParameterWidgets( QWidget* widget ); - /** - */ void SetupFileSelectionWidget( QWidget * ); private slots: @@ -119,12 +99,8 @@ private slots: // image filename{s} set by the user in this OTB application (if any). void OnApplicationExecutionDone( int ); - /** - */ inline void OnFileSelectionWidgetAdded0( QWidget * ); - /** - */ inline void OnFileSelectionWidgetAdded1( QWidget * ); }; @@ -132,16 +108,12 @@ private slots: } // end namespace 'mvd' -/*****************************************************************************/ -/* INLINE SECTION */ - namespace mvd { namespace Wrapper { -/*******************************************************************************/ inline void QtWidgetView @@ -150,7 +122,6 @@ QtWidgetView SetupFileSelectionWidget( widget ); } -/*******************************************************************************/ inline void QtWidgetView diff --git a/Modules/Visualization/MonteverdiGui/src/mvdApplicationLauncher.cxx b/Modules/Visualization/MonteverdiGui/src/mvdApplicationLauncher.cxx index 61a40b9e6996dbddaabc9c9b12d4121d54244da3..b3ef6b7baf8217938c4edebc1e13e0aa1b4b4d0a 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdApplicationLauncher.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdApplicationLauncher.cxx @@ -179,12 +179,7 @@ ApplicationLauncher } -otb::Wrapper::QtMainWindow* -ApplicationLauncher -::NewOtbApplicationWindow( const QString & appName, - bool isStandalone, - QWidget* parent, - Qt::WindowFlags flags ) const +otb::Wrapper::QtMainWindow* ApplicationLauncher ::NewOtbApplicationWindow(const QString& appName, bool isStandalone, QWidget* parent) const { // Setup the otb application auto otbApp = PrepareApplication(appName, isStandalone); @@ -194,7 +189,7 @@ ApplicationLauncher gui->CreateGui(); // Make the application window - auto window = new ::otb::Wrapper::QtMainWindow(otbApp, gui, parent, flags | Qt::Window); + auto window = new ::otb::Wrapper::QtMainWindow(otbApp, gui, parent); return window; } diff --git a/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx b/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx index 53c723bc811bc7fba33e89e8d032f9c74df110bc..d074c1aae4c92205f06daacdc0420222233930dc 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx @@ -116,13 +116,6 @@ char const * const QtWidgetView ::OBJECT_NAME = "mvd::Wrapper::QtWidgetView"; -/*****************************************************************************/ -/* STATIC IMPLEMENTATION SECTION */ - - -/*****************************************************************************/ -/* CLASS IMPLEMENTATION SECTION */ -/*****************************************************************************/ QtWidgetView ::QtWidgetView( const otb::Wrapper::Application::Pointer & otbApp, QWidget* p, @@ -131,10 +124,6 @@ QtWidgetView { setObjectName( QtWidgetView::OBJECT_NAME ); - m_IconPathDone = std::string("<img src=\":/icons/done\" width=\"16\" height=\"16\" />"); - m_IconPathFailed = std::string("<img src=\":/icons/failed\" width=\"16\" height=\"16\" />"); - - // // need to be connected to the end of a process QObject::connect( GetModel(), @@ -158,10 +147,7 @@ QtWidgetView { QWidget * widget = otb::Wrapper::QtWidgetView::CreateInputWidgets(); - otb::Wrapper::QtWidgetParameterBase *paramWidget = - widget->findChild<otb::Wrapper::QtWidgetParameterBase*>(); - - SetupParameterWidgets(paramWidget); + SetupParameterWidgets(widget); return widget; } @@ -211,197 +197,90 @@ QtWidgetView initialize( qobject_cast< FileSelectionInitializer::argument_type >( widget ) ); } -/*******************************************************************************/ -/* SLOTS */ -/*******************************************************************************/ -void -QtWidgetView -::OnExecButtonClicked() +bool QtWidgetView::BeforeExecuteButtonClicked() { - if ( !IsRunning() ) + assert(GetModel() != NULL); + assert(GetModel()->GetApplication() != NULL); + assert(I18nCoreApplication::Instance() != NULL); + + // Get layer-stack, if any + StackedLayerModel* layerStack = I18nCoreApplication::Instance()->GetModel<StackedLayerModel>(); + + otb::Wrapper::Application::Pointer otbApp(GetModel()->GetApplication()); + + // Check output parameters of OTB-application + StringVector paramKeys(otbApp->GetParametersKeys()); + QStringList filenames1; + + KeyLayerAccumulator::KeyLayerPairList layers; + + for (StringVector::const_iterator it(paramKeys.begin()); it != paramKeys.end(); ++it) + { + if (otbApp->IsParameterEnabled(*it, true) && otbApp->HasValue(*it)) { - assert( GetModel()!=NULL ); - assert( GetModel()->GetApplication()!=NULL ); - - - assert( I18nCoreApplication::Instance()!=NULL ); - - // - // Get layer-stack, if any. - StackedLayerModel * layerStack = - I18nCoreApplication::Instance()->GetModel< StackedLayerModel >(); - - otb::Wrapper::Application::Pointer otbApp( GetModel()->GetApplication() ); - - // - // Check output parameters of OTB-application. - StringVector paramKeys( otbApp->GetParametersKeys() ); - QStringList filenames1; - - KeyLayerAccumulator::KeyLayerPairList layers; - QStringList filenames2; - - for( StringVector::const_iterator it( paramKeys.begin() ); - it!=paramKeys.end(); - ++it ) + otb::Wrapper::Parameter::Pointer param(otbApp->GetParameterByKey(*it)); + assert(!param.IsNull()); + + std::string filename; + + switch (otbApp->GetParameterType(*it)) { - if( otbApp->IsParameterEnabled( *it, true ) && - otbApp->HasValue( *it ) ) - { - otb::Wrapper::Parameter::Pointer param( otbApp->GetParameterByKey( *it ) ); - assert( !param.IsNull() ); - - // qDebug() - // << it->c_str() << ": type" << otbApp->GetParameterType( *it ); - - // const char* filename = NULL; - std::string filename; - - switch( otbApp->GetParameterType( *it ) ) - { - case otb::Wrapper::ParameterType_OutputFilename: - filename = - otb::DynamicCast< otb::Wrapper::OutputFilenameParameter >( param ) - ->GetValue(); - break; - // - // FILENAME. - // - // IMAGE. - case otb::Wrapper::ParameterType_OutputImage: - filename = - otb::DynamicCast< otb::Wrapper::OutputImageParameter >( param ) - ->GetFileName(); - break; - // - // VECTOR-DATA. - case otb::Wrapper::ParameterType_OutputVectorData: - filename = - otb::DynamicCast< otb::Wrapper::OutputVectorDataParameter >( param ) - ->GetFileName(); - break; - // - // NONE. - default: - break; + case otb::Wrapper::ParameterType_OutputFilename: + filename = otb::DynamicCast<otb::Wrapper::OutputFilenameParameter>(param)->GetValue(); + break; + + case otb::Wrapper::ParameterType_OutputImage: + filename = otb::DynamicCast<otb::Wrapper::OutputImageParameter>(param)->GetFileName(); + break; + + case otb::Wrapper::ParameterType_OutputVectorData: + filename = otb::DynamicCast<otb::Wrapper::OutputVectorDataParameter>(param)->GetFileName(); + break; + + default: + break; + } + + if (QFileInfo(filename.c_str()).exists()) + filenames1.push_back(filename.c_str()); + + if (layerStack != NULL) + { + KeyLayerAccumulator accumulator(std::for_each(layerStack->Begin(), layerStack->End(), KeyLayerAccumulator(filename, layers))); + } } - - if( QFileInfo( filename.c_str() ).exists() ) - filenames1.push_back( filename.c_str() ); - - if( layerStack!=NULL ) + } + + { + QString message; + + if (filenames1.size() == 1) { - KeyLayerAccumulator accumulator( - std::for_each( - layerStack->Begin(), - layerStack->End(), KeyLayerAccumulator( filename, layers ) - ) - ); - - if( accumulator.GetCount()>0 ) - filenames2.push_back( filename.c_str() ); + message = tr("Are you sure you want to overwrite file '%1'?").arg(filenames1.front()); } - } - } - + else if (filenames1.size() > 1) { - QString message; - - if( filenames1.size()==1 ) - { - // qDebug() - // << it->c_str() << ":" << QString( filename.c_str() ); - - message = - tr( "Are you sure you want to overwrite file '%1'?" ) - .arg( filenames1.front() ); - } - else if( filenames1.size()>1 ) - { - message = - tr( "Following files will be overwritten. Are you sure you want to continue?\n- %1" ) - .arg( filenames1.join( "\n- " ) ); - } - - if( !message.isEmpty() ) - { - QMessageBox::StandardButton button = - QMessageBox::question( - this, - PROJECT_NAME, - message, - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No - ); - - if( button==QMessageBox::No ) - return; - } + message = tr("Following files will be overwritten. Are you sure you want to continue?\n- %1").arg(filenames1.join("\n- ")); } - + + if (!message.isEmpty()) { - QString message; - - if( filenames2.size()==1 ) - { - // qDebug() - // << it->c_str() << ":" << QString( filename.c_str() ); - - message = - tr( "File '%1' is being viewed in " PROJECT_NAME " and will be concurrently overwritten by running this %2. File will be removed from layer-stack before running %2 and reloaded after.\n\nDo you want to continue?" ) - .arg( filenames2.front() ) - .arg( otbApp->GetDocName() ); - } - else if( filenames2.size()>1 ) - { - message = - tr( "Following files are being viewed in " PROJECT_NAME " and will be concurrently overwritter by running %2. Files will be removed from layer-stack before running %2. Do you want to continue?\n- %1" ) - .arg( filenames2.join( "\n- " ) ) - .arg( otbApp->GetDocName() ); - } - - if( !message.isEmpty() ) - { - QMessageBox::StandardButton button = - QMessageBox::question( - this, - PROJECT_NAME, - message, - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No - ); - - if( button==QMessageBox::No ) - return; - - while( !layers.empty() ) - { - layerStack->Delete( layers.front().first ); - - layers.pop_front(); - } - } + QMessageBox::StandardButton button = QMessageBox::question(this, PROJECT_NAME, message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + + if (button == QMessageBox::No) + return false; } } - otb::Wrapper::QtWidgetView::OnExecButtonClicked(); -} + // Delete from layer stack the images that will be overwritten and reloaded + while (!layers.empty()) + { + layerStack->Delete(layers.front().first); -/*******************************************************************************/ -void -QtWidgetView -::OnExceptionRaised( QString what ) -{ - qWarning() << what; + layers.pop_front(); + } -#if defined( OTB_DEBUG ) - QMessageBox::warning( - this, - PROJECT_NAME, - what, - QMessageBox::Ok - ); -#endif + return true; } /*******************************************************************************/ @@ -429,18 +308,6 @@ QtWidgetView return; } - /* - // Removed as per MVDX-259. - QMessageBox::information( - this, - PROJECT_NAME, - tr( "'%1' has succeeded.\n" - "Result(s) will be imported as dataset(s).\n") - .arg( otbApp->GetName() ), - QMessageBox::Ok - ); - */ - CountType count = 0; // diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h index 5b19add53105b36ef412e459231f76179d7c4396..136489e96ba1cfc9acfff1d4a29f89ed9083d471 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h @@ -105,6 +105,8 @@ public: TiXmlElement* ParseApplication(Application::Pointer app); + static std::string MakeCommandLine(otb::Wrapper::Application::Pointer application); + protected: OutputProcessXMLParameter(); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx index eaaf8c7c302f9085282eaa1169465477d8a50bbd..3b020d798980c922f491e80c263fd7590a93743c 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx @@ -366,6 +366,77 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group) } } +std::string OutputProcessXMLParameter::MakeCommandLine(Application::Pointer application) +{ + OutputProcessXMLParameter::Pointer outXMLParam = OutputProcessXMLParameter::New(); + TiXmlElement* XMLAppElement = outXMLParam->ParseApplication(application); + + // Create command line from the XML document + TiXmlElement * pName, *pParam; + std::ostringstream cmdLine; + + cmdLine << ""; + + if (XMLAppElement) + { + pName = XMLAppElement->FirstChildElement("name"); + + cmdLine << "otbcli_" << pName->GetText(); +#ifdef _WIN32 + cmdLine << ".bat"; +#endif + cmdLine << " "; + + // Parse application parameters + pParam = XMLAppElement->FirstChildElement("parameter"); + + while (pParam) + { + // Get parameter key + cmdLine << "-"; + cmdLine << pParam->FirstChildElement("key")->GetText(); + cmdLine << " "; + + // Some parameters can have multiple values. Test it and handle this + // specific case + TiXmlElement* values = pParam->FirstChildElement("values"); + + if (values) + { + // Loop over value + TiXmlElement* pValue = values->FirstChildElement("value"); + while (pValue) + { + cmdLine << pValue->GetText(); + cmdLine << " "; + + pValue = pValue->NextSiblingElement(); // iteration over multiple values + } + } + else + { + // Get parameter value + cmdLine << pParam->FirstChildElement("value")->GetText(); + cmdLine << " "; + + // In case of OutputImageparameter we need to report output pixel type + TiXmlElement* pPixType = pParam->FirstChildElement("pixtype"); + + if (pPixType) + { + cmdLine << pPixType->GetText(); + cmdLine << " "; + } + } + + pParam = pParam->NextSiblingElement(); // iteration over parameters + } + } + + return cmdLine.str(); +} + + } //end namespace wrapper } //end namespace otb diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h index 6e0a005b1f9d3cd8dba6276b40da9e9fd29c2e8d..70d922b8116411a6201c0cb9569d74534153ee34 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h @@ -22,12 +22,19 @@ #define otbWrapperQtWidgetMainWindow_h #include <QMainWindow> + #include "OTBQtWidgetExport.h" #include "otbWrapperApplication.h" +namespace Ui +{ +class AppMainWindow; +} + class QAction; class QMenu; +class QPlainTextEdit; namespace otb { @@ -41,16 +48,26 @@ class OTBQtWidget_EXPORT QtMainWindow : public QMainWindow Q_OBJECT public: - QtMainWindow(Application::Pointer app, QtWidgetView* gui, QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + QtMainWindow(Application::Pointer app, QtWidgetView* gui, QWidget* parent = nullptr); + ~QtMainWindow(); + + otb::Wrapper::QtWidgetView* Gui() const; + + void closeEvent(QCloseEvent* event) override; - QtWidgetView* Gui() const; +signals: + void ExecuteAndWriteOutput(); + void Stop(); public slots: void UnhandledException(QString message); + void UpdateMessageAfterApplicationReady(bool val); + void UpdateMessageAfterExecution(int status); + void on_executeButton_clicked(); + void CopyCommandLine(); private: - QMenu* helpMenu; - QAction* helpAction; + ::Ui::AppMainWindow* ui; QtWidgetView* gui; }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h index fa4c8ffe9216fdfb2bd5a4e82f66335ccc6edb16..13dffe9fe1078859117eb80c4ae90bdb1be445e4 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h @@ -37,17 +37,16 @@ class OTBQtWidget_EXPORT AppliThread : public QThread Q_OBJECT public: - AppliThread(Application* app) - { - m_Application = app; + AppliThread(Application::Pointer app) : m_Application(app) + { } ~AppliThread() override; - void Execute() + /** Ask the running application to stop */ + void Stop() { - // Call the signal start to begin running the program - start(); + m_Application->Stop(); } signals: @@ -66,13 +65,6 @@ signals: */ void ExceptionRaised( QString what ); -public slots: - /** Ask the running application to stop */ - void Stop() - { - m_Application->Stop(); - } - protected: void run() override; @@ -107,6 +99,10 @@ public: return m_LogOutput; } + bool IsRunning() const; + + void Stop(); + /** Logger warning message sender */ void SendLogWARNING( const std::string & mes ); /** Logger info message sender */ @@ -144,8 +140,6 @@ signals: void UpdateGui(); - void Stop(); - public slots: /** * \brief Slots called every time one of the widget needs to be @@ -168,19 +162,18 @@ private slots: */ void OnApplicationExecutionDone( int status ); - void TimerDone(); - private: QtWidgetModel(const QtWidgetModel&) = delete; void operator=(const QtWidgetModel&) = delete; - Application::Pointer m_Application; - QtLogOutput::Pointer m_LogOutput; + AppliThread* m_taskAppli; + bool m_IsRunning; - QTimer *m_Timer; +public: + Application::Pointer m_Application; }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetProgressReport.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetProgressReport.h deleted file mode 100644 index a8a46382f27497d7449980724ea9fe1c69fcda29..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetProgressReport.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbWrapperQtWidgetProgressReport_h -#define otbWrapperQtWidgetProgressReport_h - -#include <QtWidgets> -#include "otbWrapperQtWidgetModel.h" -#include "itkQtProgressBar.h" -#include "itkProcessObject.h" -#include <string> - - -namespace otb -{ -namespace Wrapper -{ - -/** \class QtWidgetProgressReport - * \brief Create a widget reporting the progress of the application - * process. - * - * \ingroup OTBQtWidget - */ -class OTBQtWidget_EXPORT QtWidgetProgressReport : public QWidget -{ - Q_OBJECT -public: - QtWidgetProgressReport(QtWidgetModel * model, QWidget * parent); - ~QtWidgetProgressReport() override; - - void SetApplication(Application::Pointer app); - - typedef itk::MemberCommand< QtWidgetProgressReport > AddProcessCommandType; - - void ProcessEvent( itk::Object * caller, const itk::EventObject & event ); - - std::string GetCurrentDescription() - { - return m_CurrentDescription; - } - -/* - itk::ProcessObject* GetCurrentProcess() - { - return m_CurrentProcess; - } - - QtWidgetModel * GetModel() - { - m_Model; - } - - QVBoxLayout * GetLayout() - { - return m_Layout; - } -*/ -public slots: - void RemoveLayout(); - /*virtual */void ReportProcess(); - - signals: - void AddNewProcessToReport(); - -private: - QtWidgetProgressReport(const QtWidgetProgressReport&) = delete; - void operator=(const QtWidgetProgressReport&) = delete; - - Application::Pointer m_Application; - QtWidgetModel * m_Model; - QVBoxLayout * m_Layout; - - AddProcessCommandType::Pointer m_AddProcessCommand; - itk::ProcessObject* m_CurrentProcess; - std::string m_CurrentDescription; -}; - -} -} - -#endif diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetSimpleProgressReport.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetSimpleProgressReport.h index 47b6c1a1504e075dd61c7a892addca54f10306f2..9bfc7be1dfc8b65f20c78624cbd487da93336a62 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetSimpleProgressReport.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetSimpleProgressReport.h @@ -39,14 +39,14 @@ namespace Wrapper * * \ingroup OTBQtWidget */ -class OTBQtWidget_EXPORT QtWidgetSimpleProgressReport : public QWidget +class OTBQtWidget_EXPORT QtWidgetSimpleProgressReport : public itk::QtProgressBar { Q_OBJECT public: - QtWidgetSimpleProgressReport(QtWidgetModel * model, QWidget * parent); + QtWidgetSimpleProgressReport(QWidget* parent); ~QtWidgetSimpleProgressReport() override; - void SetApplication(Application::Pointer app); + void SetModel(QtWidgetModel* model); typedef itk::MemberCommand< QtWidgetSimpleProgressReport > AddProcessCommandType; @@ -56,25 +56,17 @@ public slots: void Init(); void ReportProcess(); - signals: +signals: void AddNewProcessToReport(); + void SetText(QString); private: QtWidgetSimpleProgressReport(const QtWidgetSimpleProgressReport&) = delete; - void operator=(const QtWidgetSimpleProgressReport&); //purposely not - //implemented - - Application::Pointer m_Application; - QtWidgetModel * m_Model; - QVBoxLayout * m_Layout; + void operator=(const QtWidgetSimpleProgressReport&) = delete; AddProcessCommandType::Pointer m_AddProcessCommand; itk::ProcessObject* m_CurrentProcess; std::string m_CurrentDescription; - - itk::QtProgressBar * m_Bar; - QLabel * m_Label; - }; } diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h index 1ec99d5aae5e40497b4690b5d2c8f872d406b675..96b8d4f6ccd4eb370f09f041c7423cab144b0396 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h @@ -44,10 +44,6 @@ class OTBQtWidget_EXPORT QtWidgetView : { Q_OBJECT - Q_PROPERTY( bool isClosable - READ IsClosable - WRITE SetClosable ); - public: static char const * const OBJECT_NAME; @@ -66,12 +62,15 @@ public: /** \brief Model Accessor */ QtWidgetModel* GetModel() const; - bool IsClosable() const; + virtual bool BeforeExecuteButtonClicked() + { + return true; + } - void UnhandledException(QString message); + void Disable(); + void Enable(); signals: - void QuitSignal(); void ExecuteAndWriteOutput(); void Stop(); void OTBApplicationOutputImageChanged( const QString &, const QString &); @@ -83,24 +82,12 @@ protected: virtual QWidget* CreateInputWidgets(); - // QWidget overloads. - void closeEvent( QCloseEvent * event ) override; - -protected: - - /** Html section for 'Done' icon */ - std::string m_IconPathDone; - - /** Html section for 'Failed' icon */ - std::string m_IconPathFailed; - protected slots: - virtual void OnExecButtonClicked(); + virtual void OnExecButtonClicked() + { + } - virtual void OnExceptionRaised( QString what ); - -// Private methods. private: QtWidgetView(const QtWidgetView&) = delete; @@ -108,29 +95,10 @@ private: QWidget* CreateFooter(); -// Private attributes. private: - otb::Wrapper::QtWidgetModel* m_Model; - QPushButton* m_ExecButton; - QPushButton* m_QuitButton; - QShortcut* m_QuitShortcut; - QLabel* m_Message; - QTextEdit *m_LogText; - QTabWidget *m_TabWidget; - - bool m_IsClosable : 1; bool m_IsRunning; - -private slots: - void UpdateMessageAfterExecution(int status); - void UpdateMessageAfterApplicationReady(bool val); - - void OnProgressReportBegin(); - void OnProgressReportEnd( int status ); - void SetClosable( bool ); - }; } // end namespace 'Wrapper' diff --git a/Modules/Wrappers/QtWidget/src/CMakeLists.txt b/Modules/Wrappers/QtWidget/src/CMakeLists.txt index 94c61a93f8d95baa51b31df9fb62679260197c3d..41fc9f1b190b29da9d7272d41f245b0c06d1a863 100644 --- a/Modules/Wrappers/QtWidget/src/CMakeLists.txt +++ b/Modules/Wrappers/QtWidget/src/CMakeLists.txt @@ -44,7 +44,6 @@ set(OTBQtWidget_SRC otbWrapperQtWidgetParameterGroup.cxx otbWrapperQtWidgetInputFilenameListParameter.cxx otbWrapperQtWidgetRAMParameter.cxx - otbWrapperQtWidgetProgressReport.cxx otbWrapperQtWidgetOutputProcessXMLParameter.cxx otbWrapperQtWidgetParameterBase.cxx otbWrapperQtWidgetInputImageParameter.cxx @@ -79,7 +78,6 @@ set(OTBQtWidget_MOC_HDR ../include/otbWrapperQtWidgetModel.h ../include/otbWrapperQtWidgetView.h ../include/otbWrapperQtWidgetMainWindow.h - ../include/otbWrapperQtWidgetProgressReport.h ../include/otbWrapperQtWidgetListViewParameter.h ../include/otbQtFileSelectionWidget.h ../include/otbQtStringSelectionWidget.h @@ -101,6 +99,7 @@ set(OTBQtWidget_MOC_HDR set( OTBQtWidget_FORMS otbWrapperQtWidgetListEditWidget.ui + appmainwindow.ui ) set( OTBQtWidget_RESOURCES diff --git a/Modules/Wrappers/QtWidget/src/appmainwindow.ui b/Modules/Wrappers/QtWidget/src/appmainwindow.ui new file mode 100644 index 0000000000000000000000000000000000000000..c376f1984f3cec0518739bf1dd22fe3b6fb4f4be --- /dev/null +++ b/Modules/Wrappers/QtWidget/src/appmainwindow.ui @@ -0,0 +1,268 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AppMainWindow</class> + <widget class="QMainWindow" name="AppMainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>900</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <property name="windowIcon"> + <iconset resource="otbWrapperQtWidgetIcons.qrc"> + <normaloff>:/Utilities/Data/Icons/monteverdi-48x48.png</normaloff>:/Utilities/Data/Icons/monteverdi-48x48.png</iconset> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>16</number> + </property> + <property name="leftMargin"> + <number>16</number> + </property> + <property name="topMargin"> + <number>12</number> + </property> + <property name="rightMargin"> + <number>16</number> + </property> + <property name="bottomMargin"> + <number>12</number> + </property> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab1"> + <attribute name="title"> + <string>Parameters</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="spacing"> + <number>16</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QScrollArea" name="scrollArea"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>864</width> + <height>425</height> + </rect> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="spacing"> + <number>16</number> + </property> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab2"> + <attribute name="title"> + <string>Log</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="spacing"> + <number>16</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QPlainTextEdit" name="plainTextEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + <item> + <widget class="QLabel" name="message"> + <property name="text"> + <string>Status text</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>16</number> + </property> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <item> + <widget class="otb::Wrapper::QtWidgetSimpleProgressReport" name="progressBar"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="executeButton"> + <property name="text"> + <string>Execute</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>900</width> + <height>22</height> + </rect> + </property> + <widget class="QMenu" name="menuApplication"> + <property name="title"> + <string>Application</string> + </property> + <addaction name="separator"/> + <addaction name="actionCopy_command_line"/> + <addaction name="actionQuit"/> + </widget> + <widget class="QMenu" name="menuHelp"> + <property name="title"> + <string>Help</string> + </property> + <addaction name="actionDocumentation"/> + </widget> + <addaction name="menuApplication"/> + <addaction name="menuHelp"/> + </widget> + <widget class="QStatusBar" name="statusBar"> + <property name="styleSheet"> + <string notr="true">color: rgb(85, 87, 83);</string> + </property> + </widget> + <action name="actionDocumentation"> + <property name="text"> + <string>Documentation</string> + </property> + <property name="shortcut"> + <string>F1</string> + </property> + </action> + <action name="actionAboutOTB"> + <property name="text"> + <string>About</string> + </property> + </action> + <action name="actionAbout"> + <property name="text"> + <string>About</string> + </property> + </action> + <action name="actionView_log"> + <property name="text"> + <string>View log</string> + </property> + </action> + <action name="actionLoad_parameters"> + <property name="text"> + <string>Load parameters</string> + </property> + </action> + <action name="actionSave_parameters"> + <property name="text"> + <string>Save parameters</string> + </property> + </action> + <action name="actionQuit"> + <property name="text"> + <string>Quit</string> + </property> + <property name="shortcut"> + <string>Ctrl+Q</string> + </property> + </action> + <action name="actionReset_parameters"> + <property name="text"> + <string>Reset parameters</string> + </property> + </action> + <action name="actionReset"> + <property name="text"> + <string>Reset All</string> + </property> + </action> + <action name="actionLoad_from_XML"> + <property name="text"> + <string>Load from XML</string> + </property> + </action> + <action name="actionSave_to_XML"> + <property name="text"> + <string>Save to XML</string> + </property> + </action> + <action name="actionCopy_command_line"> + <property name="text"> + <string>Copy command line to clipboard</string> + </property> + </action> + </widget> + <customwidgets> + <customwidget> + <class>otb::Wrapper::QtWidgetSimpleProgressReport</class> + <extends>QProgressBar</extends> + <header>otbWrapperQtWidgetSimpleProgressReport.h</header> + </customwidget> + </customwidgets> + <resources> + <include location="otbWrapperQtWidgetIcons.qrc"/> + </resources> + <connections/> +</ui> diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIcons.qrc b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIcons.qrc index 60701a70320c2449e328d4cc1d3d907e79a5f4b4..6762620b11e830eb51ee174e56f891a3386c408e 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIcons.qrc +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIcons.qrc @@ -2,5 +2,6 @@ <qresource> <file>../../../../Utilities/Data/Icons/mIconClearText.png</file> <file>../../../../Utilities/Data/Icons/mIconClearTextHover.png</file> + <file>../../../../Utilities/Data/Icons/monteverdi-48x48.png</file> </qresource> </RCC> diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx index 736a3d8fdbcf847f532fa1fd3ac277ba8326f39c..1dd3dae0c592c43c685ac47ddcd33ef6fcd26ceb 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx @@ -120,7 +120,6 @@ void QtWidgetListViewParameter::DoCreateWidget() m_VLayout = new QHBoxLayout; m_VLayout->setContentsMargins(0, 0, 0, 0); m_VLayout->addWidget(m_ListView); - m_ListView->setMaximumSize(m_ListView->width() , 4* m_LineHeight); m_VLayout->activate(); this->setLayout(m_VLayout); @@ -144,6 +143,9 @@ void QtWidgetListViewParameter::SelectedItems() // make sure parameter is enabled m_ListViewParam->SetActive(true); m_ListViewParam->SetUserValue(true); + + // Call the application DoUpdateParameters, then all widgets' DoUpdateGUI (including this one) + this->GetModel()->NotifyUpdate(); } } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx index d185a8b9a9cc3689c0edf67394901f77036ef509..93c3f459e2e43b49d43e879a84e3f83ccfa30345 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx @@ -21,44 +21,143 @@ #include "otbWrapperQtWidgetMainWindow.h" #include <QtWidgets> + #include "otbWrapperQtWidgetView.h" +#include "otbWrapperQtWidgetOutputProcessXMLParameter.h" + +#include "ui_appmainwindow.h" namespace otb { namespace Wrapper { -QtMainWindow::QtMainWindow(Application::Pointer app, QtWidgetView* gui, QWidget* parent, Qt::WindowFlags flags) : - QMainWindow(parent, flags), - gui(gui) +QtMainWindow::QtMainWindow(Application::Pointer app, QtWidgetView* gui, QWidget* parent) : QMainWindow(parent), ui(new Ui::AppMainWindow), gui(gui) { - this->setWindowIcon(QIcon(":/otb_small.png")); - this->setWindowTitle(QString(app->GetDocName()).append(" - ").append(OTB_VERSION_STRING)); + ui->setupUi(this); + + // Setup the "View command line" widget + this->setWindowTitle(QString(app->GetName()).append(" - OTB ").append(OTB_VERSION_STRING)); // Set the given application view widget gui->setParent(this); - this->setCentralWidget(gui); - - // Connect the View "Quit" signal, to the mainWindow close slot - connect(gui, &QtWidgetView::QuitSignal, this, &QMainWindow::close); - - // Setup the help menu - QMenu* helpMenu = this->menuBar()->addMenu(tr("&Help")); - helpAction = new QAction(tr("&Documentation"), this); - helpAction->setShortcuts(QKeySequence::HelpContents); - helpMenu->addAction(helpAction); - const std::string url = std::string("https://www.orfeo-toolbox.org/CookBook/Applications/app_") + app->GetName() + std::string(".html"); - QObject::connect(helpAction, &QAction::triggered, this, [=] { QDesktopServices::openUrl(QUrl(QString::fromStdString(url))); }); + ui->scrollArea->setWidget(gui); + + // Connect menu buttons + connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); + const auto url = std::string("https://www.orfeo-toolbox.org/CookBook/Applications/app_") + app->GetName() + std::string(".html"); + connect(ui->actionDocumentation, &QAction::triggered, this, [=] { QDesktopServices::openUrl(QUrl(QString::fromStdString(url))); }); + + connect(ui->actionCopy_command_line, &QAction::triggered, this, &QtMainWindow::CopyCommandLine); + + // Setup execute / cancel button + ui->executeButton->setDefault(true); + ui->executeButton->setEnabled(false); + ui->executeButton->setText(QObject::tr("Execute")); + + connect(gui->GetModel(), &QtWidgetModel::SetApplicationReady, ui->executeButton, &QPushButton::setEnabled); + connect(this, &QtMainWindow::ExecuteAndWriteOutput, gui->GetModel(), &QtWidgetModel::ExecuteAndWriteOutputSlot); + + connect(gui->GetModel(), &QtWidgetModel::SetApplicationReady, this, &QtMainWindow::UpdateMessageAfterApplicationReady); + connect(gui->GetModel(), &QtWidgetModel::SetProgressReportDone, this, &QtMainWindow::UpdateMessageAfterExecution); + + connect(gui->GetModel(), &QtWidgetModel::ExceptionRaised, [&] { ui->tabWidget->setCurrentIndex(1); }); + + // Status bar and message default text + ui->statusBar->showMessage(tr("Select parameters")); + ui->message->setText(""); + + // Setup the progress bar to observe the model + ui->progressBar->SetModel(gui->GetModel()); + + // Connect application progress text to the QLabel + connect(ui->progressBar, &QtWidgetSimpleProgressReport::SetText, ui->message, &QLabel::setText); + + // Connect log output to the textEdit area + connect(gui->GetModel()->GetLogOutput(), &QtLogOutput::NewContentLog, ui->plainTextEdit, &QPlainTextEdit::appendPlainText); } -QtWidgetView* QtMainWindow::Gui() const +void QtMainWindow::UpdateMessageAfterApplicationReady(bool val) +{ + if (!gui->GetModel()->IsRunning()) + { + if (val == true) + { + ui->statusBar->showMessage(tr("Ready to run")); + } + else + { + ui->statusBar->showMessage(tr("Select parameters")); + } + } +} + +void QtMainWindow::UpdateMessageAfterExecution(int status) +{ + if (status >= 0) + { + ui->statusBar->showMessage(tr("Done")); + } + else + { + ui->statusBar->showMessage(tr("Failed!")); + } + ui->executeButton->setText(tr("Execute")); + gui->Enable(); +} + +void QtMainWindow::on_executeButton_clicked() +{ + if (gui->GetModel()->IsRunning()) + { + ui->statusBar->showMessage(tr("Cancelling...")); + gui->GetModel()->Stop(); + } + else + { + if (gui->BeforeExecuteButtonClicked()) + { + gui->Disable(); + ui->statusBar->showMessage(tr("Running...")); + ui->executeButton->setText(tr("Cancel")); + emit ExecuteAndWriteOutput(); + } + } +} + +void QtMainWindow::CopyCommandLine() +{ + // Get command line + std::string cmdLine = OutputProcessXMLParameter::MakeCommandLine(gui->GetModel()->m_Application); + + // Copy it to clipboard + QClipboard* clipboard = QGuiApplication::clipboard(); + clipboard->setText(QString::fromStdString(cmdLine)); + + // Also show it in the log + gui->GetModel()->SendLogINFO(cmdLine); +} + +QtMainWindow::~QtMainWindow() +{ + delete ui; +} + +otb::Wrapper::QtWidgetView* QtMainWindow::Gui() const { return gui; } void QtMainWindow::UnhandledException(QString message) { - gui->UnhandledException(message); + ui->plainTextEdit->appendPlainText(message); + ui->tabWidget->setCurrentIndex(1); +} + +void QtMainWindow::closeEvent(QCloseEvent* event) +{ + gui->GetModel()->Stop(); + QMainWindow::closeEvent(event); } } // namespace Wrapper diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx index 6803a555110064cfcb0199661c6280313618b32b..dc0e9278dd532fed974eb1c8adc900e9fc5fd32b 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx @@ -31,11 +31,7 @@ namespace otb namespace Wrapper { -QtWidgetModel -::QtWidgetModel(Application* app) : - m_Application(app), - m_LogOutput(), - m_IsRunning(false) +QtWidgetModel ::QtWidgetModel(Application* app) : m_LogOutput(), m_taskAppli(nullptr), m_IsRunning(false), m_Application(app) { // Init only if not already done if(!m_Application->IsInitialized()) @@ -47,23 +43,19 @@ QtWidgetModel // Attach log output to the Application logger m_Application->GetLogger()->AddLogOutput(m_LogOutput); - - m_Timer = new QTimer(this); - m_Timer->setSingleShot(true); - m_Timer->setInterval(1000); - QObject::connect( m_Timer, &QTimer::timeout, this, &QtWidgetModel::TimerDone ); } QtWidgetModel::~QtWidgetModel() { - if (m_Timer) - delete m_Timer; + delete m_taskAppli; } void QtWidgetModel ::NotifyUpdate() { + assert(!m_IsRunning && "Cannot update parameters while application is running."); + // Update the parameters try { @@ -118,108 +110,39 @@ QtWidgetModel emit SetApplicationReady(false); m_IsRunning = true; - //Buld corresponding command line and display to the Log tab - - //Build XML DOM from m_application - OutputProcessXMLParameter::Pointer outXMLParam = OutputProcessXMLParameter::New(); - - TiXmlElement* XMLAppElement = outXMLParam->ParseApplication(m_Application); - - //Create command line from the XML document - TiXmlElement * pName, *pParam; - std::ostringstream cmdLine; - - cmdLine << ""; - - if(XMLAppElement) - { - pName = XMLAppElement->FirstChildElement("name"); - - cmdLine << "otbcli_" << pName->GetText(); -#ifdef _WIN32 - cmdLine << ".bat"; -#endif - cmdLine << " "; - - //Parse application parameters - pParam = XMLAppElement->FirstChildElement("parameter"); - - while(pParam) - { - //Get parameter key - cmdLine << "-"; - cmdLine << pParam->FirstChildElement("key")->GetText(); - cmdLine << " "; - - //Some parameters can have multiple values. Test it and handle this - //specific case - TiXmlElement * values = pParam->FirstChildElement("values"); - - if (values) - { - //Loop over value - TiXmlElement * pValue = values->FirstChildElement("value"); - while(pValue) - { - cmdLine << pValue->GetText(); - cmdLine << " "; - - pValue = pValue->NextSiblingElement(); // iteration over multiple values - } - } - else - { - //Get parameter value - cmdLine << pParam->FirstChildElement("value")->GetText(); - cmdLine << " "; - - //In case of OutputImageparameter we need to report output pixel type - TiXmlElement * pPixType = pParam->FirstChildElement("pixtype"); - - if (pPixType) - { - cmdLine << pPixType->GetText(); - cmdLine << " "; - } - } - - pParam = pParam->NextSiblingElement(); // iteration over parameters - } - - //Insert a new line character at the end of the command line - cmdLine << std::endl; - - //Report the command line string to the application logger - m_Application->GetLogger()->Write(itk::LoggerBase::INFO, cmdLine.str()); - } - // launch the output image writing - AppliThread *taskAppli = new AppliThread( m_Application ); - - QObject::connect( taskAppli, &AppliThread::ExceptionRaised, - this, &QtWidgetModel::ExceptionRaised ); + delete m_taskAppli; + m_taskAppli = new AppliThread(m_Application); - QObject::connect( taskAppli, &AppliThread::ApplicationExecutionDone, - this, &QtWidgetModel::OnApplicationExecutionDone ); + QObject::connect(m_taskAppli, &AppliThread::ExceptionRaised, this, &QtWidgetModel::ExceptionRaised); - QObject::connect( taskAppli, &AppliThread::finished, - taskAppli, &AppliThread::deleteLater ); - - QObject::connect( this, &QtWidgetModel::Stop, - taskAppli, &AppliThread::Stop ); + QObject::connect(m_taskAppli, &AppliThread::ApplicationExecutionDone, this, &QtWidgetModel::OnApplicationExecutionDone); // Tell the Progress Reporter to begin emit SetProgressReportBegin(); - taskAppli->Execute(); + // Run the application + m_taskAppli->start(); emit SetApplicationReady(true); } +void QtWidgetModel::Stop() +{ + if (m_taskAppli && m_IsRunning) + { + m_taskAppli->Stop(); + m_taskAppli->wait(); + m_IsRunning = false; + } +} + void QtWidgetModel ::OnApplicationExecutionDone( int status ) { + m_IsRunning = false; + // For the progressReport to close the Progress widget // and the GUI to update message emit SetProgressReportDone( status ); @@ -230,18 +153,6 @@ QtWidgetModel oss << "Execution took "<< m_Application->GetLastExecutionTiming() << " sec"; SendLogINFO(oss.str()); } - - // start timer - m_Timer->start(); -} - -void -QtWidgetModel -::TimerDone() -{ - m_IsRunning = false; - // Require GUI update. - NotifyUpdate(); } void @@ -333,6 +244,10 @@ AppliThread emit ApplicationExecutionDone( result ); } +bool QtWidgetModel::IsRunning() const +{ + return m_IsRunning; +} } } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx index 61c72aa250beeeffbc613e8f2beec7728dbfe7ef..5aadbca9ef2e90ef9261442586dc71882302a225 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx @@ -50,8 +50,7 @@ void QtWidgetParameterGroup::DoCreateWidget() { // a GridLayout with two columns : parameter label / parameter widget QGridLayout *gridLayout = new QGridLayout; - gridLayout->setSpacing(1); - gridLayout->setContentsMargins(0, 0, 0, 0); + this->setLayout(gridLayout); unsigned int nbParams = m_ParamList->GetNumberOfParameters(); for (unsigned int i = 0; i < nbParams; ++i) @@ -139,8 +138,6 @@ void QtWidgetParameterGroup::DoCreateWidget() } } } - - this->setLayout(gridLayout); } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetProgressReport.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetProgressReport.cxx deleted file mode 100644 index 4e958f82b2078727d204d1363c27a7579d2717ed..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetProgressReport.cxx +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "otbWrapperQtWidgetProgressReport.h" -#include "otbWrapperOutputImageParameter.h" -#include "itksys/SystemTools.hxx" - -#include "otbWrapperAddProcessToWatchEvent.h" - -namespace otb -{ -namespace Wrapper -{ - -QtWidgetProgressReport::QtWidgetProgressReport(QtWidgetModel * model, QWidget * parent) - : QWidget(parent) - , m_CurrentProcess() -{ - m_Model = model; - connect(model, &QtWidgetModel::SetProgressReportBegin, this, &QtWidgetProgressReport::show ); - connect(model, &QtWidgetModel::SetProgressReportDone, this, &QtWidgetProgressReport::close ); - connect(model, &QtWidgetModel::SetProgressReportDone, this, &QtWidgetProgressReport::RemoveLayout ); - connect(this, &QtWidgetProgressReport::AddNewProcessToReport, this, &QtWidgetProgressReport::ReportProcess ); - - m_Layout = new QVBoxLayout; - this->setLayout(m_Layout); - - m_AddProcessCommand = AddProcessCommandType::New(); - m_AddProcessCommand->SetCallbackFunction( this, &QtWidgetProgressReport::ProcessEvent ); - - this->show(); -} - -QtWidgetProgressReport::~QtWidgetProgressReport() -{ -} - -void QtWidgetProgressReport::SetApplication(Application::Pointer app) -{ - m_Application = app; - m_Application->AddObserver( AddProcessToWatchEvent(), m_AddProcessCommand.GetPointer() ); -} - -void -QtWidgetProgressReport::ProcessEvent( itk::Object * itkNotUsed(caller), - const itk::EventObject & ev ) -{ - if( typeid( otb::Wrapper::AddProcessToWatchEvent ) == typeid( ev ) ) - { - const AddProcessToWatchEvent* eventToWatch = dynamic_cast< const AddProcessToWatchEvent*> ( &ev ); - - if(eventToWatch) - { - m_CurrentProcess = eventToWatch->GetProcess(); - m_CurrentDescription = eventToWatch->GetProcessDescription(); - emit AddNewProcessToReport(); - } - } -} - -void QtWidgetProgressReport::ReportProcess ( ) -{ - // Build the widget containing the QtProgressBar for the current - // process - - // Create a itk::QtProgressBar, observing the event ProgressEvent - itk::QtProgressBar * bar = new itk::QtProgressBar(this); - connect( bar, &itk::QtProgressBar::SetValueChanged, bar, &itk::QtProgressBar::setValue ); - connect( m_Model, &QtWidgetModel::SetProgressReportDone, bar, &itk::QtProgressBar::reset ); - bar->Observe(m_CurrentProcess); - - // label - QLabel *label = new QLabel(QString(m_CurrentDescription.c_str()), this); - - // Build the layout and store the pointers - m_Layout->addWidget(label); - m_Layout->addWidget(bar); -} - -void QtWidgetProgressReport::RemoveLayout() -{ - // Remove the children of the layout (progress bar widgets) - QLayoutItem *child; - while ((child = this->layout()->takeAt(0)) != nullptr) - { - delete child->widget(); - delete child; - } -} - -} -} diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetSimpleProgressReport.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetSimpleProgressReport.cxx index 8df23531e7646587a7bf1e726cf701c365197936..19fffe036460e8a2425103319d84855328a780f2 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetSimpleProgressReport.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetSimpleProgressReport.cxx @@ -30,44 +30,29 @@ namespace otb namespace Wrapper { -QtWidgetSimpleProgressReport::QtWidgetSimpleProgressReport(QtWidgetModel * model, QWidget * parent) - : QWidget(parent) - , m_CurrentProcess() +QtWidgetSimpleProgressReport::QtWidgetSimpleProgressReport(QWidget* parent) : itk::QtProgressBar(parent), m_CurrentProcess() +{ +} + +void QtWidgetSimpleProgressReport::SetModel(QtWidgetModel* model) { - m_Model = model; connect(model, &QtWidgetModel::SetProgressReportBegin, this, &QtWidgetSimpleProgressReport::show ); connect(model, &QtWidgetModel::SetProgressReportDone, this, &QtWidgetSimpleProgressReport::Init ); connect(this, &QtWidgetSimpleProgressReport::AddNewProcessToReport, this, &QtWidgetSimpleProgressReport::ReportProcess ); - m_Layout = new QVBoxLayout; - this->setLayout(m_Layout); - m_AddProcessCommand = AddProcessCommandType::New(); m_AddProcessCommand->SetCallbackFunction( this, &QtWidgetSimpleProgressReport::ProcessEvent ); - m_Bar = new itk::QtProgressBar(this); - - m_Label = new QLabel("No process", this); - m_Label->setWordWrap(true); - connect( m_Bar, &itk::QtProgressBar::SetValueChanged, m_Bar, &itk::QtProgressBar::setValue ); - connect( m_Model, &QtWidgetModel::SetProgressReportDone, m_Bar, &itk::QtProgressBar::reset ); + connect(this, &itk::QtProgressBar::SetValueChanged, this, &itk::QtProgressBar::setValue); + connect(model, &QtWidgetModel::SetProgressReportDone, this, &itk::QtProgressBar::reset); - m_Layout->addWidget(m_Label); - m_Layout->addWidget(m_Bar); - - this->show(); + model->GetApplication()->AddObserver(AddProcessToWatchEvent(), m_AddProcessCommand.GetPointer()); } QtWidgetSimpleProgressReport::~QtWidgetSimpleProgressReport() { } -void QtWidgetSimpleProgressReport::SetApplication(Application::Pointer app) -{ - m_Application = app; - m_Application->AddObserver( AddProcessToWatchEvent(), m_AddProcessCommand.GetPointer() ); -} - void QtWidgetSimpleProgressReport::ProcessEvent( itk::Object * itkNotUsed(caller), const itk::EventObject & event2 ) @@ -87,15 +72,14 @@ QtWidgetSimpleProgressReport::ProcessEvent( itk::Object * itkNotUsed(caller), void QtWidgetSimpleProgressReport::ReportProcess() { - m_Bar->Observe(m_CurrentProcess); - m_Label->setText(QString(m_CurrentDescription.c_str())); + this->Observe(m_CurrentProcess); + emit SetText(QString::fromStdString(m_CurrentDescription)); } - void QtWidgetSimpleProgressReport::Init() { - m_Bar->setValue(0); - m_Label->setText("No process"); + this->setValue(0); + emit SetText(QString("")); } } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx index 6b84fa510c85722a183a0a1ed7ab71f0236cea69..e72a1b4dd4df05fecabe758550aa155212d53d5d 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx @@ -20,8 +20,6 @@ #include "otbWrapperQtWidgetView.h" -#include <functional> - #include "otbWrapperQtWidgetParameterGroup.h" #include "otbWrapperQtWidgetParameterFactory.h" #include "otbWrapperOutputFilenameParameter.h" @@ -54,36 +52,11 @@ QtWidgetView::QtWidgetView( const otb::Wrapper::Application::Pointer & otbApp, QWidget* parent, Qt::WindowFlags flags ) : QWidget( parent, flags ), - m_IconPathDone(""), - m_IconPathFailed(""), m_Model( NULL ), - m_ExecButton( NULL ), - m_QuitButton( NULL ), - m_Message( NULL ), - m_LogText( NULL ), - m_TabWidget( NULL ), - m_IsClosable( true ), m_IsRunning(false) { setObjectName( QtWidgetView::OBJECT_NAME ); - m_Model = new otb::Wrapper::QtWidgetModel( otbApp ); - m_QuitShortcut = new QShortcut(QKeySequence("Ctrl+Q"), this); - - QObject::connect( - m_Model, &QtWidgetModel::SetProgressReportBegin, - this, &QtWidgetView::OnProgressReportBegin - ); - - QObject::connect( - m_Model, &QtWidgetModel::SetProgressReportDone, - this, &QtWidgetView::OnProgressReportEnd - ); - - QObject::connect( - m_Model, &QtWidgetModel::ExceptionRaised, - this, &QtWidgetView::OnExceptionRaised - ); } QtWidgetView::~QtWidgetView() @@ -94,172 +67,14 @@ QtWidgetView::~QtWidgetView() void QtWidgetView::CreateGui() { - // Create a VBoxLayout with the header, the input widgets, and the footer QVBoxLayout *mainLayout = new QVBoxLayout; - m_TabWidget = new QTabWidget(this); - - m_TabWidget->addTab(CreateInputWidgets(), tr("Parameters")); - m_LogText = new QTextEdit(this); - connect( m_Model->GetLogOutput(), &QtLogOutput::NewContentLog, m_LogText, &QTextEdit::append ); - m_TabWidget->addTab(m_LogText, tr("Logs")); - mainLayout->addWidget(m_TabWidget); - - m_Message = new QLabel("<center><font color=\"#FF0000\">"+tr("Select parameters")+"</font></center>", this); - connect( m_Model, &QtWidgetModel::SetApplicationReady, this, &QtWidgetView::UpdateMessageAfterApplicationReady ); - connect( m_Model, &QtWidgetModel::SetProgressReportDone, this, &QtWidgetView::UpdateMessageAfterExecution ); - mainLayout->addWidget(m_Message); - - otb::Wrapper::QtWidgetSimpleProgressReport * progressReport = new otb::Wrapper::QtWidgetSimpleProgressReport(m_Model, this); - progressReport->SetApplication(m_Model->GetApplication()); - - QWidget* footer = CreateFooter(); - - QHBoxLayout *footLayout = new QHBoxLayout; - footLayout->addWidget(progressReport); - footLayout->addWidget(footer); - mainLayout->addLayout(footLayout); - - footLayout->setAlignment(footer, Qt::AlignBottom); - - QGroupBox *mainGroup = new QGroupBox(this); - mainGroup->setLayout(mainLayout); - - QVBoxLayout *finalLayout = new QVBoxLayout; - finalLayout->addWidget(mainGroup); - - // Make the final layout to the widget - this->setLayout(finalLayout); -} - -void QtWidgetView::UpdateMessageAfterExecution(int status) -{ - if (status >= 0) - { - m_Message->setText("<center>"+QString(m_IconPathDone.c_str())+ - "<font color=\"#00A000\">"+tr("Done")+"</font></center>"); - } - else - { - m_Message->setText("<center>"+QString(m_IconPathFailed.c_str())+ - "<font color=\"#FF0000\">"+tr("Failed")+"</font></center>"); - } - m_ExecButton->setText(QObject::tr("Execute")); - m_IsRunning = false; -} - -void QtWidgetView::UpdateMessageAfterApplicationReady( bool val ) -{ - if(!m_IsRunning) - { - if(val == true) - m_Message->setText("<center><font color=\"#00A000\">"+tr("Ready to run")+"</font></center>"); - else - m_Message->setText("<center><font color=\"#FF0000\">"+tr("Select parameters")+"</font></center>"); - } + this->setLayout(mainLayout); + mainLayout->addWidget(CreateInputWidgets()); } QWidget* QtWidgetView::CreateInputWidgets() { - QScrollArea *scrollArea = new QScrollArea(this); - - scrollArea->setWidget( otb::Wrapper::QtWidgetParameterFactory::CreateQtWidget( - m_Model->GetApplication()->GetParameterList(), - m_Model, - this)); - scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - scrollArea->setWidgetResizable(true); - - return scrollArea; -} - - -QWidget* QtWidgetView::CreateFooter() -{ - // an HLayout with two buttons : Execute and Quit - QGroupBox *footerGroup = new QGroupBox(this); - QHBoxLayout *footerLayout = new QHBoxLayout; - - m_ExecButton = new QPushButton(footerGroup); - m_ExecButton->setDefault(true); - m_ExecButton->setEnabled(false); - m_ExecButton->setText(QObject::tr("Execute")); - connect( m_Model, &QtWidgetModel::SetApplicationReady, m_ExecButton, &QPushButton::setEnabled ); - connect( m_ExecButton, &QPushButton::clicked, this, &QtWidgetView::OnExecButtonClicked ); - connect( this, &QtWidgetView::ExecuteAndWriteOutput, m_Model, &QtWidgetModel::ExecuteAndWriteOutputSlot ); - connect( this, &QtWidgetView::Stop, m_Model, &QtWidgetModel::Stop ); - - m_QuitButton = new QPushButton(footerGroup); - m_QuitButton->setText(QObject::tr("Quit")); - connect(m_QuitButton, &QPushButton::clicked, this, &QtWidgetView::close ); - - // Add Ctrl-Q shortcut to quit - connect( m_QuitShortcut, &QShortcut::activated, this, &QtWidgetView::close ); - - // Put the buttons on the right - footerLayout->addStretch(); - footerLayout->addWidget(m_ExecButton); - footerLayout->addWidget(m_QuitButton); - - footerGroup->setLayout(footerLayout); - - return footerGroup; -} - -void QtWidgetView::closeEvent( QCloseEvent * e ) -{ - assert( e!=NULL ); - - if( !IsClosable() ) - { - assert( GetModel()->GetApplication() ); - - QMessageBox::warning( - this, - tr( "Warning!" ), - tr( "OTB-Application '%1' cannot be closed while running!") - .arg( GetModel()->GetApplication()->GetDocName() ) - ); - - e->ignore(); - - return; - } - - QWidget::closeEvent( e ); - - emit QuitSignal(); - - deleteLater(); -} - -void -QtWidgetView -::OnExecButtonClicked() -{ - if (m_IsRunning) - { - m_Message->setText("<center><font color=\"#FF0000\">"+tr("Cancelling")+"...</font></center>"); - emit Stop(); - } - else - { - m_IsRunning = true; - m_Message->setText("<center><font color=\"#FF0000\">"+tr("Running")+"</font></center>"); - m_ExecButton->setText(QObject::tr("Cancel")); - emit ExecuteAndWriteOutput(); - } -} - -void QtWidgetView::UnhandledException(QString message) -{ - this->OnExceptionRaised(message); - m_LogText->append(message); -} - -void QtWidgetView::OnExceptionRaised( QString /*message*/) -{ - m_TabWidget->setCurrentIndex(1); + return otb::Wrapper::QtWidgetParameterFactory::CreateQtWidget(m_Model->GetApplication()->GetParameterList(), m_Model, this); } bool QtWidgetView::IsRunning() const @@ -272,29 +87,26 @@ QtWidgetModel* QtWidgetView::GetModel() const return m_Model; } -bool QtWidgetView::IsClosable() const -{ - return m_IsClosable; -} - -void QtWidgetView::SetClosable( bool enabled ) -{ - m_IsClosable = enabled; - - setEnabled( true ); - - if( m_QuitButton!=NULL ) - m_QuitButton->setEnabled( m_IsClosable ); -} - -void QtWidgetView::OnProgressReportBegin() +void QtWidgetView::Disable() { - SetClosable( false ); + // Disable all widgets to make sure parameters are not updated when the application is running in another thread + for (QWidget* w : this->findChildren<QWidget*>()) + { + w->setEnabled(false); + } + this->setEnabled(false); } -void QtWidgetView::OnProgressReportEnd( int ) +void QtWidgetView::Enable() { - SetClosable( true ); + // Reset all widgets of the view to their previous enabled state + this->setEnabled(true); + for (QWidget* w : this->findChildren<QWidget*>()) + { + w->setEnabled(true); + } + // Resync widgets enabled state with parameter enabled flag + this->GetModel()->NotifyUpdate(); } } // end of namespace Wrapper diff --git a/Modules/Wrappers/QtWidget/test/otbWrapperQtWidgetShowWidget.cxx b/Modules/Wrappers/QtWidget/test/otbWrapperQtWidgetShowWidget.cxx index 9477a89fa6ec0bf8c2139daa17d47bcba11fbd9f..8f566438d7d6d898e44435460c72dcb2afa85da3 100644 --- a/Modules/Wrappers/QtWidget/test/otbWrapperQtWidgetShowWidget.cxx +++ b/Modules/Wrappers/QtWidget/test/otbWrapperQtWidgetShowWidget.cxx @@ -25,7 +25,6 @@ #include "otbQtApplication.h" #include "otbWrapperApplicationRegistry.h" #include "otbWrapperQtWidgetView.h" -#include "otbWrapperQtWidgetProgressReport.h" #include "itksys/SystemTools.hxx" @@ -33,7 +32,6 @@ using otb::Wrapper::Application; using otb::Wrapper::ApplicationRegistry; using otb::Wrapper::QtApplication; using otb::Wrapper::QtWidgetView; -using otb::Wrapper::QtWidgetProgressReport; struct static_finalizer @@ -113,19 +111,6 @@ otbWrapperQtWidgetShowWidget( int argc, char* argv[] ) ); layout->addWidget( qwv ); - - // Create OTB-Application progress-report. - // - // SAT: QWidget should be created without parent when adding - // into QLayout (because QLayout will take ownership of the - // reference-counted pointer) but OTB API doesn't defined default nullptr - // value such as in Qt. - QtWidgetProgressReport * qwpr = - new QtWidgetProgressReport( qwv->GetModel(), widget ); - - qwpr->SetApplication( otb_application ); - - layout->addWidget( qwpr ); } widget->setLayout( layout ); }