MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / updateNodeSize

Method updateNodeSize

bt_editor/models/BehaviorTreeNodeModel.cpp:244–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242}
243
244void BehaviorTreeDataModel::updateNodeSize()
245{
246 int caption_width = _caption_label->width();
247 caption_width += _caption_logo_left->width() + _caption_logo_right->width();
248 int line_edit_width = caption_width;
249
250 if( _line_edit_name->isHidden() == false)
251 {
252 QFontMetrics fm = _line_edit_name->fontMetrics();
253 const QString& txt = _line_edit_name->text();
254 int text_width = fm.boundingRect(txt).width();
255 line_edit_width = std::max( line_edit_width, text_width + MARGIN);
256 }
257
258 //----------------------------
259 int field_colum_width = DEFAULT_LABEL_WIDTH;
260 int label_colum_width = 0;
261
262 for(int row = 0; row< _form_layout->rowCount(); row++)
263 {
264 auto label_widget = _form_layout->itemAt(row, QFormLayout::LabelRole)->widget();
265 auto field_widget = _form_layout->itemAt(row, QFormLayout::FieldRole)->widget();
266 if(auto field_line_edit = dynamic_cast<QLineEdit*>(field_widget))
267 {
268 QFontMetrics fontMetrics = field_line_edit->fontMetrics();
269 QString text = field_line_edit->text();
270 int text_width = fontMetrics.boundingRect(text).width();
271 field_colum_width = std::max( field_colum_width, text_width + MARGIN);
272 }
273 label_colum_width = std::max(label_colum_width, label_widget->width());
274 }
275
276 field_colum_width = std::max( field_colum_width,
277 line_edit_width - label_colum_width - _form_layout->spacing());
278
279 for(int row = 0; row< _form_layout->rowCount(); row++)
280 {
281 auto field_widget = _form_layout->itemAt(row, QFormLayout::FieldRole)->widget();
282 if(auto field_line_edit = dynamic_cast<QLineEdit*>(field_widget))
283 {
284 field_line_edit->setFixedWidth( field_colum_width );
285 }
286 }
287 line_edit_width = std::max( line_edit_width, label_colum_width + field_colum_width );
288 _line_edit_name->setFixedWidth( line_edit_width);
289
290 _params_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
291 _params_widget->adjustSize();
292
293 _main_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
294 _main_widget->adjustSize();
295
296 //----------------------------
297
298 emit embeddedWidgetSizeUpdated();
299}
300
301QtNodes::NodeDataType BehaviorTreeDataModel::dataType(QtNodes::PortType, QtNodes::PortIndex) const

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected