Commit 5990db2f authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD #256] implemented texture sorter.

We need to link the marked textures with the marked data modules in the
future
parent 2b8874bc
......@@ -129,7 +129,7 @@ public:
// /**
// * Returns the dataset which corresponds to the specified ID. It throws an exception, if the dataset does not exists anymore.
// *
// * \param datasetID the ID to search the dataset for
// * \ param datasetID the ID to search the dataset for
// *
// * \return the dataset.
// *
......
......@@ -29,6 +29,7 @@ SET(GUI_QT4_MOC_HDRS
datasetbrowser/WQtNumberEditDouble.h
datasetbrowser/WQtTreeWidget.h
datasetbrowser/WQtTreeItem.h
datasetbrowser/WQtTextureSorter.h
)
QT4_WRAP_CPP(GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
......
......@@ -39,12 +39,15 @@
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../kernel/WModuleProjectFileCombiner.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "WOpenCustomDockWidgetEvent.h"
#include "WQt4Gui.h"
#include "events/WModuleAssocEvent.h"
#include "events/WRoiAssocEvent.h"
#include "events/WModuleReadyEvent.h"
#include "events/WModuleCrashEvent.h"
#include "events/WUpdateTextureSorterEvent.h"
WQt4Gui::WQt4Gui( int argc, char** argv )
: WGUI( argc, argv )
......@@ -55,24 +58,16 @@ WQt4Gui::~WQt4Gui()
{
}
#ifdef _WIN32
// need this on windows to make it link correctly.
//const unsigned int boost::program_options::options_description::m_default_line_length = 2048;
#endif
bool WQt4Gui::parseOptions()
{
namespace po = boost::program_options; // since the namespace is far to big we use a shortcut here
po::options_description desc( "Allowed options" );
//#ifndef _WIN32
// TODO(wiebel): this does not link on windows at the moment. But it should!
desc.add_options()
( "help,h", "Prints this help message" )
( "project,p", po::value< std::string >(), "Project file to be loaded on startup." )
( "input,i", po::value< std::vector< std::string > >(), "Input data files that should be loaded automatically" )
( "timed-output,t", "Flag indicating if all log strings should have a time string preceding" );
//#endif
po::positional_options_description p;
p.add( "input", -1 );
......@@ -149,6 +144,9 @@ int WQt4Gui::run()
m_mainWindow->getModuleButtonSignal()->connect( boost::bind( &WKernel::applyModule, m_kernel, _1, _2 ) );
WCondition::t_ConditionNotifierType newDatasetSignal = boost::bind( &WQt4Gui::slotUpdateTextureSorter, this );
WDataHandler::getDefaultSubject()->getListChangeCondition()->subscribeSignal( newDatasetSignal );
// 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 );
......@@ -194,6 +192,12 @@ int WQt4Gui::run()
return qtRetCode;
}
void WQt4Gui::slotUpdateTextureSorter()
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WUpdateTextureSorterEvent() );
}
void WQt4Gui::slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
......
......@@ -73,6 +73,11 @@ public:
*/
virtual boost::shared_ptr< WModule > getSelectedModule();
/**
* Slot gets called whenever we need to update the texture sorter.
*/
virtual void slotUpdateTextureSorter();
/**
* Slot gets called whenever a new module is added.
*
......
......@@ -121,6 +121,12 @@ WQtSubjectTreeItem* WQtDatasetBrowser::addSubject( std::string name )
bool WQtDatasetBrowser::event( QEvent* event )
{
// a subject singals a newly registered data set
if ( event->type() == WQT_UPDATE_TEXTURE_SORTER_EVENT )
{
m_textureSorter->update();
}
// a module got associated with the root container -> add it to the list
if ( event->type() == WQT_ASSOC_EVENT )
{
......
......@@ -27,35 +27,31 @@
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
#include <QtCore/QList>
#include <QtGui/QScrollArea>
#include <QtGui/QVBoxLayout>
#include "../../../common/WLogger.h"
#include "../../../common/WPreferences.h"
#include <QtGui/QListWidgetItem>
#include "../../../dataHandler/WDataSet.h"
#include "../../../dataHandler/WSubject.h"
#include "../../../dataHandler/WDataHandler.h"
#include "../../../dataHandler/exceptions/WDHNoSuchSubject.h"
#include "WQtTextureSorter.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WRoiAssocEvent.h"
#include "../events/WModuleReadyEvent.h"
#include "../events/WEventTypes.h"
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
#include "../../../kernel/WModuleFactory.h"
#include "../WMainWindow.h"
#include "../../../modules/data/WMData.h"
WQtTextureSorter::WQtTextureSorter( QWidget* parent )
: QWidget( parent )
{
m_textureListWidget = new QListWidget( this );
m_textureListWidget->setToolTip( "List of available textures." );
m_textureListWidget->setToolTip( "List of available textures. <b>Sorting Does not work yet.</b>" );
m_layout = new QVBoxLayout();
......@@ -65,13 +61,12 @@ WQtTextureSorter::WQtTextureSorter( QWidget* parent )
m_upButton = new QPushButton();
m_upButton->setText( QString( "up" ) );
// TODO(all): reenable these buttons if sorting works again
m_downButton->setDisabled( true );
m_upButton->setDisabled( true );
buttonLayout->addWidget( m_downButton );
buttonLayout->addWidget( m_upButton );
connect( m_upButton, SIGNAL( pressed() ), this, SLOT( moveItemUp() ) );
connect( m_downButton, SIGNAL( pressed() ), this, SLOT( moveItemDown() ) );
m_layout->addWidget( m_textureListWidget );
m_layout->addLayout( buttonLayout );
......@@ -82,12 +77,169 @@ WQtTextureSorter::~WQtTextureSorter()
{
}
// TODO(wiebel): have a second look on this begin/end read/write mess.
void WQtTextureSorter::update()
{
boost::shared_ptr< WSubject > subject;
try
{
subject = WDataHandler::getDefaultSubject();
}
catch( WDHNoSuchSubject )
{
return;
}
if( !subject )
{
return;
}
DatasetAccess ta = textures.getAccessObject();
ta->beginRead();
if( ta->get().empty() )
{
ta->endRead();
DatasetAccess da = subject->getAccessObject();
da->beginRead();
for( DatasetContainerType::iterator it = da->get().begin(); it != da->get().end(); ++it )
{
if( ( *it )->isTexture() )
{
da->endRead();
ta->beginWrite();
ta->get().push_back( *it );
ta->endWrite();
da->beginRead();
}
}
da->endRead();
}
else
{
ta->endRead();
DatasetAccess da = subject->getAccessObject();
da->beginRead();
for( DatasetContainerType::iterator it = da->get().begin(); it != da->get().end(); ++it )
{
if( ( *it )->isTexture() )
{
ta->beginRead();
if( std::find( ta->get().begin(), ta->get().end(), *it ) == ta->get().end() )
{
ta->endRead();
ta->beginWrite();
ta->get().push_back( *it );
ta->endWrite();
}
else
{
ta->endRead();
}
}
}
da->endRead();
}
int index = m_textureListWidget->currentIndex().row();
m_textureListWidget->clear();
ta->beginRead();
for( DatasetContainerType::iterator it = ta->get().begin(); it != ta->get().end(); ++it )
{
std::string name = string_utils::tokenize( ( *it )->getFileName().c_str(), "/" ).back();
m_textureListWidget->addItem( name.c_str() );
}
ta->endRead();
m_textureListWidget->setCurrentRow( index );
}
void WQtTextureSorter::moveItemDown()
{
// m_treeWidget->moveTreeItemDown();
unsigned int index = m_textureListWidget->currentIndex().row();
DatasetAccess ta = textures.getAccessObject();
ta->beginRead();
if( index < ta->get().size() - 1 )
{
ta->endRead();
QListWidgetItem* ci = m_textureListWidget->takeItem( index );
if( ci )
{
m_textureListWidget->insertItem( index + 1, ci );
m_textureListWidget->clearSelection();
m_textureListWidget->setCurrentItem( ci );
ci->setSelected( true );
ta->beginWrite();
boost::shared_ptr< WDataSet > tmp = ta->get()[index+1];
ta->get()[index+1] = ta->get()[index];
ta->get()[index] = tmp;
ta->endWrite();
}
}
else
{
ta->endRead();
}
sort();
}
void WQtTextureSorter::moveItemUp()
{
// m_treeWidget->moveTreeItemUp();
unsigned int index = m_textureListWidget->currentIndex().row();
if( index > 0 )
{
QListWidgetItem* ci = m_textureListWidget->takeItem( index );
if( ci )
{
DatasetAccess ta = textures.getAccessObject();
ta->beginWrite();
m_textureListWidget->insertItem( index - 1, ci );
m_textureListWidget->clearSelection();
m_textureListWidget->setCurrentItem( ci );
ci->setSelected( true );
boost::shared_ptr< WDataSet > tmp = ta->get()[index-1];
ta->get()[index-1] = ta->get()[index];
ta->get()[index] = tmp;
ta->endWrite();
}
}
sort();
}
bool WQtTextureSorter::isLess( boost::shared_ptr< WDataSet > lhs, boost::shared_ptr< WDataSet > rhs )
{
DatasetAccess ta = textures.getAccessObject();
ta->beginRead();
DatasetContainerType::iterator itLHS = std::find( ta->get().begin(), ta->get().end(), lhs );
DatasetContainerType::iterator itRHS = std::find( ta->get().begin(), ta->get().end(), rhs );
bool result = itLHS < itRHS;
ta->endRead();
return result;
}
void WQtTextureSorter::sort()
{
DatasetAccess da = WDataHandler::getDefaultSubject()->getAccessObject();
da->beginWrite();
std::sort( da->get().begin(), da->get().end(), boost::bind( boost::mem_fn( &WQtTextureSorter::isLess ), this, _1, _2 ) );
da->endWrite();
WDataHandler::getDefaultSubject()->getChangeCondition()->notify();
}
......@@ -25,15 +25,26 @@
#ifndef WQTTEXTURESORTER_H
#define WQTTEXTURESORTER_H
#include <vector>
#include <boost/shared_ptr.hpp>
#include <QtGui/QWidget>
#include <QtGui/QListWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include "../../../common/WSharedSequenceContainer.h"
#include "../../../common/WSharedObject.h"
class WDataSet;
/**
* container widget for a tree widget with context menu and some control widgets
*/
class WQtTextureSorter : public QWidget
{
Q_OBJECT
public:
/**
* Default constructor.
......@@ -49,6 +60,11 @@ public:
*/
virtual ~WQtTextureSorter();
/**
* Update the list view from the list of data sets.
*/
virtual void update();
private:
QListWidget* m_textureListWidget; //!< pointer to the tree widget
QVBoxLayout* m_layout; //!< Layout of the widget
......@@ -56,6 +72,23 @@ private:
QPushButton* m_downButton; //!< button down
QPushButton* m_upButton; //!< button up
typedef std::vector< boost::shared_ptr< WDataSet > > DatasetContainerType; //!< Short for container we want to access b< WSharedSequenceContainer
typedef WSharedSequenceContainer< boost::shared_ptr< WDataSet >, DatasetContainerType > DatasetSharedContainerType; //!< The SharedContainer
typedef DatasetSharedContainerType::WSharedAccess DatasetAccess; //!< Shorthand for the access handler.
DatasetSharedContainerType textures; //!< Local list of of the textures to sort.
/**
* This function returns whether the dataset lhs is above rhs in the texture sorter.
* \param lhs First dataset.
* \param rhs Second dataset.
*/
bool isLess( boost::shared_ptr< WDataSet > lhs, boost::shared_ptr< WDataSet > rhs );
/**
* Resorts the datasets in the subject according to the list in the texture sorter.
*/
void sort();
private slots:
/**
* change order of items, move currently selected item down
......
......@@ -45,5 +45,9 @@
// when a module crashes
#define WQT_CRASH_EVENT QEvent::User + 4
// when a subject signals a newly registered data set
#define WQT_UPDATE_TEXTURE_SORTER_EVENT QEvent::User + 5
#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 "WUpdateTextureSorterEvent.h"
WUpdateTextureSorterEvent::WUpdateTextureSorterEvent()
: QEvent( static_cast< QEvent::Type >( WQT_UPDATE_TEXTURE_SORTER_EVENT ) )
{
// initialize members
}
WUpdateTextureSorterEvent::~WUpdateTextureSorterEvent()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// 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 WUPDATETEXTURESORTEREVENT_H
#define WUPDATETEXTURESORTEREVENT_H
#include <QtCore/QEvent>
/**
* 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 WUpdateTextureSorterEvent: public QEvent
{
public:
/**
* Creates a new event instance denoting that the specified module got associated in the root container.
*/
explicit WUpdateTextureSorterEvent();
/**
* Destructor.
*/
virtual ~WUpdateTextureSorterEvent();
private:
};
#endif // WUPDATETEXTURESORTEREVENT_H
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