Skip to content

Commit

Permalink
Add actions to show field editor (#5211)
Browse files Browse the repository at this point in the history
* Add actions to show field editor and do it only once on selection change

* Update ChangeLog

* Remove unused function declaration

* Add edit field button

* Update doc screenshots
  • Loading branch information
stefaniapedrazzi authored Sep 12, 2022
1 parent 19284e4 commit a5ad48b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 18 deletions.
Binary file modified docs/guide/images/context_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/guide/images/scene_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/reference/changelog-r2022.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Released on September, 13th, 2022.
- Changed the layout and behavior of the loading screen and progress bar for the [Web Interface](../guide/web-interface.md) ([#4593](https://github.com/cyberbotics/webots/pull/4593)).
- Improved display of generated PROTO sources in Text Editor that are now opened in read-only mode ([#5023](https://github.com/cyberbotics/webots/pull/5023)).
- Improved terminology and keyboard shortcuts of [Viewpoint](viewpoint.md) standard views related to the world ([#5149](https://github.com/cyberbotics/webots/pull/5149)).
- Added shortcuts to open the Field Editor from the Context Menu and double clicking on the Scene Tree node or field item ([#5211](https://github.com/cyberbotics/webots/pull/5211)).
- Bug Fixes
- Fixed execution of Webots on Windows in a UTF-8 path with non-ASCII characters ([#5103](https://github.com/cyberbotics/webots/pull/5103)).
- Fixed bug in `wb_supervisor_node_get_field_by_index` and `wb_supervisor_node_get_proto_field_by_index` API functions ([#4366](https://github.com/cyberbotics/webots/pull/4366)).
Expand Down
Binary file added resources/icons/dark/edit_field_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/light/edit_field_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/webots/core/WbAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace WbAction {
// node/field actions
OPEN_HELP,
RESET_VALUE,
EDIT_FIELD,
EXPORT_URDF,
// PROTO actions
EDIT_PROTO_SOURCE,
Expand Down
41 changes: 24 additions & 17 deletions src/webots/scene_tree/WbSceneTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ WbSceneTree::WbSceneTree(QWidget *parent) :
connect(mActionManager->action(WbAction::MOVE_VIEWPOINT_TO_OBJECT), &QAction::triggered, this,
&WbSceneTree::moveViewpointToObject);
connect(mActionManager->action(WbAction::RESET_VALUE), &QAction::triggered, this, &WbSceneTree::reset);
connect(mActionManager->action(WbAction::EDIT_FIELD), &QAction::triggered, this, &WbSceneTree::showFieldEditor);
connect(mActionManager->action(WbAction::CONVERT_TO_BASE_NODES), &QAction::triggered, this, &WbSceneTree::convertToBaseNode);
connect(mActionManager->action(WbAction::CONVERT_ROOT_TO_BASE_NODES), &QAction::triggered, this,
&WbSceneTree::convertRootToBaseNode);
Expand Down Expand Up @@ -268,7 +269,7 @@ void WbSceneTree::setWorld(WbWorld *world) {
void WbSceneTree::showExternProtoPanel() {
clearSelection();
// uncollapse the field editor
handleFieldEditorVisibility(true);
showFieldEditor(true);
emit nodeSelected(NULL);
mFieldEditor->editExternProto();
}
Expand Down Expand Up @@ -1091,9 +1092,6 @@ void WbSceneTree::clearSelection() {

mFieldEditor->setTitle("");
mFieldEditor->editField(NULL, NULL);

// collapse the field editor
handleFieldEditorVisibility(false);
}

void WbSceneTree::enableObjectViewActions(bool enabled) {
Expand Down Expand Up @@ -1125,6 +1123,7 @@ void WbSceneTree::updateSelection() {
mSelectedItem = NULL;
enableObjectViewActions(false);
mActionManager->action(WbAction::OPEN_HELP)->setEnabled(false);
mActionManager->action(WbAction::EDIT_FIELD)->setEnabled(false);
updateToolbar();
// no item selected
return;
Expand All @@ -1134,6 +1133,7 @@ void WbSceneTree::updateSelection() {
mSelectedItem = NULL;
enableObjectViewActions(false);
mActionManager->action(WbAction::OPEN_HELP)->setEnabled(false);
mActionManager->action(WbAction::EDIT_FIELD)->setEnabled(false);
updateToolbar();
return;
}
Expand All @@ -1155,6 +1155,7 @@ void WbSceneTree::updateSelection() {
mFieldEditor->editField(node, mSelectedItem->parent()->field(), mSelectedItem->row());
}

mActionManager->action(WbAction::EDIT_FIELD)->setEnabled(mSplitter->sizes()[2] == 0);
WbContextMenuGenerator::enableNodeActions(mSelectedItem->isNode());
WbContextMenuGenerator::enableRobotActions(mSelectedItem->node() &&
WbNodeUtilities::isRobotTypeName(mSelectedItem->node()->nodeModelName()));
Expand Down Expand Up @@ -1194,7 +1195,7 @@ void WbSceneTree::updateSelection() {
}

// uncollapse the field editor
handleFieldEditorVisibility(true);
showFieldEditor();
}

void WbSceneTree::startWatching(const QModelIndex &index) {
Expand Down Expand Up @@ -1504,10 +1505,14 @@ void WbSceneTree::handleDoubleClickOrEnterPress() {
(mSelectedItem->isField() && !mSelectedItem->isSFNode() && !mSelectedItem->field()->isMultiple()))
mFieldEditor->currentEditor()->takeKeyboardFocus();
// default behavior, collapse/expand tree item
else if (mTreeView->isExpanded(mTreeView->currentIndex()))
mTreeView->collapse(mTreeView->currentIndex());
else
else if (!mTreeView->isExpanded(mTreeView->currentIndex()))
mTreeView->expand(mTreeView->currentIndex());
else {
mTreeView->collapse(mTreeView->currentIndex());
return; // do not show field editor when collasping tree item
}

showFieldEditor(true);
}

void WbSceneTree::refreshTreeView() {
Expand Down Expand Up @@ -1597,17 +1602,19 @@ void WbSceneTree::openTemplateInstanceInTextEditor() {
emit editRequested(file.fileName());
}

void WbSceneTree::handleFieldEditorVisibility(bool isVisible) {
void WbSceneTree::showFieldEditor(bool force) {
if (dynamic_cast<QAction *>(sender()) != NULL)
force = true;
static bool hiddenByUser = false;
const QList<int> currentSize = mSplitter->sizes();
QList<int> sizes;
int newSize;
if (isVisible && currentSize[2] == 0)
newSize = 1;
else if (!isVisible && currentSize[2] != 0)
newSize = 0;
else
if (currentSize[2] != 0) {
hiddenByUser = true;
return;
sizes << currentSize[0] << (mSplitter->height() - newSize) << newSize;
}
if (!force && hiddenByUser)
return;
QList<int> sizes;
sizes << currentSize[0] << (mSplitter->height() - 1) << 1;
mSplitter->setSizes(sizes);
mSplitter->setHandleWidth(mHandleWidth);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/webots/scene_tree/WbSceneTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private slots:
void openProtoInTextEditor();
void editProtoInTextEditor();
void openTemplateInstanceInTextEditor();
void handleFieldEditorVisibility(bool isVisible);
void showFieldEditor(bool force = false);

void del(WbNode *nodeToDel = NULL);

Expand Down
11 changes: 11 additions & 0 deletions src/webots/user_commands/WbActionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,17 @@ void WbActionManager::populateActions() {
newAction->setEnabled(false);
mActions[RESET_VALUE] = newAction;

icon = QIcon();
icon.addFile("enabledIcons:edit_field_button.png", QSize(), QIcon::Normal);
icon.addFile("disabledIcons:edit_field_button.png", QSize(), QIcon::Disabled);
newAction = new QAction(this);
newAction->setText(tr("&Edit..."));
newAction->setStatusTip(tr("Open field/node editor."));
newAction->setToolTip(newAction->statusTip());
newAction->setIcon(icon);
newAction->setEnabled(false);
mActions[EDIT_FIELD] = newAction;

newAction = new QAction(this);
newAction->setText(tr("&Export URDF"));
newAction->setStatusTip(tr("Export this robot model to URDF."));
Expand Down
1 change: 1 addition & 0 deletions src/webots/user_commands/WbContextMenuGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace WbContextMenuGenerator {
contextMenu.addAction(WbActionManager::instance()->action(WbAction::COPY));
contextMenu.addAction(WbActionManager::instance()->action(WbAction::PASTE));
contextMenu.addAction(WbActionManager::instance()->action(WbAction::RESET_VALUE));
contextMenu.addAction(WbActionManager::instance()->action(WbAction::EDIT_FIELD));
contextMenu.addSeparator();
contextMenu.addAction(WbActionManager::instance()->action(WbAction::ADD_NEW));
contextMenu.addAction(WbActionManager::instance()->action(WbAction::DEL));
Expand Down

0 comments on commit a5ad48b

Please sign in to comment.