Commit 7fc6ba19 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD #138] - coupled network editor and tree view. Cleaned GUI code a little bit.

parent ee749552
......@@ -282,11 +282,11 @@ void WQt4Gui::slotAddLog( const WLogEntry& /*entry*/ )
void WQt4Gui::slotAddDatasetOrModuleToTree( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleAssocEvent( module ) );
if( m_mainWindow->getNetworkEditor() )
{
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleAssocEvent( module ) );
}
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleAssocEvent( module ) );
}
void WQt4Gui::slotAddRoiToTree( osg::ref_ptr< WROI > roi )
......@@ -302,23 +302,23 @@ void WQt4Gui::slotRemoveRoiFromTree( osg::ref_ptr< WROI > roi )
void WQt4Gui::slotActivateDatasetOrModuleInTree( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleReadyEvent( module ) );
QCoreApplication::postEvent( m_mainWindow, new WModuleReadyEvent( module ) );
if( m_mainWindow->getNetworkEditor() )
{
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleReadyEvent( module ) );
}
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleReadyEvent( module ) );
QCoreApplication::postEvent( m_mainWindow, new WModuleReadyEvent( module ) );
}
void WQt4Gui::slotRemoveDatasetOrModuleInTree( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleRemovedEvent( module ) );
QCoreApplication::postEvent( m_mainWindow, new WModuleRemovedEvent( module ) );
if( m_mainWindow->getNetworkEditor() )
{
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleRemovedEvent( module ) );
}
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleRemovedEvent( module ) );
QCoreApplication::postEvent( m_mainWindow, new WModuleRemovedEvent( module ) );
}
void WQt4Gui::slotConnectionEstablished( boost::shared_ptr<WModuleConnector> in, boost::shared_ptr<WModuleConnector> out )
......
......@@ -56,6 +56,7 @@
#include "../events/WRoiAssocEvent.h"
#include "../events/WRoiRemoveEvent.h"
#include "../WMainWindow.h"
#include "../networkEditor/WQtNetworkEditor.h"
#include "../WQt4Gui.h"
#include "../WQtCombinerActionList.h"
#include "../WQtModuleConfig.h"
......@@ -67,7 +68,8 @@
WQtControlPanel::WQtControlPanel( WMainWindow* parent )
: QDockWidget( "Control Panel", parent ),
m_ignoreSelectionChange( false )
m_ignoreSelectionChange( false ),
m_activeModule( WModule::SPtr() )
{
setObjectName( "Control Panel Dock" );
......@@ -298,18 +300,13 @@ bool WQtControlPanel::event( QEvent* event )
return true;
}
WLogger::getLogger()->addLogMessage( "Activating module " + e->getModule()->getName() + " in control panel.",
"ControlPanel", LL_DEBUG );
// search all the item matching the module
std::list< WQtTreeItem* > items = findItemsByModule( e->getModule() );
for( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
for( std::list< WQtTreeItem* >::const_iterator it = items.begin(); it != items.end(); ++it )
{
( *iter )->setSelected( true );
( *iter )->setDisabled( false );
( *it )->setDisabled( false );
}
selectTreeItem();
setActiveModule( e->getModule() );
return true;
}
......@@ -545,7 +542,6 @@ WQtDatasetTreeItem* WQtControlPanel::addDataset( boost::shared_ptr< WModule > mo
WQtSubjectTreeItem* subject = static_cast< WQtSubjectTreeItem* >( m_moduleTreeWidget->topLevelItem( subjectId + c ) );
subject->setExpanded( true );
WQtDatasetTreeItem* item = subject->addDatasetItem( module );
m_moduleTreeWidget->setCurrentItem( item );
item->setDisabled( true );
item->setExpanded( true );
......@@ -663,94 +659,42 @@ void WQtControlPanel::selectTreeItem()
return;
}
boost::shared_ptr< WModule > module;
boost::shared_ptr< WProperties > props;
boost::shared_ptr< WProperties > infoProps;
if( m_moduleTreeWidget->selectedItems().size() != 0 )
{
clearAndDeleteTabs();
// disable delete action for tree items that have children.
if( m_moduleTreeWidget->selectedItems().at( 0 )->childCount() != 0 )
{
m_deleteModuleAction->setEnabled( false );
}
else
{
m_deleteModuleAction->setEnabled( true );
}
switch( m_moduleTreeWidget->selectedItems().at( 0 )->type() )
{
case SUBJECT:
case MODULEHEADER:
// deletion of headers and subjects is not allowed
m_deleteModuleAction->setEnabled( false );
createCompatibleButtons( module ); // module is NULL at this point
break;
case DATASET:
module = ( static_cast< WQtDatasetTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
// crashed modules should not provide any props
if( module->isCrashed()() )
{
return;
// deletion of headers and subjects is not allowed
deactivateModuleSelection( false );
}
props = module->getProperties();
infoProps = module->getInformationProperties();
createCompatibleButtons( module );
break;
case DATASET:
{
boost::shared_ptr< WDataModule > dataModule = boost::shared_dynamic_cast< WDataModule >( module );
// if the selected module contains a texture, select the corresponding texture in the texture sorter.
if( dataModule )
{
if( dataModule->getDataSet() )
{
m_colormapper->selectTexture( dataModule->getDataSet() );
}
}
WModule::SPtr module = ( static_cast< WQtDatasetTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
setActiveModule( module );
}
break;
case MODULE:
{
module = ( static_cast< WQtModuleTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
m_deleteModuleAction->setEnabled( true );
// this is ugly since it causes the property tab to update multiple times if multiple items get selected by this call
// but it highlights all the same items which is nice and wanted here
// Set the ignore flag to avoid that this method gets called several times
m_ignoreSelectionChange = true;
std::list< WQtTreeItem* > items = findItemsByModule( module );
for( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
{
( *iter )->setSelected( true );
}
m_ignoreSelectionChange = false;
// crashed modules should not provide any props
if( module->isCrashed()() )
{
return;
}
props = module->getProperties();
infoProps = module->getInformationProperties();
createCompatibleButtons( module );
WModule::SPtr module = ( static_cast< WQtModuleTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
setActiveModule( module );
}
break;
case ROIHEADER:
case ROIBRANCH:
case ROI:
break;
default:
deactivateModuleSelection( false );
break;
}
}
buildPropTab( props, infoProps );
else
{
// clean up if nothing is selected
setActiveModule( WModule::SPtr() ); // module is NULL at this point
}
}
void WQtControlPanel::selectRoiTreeItem()
......@@ -805,49 +749,139 @@ void WQtControlPanel::selectRoiTreeItem()
buildPropTab( props, boost::shared_ptr< WProperties >() );
}
void WQtControlPanel::selectDataModule( boost::shared_ptr< WDataSet > dataSet )
void WQtControlPanel::selectDataModule( osg::ref_ptr< WGETexture3D > texture )
{
m_moduleTreeWidget->clearSelection();
clearAndDeleteTabs();
buildPropTab( texture->getProperties(), texture->getInformationProperties() );
}
QTreeWidgetItem* WQtControlPanel::findModuleItem( WModule::SPtr module ) const
{
QTreeWidgetItemIterator it( m_moduleTreeWidget );
QTreeWidgetItem* item = NULL;
while( *it )
{
if( dynamic_cast< WQtDatasetTreeItem* >( *it ) )
if( dynamic_cast< WQtModuleTreeItem* >( *it ) )
{
WModule::SPtr currentModule;
currentModule = boost::shared_dynamic_cast< WModule >( ( dynamic_cast< WQtModuleTreeItem* >( *it ) )->getModule() );
if( currentModule )
{
if( currentModule == module )
{
item = *it;
break;
}
}
}
else if( dynamic_cast< WQtDatasetTreeItem* >( *it ) )
{
boost::shared_ptr< WDataModule > dataModule;
dataModule = boost::shared_dynamic_cast< WDataModule >( ( dynamic_cast< WQtDatasetTreeItem* >( *it ) )->getModule() );
if( dataModule )
{
if( dataModule->getDataSet() == dataSet )
if( dataModule == module )
{
( *it )->setSelected( true );
item = *it;
break;
}
}
}
++it;
}
selectTreeItem();
return item;
}
void WQtControlPanel::selectDataModule( osg::ref_ptr< WGETexture3D > texture )
void WQtControlPanel::deactivateModuleSelection( bool selectTopmost )
{
m_ignoreSelectionChange = true;
m_activeModule = WModule::SPtr();
// select top element and reset some menu actions
if( selectTopmost )
{
m_moduleTreeWidget->clearSelection();
selectUpperMostEntry();
}
m_deleteModuleAction->setEnabled( false );
// remove properties tabs
clearAndDeleteTabs();
buildPropTab( texture->getProperties(), texture->getInformationProperties() );
// clean compatibles toolbar, add only subject independent items
createCompatibleButtons( m_activeModule );
// also notify network editor
WQtNetworkEditor* nwe = m_mainWindow->getNetworkEditor();
if( nwe )
{
nwe->clearSelection();
}
m_ignoreSelectionChange = false;
return;
}
void WQtControlPanel::setNewActiveModule( boost::shared_ptr< WModule > module )
void WQtControlPanel::setActiveModule( WModule::SPtr module )
{
m_ignoreSelectionChange = true;
// is module NULL? remove everything
if( !module || module->isCrashed() )
{
deactivateModuleSelection();
m_ignoreSelectionChange = false;
return;
}
// only if something has changed
if( m_activeModule == module )
{
m_ignoreSelectionChange = false;
return;
}
m_activeModule = module;
wlog::debug( "ControlPanel" ) << "Activating module \"" << module->getName() << "\".";
// update the m_moduleTreeWidget
std::list< WQtTreeItem* > items = findItemsByModule( module );
WAssert( items.size(), "No item found for module " + module->getName() );
m_moduleTreeWidget->clearSelection();
for( std::list< WQtTreeItem* >::const_iterator it = items.begin(); it != items.end(); ++it )
{
( *it )->setSelected( true );
}
// also notify network editor
WQtNetworkEditor* nwe = m_mainWindow->getNetworkEditor();
if( nwe )
{
nwe->selectByModule( module );
}
// remove property tabs
clearAndDeleteTabs();
// set new property tabs
buildPropTab( module->getProperties(), module->getInformationProperties() );
// NOTE: this handles null pointers properly.
// update compatibles toolbar
createCompatibleButtons( module );
if( module )
// disable delete action for tree items that have children.
if( m_moduleTreeWidget->selectedItems().at( 0 )->childCount() != 0 )
{
createCompatibleButtons( module );
buildPropTab( module->getProperties(), module->getInformationProperties() );
m_deleteModuleAction->setEnabled( false );
}
else
{
m_deleteModuleAction->setEnabled( true );
}
m_ignoreSelectionChange = false;
}
WQtPropertyGroupWidget* WQtControlPanel::buildPropWidget( WPropertyGroupBase::SPtr props )
......
......@@ -170,13 +170,6 @@ public:
*/
void selectUpperMostEntry();
/**
* allows other objects to build the property tab (probably only for WQtNetworkeditor)
*
* \param module the module from which the property tab is created
**/
void setNewActiveModule( boost::shared_ptr< WModule > module );
/**
* Gets the ROI dock widget.
*
......@@ -212,6 +205,19 @@ public:
*/
QAction* getMissingModuleAction() const;
/**
* Sets the module which is now active. Updates the GUI accordingly. Can be NULL which causes the GUI to remove all module specific stuff.
*
* \param module the module to activate
*/
void setActiveModule( WModule::SPtr module );
/**
* Used to clean the GUI from any module specify widgets.
*
* \param selectTopmost select top element or keep current
*/
void deactivateModuleSelection( bool selectTopmost = true );
protected:
/**
* Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
......@@ -350,6 +356,11 @@ private:
*/
bool m_ignoreSelectionChange;
/**
* Ignore recursive selection update in network editor.
*/
bool m_ignoreSelectionChangeNWE;
/**
* The WQtCombinerActionList needs some predicate which decides whether to exclude a certain module from the list or not. We use this
* predicate here. It is configured internally using a white and blacklist.
......@@ -361,6 +372,10 @@ private:
*/
QAction* m_missingModuleAction;
/**
* The module currently active
*/
WModule::SPtr m_activeModule;
private slots:
/**
* function that gets called when a tree item is selected, on a new select that tab widget
......@@ -374,18 +389,21 @@ private slots:
*/
void selectRoiTreeItem();
/**
* Will be called to select the data module for the given dataset.
* \param dataSet the module for this dataset will be selected.
*/
void selectDataModule( boost::shared_ptr< WDataSet > dataSet );
/**
* Will be called to select the data module for the given texture.
* \param texture the texture currently selected.
*/
void selectDataModule( osg::ref_ptr< WGETexture3D > texture );
/**
* Search the tree item representing this module
*
* \param module the module
*
* \return the item or null if not found
*/
QTreeWidgetItem* findModuleItem( WModule::SPtr module ) const;
/**
* function that builds the property tab
*
......
......@@ -94,30 +94,36 @@ QList<QGraphicsItem *> WQtNetworkEditor::selectedItems() const
return m_scene->selectedItems();
}
void WQtNetworkEditor::clearSelection()
{
m_scene->clearSelection();
}
void WQtNetworkEditor::selectByModule( WModule::SPtr module )
{
WQtNetworkItem* item = findItemByModule( module );
if( item && !item->isSelected() )
{
m_scene->clearSelection();
item->setSelected( true );
}
}
void WQtNetworkEditor::selectItem()
{
boost::shared_ptr< WModule > module;
if( m_scene->selectedItems().size() != 0 &&
m_scene->selectedItems().at( 0 )->type() == WQtNetworkItem::Type )
{
if( m_scene->selectedItems().at(0)->type() == WQtNetworkItem::Type )
{
module = ( static_cast< WQtNetworkItem* >( m_scene->selectedItems().at( 0 ) ) )->getModule();
m_mainWindow->getControlPanel()->setActiveModule( module );
return;
}
// crashed modules should not provide any props
if( module->isCrashed() )
{
return;
}
m_mainWindow->getControlPanel()->setNewActiveModule( module );
}
else
{
m_mainWindow->getControlPanel()->setNewActiveModule( module );
}
m_mainWindow->getControlPanel()->deactivateModuleSelection();
}
void WQtNetworkEditor::deleteSelectedItems()
......@@ -181,8 +187,6 @@ bool WQtNetworkEditor::event( QEvent* event )
m_layout->addItem( item );
m_scene->addItem( item );
}
//TODO(skiunke): disablen des moduls solange nicht rdy!
return true;
}
......@@ -246,7 +250,6 @@ bool WQtNetworkEditor::event( QEvent* event )
else
{
return true;
//TODO(skiunke): warning
}
WQtNetworkItem *inItem = findItemByModule( mIn );
......@@ -328,7 +331,6 @@ bool WQtNetworkEditor::event( QEvent* event )
else
{
return true;
//TODO(skiunke): warning
}
......
......@@ -34,6 +34,8 @@
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
#include "core/kernel/WModule.h"
#include "../WQtCombinerToolbar.h"
#include "layout/WNetworkLayout.h"
#include "WQtNetworkItem.h"
......@@ -87,6 +89,18 @@ public:
**/
QList< QGraphicsItem* > selectedItems() const;
/**
* Clears the selection.
*/
void clearSelection();
/**
* Select the item representing the given module. If module not found or NULL, nothing is selected.
*
* \param module the module
*/
void selectByModule( WModule::SPtr module );
protected:
/**
* Reference to the main window of the application.
......
......@@ -51,21 +51,3 @@ WQtNetworkScene::~WQtNetworkScene()
{
}
void WQtNetworkScene::mousePressEvent( QGraphicsSceneMouseEvent *mouseEvent )
{
clearSelection();
//emit selectionChanged();
QGraphicsScene::mousePressEvent( mouseEvent );
}
void WQtNetworkScene::setFakeItem( QGraphicsItem *fake )
{
m_fakeItem = fake;
}
QGraphicsItem* WQtNetworkScene::getFakeItem()
{
return m_fakeItem;
}
......@@ -45,32 +45,8 @@ public:
*/
virtual ~WQtNetworkScene();
/**
* Set a fakeitem to the scene to avoid that groups of connected items
* or single items in the scene push away each other.
*
* \param fake the fake item
*/
void setFakeItem( QGraphicsItem* fake );
/**
* Return the fakeitem in the scene to calculate forces in a more
* beautiful way.
*
* \return the fake item
*/
QGraphicsItem* getFakeItem();
protected:
/**
* Emits a Signal to notify the WQtNetworkEditor to build a default WQtCombinerToolbar
*
* \param mouseEvent the mouse event
*/
void mousePressEvent( QGraphicsSceneMouseEvent* mouseEvent );
private:
QGraphicsItem *m_fakeItem; //!< the fakeitem for the forcebased layout
};
#endif // WQTNETWORKSCENE_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