From 7c5051a356ebf0cafc1703146236dfb6991c0ffb Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Mon, 5 Sep 2011 16:41:09 +0200 Subject: [PATCH] ENH : add notifications handling to update the view --- .../QtWidget/otbWrapperQtWidgetModel.cxx | 6 ++++-- .../Wrappers/QtWidget/otbWrapperQtWidgetModel.h | 7 +++---- .../QtWidget/otbWrapperQtWidgetView.cxx | 17 +++++++++++++++++ Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h | 7 +++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx index 48cadf1078..39263dfca9 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.cxx @@ -29,10 +29,8 @@ namespace Wrapper QtWidgetModel::QtWidgetModel(Application* app) : m_Application(app) { - m_Application->Init(); m_ProgressWindow = new QWidget(); - //m_Application->RegisterListener( this ); } QtWidgetModel::~QtWidgetModel() @@ -41,7 +39,11 @@ QtWidgetModel::~QtWidgetModel() void QtWidgetModel::NotifyUpdate() { + // Update the parameters m_Application->UpdateParameters(); + + // Notify all + this->NotifyAll("ParametersUpdated"); } void QtWidgetModel::ExecuteAndWriteOutput() diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h index 78ea474536..b74003d22b 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetModel.h @@ -21,7 +21,8 @@ #include <QtGui> #include "otbWrapperApplication.h" #include "otbWrapperChoiceParameter.h" -//#include "otbWrapperEventsListener.h" +#include "otbWrapperEventsSender.h" +#include "otbWrapperEvent.h" namespace otb { @@ -55,7 +56,7 @@ private: /** \class * \brief */ - class QtWidgetModel : public QObject /*, public EventsListener<std::string>*/ +class QtWidgetModel : public QObject, public EventsSender<std::string> { Q_OBJECT public: @@ -75,8 +76,6 @@ protected slots: // slot called everytime one of the widget is updated void NotifyUpdate(); - //void Notify(); - private: QtWidgetModel(const QtWidgetModel&); //purposely not implemented void operator=(const QtWidgetModel&); //purposely not implemented diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx index d4765c2c44..69331f7cdd 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx @@ -34,6 +34,7 @@ QtWidgetView::QtWidgetView(Application* app) m_Model = new QtWidgetModel(app); m_Application = app; + m_Model->RegisterListener( this ); } QtWidgetView::~QtWidgetView() @@ -124,6 +125,7 @@ QWidget* QtWidgetView::CreateFooter() m_ExecButton = new QPushButton(footerGroup); m_ExecButton->setDefault(true); + m_ExecButton->setEnabled(false); m_ExecButton->setText(QObject::tr("Execute")); connect( m_ExecButton, SIGNAL(clicked()), this, SLOT(ExecuteAndWriteOutputSlot() ) ); @@ -251,6 +253,21 @@ void QtWidgetView::CloseSlot() { this->close(); } +void QtWidgetView::Notify(const std::string& event) +{ + if(event == "ParametersUpdated") + { + // "Execute" button activation depends on the application status + if(m_Model->GetApplication()->IsApplicationReady()) + { + m_ExecButton->setEnabled(true); + } + else + { + m_ExecButton->setEnabled(false); + } + } +} } } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h index 26b4c367de..95cecc4180 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h @@ -21,7 +21,7 @@ #include <QtGui> #include "otbWrapperApplication.h" #include "otbWrapperQtWidgetModel.h" -//#include "otbWrapperEventsListener.h" +#include "otbWrapperEventsListener.h" namespace otb @@ -32,7 +32,7 @@ namespace Wrapper /** \class * \brief */ - class QtWidgetView : public QWidget /*, public EventsListener<std::string>*/ + class QtWidgetView : public QWidget , public EventsListener<std::string> { Q_OBJECT public: @@ -48,6 +48,9 @@ public: } */ + // Get the notifications + void Notify(const std::string& event); + public slots: void ExecuteAndWriteOutputSlot(); void CloseSlot(); -- GitLab