Skip to content
Snippets Groups Projects
Commit fdd7383e authored by Julien Michel's avatar Julien Michel
Browse files

ENH: (Visu Refactoring) Adding a widget controller

parent 73be1d0d
Branches
Tags
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt 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.
=========================================================================*/
#ifndef __otbImageWidgetController_cxx
#define __otbImageWidgetController_cxx
#include "otbImageWidgetController.h"
namespace otb
{
ImageWidgetController::ImageWidgetController()
{
// Instantiate action handlers list
m_ActionHandlersList = ActionHandlerListType::New();
}
ImageWidgetController::~ImageWidgetController()
{}
void ImageWidgetController::AddActionHandler(ActionHandlerType * handler)
{
// Add the handler to the list
m_ActionHandlersList->PushBack(handler);
}
void ImageWidgetController::RemoveActionHandler(unsigned int index)
{
// Remove the given handler
m_ActionHandlersList->Erase(index);
}
void ImageWidgetController::ClearAllActionHandlers()
{
// Clear the handlers list
m_ActionHandlersList->Clear();
}
int ImageWidgetController::HandleWidgetEvent(std::string widgetId, int event)
{
// Define an iterator on the action handlers list
ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin();
// Found indicates if a handler was found to respond to this event
bool found = false;
// The action handler found
ActionHandlerType * handler;
while(!found && it!=m_ActionHandlersList->End())
{
// Get the current handler
handler = it.Get();
// Check if it listens to (widget,event)
found = handler->ListenToEvent(widgetId,event);
++it;
}
// If an handler was found, use it
if(found)
{
return handler->HandleWidgetEvent(widgetId,event);
}
else
{
return 0;
}
}
void ImageWidgetController::HandleWidgetResize(std::string widgetId, int x, int y, int w, int h)
{
// Define an iterator on the action handlers list
ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin();
// Found indicates if a handler was found to respond to this event
bool found = false;
// The action handler found
ActionHandlerType * handler;
while(!found && it!=m_ActionHandlersList->End())
{
// Get the current handler
handler = it.Get();
// Check if it listens to (widget,event)
found = handler->ListenToResize(widgetId);
++it;
}
// If an handler was found, use it
if(found)
{
handler->HandleWidgetResize(widgetId,x,y,w,h);
}
}
void ImageWidgetController::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
os<<indent<<"Number of action handlers: "<<m_ActionHandlersList->Size()<<std::endl;
}
} // end namespace otb
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt 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.
=========================================================================*/
#ifndef __otbImageWidgetController_h
#define __otbImageWidgetController_h
#include "otbImageWidgetActionHandler.h"
#include "otbObjectList.h"
namespace otb
{
/** \class ImageWidgetController
* \brief This controller processes the events from a set of image
* widget.
* Events are procesed by instances of the ImageWidgetActionHandler
* class which are registered dynamically via the AddActionHandler
* method.
* \sa ImageWidget
* \sa ImageWidgetActionHandler
*/
class ImageWidgetController
: public itk::Object
{
public:
/** Standard class typedefs */
typedef ImageWidgetController Self;
typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory */
itkNewMacro(Self);
/** Runtime information */
itkTypeMacro(ImageWidgetController,Object);
/** Handler typedef */
typedef otb::ImageWidgetActionHandler ActionHandlerType;
typedef otb::ObjectList<ActionHandlerType> ActionHandlerListType;
typedef ActionHandlerListType::Pointer ActionHandlerListPointerType;
/** Add an action handler
* \param handler The action handler.
**/
virtual void AddActionHandler(ActionHandlerType * handler);
/** Remove an action handler if it exists
* \param index The index of the action handler.
**/
virtual void RemoveActionHandler(unsigned int index);
/** Remove all actions handler
*/
virtual void ClearAllActionHandlers();
/** Handle an event from a widget
* \param widgetId The id of the widget the event comes from
* \param event The event code
*/
int HandleWidgetEvent(std::string widgetId, int event);
/** Handle widget resizing
* \param widgetId The id of the resized widget
* \param x new x location
* \param y new y location
* \param w new width
* \param h new height
*/
void HandleWidgetResize(std::string widgetId,int x,int y, int w, int h);
protected:
/** Constructor */
ImageWidgetController();
/** Destructor */
~ImageWidgetController();
/** Printself method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
ImageWidgetController(const Self&); // purposely not implemented
void operator=(const Self&); // purposely not implemented
/** Action handlers list */
ActionHandlerListPointerType m_ActionHandlersList;
}; // end class
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment