Skip to content

Commit dac09f4

Browse files
author
Daniele Giunchi
committed
Merge branch 'master' of github.com:SCS-B3C/MAF
2 parents 58e27f3 + 7754738 commit dac09f4

27 files changed

+527
-72
lines changed

src/mafApplicationLogic/mafLogic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool mafLogic::initialize() {
8282

8383
// Initialize data hierarchy
8484
QGenericReturnArgument ret_val = mafEventReturnArgument(mafCore::mafHierarchyPointer, m_Hierarchy);
85-
mafEventBus::mafEventBusManager::instance()->notifyEvent("maf.local.resources.hierarchy.create", mafEventTypeLocal, NULL, &ret_val);
85+
mafEventBus::mafEventBusManager::instance()->notifyEvent("maf.local.resources.hierarchy.request", mafEventTypeLocal, NULL, &ret_val);
8686

8787
// Perform design by contract check.
8888
ENSURE(handler);

src/mafCore/mafHierarchy.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ void mafHierarchy::clear() {
150150
m_TreeIterator.null();
151151
}
152152

153+
void mafHierarchy::setIterator(mafTree<QObject *>::iterator iterator) {
154+
m_TreeIterator = iterator;
155+
}
156+
157+
mafTree<QObject *>::iterator mafHierarchy::iterator() {
158+
return m_TreeIterator;
159+
160+
}
161+
153162
void mafHierarchy::printInformation(QString &string) {
154163
for (mafTree<QObject *>::prefix_iterator i = m_Tree->prefix_begin(); i != m_Tree->prefix_end(); ++i) {
155164
mafTreeNode<QObject *> *n = i.simplify().node();

src/mafCore/mafHierarchy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class MAFCORESHARED_EXPORT mafHierarchy : public mafObject {
7474
/// Remove all the nodes and delete them.
7575
void clear();
7676

77+
/// set current iterator.
78+
void setIterator(mafTree<QObject *>::iterator iterator);
79+
80+
/// Return current iterator.
81+
mafTree<QObject *>::iterator iterator();
82+
7783
signals:
7884
/// Signal emitted when a new item is attached to the hierarchy.
7985
void itemAttached(QObject *item, QObject *parent);

src/mafGUI/mafDragDropModel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ Qt::ItemFlags mafDragDropModel::flags(const QModelIndex &index) const
5454
Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index);
5555
if (index.isValid()) {
5656
mafTreeItem *item = (mafTreeItem *)this->itemFromIndex(index);
57-
if (item->data()->objectName().compare("root") == 0) {
58-
// Not allow Drag of the Root
59-
return Qt::ItemIsDropEnabled | defaultFlags;
57+
if(item->parent() == 0) {
58+
//Not allow Drag of the Root
59+
return Qt::ItemIsDropEnabled | defaultFlags;
6060
}
61+
// if (item->->data()) != NULL) {
62+
// if (item->data()->objectName().compare("root") == 0) {
63+
// // Not allow Drag of the Root
64+
// return Qt::ItemIsDropEnabled | defaultFlags;
65+
// }
66+
// }
6167
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
6268
} else
6369
return Qt::ItemIsDropEnabled | defaultFlags;

src/mafGUI/mafGUIManager.cpp

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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

268271
void mafGUIManager::createMenus() {
@@ -378,26 +381,26 @@ void mafGUIManager::removeOperationGUI() {
378381

379382
mafTreeWidget *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

403406
mafTextEditWidget *mafGUIManager::createLogWidget(QWidget *parent) {
@@ -452,6 +455,20 @@ void mafGUIManager::createView() {
452455

453456
void 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+
466500
void 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

475514
void mafGUIManager::chooseFileDialog(const QString title, const QString start_dir, const QString wildcard) {

src/mafGUI/mafGUIManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ private slots:
136136
/// Update the GUI associated to the selected view.
137137
void viewSelected(mafCore::mafObjectBase *view);
138138

139+
/// Set mafVMEManager hierarchy to the tree model.
140+
void viewDestroyed();
141+
139142
/// Allow to send a vme selection request when an item has been clicked into the mafTreWidget.
140143
void selectVME(QModelIndex);
141144

@@ -210,6 +213,8 @@ private slots:
210213
QMainWindow *m_MainWindow; ///< Main window associated to the application.
211214
mafUILoaderQt *m_UILoader; ///< Class in charge to load the GUI.
212215
mafGUILoadedType m_GUILoadedType; ///< Type of GUI loaded.
216+
mafTreeModel *m_Model; ///< Tree model of VME.
217+
mafTreeWidget *m_TreeWidget; ///< Visualize the tree model.
213218
};
214219

215220
/////////////////////////////////////////////////////////////

src/mafGUI/mafTreeItem.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ mafTreeItem::mafTreeItem(QObject *obj, bool done) : QStandardItem(obj->objectNam
1818
setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|
1919
Qt::ItemIsEditable);
2020
bool canVisualize = false;
21-
if (obj->metaObject()->className() != "mafResources::mafSceneNode"){
21+
QString nodeName(obj->metaObject()->className()); ;
22+
if (nodeName == "mafResources::mafSceneNode"){
23+
//set icon from VME
2224
canVisualize = obj->property("canVisualize").toBool();
23-
if (!canVisualize) {
25+
if (canVisualize) {
2426
setCheckState(done ? Qt::Checked : Qt::Unchecked);
2527
this->flags() |= Qt::ItemIsUserCheckable;
2628
}
2729
}
28-
setCheckable(!canVisualize);
30+
setCheckable(canVisualize);
2931
m_Data = obj;
3032
}

src/mafGUI/mafTreeItemDelegate.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
using namespace mafCore;
2626
using namespace mafGUI;
27+
using namespace mafEventBus;
2728

2829
mafTreeItemDelegate::mafTreeItemDelegate(QObject *parent) : QStyledItemDelegate(parent), m_isSceneNode(false ){
2930
}
@@ -58,6 +59,9 @@ void mafTreeItemDelegate::setModelData(QWidget * editor, QAbstractItemModel * mo
5859
}
5960

6061
void mafTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
62+
if(!index.isValid()) {
63+
return;
64+
}
6165
mafTreeItem *item = (mafTreeItem *)((QStandardItemModel *)index.model())->itemFromIndex(index);
6266
QStyleOptionViewItemV4 options = option;
6367
initStyleOption(&options, index);
@@ -114,13 +118,21 @@ bool mafTreeItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
114118
bool result = QStyledItemDelegate::editorEvent(event, model, option, index);
115119
QObject *sceneNode = objFromIndex(index);
116120
//If item is a SceneNode, set visibility property to item checked
117-
if (sceneNode->metaObject()->className() == "mafResources::mafSceneNode") {
121+
QString objName = "mafResources::mafSceneNode";
122+
if (objName.compare(sceneNode->metaObject()->className()) == 0) {
118123
m_isSceneNode = true;
119124
QVariant value = index.data(Qt::CheckStateRole);
120125
if (!value.isValid())
121126
return result;
122127
bool state = (static_cast<Qt::CheckState>(value.toInt())) ? true : false;
123-
sceneNode->setProperty("visibility", state);
128+
bool visibility = sceneNode->property("visibility").toBool();
129+
if (visibility != state) {
130+
sceneNode->setProperty("visibility", state);
131+
mafEventArgumentsList argList;
132+
argList.append(mafEventArgument(mafCore::mafObjectBase*, (mafObjectBase*)sceneNode));
133+
argList.append(mafEventArgument(bool, state));
134+
mafEventBusManager::instance()->notifyEvent("maf.local.resources.view.sceneNodeShow", mafEventTypeLocal, &argList);
135+
}
124136
} else {
125137
m_isSceneNode = false;
126138
}

0 commit comments

Comments
 (0)