1818#include " mafTextHighlighter.h"
1919#include " mafGUIApplicationSettingsDialog.h"
2020#include " mafTreeItemDelegate.h"
21+ #include " mafTreeItemSceneNodeDelegate.h"
2122
2223#include < mafOperationWidget.h>
2324
@@ -29,7 +30,8 @@ mafGUIManager::mafGUIManager(QMainWindow *main_win, const QString code_location)
2930 , m_NewAct(NULL ), m_CollaborateAct(NULL )
3031 , m_OpenAct(NULL ), m_SaveAct(NULL ), m_SaveAsAct(NULL ), m_RecentFilesSeparatorAct(NULL ), m_ExitAct(NULL )
3132 , m_CutAct(NULL ), m_CopyAct(NULL ), m_PasteAct(NULL ), m_AboutAct(NULL )
32- , m_MaxRecentFiles(5 ), m_ActionsCreated(false ), m_MainWindow(main_win) {
33+ , m_MaxRecentFiles(5 ), m_ActionsCreated(false ), m_MainWindow(main_win)
34+ , m_Model(NULL ), m_TreeWidget(NULL ) {
3335
3436 m_SettingsDialog = new mafGUIApplicationSettingsDialog ();
3537 m_OperationWidget = new mafOperationWidget ();
@@ -261,8 +263,9 @@ void mafGUIManager::registerEvents() {
261263 // OperationManager's callback
262264 mafRegisterLocalCallback (" maf.local.resources.operation.started" , this , " operationDidStart(mafCore::mafObjectBase *)" );
263265
264- // ViewManager's callbacks .
266+ // ViewManager's callback .
265267 mafRegisterLocalCallback (" maf.local.resources.view.selected" , this , " viewSelected(mafCore::mafObjectBase *)" );
268+ mafRegisterLocalCallback (" maf.local.resources.view.noneViews" , this , " viewDestroyed()" );
266269}
267270
268271void mafGUIManager::createMenus () {
@@ -378,26 +381,26 @@ void mafGUIManager::removeOperationGUI() {
378381
379382mafTreeWidget *mafGUIManager::createTreeWidget (mafTreeModel *model, QWidget *parent) {
380383// QSettings settings;
381- mafTreeWidget *w = new mafTreeWidget ();
384+ m_Model = model;
385+ m_TreeWidget = new mafTreeWidget ();
382386 mafTreeItemDelegate *itemDelegate = new mafTreeItemDelegate (this );
383- w ->setAnimated (true );
384- w ->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
385- w ->setMinimumSize (200 , 0 );
386- w ->setMaximumSize (16777215 , 16777215 );
387- connect (w , SIGNAL (clicked (QModelIndex)), this , SLOT (selectVME (QModelIndex)));
388- connect (model , SIGNAL (itemAdded (QModelIndex)), w , SLOT (expand (QModelIndex)));
387+ m_TreeWidget ->setAnimated (true );
388+ m_TreeWidget ->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
389+ m_TreeWidget ->setMinimumSize (200 , 0 );
390+ m_TreeWidget ->setMaximumSize (16777215 , 16777215 );
391+ connect (m_TreeWidget , SIGNAL (clicked (QModelIndex)), this , SLOT (selectVME (QModelIndex)));
392+ connect (m_Model , SIGNAL (itemAdded (QModelIndex)), m_TreeWidget , SLOT (expand (QModelIndex)));
389393
390394 if (parent) {
391395 if (parent->layout ()) {
392- parent->layout ()->addWidget (w );
396+ parent->layout ()->addWidget (m_TreeWidget );
393397 } else {
394- w ->setParent (parent);
398+ m_TreeWidget ->setParent (parent);
395399 }
396400 }
397-
398- w->setModel ( model );
399- w->setItemDelegate (itemDelegate);
400- return w;
401+ m_TreeWidget->setModel ( m_Model );
402+ m_TreeWidget->setItemDelegate (itemDelegate);
403+ return m_TreeWidget;
401404}
402405
403406mafTextEditWidget *mafGUIManager::createLogWidget (QWidget *parent) {
@@ -452,6 +455,20 @@ void mafGUIManager::createView() {
452455
453456void mafGUIManager::viewSelected (mafCore::mafObjectBase *view) {
454457 REQUIRE (view != NULL );
458+ // Set current hierarchy
459+ mafHierarchyPointer sceneGraph;
460+ sceneGraph = view->property (" hierarchy" ).value <mafCore::mafHierarchyPointer>();
461+ if (m_Model) {
462+ // Set hierarchy of selected view and set the current index
463+ m_Model->clear ();
464+ m_Model->setHierarchy (sceneGraph);
465+ QModelIndex index = m_Model->index (0 , 0 );
466+ // TODO: select previous index
467+ m_TreeWidget->selectionModel ()->setCurrentIndex (index, QItemSelectionModel::Select);
468+ mafTreeItemSceneNodeDelegate *itemSceneNodeDelegate = new mafTreeItemSceneNodeDelegate (this );
469+ m_TreeWidget->setItemDelegate (itemSceneNodeDelegate);
470+
471+ }
455472 // Get the selected view's UI file
456473 QString guiFilename = view->uiFilename ();
457474 if (guiFilename.isEmpty ()) {
@@ -463,13 +480,35 @@ void mafGUIManager::viewSelected(mafCore::mafObjectBase *view) {
463480 m_UILoader->uiLoad (guiFilename);
464481}
465482
483+ void mafGUIManager::viewDestroyed () {
484+ // Get hierarchy from mafVMEManager
485+ mafCore::mafHierarchyPointer hierarchy;
486+ QGenericReturnArgument ret_val = mafEventReturnArgument (mafCore::mafHierarchyPointer, hierarchy);
487+ mafEventBusManager::instance ()->notifyEvent (" maf.local.resources.hierarchy.request" , mafEventTypeLocal, NULL , &ret_val);
488+ if (m_Model) {
489+ // Set hierarchy of selected view and set the current index
490+ m_Model->clear ();
491+ m_Model->setHierarchy (hierarchy);
492+ QModelIndex index = m_Model->index (0 , 0 );
493+ // TODO: select previous index
494+ m_TreeWidget->selectionModel ()->setCurrentIndex (index, QItemSelectionModel::Select);
495+ mafTreeItemDelegate *itemDelegate = new mafTreeItemDelegate (this );
496+ m_TreeWidget->setItemDelegate (itemDelegate);
497+ }
498+ }
499+
466500void mafGUIManager::selectVME (QModelIndex index) {
467501 QTreeView *tree = (QTreeView *)QObject::sender ();
468- mafTreeModel *model = (mafTreeModel *)tree->model ();
469- mafTreeItem *item = (mafTreeItem *)model ->itemFromIndex (index);
502+ // m_Model = (mafTreeModel *)tree->model();
503+ mafTreeItem *item = (mafTreeItem *)m_Model ->itemFromIndex (index);
470504 QObject *obj = item->data ();
471505 QVariant sel (true );
472506 obj->setProperty (" selected" , sel);
507+
508+ // Notify the item selection.
509+ mafEventArgumentsList argList;
510+ argList.append (mafEventArgument (mafCore::mafObjectBase*, qobject_cast<mafCore::mafObjectBase *>(obj)));
511+ mafEventBusManager::instance ()->notifyEvent (" maf.local.resources.vme.select" , mafEventTypeLocal, &argList);
473512}
474513
475514void mafGUIManager::chooseFileDialog (const QString title, const QString start_dir, const QString wildcard) {
0 commit comments