Commit a3e07c08 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - added ready event which activates module in dataset browser

parent 14d6ee1a
......@@ -27,7 +27,7 @@ SET(GUI_QT4_MOC_HDRS
QT4_WRAP_CPP(GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*cpp" "datasetbrowser/*cpp" "ribbonMenu/*cpp" )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*cpp" "datasetbrowser/*cpp" "ribbonMenu/*cpp" "events/*.cpp" )
IF( CMAKE_HOST_SYSTEM MATCHES Windows )
ADD_LIBRARY( guiqt4 ${GUI_QT4_SRC} ${GUI_QT4_MOC_SRCS} )
......@@ -35,4 +35,4 @@ ELSE()
ADD_LIBRARY( guiqt4 SHARED ${GUI_QT4_SRC} ${GUI_QT4_MOC_SRCS} )
ENDIF()
TARGET_LINK_LIBRARIES( guiqt4 common gui ge kernel ${QT_LIBS} ${Boost_LIBRARIES} )
\ No newline at end of file
TARGET_LINK_LIBRARIES( guiqt4 common gui ge kernel ${QT_LIBS} ${Boost_LIBRARIES} )
......@@ -34,7 +34,8 @@
#include <QtGui/QFileDialog>
#include "WMainWindow.h" // this has to be included before any other includes
#include "WModuleAssocEvent.h"
#include "events/WModuleAssocEvent.h"
#include "events/WModuleReadyEvent.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../modules/data/WMData.h"
......@@ -136,6 +137,8 @@ int WQt4Gui::run()
// bind the GUI's slot with the ready signal
t_ModuleGenericSignalHandlerType assocSignal = boost::bind( &WQt4Gui::slotAddDatasetOrModuleToBrowser, this, _1 );
m_kernel->getRootContainer()->addDefaultNotifier( WM_ASSOCIATED, assocSignal );
t_ModuleGenericSignalHandlerType readySignal = boost::bind( &WQt4Gui::slotActivateDatasetOrModuleInBrowser, this, _1 );
m_kernel->getRootContainer()->addDefaultNotifier( WM_READY, readySignal );
// now we are initialized
m_isInitialized( true );
......@@ -165,6 +168,12 @@ void WQt4Gui::slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > modu
QCoreApplication::postEvent ( m_mainWindow->getDatasetBrowser(), new WModuleAssocEvent( module ) );
}
void WQt4Gui::slotActivateDatasetOrModuleInBrowser( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent ( m_mainWindow->getDatasetBrowser(), new WModuleReadyEvent( module ) );
}
std::vector< boost::shared_ptr< WDataSet > > WQt4Gui::getDataSetList( int subjectId, bool onlyTextures )
{
return m_mainWindow->getDatasetBrowser()->getDataSetList( subjectId, onlyTextures );
......
......@@ -90,6 +90,13 @@ public:
*/
virtual void slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > module );
/**
* Slot gets called whenever a module switches its state to "ready".
*
* \param module the module.
*/
virtual void slotActivateDatasetOrModuleInBrowser( boost::shared_ptr< WModule > module );
/**
* getter functions for the signales proved by the gui
*/
......
......@@ -35,8 +35,9 @@
#include "../../../dataHandler/WDataSet.h"
#include "WQtDatasetBrowser.h"
#include "../WModuleAssocEvent.h"
#include "../WEventTypes.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WModuleReadyEvent.h"
#include "../events/WEventTypes.h"
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
#include "WQtCheckBox.h"
......@@ -122,7 +123,7 @@ bool WQtDatasetBrowser::event( QEvent* event )
if ( !e )
{
// this should never happen, since the type is set to WQT_ASSOC_EVENT.
WLogger::getLogger()->addLogMessage( "Event is not an WModueAssocEvent although its type claims it.", "DatasetBrowser", LL_WARNING );
WLogger::getLogger()->addLogMessage( "Event is not an WModueAssocEvent although its type claims it. Ignoring event.", "DatasetBrowser", LL_WARNING );
}
WLogger::getLogger()->addLogMessage( "Inserting module " + e->getModule()->getName() + " to dataset browser.", "DatasetBrowser", LL_DEBUG );
......@@ -141,6 +142,59 @@ bool WQtDatasetBrowser::event( QEvent* event )
return true;
}
// a module changed its state to "ready" -> activate it in dataset browser
if ( event->type() == WQT_READY_EVENT )
{
// convert event to assoc event
WModuleReadyEvent* e = dynamic_cast< WModuleReadyEvent* >( event ); // NOLINT
if ( !e )
{
// this should never happen, since the type is set to WQT_Ready_EVENT.
WLogger::getLogger()->addLogMessage( "Event is not an WModueReadyEvent although its type claims it. Ignoring event.", "DatasetBrowser", LL_WARNING );
}
WLogger::getLogger()->addLogMessage( "Activating module " + e->getModule()->getName() + " in dataset browser.", "DatasetBrowser", LL_DEBUG );
// iterate tree items and find proper one
QTreeWidgetItemIterator it( m_treeWidget );
while ( *it )
{
// convert to the different types
// This is ugly. Why do we need to differentiate different types?!
WQtModuleTreeItem* itemM = dynamic_cast< WQtModuleTreeItem* >( *it );
boost::shared_ptr< WModule > module = boost::shared_ptr< WModule >();
if ( itemM )
{
module = itemM->getModule();
}
// if both would be derived from a common parent class this two casts would not be needed!
// But unfortunately they aren't.
WQtDatasetTreeItem* itemD = dynamic_cast< WQtDatasetTreeItem* >( *it );
if ( itemD )
{
module = itemD->getModule();
}
// if the pointer is NULL the item was none of the above
if ( !module.get() )
{
++it;
continue;
}
// we found it
if ( e->getModule() == module )
{
// activate it
//itemD->setDisabled( false );
//itemM->setDisabled( false );
}
++it;
}
}
return QDockWidget::event( event );
}
......
......@@ -28,10 +28,16 @@
#include <QtCore/QEvent>
/**
* This header contains every custom event ID used in QT's event mechanism.
* This header contains every custom event ID used in QT's event mechanism. Please note, that since Qt4.4 there is
* QEvent::registerEventType which can handle this job better than this header. But as we use an older Qt Version we need to do it
* this way.
*/
// when a module got associated
#define WQT_ASSOC_EVENT QEvent::User + 1
// when a module signals its ready state
#define WQT_READY_EVENT QEvent::User + 2
#endif // WEVENTTYPES_H
......@@ -29,7 +29,7 @@
#include <QtCore/QEvent>
#include "../../kernel/WModule.h"
#include "../../../kernel/WModule.h"
/**
* Event signalling a new module has been associated with the root container in the kernel. Please note that it is possible that
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment