Commit f3b9e9ab authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - module now get added to the dataset browser in a thread safe way...

[CHANGE] - module now get added to the dataset browser in a thread safe way (from the gui thread) using events.
parent 18dffaa4
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WEVENTTYPES_H
#define WEVENTTYPES_H
#include <QtCore/QEvent>
/**
* This header contains every custom event ID used in QT's event mechanism.
*/
#define WQT_ASSOC_EVENT QEvent::User + 1
#endif // WEVENTTYPES_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WEventTypes.h"
#include "WModuleAssocEvent.h"
WModuleAssocEvent::WModuleAssocEvent( boost::shared_ptr< WModule > module )
: QEvent( static_cast< QEvent::Type >( WQT_ASSOC_EVENT ) ),
m_module( module )
{
// initialize members
}
WModuleAssocEvent::~WModuleAssocEvent()
{
// cleanup
}
boost::shared_ptr< WModule > WModuleAssocEvent::getModule()
{
return m_module;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMODULEASSOCEVENT_H
#define WMODULEASSOCEVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
#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
* the module is already marked as "ready" while processing this event due to the multithreading.
*/
class WModuleAssocEvent: public QEvent
{
public:
/**
* Creates a new event instance denoting that the specified module got associated in the root container.
*/
explicit WModuleAssocEvent( boost::shared_ptr< WModule > module );
/**
* Destructor.
*/
virtual ~WModuleAssocEvent();
/**
* Getter for the module that got associated.
*
* \return the module.
*/
boost::shared_ptr< WModule > getModule();
protected:
/**
* The module that got associated.
*/
boost::shared_ptr< WModule > m_module;
private:
};
#endif // WMODULEASSOCEVENT_H
......@@ -34,6 +34,7 @@
#include <QtGui/QFileDialog>
#include "WMainWindow.h" // this has to be included before any other includes
#include "WModuleAssocEvent.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../modules/data/WMData.h"
......@@ -160,15 +161,8 @@ void WQt4Gui::slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > modu
// get properties from the module and register them
m_mainWindow->getPropertyManager()->connectProperties( module->getProperties() );
// TODO(schurade): is this differentiation between data and "normal" modules really needed?
if ( boost::shared_dynamic_cast< WMData >( module ).get() )
{
m_mainWindow->getDatasetBrowser()->addDataset( module, 0 );
}
else
{
m_mainWindow->getDatasetBrowser()->addModule( module );
}
// create a new event for this and insert it into event queue
QCoreApplication::postEvent ( m_mainWindow->getDatasetBrowser(), new WModuleAssocEvent( module ) );
}
std::vector< boost::shared_ptr< WDataSet > > WQt4Gui::getDataSetList( int subjectId, bool onlyTextures )
......
......@@ -35,6 +35,8 @@
#include "../../../dataHandler/WDataSet.h"
#include "WQtDatasetBrowser.h"
#include "../WModuleAssocEvent.h"
#include "../WEventTypes.h"
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
#include "WQtCheckBox.h"
......@@ -110,6 +112,37 @@ WQtSubjectTreeItem* WQtDatasetBrowser::addSubject( std::string name )
return subject;
}
bool WQtDatasetBrowser::event( QEvent* event )
{
// a module got associated with the root container -> add it to the list
if ( event->type() == WQT_ASSOC_EVENT )
{
// convert event to assoc event
WModuleAssocEvent* e = dynamic_cast< WModuleAssocEvent* >( event ); // NOLINT
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( "Inserting module " + e->getModule()->getName() + " to dataset browser.", "DatasetBrowser", LL_DEBUG );
// finally add the module
// TODO(schurade): is this differentiation between data and "normal" modules really needed?
if ( boost::shared_dynamic_cast< WMData >( e->getModule() ).get() )
{
addDataset( e->getModule(), 0 );
}
else
{
addModule( e->getModule() );
}
return true;
}
return QDockWidget::event( event );
}
WQtDatasetTreeItem* WQtDatasetBrowser::addDataset( boost::shared_ptr< WModule > module, int subjectId )
{
......@@ -118,7 +151,7 @@ WQtDatasetTreeItem* WQtDatasetBrowser::addDataset( boost::shared_ptr< WModule >
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
emit dataSetBrowserEvent( QString( "dataSetAdded" ), true );
WQtDatasetTreeItem* item = subject->addDatasetItem( module );
item->setDisabled( true );
item->setDisabled( false );
return item;
}
......
......@@ -156,6 +156,16 @@ public slots:
protected:
/**
* Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
* processes several custom events, like WModuleAssocEvent.
*
* \param event the event that got transmitted.
*
* \return true if the event got handled properly.
*/
virtual bool event( QEvent* event );
/**
* Reference to the main window of the application.
*/
......
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