Skip to content

Commit 5deaf85

Browse files
authored
Fix for Issue #101 (#102)
* disabling right click context menu in log replay and monitor * lock editing of nodes in replay and monitor modes. I had to expode lockEditing as public and also capture a pointer to the mainwindow
1 parent b12c4b7 commit 5deaf85

File tree

7 files changed

+45
-4
lines changed

7 files changed

+45
-4
lines changed

bt_editor/graphic_container.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ void GraphicContainer::onNodeCreated(Node &node)
352352

353353
void GraphicContainer::onNodeContextMenu(Node &node, const QPointF &)
354354
{
355+
// only allow context menu in editor mode
356+
auto main_win = dynamic_cast<MainWindow*>( parent() );
357+
if( main_win->getGraphicMode() != GraphicMode::EDITOR )
358+
{
359+
return;
360+
}
361+
355362
QMenu* node_menu = new QMenu(_view);
356363
//--------------------------------
357364
createMorphSubMenu(node, node_menu);
@@ -566,6 +573,13 @@ void GraphicContainer::insertNodeInConnection(Connection &connection, QString no
566573

567574
void GraphicContainer::onConnectionContextMenu(QtNodes::Connection &connection, const QPointF&)
568575
{
576+
// only allow connection context menu in editor mode
577+
auto main_win = dynamic_cast<MainWindow*>( parent() );
578+
if( main_win->getGraphicMode() != GraphicMode::EDITOR )
579+
{
580+
return;
581+
}
582+
569583
QMenu* conn_menu = new QMenu(_view);
570584

571585
auto categories = {"Control", "Decorator"};

bt_editor/mainwindow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,3 +1675,9 @@ void MainWindow::on_actionReportIssue_triggered()
16751675
QMessageBox::Ok);
16761676
QDesktopServices::openUrl(QUrl(url));
16771677
}
1678+
1679+
// returns the current graphic mode
1680+
GraphicMode MainWindow::getGraphicMode(void) const
1681+
{
1682+
return _current_mode;
1683+
}

bt_editor/mainwindow.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class MainWindow : public QMainWindow
5959

6060
void resetTreeStyle(AbsBehaviorTree &tree);
6161

62+
GraphicMode getGraphicMode(void) const;
63+
6264
public slots:
6365

6466
void onAutoArrange();
@@ -130,12 +132,14 @@ private slots:
130132

131133
void on_actionReportIssue_triggered();
132134

135+
public:
136+
137+
void lockEditing(const bool locked);
138+
133139
private:
134140

135141
void updateCurrentMode();
136142

137-
void lockEditing(const bool locked);
138-
139143
bool eventFilter(QObject *obj, QEvent *event) override;
140144

141145
void resizeEvent(QResizeEvent *) override;

bt_editor/sidepanel_monitor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QLabel>
88
#include <QDebug>
99

10+
#include "mainwindow.h"
1011
#include "utils.h"
1112

1213
SidepanelMonitor::SidepanelMonitor(QWidget *parent) :
@@ -15,7 +16,8 @@ SidepanelMonitor::SidepanelMonitor(QWidget *parent) :
1516
_zmq_context(1),
1617
_zmq_subscriber(_zmq_context, ZMQ_SUB),
1718
_connected(false),
18-
_msg_count(0)
19+
_msg_count(0),
20+
_parent(parent)
1921
{
2022
ui->setupUi(this);
2123
_timer = new QTimer(this);
@@ -104,6 +106,10 @@ void SidepanelMonitor::on_timer()
104106

105107
// update the graphic part
106108
emit changeNodeStyle( "BehaviorTree", node_status );
109+
110+
// lock editing of nodes
111+
auto main_win = dynamic_cast<MainWindow*>( _parent );
112+
main_win->lockEditing(true);
107113
}
108114
}
109115
catch( zmq::error_t& err)

bt_editor/sidepanel_monitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ private slots:
5454

5555
bool getTreeFromServer();
5656

57+
QWidget *_parent;
58+
5759
};
5860

5961
#endif // SIDEPANEL_MONITOR_H

bt_editor/sidepanel_replay.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
#include <QMessageBox>
1515

1616
#include "bt_editor_base.h"
17+
#include "mainwindow.h"
1718
#include "utils.h"
1819

1920

2021
SidepanelReplay::SidepanelReplay(QWidget *parent) :
2122
QFrame(parent),
2223
ui(new Ui::SidepanelReplay),
23-
_prev_row(-1)
24+
_prev_row(-1),
25+
_parent(parent)
2426
{
2527
ui->setupUi(this);
2628

@@ -271,6 +273,11 @@ void SidepanelReplay::loadLog(const QByteArray &content)
271273
_timepoint.clear();
272274
_prev_row = -1;
273275
updateTableModel(_loaded_tree);
276+
277+
278+
// We need to lock the nodes after they are loaded
279+
auto main_win = dynamic_cast<MainWindow*>( _parent );
280+
main_win->lockEditing(true);
274281
}
275282

276283

bt_editor/sidepanel_replay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ private slots:
8989
AbsBehaviorTree _loaded_tree;
9090

9191
void updateTableModel(const AbsBehaviorTree &tree);
92+
93+
QWidget *_parent;
9294
};
9395

9496
#endif // SIDEPANEL_REPLAY_H

0 commit comments

Comments
 (0)