From 1acdbfedb91a2bb9d4a072882ba2558ce81d655c Mon Sep 17 00:00:00 2001
From: Stephane Albert <stephane.albert@c-s.fr>
Date: Mon, 18 Feb 2013 13:01:01 +0100
Subject: [PATCH] COMP: Fixed compilation errors due to merge of Quicklook and
 Color-dynamics merge.

---
 Code/Application/mvdMainWindow.cxx       | 79 ++++++++++++++++--------
 Code/Common/mvdAbstractModelRenderer.h   | 12 ++--
 Code/Common/mvdAbstractViewManipulator.h |  4 +-
 Code/Common/mvdColorSetupController.cxx  | 24 +++----
 Code/Common/mvdGLImageWidget.cxx         | 39 +++++++-----
 Code/Common/mvdGLImageWidget.h           |  6 +-
 Code/Common/mvdImageModelRenderer.cxx    |  8 ++-
 Code/Common/mvdQuicklookModel.cxx        |  3 +-
 Code/Common/mvdQuicklookModel.h          |  6 +-
 9 files changed, 111 insertions(+), 70 deletions(-)

diff --git a/Code/Application/mvdMainWindow.cxx b/Code/Application/mvdMainWindow.cxx
index 639080b58b..833ce29ff3 100644
--- a/Code/Application/mvdMainWindow.cxx
+++ b/Code/Application/mvdMainWindow.cxx
@@ -42,11 +42,12 @@
 #include "mvdColorSetupController.h"
 #include "mvdDatasetModel.h"
 #include "mvdGLImageWidget.h"
-#include "mvdVectorImageModel.h"
-
 #include "mvdImageModelRenderer.h"
 #include "mvdImageViewManipulator.h"
+#include "mvdQuicklookModel.h"
 #include "mvdQuicklookViewManipulator.h"
+#include "mvdVectorImageModel.h"
+
 namespace mvd
 {
 /*
@@ -83,14 +84,18 @@ MainWindow
   setWindowTitle( PROJECT_NAME );
 
   // instanciate the manipulator and the renderer relative to this widget
-  ImageViewManipulator * imageViewManipulator = new ImageViewManipulator();
-  ImageModelRenderer *   imageModelRenderer   = new ImageModelRenderer();
+  ImageViewManipulator* imageViewManipulator = new ImageViewManipulator();
+  ImageModelRenderer* imageModelRenderer = new ImageModelRenderer();
 
   // set the GLImageWidget as the centralWidget in MainWindow.
-  setCentralWidget( new GLImageWidget( imageViewManipulator, 
-                                       imageModelRenderer, 
-                                       this ) );
-  
+  setCentralWidget(
+    new GLImageWidget(
+      imageViewManipulator,
+      imageModelRenderer,
+      this
+    )
+  );
+
   // grab the keyboard notifications in this widget
   centralWidget()->grabKeyboard();
 
@@ -134,14 +139,19 @@ MainWindow
 ::InitializeDockWidgets()
 {
   // instanciate the manipulator and the renderer relative to this widget
-  QuicklookViewManipulator * qlViewManipulator = new QuicklookViewManipulator();
-  ImageModelRenderer *   qlModelRenderer   = new ImageModelRenderer();
+  QuicklookViewManipulator* qlViewManipulator = new QuicklookViewManipulator();
+  ImageModelRenderer* qlModelRenderer = new ImageModelRenderer();
 
   //
   // EXPERIMENTAL QUICKLOOK Widget.
-  GLImageWidget * qlWidget = new GLImageWidget( qlViewManipulator, qlModelRenderer, this );
-  qlWidget->setMinimumSize(100,100); // TODO : temporary
-  
+  GLImageWidget* qlWidget = new GLImageWidget(
+    qlViewManipulator,
+    qlModelRenderer,
+    this
+  );
+  // TODO: Set better minimum size for quicklook GL widget.
+  qlWidget->setMinimumSize(100,100);
+
   AddWidgetToDock( 
     qlWidget,
     QUICKLOOK_DOCK,
@@ -154,7 +164,6 @@ MainWindow
     qlWidget, SIGNAL( ModelImageRegionChanged(const ImageRegionType&) ),
     qlViewManipulator, SLOT( OnModelImageRegionChanged(const ImageRegionType&)) );
 
-
   //
   // COLOR SETUP.
   ColorSetupWidget* colorSetupWgt = new ColorSetupWidget( this );
@@ -275,7 +284,10 @@ MainWindow
     // Init parameters :
     // - filename
     // - widget size (-> compute the best lod fitting the widget size )
-    model->ImportImage( filename, centralWidget()->width(), centralWidget()->height() );
+    model->ImportImage(
+      filename,
+      centralWidget()->width(), centralWidget()->height()
+    );
     }
   catch( std::exception& exc )
     {
@@ -312,6 +324,12 @@ MainWindow
   // COLOR DYNAMICS.
   SetControllerModel( GetColorDynamicsDock(), NULL );
 
+  // De-assign models to view after controllers (LIFO disconnect).
+  qobject_cast< GLImageWidget *>( centralWidget() )->SetImageModel( NULL );
+  qobject_cast< GLImageWidget * >( GetQuicklookDock()->widget() )->SetImageModel(
+    NULL
+  );
+
   //
   //
   const Application* app = Application::ConstInstance();
@@ -349,14 +367,13 @@ MainWindow
   );
 
   // TODO : where to do this
-    QObject::disconnect(
+  QObject::disconnect(
     vectorImageModel->GetQuicklookModel(),
     SIGNAL( SettingsUpdated() ),
     // to:
-    qobject_cast<GLImageWidget *>(GetQuicklookDock()->widget()),
+    GetQuicklookDock()->widget(),
     SLOT( updateGL()  )
   );
-
 }
 
 /*****************************************************************************/
@@ -379,6 +396,18 @@ MainWindow
 
   assert( vectorImageModel!=NULL );
 
+  // Assign models to view before controllers (because controllers
+  // will setup rendering settings and emit a signals which causes
+  // display refresh)!
+  qobject_cast< GLImageWidget *>( centralWidget() )->SetImageModel(
+    vectorImageModel
+  );
+  /*
+  qobject_cast< GLImageWidget * >( GetQuicklookDock()->widget() )->SetImageModel(
+    vectorImageModel->GetQuicklookModel()
+  );
+  */
+
   //
   // COLOR SETUP.
   SetControllerModel( GetColorSetupDock(), vectorImageModel );
@@ -401,29 +430,25 @@ MainWindow
     SLOT( updateGL()  )
   );
 
-
   // TODO : where to do this
-    QObject::connect(
+  QObject::connect(
     vectorImageModel->GetQuicklookModel(),
     SIGNAL( SettingsUpdated() ),
     // to:
-    qobject_cast<GLImageWidget *>(GetQuicklookDock()->widget()),
+    GetQuicklookDock()->widget(),
     SLOT( updateGL()  )
   );
 
+  /*
   // Connect newly selected model to UI controller.
   QObject::connect(
-    colorSetupWidget,
+    GetColorSetupDock()->widget(),
     SIGNAL( CurrentIndexChanged( RgbaChannel, int ) ),
     // to:
     vectorImageModel->GetQuicklookModel(),
     SLOT( OnCurrentIndexChanged( RgbaChannel, int ) )
   );
-
-
-  // 
-  qobject_cast<GLImageWidget *>(centralWidget())->SetImageModel(vectorImageModel);
-  qobject_cast<GLImageWidget *>(GetQuicklookDock()->widget())->SetImageModel(vectorImageModel->GetQuicklookModel());
+  */
 }
 
 /*****************************************************************************/
diff --git a/Code/Common/mvdAbstractModelRenderer.h b/Code/Common/mvdAbstractModelRenderer.h
index ea65a50115..454fa3125c 100644
--- a/Code/Common/mvdAbstractModelRenderer.h
+++ b/Code/Common/mvdAbstractModelRenderer.h
@@ -66,6 +66,8 @@ class AbstractModelRenderer :
 //
 // Public types.
 public:
+  /**
+   */
   struct RenderingContext
   {
      inline
@@ -77,7 +79,7 @@ public:
                        int dx = 0,
                        int dy = 0,
                        bool refresh = true) :
-       m_AbstractImageModel( model ),
+       m_ImageModel( model ),
        m_ImageRegion( region ),
        m_IsotropicZoom( zoom ),
        m_WidgetWidth(width),
@@ -86,12 +88,14 @@ public:
     {
     }
 
-    const AbstractImageModel* m_AbstractImageModel;
+    const AbstractImageModel* m_ImageModel;
     ImageRegionType m_ImageRegion;
-    double       m_IsotropicZoom;
+    double m_IsotropicZoom;
+    // TODO: remove unsigned before int (because Qt uses signed int).
     unsigned int m_WidgetWidth;
+    // TODO: remove unsigned before int (becayse Qt uses signed int).
     unsigned int m_WidgetHeight;
-    bool         m_ForceRefresh;
+    bool m_ForceRefresh;
   };
 
 //
diff --git a/Code/Common/mvdAbstractViewManipulator.h b/Code/Common/mvdAbstractViewManipulator.h
index caf6852155..1cf58482d7 100644
--- a/Code/Common/mvdAbstractViewManipulator.h
+++ b/Code/Common/mvdAbstractViewManipulator.h
@@ -72,7 +72,9 @@ public:
     QObject(parent),
     m_NavigationContext(),
     m_MouseContext(),
-    m_IsotropicZoom(1.){}
+    m_IsotropicZoom(1.)
+      {
+      }
 
   /** Destructor */
   virtual ~AbstractViewManipulator(){};
diff --git a/Code/Common/mvdColorSetupController.cxx b/Code/Common/mvdColorSetupController.cxx
index bbe3b5c0f1..521d043563 100644
--- a/Code/Common/mvdColorSetupController.cxx
+++ b/Code/Common/mvdColorSetupController.cxx
@@ -93,18 +93,6 @@ ColorSetupController
   );
 }
 
-/*******************************************************************************/
-void
-ColorSetupController
-::ResetWidget()
-{
-  // Reset color-setup widget.
-  ResetIndices( RGBA_CHANNEL_RGB );
-
-  // Signal model has been updated.
-  emit ModelUpdated();
-}
-
 /*******************************************************************************/
 void
 ColorSetupController
@@ -131,6 +119,18 @@ ColorSetupController
   );
 }
 
+/*******************************************************************************/
+void
+ColorSetupController
+::ResetWidget()
+{
+  // Reset color-setup widget.
+  ResetIndices( RGBA_CHANNEL_RGB );
+
+  // Signal model has been updated.
+  emit ModelUpdated();
+}
+
 /*******************************************************************************/
 void
 ColorSetupController
diff --git a/Code/Common/mvdGLImageWidget.cxx b/Code/Common/mvdGLImageWidget.cxx
index 8f1d107f9a..afda3d0c96 100644
--- a/Code/Common/mvdGLImageWidget.cxx
+++ b/Code/Common/mvdGLImageWidget.cxx
@@ -107,17 +107,27 @@ GLImageWidget
 /*******************************************************************************/
 void
 GLImageWidget
-::Initialize(AbstractViewManipulator * manipulator,
-             AbstractModelRenderer * renderer)
+::Initialize( AbstractViewManipulator* manipulator,
+	      AbstractModelRenderer* renderer )
 {
+  assert( manipulator!=NULL );
+  assert( renderer!=NULL );
+
   m_ImageViewManipulator = manipulator;
   m_ImageViewManipulator->setParent(this);
 
-  m_ImageModelRenderer =  renderer;
+  m_ImageModelRenderer = renderer;
   m_ImageModelRenderer->setParent(this);
 
-  connect(this, SIGNAL(movingMouse()), m_ImageModelRenderer, SLOT(onMovingEvent()));
-  connect(this, SIGNAL(releasingMouse()), m_ImageModelRenderer, SLOT(onReleasedMouse()));
+  QObject::connect(
+    this, SIGNAL( movingMouse() ),
+    m_ImageModelRenderer, SLOT( onMovingEvent() )
+  );
+
+  QObject::connect(
+    this, SIGNAL( releasingMouse() ),
+    m_ImageModelRenderer, SLOT(onReleasedMouse())
+  );
 }
 
 /*******************************************************************************/
@@ -212,15 +222,12 @@ GLImageWidget
   // Get the zoom 
   const double isotropicZoom = m_ImageViewManipulator->GetIsotropicZoom();
 
-  // Do not render if there is no model to render.
-  if( Application::ConstInstance()->GetModel()==NULL )
-    return;
-
   // Setup rendering context with image-model and redering information.
   AbstractModelRenderer::RenderingContext context(
     m_ImageModel,
     region, isotropicZoom, 
-    width(), height(), m_ImageViewManipulator->HasZoomChanged()
+    width(), height(),
+    m_ImageViewManipulator->HasZoomChanged()
   );
 
     // use the model renderer to paint the requested region of the image.
@@ -231,7 +238,7 @@ GLImageWidget
 // Delegate the event to the ImageViewManipulator
 void
 GLImageWidget
-::mousePressEvent(  QMouseEvent * event)
+::mousePressEvent( QMouseEvent* event )
 {
   QCursor dragCursor;
   dragCursor.setShape(Qt::ClosedHandCursor) ;
@@ -243,7 +250,7 @@ GLImageWidget
 /*******************************************************************************/
 void
 GLImageWidget
-::mouseMoveEvent(  QMouseEvent * event)
+::mouseMoveEvent( QMouseEvent* event )
 {
   // emit a signal
   emit movingMouse();
@@ -258,7 +265,7 @@ GLImageWidget
 /*******************************************************************************/
 void
 GLImageWidget
-::mouseReleaseEvent(  QMouseEvent * event)
+::mouseReleaseEvent( QMouseEvent* event )
 {
   QCursor stdCursor;
   stdCursor.setShape(Qt::ArrowCursor) ;
@@ -274,7 +281,7 @@ GLImageWidget
 /*******************************************************************************/
 void
 GLImageWidget
-::wheelEvent( QWheelEvent *event)
+::wheelEvent( QWheelEvent* event )
 {
   // emit a signal
   emit releasingMouse();
@@ -288,7 +295,7 @@ GLImageWidget
 /*******************************************************************************/
 void
 GLImageWidget
-::resizeEvent( QResizeEvent  * event)
+::resizeEvent( QResizeEvent* event )
 {
   m_ImageViewManipulator->resizeEvent(event);
 
@@ -302,7 +309,7 @@ GLImageWidget
 /*******************************************************************************/
 void
 GLImageWidget
-::keyPressEvent( QKeyEvent * event )
+::keyPressEvent( QKeyEvent* event )
 {
   m_ImageViewManipulator->keyPressEvent(event);
   this->update();
diff --git a/Code/Common/mvdGLImageWidget.h b/Code/Common/mvdGLImageWidget.h
index 871e070e50..be8db696a1 100644
--- a/Code/Common/mvdGLImageWidget.h
+++ b/Code/Common/mvdGLImageWidget.h
@@ -187,11 +187,14 @@ private:
 
 namespace mvd
 {
+/*****************************************************************************/
 void 
-GLImageWidget::SetImageModel(AbstractImageModel* model)
+GLImageWidget
+::SetImageModel(AbstractImageModel* model)
 {
   m_ImageModel = model;
 
+#if 0
   //
   // REFRESH DISPLAY.
 
@@ -202,6 +205,7 @@ GLImageWidget::SetImageModel(AbstractImageModel* model)
   emit ModelImageRegionChanged(
     model->GetNativeLargestRegion()
   );
+#endif
 }
 
 }
diff --git a/Code/Common/mvdImageModelRenderer.cxx b/Code/Common/mvdImageModelRenderer.cxx
index 918773e006..a28e07f837 100644
--- a/Code/Common/mvdImageModelRenderer.cxx
+++ b/Code/Common/mvdImageModelRenderer.cxx
@@ -65,10 +65,14 @@ ImageModelRenderer
 /*****************************************************************************/
 void ImageModelRenderer::paintGL( const RenderingContext& context )
 {
+  if( context.m_ImageModel==NULL )
+    return;
+
   // the VectorImageModel used for the rendering
-  VectorImageModel * viModel = qobject_cast< VectorImageModel * >(
-    const_cast<AbstractImageModel*>(context.m_AbstractImageModel)
+  VectorImageModel* viModel = qobject_cast< VectorImageModel * >(
+    const_cast< AbstractImageModel* >( context.m_ImageModel )
   );
+  assert( viModel );
 
   // the region of the image to be rendered
   const ImageRegionType&  region = context.m_ImageRegion;
diff --git a/Code/Common/mvdQuicklookModel.cxx b/Code/Common/mvdQuicklookModel.cxx
index d9761431e9..643f3aa06f 100644
--- a/Code/Common/mvdQuicklookModel.cxx
+++ b/Code/Common/mvdQuicklookModel.cxx
@@ -64,8 +64,7 @@ QuicklookModel
 {
   //
   // Step #1: Check if it is a multi-resolution file
-  
-    
+
   //
   // Step #2: get the image used as quicklook
   VectorImageModel* imageModel = qobject_cast< VectorImageModel* >( parent() );
diff --git a/Code/Common/mvdQuicklookModel.h b/Code/Common/mvdQuicklookModel.h
index 55a4303897..1587774a1f 100644
--- a/Code/Common/mvdQuicklookModel.h
+++ b/Code/Common/mvdQuicklookModel.h
@@ -83,10 +83,6 @@ class Monteverdi2_EXPORT QuicklookModel :
 //
 // Public types.
 public:
-  /**
-   * In-memory storage type of source image (from file).
-   */
-  typedef DefaultImageType SourceImageType;
 
 //
 // Public methods.
@@ -103,7 +99,7 @@ public:
   const Settings& GetSettings() const;
 
   /** */
-   Settings& GetSettings();
+  Settings& GetSettings();
 
   /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
 
-- 
GitLab