From 2c2cb84e12a18e6630fca66c1d615d3c4d0c3f4e Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Thu, 8 Sep 2011 17:03:29 +0200
Subject: [PATCH] ENH : Add class from ITKApp to manage progressEvents of
 ProcessObject filters

---
 Code/Wrappers/QtWidget/itkQtProgressBar.cxx | 87 +++++++++++++++++++++
 Code/Wrappers/QtWidget/itkQtProgressBar.h   | 55 +++++++++++++
 2 files changed, 142 insertions(+)
 create mode 100644 Code/Wrappers/QtWidget/itkQtProgressBar.cxx
 create mode 100644 Code/Wrappers/QtWidget/itkQtProgressBar.h

diff --git a/Code/Wrappers/QtWidget/itkQtProgressBar.cxx b/Code/Wrappers/QtWidget/itkQtProgressBar.cxx
new file mode 100644
index 0000000000..2bc74ab3b5
--- /dev/null
+++ b/Code/Wrappers/QtWidget/itkQtProgressBar.cxx
@@ -0,0 +1,87 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    itkQtProgressBar.cxx
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+  Copyright (c) 2002 Insight Consortium. All rights reserved.
+  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even 
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+
+#include "itkProcessObject.h"
+#include "itkQtProgressBar.h"
+
+
+namespace itk {
+
+
+/** Constructor */
+QtProgressBar::QtProgressBar( QWidget *parent):QProgressBar(parent)
+{
+  m_RedrawCommand = RedrawCommandType::New();
+  m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ProcessEvent );
+  m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ConstProcessEvent );
+
+  this->setMaximum( 100 );
+  this->reset();
+}
+
+
+  
+/** Get Command */
+QtProgressBar::RedrawCommandType * 
+QtProgressBar::GetRedrawCommand( void ) const
+{
+  return m_RedrawCommand.GetPointer();
+}
+
+/** Manage a Progress event */
+void 
+QtProgressBar::ProcessEvent( itk::Object * caller, 
+                           const itk::EventObject & event )
+{
+  if( typeid( itk::ProgressEvent )   ==  typeid( event ) )
+    {
+    ::itk::ProcessObject::Pointer  process = 
+             dynamic_cast< itk::ProcessObject *>( caller );
+
+    const int value = static_cast<int>( 
+                        process->GetProgress() * this->maximum() );
+
+    emit SetValueChanged( value );
+    }
+}
+
+void 
+QtProgressBar::ConstProcessEvent( const itk::Object * caller, 
+                                const itk::EventObject & event )
+{
+  if( typeid( itk::ProgressEvent )   ==  typeid( event ) ) 
+    {
+    itk::ProcessObject::ConstPointer  process = 
+              dynamic_cast< const itk::ProcessObject *>( caller );
+
+    const int value = static_cast<int>( 
+                        process->GetProgress() * this->maximum() );
+
+    emit SetValueChanged( value );
+    }
+}
+
+/** Manage a Progress event */
+void 
+QtProgressBar::Observe( itk::Object *caller )
+{
+  caller->AddObserver(  itk::ProgressEvent(), m_RedrawCommand.GetPointer() );
+}
+
+} // end namespace fltk
+
+
diff --git a/Code/Wrappers/QtWidget/itkQtProgressBar.h b/Code/Wrappers/QtWidget/itkQtProgressBar.h
new file mode 100644
index 0000000000..493da8faac
--- /dev/null
+++ b/Code/Wrappers/QtWidget/itkQtProgressBar.h
@@ -0,0 +1,55 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    itkQtProgressBar.h
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+  Copyright (c) 2002 Insight Consortium. All rights reserved.
+  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even 
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#include <QtGui>
+#include "itkCommand.h"
+
+namespace itk {
+
+
+class QtProgressBar : public ::QProgressBar
+{
+  Q_OBJECT
+public:
+
+  /** Command Class invoked for button redraw */
+  typedef itk::MemberCommand< QtProgressBar >  RedrawCommandType;
+
+  /** Constructor */
+  QtProgressBar( QWidget *parent );
+
+  /** Get Command */
+  RedrawCommandType * GetRedrawCommand( void ) const;
+
+  
+  /** Manage a Progress event */
+  void ProcessEvent(itk::Object * caller, const itk::EventObject & event );
+  void ConstProcessEvent(const itk::Object * caller, const itk::EventObject & event );
+ 
+
+  /** Manage a Progress event */
+  void Observe( itk::Object *caller );
+
+signals:
+  void SetValueChanged(int);
+
+private:
+
+  RedrawCommandType::Pointer m_RedrawCommand;
+};
+
+
+}  // end of namespace
-- 
GitLab