Skip to content

Commit 49c5296

Browse files
author
Davide Faconti
committed
Highlight ports with the same value (enhancements #20)
1 parent 09c9f3f commit 49c5296

File tree

4 files changed

+121
-50
lines changed

4 files changed

+121
-50
lines changed

bt_editor/graphic_container.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,28 @@ void GraphicContainer::onNodeDoubleClicked(Node &root_node)
308308
}
309309
}
310310

311+
void GraphicContainer::onPortValueDoubleClicked(QLineEdit *edit_value)
312+
{
313+
for (const auto& it: _scene->nodes())
314+
{
315+
auto node_model = dynamic_cast<BehaviorTreeDataModel*>( it.second->nodeDataModel() );
316+
QString val = edit_value ? edit_value->text() : QString();
317+
node_model->onHighlightPortValue( val );
318+
}
319+
}
320+
311321
void GraphicContainer::onNodeCreated(Node &node)
312322
{
313323
if( auto bt_node = dynamic_cast<BehaviorTreeDataModel*>( node.nodeDataModel() ) )
314324
{
315325
connect( bt_node, &BehaviorTreeDataModel::parameterUpdated,
316326
this, &GraphicContainer::undoableChange );
317327

328+
connect( bt_node, &BehaviorTreeDataModel::portValueDoubleChicked,
329+
this, &GraphicContainer::onPortValueDoubleClicked );
330+
318331
connect( bt_node, &BehaviorTreeDataModel::instanceNameChanged,
319-
this, &GraphicContainer::undoableChange );
332+
this, &GraphicContainer::undoableChange );
320333

321334
if( auto subtree_node = dynamic_cast<SubtreeNodeModel*>( bt_node ) )
322335
{

bt_editor/graphic_container.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <QObject>
55
#include <QWidget>
6+
#include <QLineEdit>
67

78
#include "bt_editor_base.h"
89
#include "editor_flowscene.h"
@@ -58,6 +59,8 @@ public slots:
5859

5960
void onNodeDoubleClicked(QtNodes::Node& root_node);
6061

62+
void onPortValueDoubleClicked(QLineEdit* edit_value);
63+
6164
void onNodeCreated(QtNodes::Node &node);
6265

6366
void onNodeContextMenu(QtNodes::Node& node, const QPointF& pos);

bt_editor/models/BehaviorTreeNodeModel.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,29 @@ BehaviorTreeDataModel::BehaviorTreeDataModel(const NodeModel &model):
116116
}
117117
}
118118

119-
QLineEdit* form_field = new QLineEdit();
119+
GrootLineEdit* form_field = new GrootLineEdit();
120120
form_field->setAlignment( Qt::AlignHCenter);
121121
form_field->setMaximumWidth(140);
122122
form_field->setText( port_it.second.default_value );
123123

124+
connect(form_field, &GrootLineEdit::doubleClicked,
125+
this, [this,form_field]()
126+
{ emit this->portValueDoubleChicked(form_field); });
127+
128+
connect(form_field, &GrootLineEdit::lostFocus,
129+
this, [this]()
130+
{ emit this->portValueDoubleChicked(nullptr); });
131+
124132
QLabel* form_label = new QLabel( label, _params_widget );
125133
form_label->setToolTip( description );
126134

127135
form_field->setMinimumWidth(DEFAULT_FIELD_WIDTH);
128136

129137
_ports_widgets.insert( std::make_pair( port_it.first, form_field) );
130138

131-
form_field->setStyleSheet(" color: rgb(30,30,30); "
132-
"background-color: rgb(180,180,180); "
133-
"border: 0px; "
134-
"padding: 0px 0px 0px 0px;");
139+
form_field->setStyleSheet("color: rgb(30,30,30); "
140+
"background-color: rgb(200,200,200); "
141+
"border: 0px; ");
135142

136143
_form_layout->addRow( form_label, form_field );
137144

@@ -488,6 +495,36 @@ void BehaviorTreeDataModel::setInstanceName(const QString &name)
488495
}
489496

490497

498+
void BehaviorTreeDataModel::onHighlightPortValue(QString value)
499+
{
500+
for( const auto& it: _ports_widgets)
501+
{
502+
if( auto line_edit = dynamic_cast<QLineEdit*>(it.second) )
503+
{
504+
QString line_str = line_edit->text();
505+
if( !value.isEmpty() && line_str == value )
506+
{
507+
line_edit->setStyleSheet("color: rgb(30,30,30); "
508+
"background-color: #ffef0b; "
509+
"border: 0px; ");
510+
}
511+
else{
512+
line_edit->setStyleSheet("color: rgb(30,30,30); "
513+
"background-color: rgb(200,200,200); "
514+
"border: 0px; ");
515+
}
516+
}
517+
}
518+
}
491519

520+
void GrootLineEdit::mouseDoubleClickEvent(QMouseEvent *ev)
521+
{
522+
//QLineEdit::mouseDoubleClickEvent(ev);
523+
emit doubleClicked();
524+
}
492525

493-
526+
void GrootLineEdit::focusOutEvent(QFocusEvent *ev)
527+
{
528+
QLineEdit::focusOutEvent(ev);
529+
emit lostFocus();
530+
}

bt_editor/models/BehaviorTreeNodeModel.hpp

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,92 +27,110 @@ class BehaviorTreeDataModel : public NodeDataModel
2727
Q_OBJECT
2828

2929
public:
30-
BehaviorTreeDataModel(const NodeModel &model );
30+
BehaviorTreeDataModel(const NodeModel &model );
3131

32-
~BehaviorTreeDataModel() override;
32+
~BehaviorTreeDataModel() override;
3333

3434
public:
3535

36-
NodeType nodeType() const;
36+
NodeType nodeType() const;
3737

38-
virtual void setInstanceName(const QString& name);
38+
virtual void setInstanceName(const QString& name);
3939

4040
public:
4141

42-
void initWidget();
42+
void initWidget();
4343

44-
virtual unsigned int nPorts(PortType portType) const override;
44+
virtual unsigned int nPorts(PortType portType) const override;
4545

46-
ConnectionPolicy portOutConnectionPolicy(PortIndex) const final;
46+
ConnectionPolicy portOutConnectionPolicy(PortIndex) const final;
4747

48-
NodeDataType dataType(PortType , PortIndex ) const final;
48+
NodeDataType dataType(PortType , PortIndex ) const final;
4949

50-
std::shared_ptr<NodeData> outData(PortIndex port) final;
50+
std::shared_ptr<NodeData> outData(PortIndex port) final;
5151

52-
void setInData(std::shared_ptr<NodeData>, int) final {}
52+
void setInData(std::shared_ptr<NodeData>, int) final {}
5353

54-
const QString &registrationName() const;
54+
const QString &registrationName() const;
5555

56-
const NodeModel &model() const { return _model; }
56+
const NodeModel &model() const { return _model; }
5757

58-
QString name() const final { return registrationName(); }
58+
QString name() const final { return registrationName(); }
5959

60-
const QString& instanceName() const;
60+
const QString& instanceName() const;
6161

62-
PortsMapping getCurrentPortMapping() const;
62+
PortsMapping getCurrentPortMapping() const;
6363

64-
QWidget *embeddedWidget() final { return _main_widget; }
64+
QWidget *embeddedWidget() final { return _main_widget; }
6565

66-
QWidget *parametersWidget() { return _params_widget; }
66+
QWidget *parametersWidget() { return _params_widget; }
6767

68-
QJsonObject save() const override;
68+
QJsonObject save() const override;
6969

70-
void restore(QJsonObject const &) override;
70+
void restore(QJsonObject const &) override;
7171

72-
void lock(bool locked);
72+
void lock(bool locked);
7373

74-
void setParameterValue(const QString& label, const QString& value);
74+
void setParameterValue(const QString& label, const QString& value);
7575

76-
int UID() const { return _uid; }
76+
int UID() const { return _uid; }
7777

78-
bool eventFilter(QObject *obj, QEvent *event) override;
78+
bool eventFilter(QObject *obj, QEvent *event) override;
7979

8080

8181
public slots:
8282

83-
void updateNodeSize();
83+
void updateNodeSize();
8484

85+
void onHighlightPortValue(QString value);
8586

8687
protected:
8788

88-
QFrame* _main_widget;
89-
QFrame* _params_widget;
89+
QFrame* _main_widget;
90+
QFrame* _params_widget;
9091

91-
QLineEdit* _line_edit_name;
92+
QLineEdit* _line_edit_name;
9293

93-
std::map<QString, QWidget*> _ports_widgets;
94-
int16_t _uid;
94+
std::map<QString, QWidget*> _ports_widgets;
95+
int16_t _uid;
9596

96-
QFormLayout* _form_layout;
97-
QVBoxLayout* _main_layout;
98-
QLabel* _caption_label;
99-
QFrame* _caption_logo_left;
100-
QFrame* _caption_logo_right;
97+
QFormLayout* _form_layout;
98+
QVBoxLayout* _main_layout;
99+
QLabel* _caption_label;
100+
QFrame* _caption_logo_left;
101+
QFrame* _caption_logo_right;
101102

102103
private:
103-
const NodeModel _model;
104-
QString _instance_name;
105-
QSvgRenderer* _icon_renderer;
104+
const NodeModel _model;
105+
QString _instance_name;
106+
QSvgRenderer* _icon_renderer;
106107

107-
void readStyle();
108-
QString _style_icon;
109-
QColor _style_caption_color;
110-
QString _style_caption_alias;
108+
void readStyle();
109+
QString _style_icon;
110+
QColor _style_caption_color;
111+
QString _style_caption_alias;
111112

112113
signals:
113114

114-
void parameterUpdated(QString, QWidget*);
115+
void parameterUpdated(QString, QWidget*);
115116

116-
void instanceNameChanged();
117+
void instanceNameChanged();
117118

119+
void portValueDoubleChicked(QLineEdit* value_port);
120+
121+
};
122+
123+
124+
class GrootLineEdit: public QLineEdit
125+
{
126+
Q_OBJECT
127+
public:
128+
GrootLineEdit(QWidget* parent = nullptr): QLineEdit(parent) {}
129+
130+
void mouseDoubleClickEvent(QMouseEvent *ev) override;
131+
void focusOutEvent(QFocusEvent* ev) override;
132+
signals:
133+
void doubleClicked();
134+
void lostFocus();
118135
};
136+

0 commit comments

Comments
 (0)