Skip to content

Commit bc6b36e

Browse files
author
Daniele Giunchi
committed
add nodes and start drwing graph for eventbus
1 parent 0ea2097 commit bc6b36e

23 files changed

+934
-50
lines changed

examples/chartSample/mainwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ MainWindow::MainWindow()
4747
//view = new MyFasterGraphicView(scene);
4848
view->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
4949

50+
// add the canvas
5051
layout->addWidget(view);
5152

5253
QWidget *widget = new QWidget;
@@ -894,4 +895,4 @@ QIcon MainWindow::createColorIcon(QColor color)
894895

895896
return QIcon(pixmap);
896897
}
897-
//! [32]
898+
//! [32]

examples/chartSample/mainwindow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class ExampleBaseNode : public mafNodeGraphicWidget {
167167
//innerGridLayout->addLayout(rightLayout, 1, 1, 1, 1/*, Qt::AlignRight*/);
168168
QFrame *rightFrame = new QFrame;
169169
rightFrame->setLayout(rightLayout);
170-
innerGridLayout->addWidget(rightFrame, 1, 1, 1, 1/*, Qt::AlignRight*/);
170+
innerGridLayout->addWidget(rightFrame, 1, 1, 1, 1/*, Qt::AlignRight*/);
171171
bottomLayout = new QHBoxLayout();
172172
//innerGridLayout->addLayout(bottomLayout, 2, 0, 1, 2/*, Qt::AlignCenter*/);
173173
QFrame *bottomFrame = new QFrame;
@@ -619,4 +619,4 @@ Q_OBJECT
619619
};
620620

621621

622-
#endif
622+
#endif

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ if(${MAF_PLUGIN_ZIP})
5050
ADD_SUBDIRECTORY(mafPluginZip)
5151
endif(${MAF_PLUGIN_ZIP})
5252

53+
ADD_SUBDIRECTORY(mafPluginEventBusMonitor)
5354
#ADD_SUBDIRECTORY(mafPluginGimias)
5455

5556

src/mafEventBus/mafEventBusManager.cpp

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
using namespace mafEventBus;
1818

19-
2019
mafEventBusManager::mafEventBusManager() : m_EnableEventLogging(false), m_LogEventTopic("*"), m_SkipDetach(false) {
2120
// Create local event dispatcher.
2221
m_LocalDispatcher = new mafEventDispatcherLocal();
@@ -39,6 +38,9 @@ mafEventBusManager::~mafEventBusManager() {
3938
delete i.value();
4039
++i;
4140
}
41+
// clean connection info vector.
42+
m_ConnectionInfoHash.clear();
43+
// clean hash for network connectors.
4244
m_NetworkConnectorHash.clear();
4345

4446
// disconnect detachFromEventBus
@@ -81,6 +83,34 @@ bool mafEventBusManager::addEventProperty(const mafEvent &props) const {
8183
QString topic = props[TOPIC].toString();
8284
QObject *obj = props[OBJECT].value<QObject*>();
8385

86+
/// add to connection infos array this connection
87+
/// chek also if already exists and one of observer or signal is empty
88+
if(!m_ConnectionInfoHash.contains(topic)) {
89+
mafEventBusConnectionInfo info;
90+
info.type = (mafEventType) props[TYPE].toInt();
91+
if(props[SIGTYPE].toInt() == mafSignatureTypeCallback) {
92+
info.slotName.push_back(props[SIGNATURE].toString());
93+
info.observers.push_back(obj);
94+
} else { //is a signal
95+
info.emitter = obj;
96+
info.signalName.append(props[SIGNATURE].toString());
97+
}
98+
//info.callers;
99+
//info.counter;
100+
m_ConnectionInfoHash.insert(topic,info);
101+
} else {
102+
//check the type, and complete the information
103+
mafEventBusConnectionInfo info = m_ConnectionInfoHash.value(topic);
104+
if(info.type == mafSignatureTypeCallback) {
105+
info.slotName.push_back(props[SIGNATURE].toString());
106+
info.observers.push_back(obj);
107+
m_ConnectionInfoHash.insert(topic,info);
108+
} else { //no sense if is a signal
109+
}
110+
}
111+
112+
113+
84114
if(props[TYPE].toInt() == mafEventTypeLocal) {
85115
// Local event dispatching.
86116
if(props[SIGTYPE].toInt() == mafSignatureTypeCallback) {
@@ -122,6 +152,19 @@ void mafEventBusManager::detachObjectFromBus() {
122152
}
123153

124154
void mafEventBusManager::removeObserver(const QObject *obj, const QString topic, bool qt_disconnect) {
155+
/// remove to connection infos array this connection
156+
mafEventBusConnectionInfo info = m_ConnectionInfoHash.value(topic);
157+
int counter = 0;
158+
foreach (QObject *o, info.observers) {
159+
if(o == obj) {
160+
info.observers.remove(counter);
161+
info.slotName.remove(counter);
162+
break;
163+
}
164+
counter++;
165+
}
166+
167+
125168
if(obj == NULL) {
126169
return;
127170
}
@@ -130,6 +173,12 @@ void mafEventBusManager::removeObserver(const QObject *obj, const QString topic,
130173
}
131174

132175
void mafEventBusManager::removeSignal(const QObject *obj, QString topic, bool qt_disconnect) {
176+
/// remove to connection infos array this connection
177+
mafEventBusConnectionInfo info = m_ConnectionInfoHash.value(topic);
178+
info.emitter = NULL;
179+
info.signalName = "";
180+
181+
133182
if(obj == NULL) {
134183
return;
135184
}
@@ -146,7 +195,27 @@ void mafEventBusManager::removeSignal(const QObject *obj, QString topic, bool qt
146195
bool mafEventBusManager::removeEventProperty(const mafEvent &props) const {
147196
bool result(false);
148197
QString topic = props[TOPIC].toString();
149-
198+
QObject *obj = props[OBJECT].value<QObject*>();
199+
200+
/// remove from connection info
201+
if(props[SIGTYPE].toInt() == mafSignatureTypeCallback) {
202+
mafEventBusConnectionInfo info = m_ConnectionInfoHash.value(topic);
203+
int counter = 0;
204+
foreach (QObject *o, info.observers) {
205+
if(o == obj) {
206+
info.observers.remove(counter);
207+
info.slotName.remove(counter);
208+
break;
209+
}
210+
counter++;
211+
}
212+
} else {
213+
mafEventBusConnectionInfo info = m_ConnectionInfoHash.value(topic);
214+
info.emitter = NULL;
215+
info.signalName = "";
216+
}
217+
218+
150219
if(props.eventType() == mafEventTypeLocal) {
151220
// Local event dispatching.
152221
if(props[SIGTYPE].toInt() == mafSignatureTypeCallback) {
@@ -180,6 +249,11 @@ void mafEventBusManager::notifyEvent(const QString topic, mafEventType ev_type,
180249
}
181250
}
182251

252+
/// increment in correct connection info item inside the array, the counter and insert the caller if possible
253+
mafEventBusConnectionInfo info = m_ConnectionInfoHash.value(topic);
254+
info.counter++;
255+
256+
183257
//event dispatched in local channel
184258
mafEvent *event_dic = new mafEvent(topic, ev_type, synch);
185259
notifyEvent(*event_dic, argList, returnArg);
@@ -253,3 +327,7 @@ bool mafEventBusManager::createClient(const QString &communication_protocol, con
253327
}
254328
return res;
255329
}
330+
331+
const mafEventBusConnectionInfoHash &mafEventBusManager::connectionInfosDump() {
332+
return m_ConnectionInfoHash;
333+
}

src/mafEventBus/mafEventBusManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class MAFEVENTBUSSHARED_EXPORT mafEventBusManager : public QObject {
9191
/// Create the client for remote communication according to the given protocol, server host and port.
9292
bool createClient(const QString &communication_protocol, const QString &server_host, unsigned int port);
9393

94+
/// retireve all information for event bus manager connections
95+
const mafEventBusConnectionInfoHash &connectionInfosDump();
96+
9497
public Q_SLOTS:
9598
/// Intercepts objects deletion and detach them from the event bus.
9699
void detachObjectFromBus();
@@ -111,6 +114,7 @@ public Q_SLOTS:
111114

112115
bool m_SkipDetach; ///< lifesafe variable to avoid the detach from eventbus.
113116

117+
mutable mafEventBusConnectionInfoHash m_ConnectionInfoHash;
114118
};
115119

116120
} // namespace mafEventBus

src/mafEventBus/mafEventDefinitions.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ typedef QHash<QString, mafNetworkConnector *> mafNetworkConnectorHash;
104104
///< Enum that identify the mafEventType's type: Local or Remote.
105105
typedef enum {
106106
mafEventTypeLocal,
107-
mafEventTypeRemote
107+
mafEventTypeRemote,
108+
mafEventTypeAll,
108109
} mafEventType;
109110

110111
///< Enum that identify the mafSignatureType's type: Signal or Callback.
@@ -130,6 +131,20 @@ typedef QList<mafEvent *> mafEventItemListType;
130131
/// map which represent list of function to be registered in the server, with parameters
131132
typedef QMap<QString, QList<QVariant::Type> > mafRegisterMethodsMap;
132133

134+
135+
/// this struct will be usefull for tracing all the connection inside the event bus manager.
136+
typedef struct {
137+
mafEventType type;
138+
QObject *emitter;
139+
QVector<QObject*> observers;
140+
QString signalName;
141+
QVector<QString> slotName;
142+
QVector<QObject*> callers;
143+
unsigned int counter;
144+
} mafEventBusConnectionInfo;
145+
146+
typedef QHash<QString, mafEventBusConnectionInfo> mafEventBusConnectionInfoHash;
147+
133148
} // namespace mafEventBus
134149

135150

src/mafGUI/mafDiagramScene.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ mafDiagramScene::mafDiagramScene(QMenu *itemMenu, QObject *parent)
2020
}
2121
//! [0]
2222

23+
void mafDiagramScene::drawNode(mafNodeGraphicWidget *node) {
24+
emit mafNodeGraphicWidgetInserted(node);
25+
}
26+
27+
void mafDiagramScene::drawArrow() {
28+
29+
}
30+
31+
void mafDiagramScene::deleteNode() {
32+
33+
}
34+
35+
void mafDiagramScene::deleteArrow() {
36+
37+
}
38+
2339
//! [1]
2440
void mafDiagramScene::setLineColor(const QColor &color)
2541
{

src/mafGUI/mafDiagramScene.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@ class mafDiagramScene : public QGraphicsScene
2727
Q_OBJECT
2828

2929
public:
30-
enum Mode { InsertItem, InsertLine, InsertText, MoveItem, /*//dw*/ InsertNode, InsertNode2 };
30+
enum Mode { InsertItem, InsertLine, InsertText, MoveItem, InsertNode, InsertNode2 };
3131

3232
mafDiagramScene(QMenu *itemMenu, QObject *parent = 0);
3333
QColor lineColor() const
3434
{ return mLineColor; }
3535
void setLineColor(const QColor &color);
3636

37-
//dw new3: moved and ugly
38-
QMenu *mItemMenu;
37+
QMenu *mItemMenu;
38+
39+
//extended API for draw by functions.
40+
void drawNode(mafNodeGraphicWidget *node);
41+
void drawArrow();
42+
void deleteNode();
43+
void deleteArrow();
44+
3945

4046
public slots:
4147
void setMode(Mode mode);
@@ -78,4 +84,4 @@ public slots:
7884
};
7985
//! [0]
8086

81-
#endif
87+
#endif

src/mafGUI/mafNodeGraphicWidget.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,46 @@
77
//#include "mafNodeConnectorGraphicWidget.h"
88

99
void mafNodeGraphicWidget::hide() {
10-
this->widget()->close();
10+
this->widget()->close();
1111
}
1212

1313
//dw slot
1414
void mafNodeGraphicWidget::deleted() {
15-
this->widget()->close();
16-
//delete this;
15+
this->widget()->close();
16+
//delete this;
1717
}
1818

1919
void mafNodeGraphicWidget::deleted(int result) {
20-
this->widget()->close();
20+
this->widget()->close();
2121
}
2222

2323
mafNodeGraphicWidget::~mafNodeGraphicWidget() {
24-
removeWigetFromConnectors();
25-
//deleteConnections();
26-
//dw new
27-
if (scene() != NULL) {
28-
this->scene()->removeItem(this);
29-
}
24+
removeWigetFromConnectors();
25+
//deleteConnections();
26+
if (scene() != NULL) {
27+
this->scene()->removeItem(this);
28+
}
3029
}
3130

3231
//! [0]
3332
mafNodeGraphicWidget::mafNodeGraphicWidget(QMenu *contextMenu,
3433
QGraphicsItem *parent, /*//dw can we really assume our scene type*/ QGraphicsScene /*mafDiagramScene*/ *scene, Qt::WindowFlags wFlags)
3534
: /*QGraphicsPolygonItem(parent, scene) //dw*/ /*QFrame(parent->parentWidget(), 0)*/
36-
QGraphicsProxyWidget(parent, /*//dw668: did this cause decorations now in 4.7 but no in 4.5.2?: Qt::Window*/ wFlags), mMaxRadius(1)
35+
QGraphicsProxyWidget(parent, wFlags), mMaxRadius(1)
3736
{
38-
//dw new4: is this a problem? check it
3937
setCacheMode(DeviceCoordinateCache);
4038

4139
mContextMenu = contextMenu;
42-
isMoving = false;
43-
44-
//dw new:
45-
setZValue(1);
46-
//param
47-
mNoResize = true;
48-
if (mNoResize) {
49-
mControlResizeHandles = true;
50-
}
51-
else {
52-
//param
53-
mControlResizeHandles = false;
54-
}
55-
40+
isMoving = false;
41+
42+
setZValue(1);
43+
//param
44+
mNoResize = true;
45+
if (mNoResize) {
46+
mControlResizeHandles = true;
47+
} else {
48+
mControlResizeHandles = false;
49+
}
5650

5751
/*
5852
QPainterPath path;

src/mafGUI/mafNodeGraphicWidget.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,25 @@ class mafNodeGraphicWidget : public /*QGraphicsPolygonItem //dw*/ /*QFrame*/ QGr
4343
virtual ~mafNodeGraphicWidget();
4444
void deleteConnections();
4545

46-
void addConnector(mafNodeConnectorGraphicWidget* nc);
46+
void addConnector(mafNodeConnectorGraphicWidget* nc);
4747

4848

4949
//dw
50-
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
51-
void setWidget(QWidget *widget);
50+
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
51+
void setWidget(QWidget *widget);
5252

53-
QRectF boundingRect() const;
54-
QPainterPath shape() const;
53+
QRectF boundingRect() const;
54+
QPainterPath shape() const;
5555

56-
//void update(const QRectF & rect = QRectF());
56+
//void update(const QRectF & rect = QRectF());
57+
QList<mafNodeConnectorGraphicWidget *> connectors;
5758

58-
QList<mafNodeConnectorGraphicWidget *> connectors;
59+
public slots:
60+
void deleted();
61+
void deleted(int result);
5962

60-
public slots:
61-
void deleted();
62-
void deleted(int result);
63-
64-
//dw try overriding QWidget slot
65-
void hide();
63+
//dw try overriding QWidget slot
64+
void hide();
6665

6766
/*
6867
void accepted ()
@@ -118,4 +117,4 @@ void rejected ()
118117
//! [0]
119118

120119

121-
#endif
120+
#endif

0 commit comments

Comments
 (0)