From 1e6f2743ae17629f371894f7585aed0bfddd02a4 Mon Sep 17 00:00:00 2001 From: Stephane Albert <stephane.albert@c-s.fr> Date: Mon, 18 Feb 2013 17:28:46 +0100 Subject: [PATCH] ENH: Cleaned duplicate code in Manipulator classes tree; Moved ModelImageRegionChanged() connection. --- Code/Application/mvdMainWindow.cxx | 6 +- Code/Common/mvdAbstractViewManipulator.h | 47 +++++--- Code/Common/mvdGLImageWidget.cxx | 9 ++ Code/Common/mvdImageViewManipulator.cxx | 20 ++-- Code/Common/mvdImageViewManipulator.h | 86 ++++++++++----- Code/Common/mvdMyClass.h | 12 ++- Code/Common/mvdQuicklookViewManipulator.cxx | 21 ++-- Code/Common/mvdQuicklookViewManipulator.h | 113 +++++++++++--------- 8 files changed, 201 insertions(+), 113 deletions(-) diff --git a/Code/Application/mvdMainWindow.cxx b/Code/Application/mvdMainWindow.cxx index d1947affff..03e2db639d 100644 --- a/Code/Application/mvdMainWindow.cxx +++ b/Code/Application/mvdMainWindow.cxx @@ -108,10 +108,12 @@ MainWindow qApp, SLOT( quit() ) ); + /* // Connect the setLargestPossibleregion QObject::connect( centralWidget(), SIGNAL( ModelImageRegionChanged(const ImageRegionType&) ), imageViewManipulator, SLOT( OnModelImageRegionChanged(const ImageRegionType&)) ); + */ // Connect Appllication and MainWindow when selected model is about // to change. @@ -159,10 +161,12 @@ MainWindow Qt::LeftDockWidgetArea ); + /* // Connect the setLargestPossibleregion QObject::connect( qlWidget, SIGNAL( ModelImageRegionChanged(const ImageRegionType&) ), qlViewManipulator, SLOT( OnModelImageRegionChanged(const ImageRegionType&)) ); + */ // // COLOR SETUP. @@ -428,7 +432,7 @@ MainWindow // QUICKLOOK VIEW. // Assign newly selected model to view. -#if 0 +#if 1 qobject_cast< GLImageWidget * >( GetQuicklookDock()->widget() )->SetImageModel( vectorImageModel->GetQuicklookModel() ); diff --git a/Code/Common/mvdAbstractViewManipulator.h b/Code/Common/mvdAbstractViewManipulator.h index 833ecd5216..3c81b2d73a 100644 --- a/Code/Common/mvdAbstractViewManipulator.h +++ b/Code/Common/mvdAbstractViewManipulator.h @@ -67,7 +67,8 @@ namespace mvd /* CLASS DEFINITION SECTION */ /** \class AbstractViewManipulator - * Base class for QWidget manipulation + * + * \brief Base class for QWidget manipulation */ class Monteverdi2_EXPORT AbstractViewManipulator : public QObject @@ -97,6 +98,7 @@ public: virtual void resizeEvent ( QResizeEvent * event ) = 0; virtual void keyPressEvent( QKeyEvent * event ) = 0; + // TODO: See if HasZoomChanged() pure virtual method can be transformed into Qt signal. virtual bool HasZoomChanged() const = 0; /** */ @@ -122,25 +124,44 @@ signals: // Protected types. protected: /** Navigation context */ - struct NavigationContextType + struct NavigationContext { - // TODO: Implement default construtor (to safely initialize POD). - // TODO: Rename NavigationContextType struct into NagivationContext (this is not a typedef). + /** + * \brief Constructor. + * + * Default constructor (safely) initializes POD (Plain Old Data) + * structure. + */ + NavigationContext() : + m_ViewportImageRegion(), + m_ModelImageRegion(), + m_SizeXBeforeConstrain(), + m_SizeYBeforeConstrain() + { + // TODO: Initialize default viewport region to (0, 0) i.e. no + // viewed image. + + ImageRegionType::SizeType region; + + region[ 0 ] = 1; + region[ 1 ] = 1; + + m_ViewportImageRegion.SetSize( region ); + } + ImageRegionType m_ViewportImageRegion; ImageRegionType m_ModelImageRegion; // Stored as double to keep precision when dividing // by scale - double m_SizeXBeforeConstrain; - double m_SizeYBeforeConstrain; + double m_SizeXBeforeConstrain; + double m_SizeYBeforeConstrain; }; /** Mouse context */ - struct MouseContextType + struct MouseContext { - // TODO: Rename MouseContextType struct into NagivationContext (this is not a typedef). - - /** Default constructor */ - MouseContextType() : + /** \brief Default constructor. */ + MouseContext() : x( 0 ), y( 0 ), xMove( 0 ), @@ -167,10 +188,10 @@ protected: protected: /** */ - NavigationContextType m_NavigationContext; + NavigationContext m_NavigationContext; /** */ - MouseContextType m_MouseContext; + MouseContext m_MouseContext; /** */ double m_IsotropicZoom; diff --git a/Code/Common/mvdGLImageWidget.cxx b/Code/Common/mvdGLImageWidget.cxx index afda3d0c96..0c9aab7618 100644 --- a/Code/Common/mvdGLImageWidget.cxx +++ b/Code/Common/mvdGLImageWidget.cxx @@ -128,6 +128,15 @@ GLImageWidget this, SIGNAL( releasingMouse() ), m_ImageModelRenderer, SLOT(onReleasedMouse()) ); + + // Connect this model region changed. + QObject::connect( + this, + SIGNAL( ModelImageRegionChanged( const ImageRegionType& ) ), + // to: + m_ImageViewManipulator, + SLOT( OnModelImageRegionChanged( const ImageRegionType& ) ) + ); } /*******************************************************************************/ diff --git a/Code/Common/mvdImageViewManipulator.cxx b/Code/Common/mvdImageViewManipulator.cxx index 4c66bcc85e..04e9868f28 100644 --- a/Code/Common/mvdImageViewManipulator.cxx +++ b/Code/Common/mvdImageViewManipulator.cxx @@ -51,8 +51,6 @@ ImageViewManipulator AbstractViewManipulator( parent ), m_PreviousIsotropicZoom(1.) { - // TODO: Remove later because initialized in struct's default constructor and resizeEvent(). - this->InitializeContext(1,1); } /*****************************************************************************/ @@ -61,17 +59,19 @@ ImageViewManipulator { } -/*******************************************************************************/ -void +/*****************************************************************************/ +bool ImageViewManipulator -::InitializeContext(int width, int height) +::HasZoomChanged() const { - ImageRegionType::SizeType initialSize; - initialSize[0] = width; - initialSize[1] = height; + bool res = false; + + if (vcl_abs(m_IsotropicZoom - m_PreviousIsotropicZoom) > 0.00000001 ) + { + res = true; + } - // initialize with the given size - m_NavigationContext.m_ViewportImageRegion.SetSize(initialSize); + return res; } /******************************************************************************/ diff --git a/Code/Common/mvdImageViewManipulator.h b/Code/Common/mvdImageViewManipulator.h index e7d44fc4a5..425da49fa9 100644 --- a/Code/Common/mvdImageViewManipulator.h +++ b/Code/Common/mvdImageViewManipulator.h @@ -25,6 +25,10 @@ //// Included at first position before any other ones. #include "ConfigureMonteverdi2.h" + +/*****************************************************************************/ +/* INCLUDE SECTION */ + // // Qt includes (sorted by alphabetic order) //// Must be included before system/custom includes. @@ -43,6 +47,10 @@ #include "mvdTypes.h" #include "mvdAbstractViewManipulator.h" + +/*****************************************************************************/ +/* PRE-DECLARATION SECTION */ + // // External classes pre-declaration. namespace @@ -54,8 +62,14 @@ namespace mvd // // Internal classes pre-declaration. -/** \class ImageViewManipulator - * Brief this class handles the event related to a QGLWidget. It also + +/*****************************************************************************/ +/* CLASS DEFINITION SECTION */ + +/** + * \class ImageViewManipulator + * + * \brief This class handles the event related to a QGLWidget. It also * handles : * - NavigationContext : to store the region of the image to be * rendered. @@ -67,60 +81,72 @@ namespace mvd class Monteverdi2_EXPORT ImageViewManipulator : public AbstractViewManipulator { + + /*-[ QOBJECT SECTION ]-----------------------------------------------------*/ + Q_OBJECT; + /*-[ PUBLIC SECTION ]------------------------------------------------------*/ + // // Public methods. public: - /** Constructor */ + /** \brief Constructor. */ ImageViewManipulator( QObject* parent =NULL ); - /** Destructor */ + /** \brief Destructor. */ virtual ~ImageViewManipulator(); /** */ void mouseMoveEvent ( QMouseEvent * event ); + /** */ void mousePressEvent ( QMouseEvent * event ); + /** */ void mouseReleaseEvent ( QMouseEvent * event ); + /** */ void wheelEvent ( QWheelEvent* event); + /** */ void resizeEvent ( QResizeEvent * event ); + /** */ void keyPressEvent( QKeyEvent * event ); - inline - bool HasZoomChanged() const - { - bool res = false; - - if (vcl_abs(m_IsotropicZoom - m_PreviousIsotropicZoom) > 0.00000001 ) - { - res = true; - } + /** */ + bool HasZoomChanged() const; - return res; - } - -// -// SIGNALS. -signals: + /*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/ // // Public SLOTS. public slots: - void InitializeContext(int width, int height); void OnModelImageRegionChanged(const ImageRegionType & largestRegion); - + + /*-[ SIGNALS SECTION ]-----------------------------------------------------*/ + +// +// Signals. +signals: + + /*-[ PROTECTED SECTION ]---------------------------------------------------*/ + // // Protected methods. protected: + /** */ void ConstrainRegion( ImageRegionType& region, const ImageRegionType& largest); + + /** */ void CenterRegion(double scale); + + /** */ void ResizeRegion(unsigned int w, unsigned int h); // // Protected attributes. protected: + /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ + // // Private types. private: @@ -128,20 +154,32 @@ private: // // Private methods. private: - + /** */ void Zoom(const double scale); + + /** */ void moveRegion(double dx, double dy); // // Private attributes. private: - double m_PreviousIsotropicZoom; + /** */ + double m_PreviousIsotropicZoom; + + /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ // -// SLOTS. +// Slots. private slots: }; } // end namespace 'mvd' +/*****************************************************************************/ +/* INLINE SECTION */ + +namespace mvd +{ +} // end namespace 'mvd' + #endif // __mvdImageViewManipulator_h diff --git a/Code/Common/mvdMyClass.h b/Code/Common/mvdMyClass.h index 9ed00e7477..501f5597d5 100644 --- a/Code/Common/mvdMyClass.h +++ b/Code/Common/mvdMyClass.h @@ -66,6 +66,8 @@ namespace mvd /** * \class MyClass + * + * \brief WIP. */ class Monteverdi2_EXPORT MyClass : public QObject @@ -81,12 +83,18 @@ class Monteverdi2_EXPORT MyClass : // Public methods. public: - /** Constructor */ + /** \brief Constructor. */ MyClass( QObject* parent =NULL ); - /** Destructor */ + /** \brief Destructor. */ virtual ~MyClass(); + /*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/ + +// +// Public SLOTS. +public slots: + /*-[ SIGNALS SECTION ]-----------------------------------------------------*/ // diff --git a/Code/Common/mvdQuicklookViewManipulator.cxx b/Code/Common/mvdQuicklookViewManipulator.cxx index c15c513c88..c7dee19347 100644 --- a/Code/Common/mvdQuicklookViewManipulator.cxx +++ b/Code/Common/mvdQuicklookViewManipulator.cxx @@ -51,8 +51,6 @@ QuicklookViewManipulator AbstractViewManipulator( parent ), m_PreviousIsotropicZoom(1.) { - // TODO: Remove later because initialized in struct's default constructor and resizeEvent(). - this->InitializeContext(1,1); } /*****************************************************************************/ @@ -61,17 +59,12 @@ QuicklookViewManipulator { } -/*******************************************************************************/ -void +/*****************************************************************************/ +bool QuicklookViewManipulator -::InitializeContext(int width, int height) +::HasZoomChanged() const { - ImageRegionType::SizeType initialSize; - initialSize[0] = width; - initialSize[1] = height; - - // initialize with the given size - m_NavigationContext.m_ViewportImageRegion.SetSize(initialSize); + return false; } /******************************************************************************/ @@ -329,14 +322,14 @@ QuicklookViewManipulator void QuicklookViewManipulator ::keyPressEvent( QKeyEvent * event ) -{ - +{ } /*****************************************************************************/ /* SLOTS */ /*****************************************************************************/ -void QuicklookViewManipulator +void +QuicklookViewManipulator ::OnModelImageRegionChanged(const ImageRegionType & largestRegion) { // set back the zoom to 1 diff --git a/Code/Common/mvdQuicklookViewManipulator.h b/Code/Common/mvdQuicklookViewManipulator.h index 032e85faba..69d59f6458 100644 --- a/Code/Common/mvdQuicklookViewManipulator.h +++ b/Code/Common/mvdQuicklookViewManipulator.h @@ -25,6 +25,10 @@ //// Included at first position before any other ones. #include "ConfigureMonteverdi2.h" + +/*****************************************************************************/ +/* INCLUDE SECTION */ + // // Qt includes (sorted by alphabetic order) //// Must be included before system/custom includes. @@ -44,6 +48,10 @@ #include "mvdTypes.h" #include "mvdAbstractViewManipulator.h" + +/*****************************************************************************/ +/* PRE-DECLARATION SECTION */ + // // External classes pre-declaration. namespace @@ -55,8 +63,14 @@ namespace mvd // // Internal classes pre-declaration. -/** \class QuicklookViewManipulator - * Brief this class handles the event related to a QGLWidget. It also + +/*****************************************************************************/ +/* CLASS DEFINITION SECTION */ + +/** + * \class QuicklookViewManipulator + * + * \brief This class handles the event related to a QGLWidget. It also * handles : * - NavigationContext : to store the region of the image to be * rendered. @@ -68,105 +82,106 @@ namespace mvd class Monteverdi2_EXPORT QuicklookViewManipulator : public AbstractViewManipulator { + + /*-[ QOBJECT SECTION ]-----------------------------------------------------*/ + Q_OBJECT; + /*-[ PUBLIC SECTION ]------------------------------------------------------*/ + // // Public methods. public: - /** Constructor */ + /** \brief Constructor. */ QuicklookViewManipulator( QObject* parent =NULL ); - /** Destructor */ + /** \brief Destructor. */ virtual ~QuicklookViewManipulator(); /** */ void mouseMoveEvent ( QMouseEvent * event ); + /** */ void mousePressEvent ( QMouseEvent * event ); + /** */ void mouseReleaseEvent ( QMouseEvent * event ); + /** */ void wheelEvent ( QWheelEvent* event); + /** */ void resizeEvent ( QResizeEvent * event ); + /** */ void keyPressEvent( QKeyEvent * event ); - inline - bool HasZoomChanged() const - { - return false; - } - -// -// SIGNALS. -signals: + /** */ + bool HasZoomChanged() const; + + /*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/ // // Public SLOTS. public slots: - void InitializeContext(int width, int height); void OnModelImageRegionChanged(const ImageRegionType & largestRegion); + /*-[ SIGNALS SECTION ]-----------------------------------------------------*/ + +// +// Signals. +signals: + + /*-[ PROTECTED SECTION ]---------------------------------------------------*/ + // // Protected methods. protected: + /** */ void ConstrainRegion( ImageRegionType& region, const ImageRegionType& largest); + + /** */ void CenterRegion(double scale); + + /** */ void ResizeRegion(unsigned int w, unsigned int h); - + // // Protected attributes. protected: + /*-[ PRIVATE SECTION ]-----------------------------------------------------*/ + // // Private types. private: - /** Navigation context */ - struct NavigationContextType - { - ImageRegionType m_ViewportImageRegion; - ImageRegionType m_ModelImageRegion; - // Stored as double to keep precision when dividing - // by scale - double m_SizeXBeforeConstrain; - double m_SizeYBeforeConstrain; - }; - - /** Mouse context */ - struct MouseContextType - { - /** Default constructor */ - MouseContextType() : - x( 0 ), - y( 0 ), - xMove( 0 ), - yMove( 0 ), - dx( 0 ), - dy( 0 ) - { - } - - int x; // mousePress x - int y; // mousePress y - int xMove; // for mouseMove x - int yMove; // for mouseMove y - int dx; // mouseMove in x (Drag) - int dy; // mouseMove in y (Drag) - }; // // Private methods. private: + /** */ void Zoom(const double scale); + + /** */ void moveRegion(double dx, double dy); // // Private attributes. private: - double m_PreviousIsotropicZoom; + // TODO: No zoom for quicklook. Remove when implementation is cleaned. + double m_PreviousIsotropicZoom; + + /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ + // -// SLOTS. +// Slots. private slots: }; } // end namespace 'mvd' +/*****************************************************************************/ +/* INLINE SECTION */ + +namespace mvd +{ +} // end namespace 'mvd' + #endif // __mvdQuicklookViewManipulator_h -- GitLab