From 5a4ab1165730f9f61770ff2ae51791f4deeda684 Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Sun, 29 Oct 2023 12:53:15 -0500 Subject: [PATCH] Fix sendEvent calls --- acm/demo/acm_demo.cpp | 3 +- .../models/allowed_collision_matrix_model.cpp | 12 ++-- .../add_allowed_collision_entry_dialog.cpp | 3 +- ...allowed_collision_matrix_editor_widget.cpp | 10 +-- .../src/models/contact_results_model.cpp | 17 +++-- .../contact_results_compute_widget.cpp | 7 +- .../demo/command_language_demo.cpp | 3 +- common/src/environment_wrapper.cpp | 65 ++++++++++++------- .../demo/joint_trajectory_demo.cpp | 20 ++++-- .../src/models/joint_trajectory_utils.cpp | 13 ++-- .../src/widgets/joint_trajectory_tool_bar.cpp | 15 +++-- .../src/widgets/joint_trajectory_widget.cpp | 43 ++++++------ .../src/models/group_joint_states_model.cpp | 17 +++-- .../group_joint_states_editor_widget.cpp | 18 ++--- .../kinematic_groups_editor_widget.cpp | 15 +++-- manipulation/src/manipulation_tool_bar.cpp | 40 ++++++------ manipulation/src/manipulation_widget.cpp | 33 +++++----- .../demo/render_environment_widget_demo.cpp | 6 +- rendering/src/render_widget.cpp | 6 +- scene_graph/demo/scene_graph_demo.cpp | 3 +- scene_graph/src/models/scene_graph_model.cpp | 30 ++++----- scene_graph/src/models/scene_state_model.cpp | 10 +-- .../src/widgets/scene_graph_tool_bar.cpp | 50 +++++++------- srdf/src/srdf_editor_widget.cpp | 11 +++- tool_path/demo/tool_path_demo.cpp | 23 +++++-- tool_path/src/models/tool_path_model.cpp | 38 +++++++---- .../src/models/tool_path_selection_model.cpp | 3 +- tool_path/src/models/tool_path_utils.cpp | 9 ++- tool_path/src/widgets/tool_path_tool_bar.cpp | 18 +++-- 29 files changed, 311 insertions(+), 230 deletions(-) diff --git a/acm/demo/acm_demo.cpp b/acm/demo/acm_demo.cpp index 0fad1ae8..21d60d3f 100644 --- a/acm/demo/acm_demo.cpp +++ b/acm/demo/acm_demo.cpp @@ -49,7 +49,8 @@ int main(int argc, char** argv) entries.push_back({ "link_2", "link_3", "Adjacent" }); entries.push_back({ "link_3", "link_4", "Adjacent" }); - QApplication::sendEvent(qApp, new tesseract_gui::events::AllowedCollisionMatrixAdd(component_info, entries)); + tesseract_gui::events::AllowedCollisionMatrixAdd event(component_info, entries); + QApplication::sendEvent(qApp, &event); return QApplication::exec(); } diff --git a/acm/src/models/allowed_collision_matrix_model.cpp b/acm/src/models/allowed_collision_matrix_model.cpp index 6bc49c16..145e77f8 100644 --- a/acm/src/models/allowed_collision_matrix_model.cpp +++ b/acm/src/models/allowed_collision_matrix_model.cpp @@ -256,13 +256,13 @@ bool AllowedCollisionMatrixModel::setData(const QModelIndex& index, const QVaria } } - QApplication::sendEvent( - qApp, - new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::WIREBOX, false)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::WIREBOX, false); + QApplication::sendEvent(qApp, &event); if (!links.empty()) - QApplication::sendEvent( - qApp, - new events::SceneGraphModifyLinkVisibility(data_->component_info, links, LinkVisibilityFlags::WIREBOX, true)); + { + events::SceneGraphModifyLinkVisibility event(data_->component_info, links, LinkVisibilityFlags::WIREBOX, true); + QApplication::sendEvent(qApp, &event); + } } return true; } diff --git a/acm/src/widgets/add_allowed_collision_entry_dialog.cpp b/acm/src/widgets/add_allowed_collision_entry_dialog.cpp index f744796f..da62c4b6 100644 --- a/acm/src/widgets/add_allowed_collision_entry_dialog.cpp +++ b/acm/src/widgets/add_allowed_collision_entry_dialog.cpp @@ -64,7 +64,8 @@ void AddAllowedCollisionEntryDialog::accept() entry[2] = ui_->reasonLineEdit->text().toStdString(); data.push_back(entry); - QApplication::sendEvent(qApp, new events::AllowedCollisionMatrixAdd(component_info_, data)); + events::AllowedCollisionMatrixAdd event(component_info_, data); + QApplication::sendEvent(qApp, &event); } } // namespace tesseract_gui diff --git a/acm/src/widgets/allowed_collision_matrix_editor_widget.cpp b/acm/src/widgets/allowed_collision_matrix_editor_widget.cpp index fc5d3f83..c5960918 100644 --- a/acm/src/widgets/allowed_collision_matrix_editor_widget.cpp +++ b/acm/src/widgets/allowed_collision_matrix_editor_widget.cpp @@ -112,7 +112,8 @@ void AllowedCollisionMatrixEditorWidget::onRemoveButtonClicked() if (idx.isValid() && idx.parent().isValid()) remove.push_back({ m->data(idx.parent()).toString().toStdString(), m->data(idx).toString().toStdString() }); - QApplication::sendEvent(qApp, new events::AllowedCollisionMatrixRemove(m->getComponentInfo(), remove)); + events::AllowedCollisionMatrixRemove event(m->getComponentInfo(), remove); + QApplication::sendEvent(qApp, &event); } } @@ -124,8 +125,8 @@ void AllowedCollisionMatrixEditorWidget::onAddButtonClicked() void AllowedCollisionMatrixEditorWidget::onGenerateButtonClicked() { - QApplication::sendEvent( - qApp, new events::AllowedCollisionMatrixGenerate(getComponentInfo(), ui_->resolutionSlider->value())); + events::AllowedCollisionMatrixGenerate event(getComponentInfo(), ui_->resolutionSlider->value()); + QApplication::sendEvent(qApp, &event); } void AllowedCollisionMatrixEditorWidget::onApplyButtonClicked() @@ -133,7 +134,8 @@ void AllowedCollisionMatrixEditorWidget::onApplyButtonClicked() auto cmd = std::make_shared( ui_->acm_widget->getModel()->getAllowedCollisionMatrix(), tesseract_environment::ModifyAllowedCollisionsType::REPLACE); - QApplication::sendEvent(qApp, new events::EnvironmentApplyCommand(getComponentInfo(), { cmd })); + events::EnvironmentApplyCommand event(getComponentInfo(), { cmd }); + QApplication::sendEvent(qApp, &event); } } // namespace tesseract_gui diff --git a/collision/src/models/contact_results_model.cpp b/collision/src/models/contact_results_model.cpp index 62d9af2d..f4598a22 100644 --- a/collision/src/models/contact_results_model.cpp +++ b/collision/src/models/contact_results_model.cpp @@ -77,21 +77,20 @@ bool ContactResultsModel::setData(const QModelIndex& index, const QVariant& valu auto* derived_item = static_cast(item); auto* parent_item = static_cast(item->parent()); - QApplication::sendEvent(qApp, - new events::ContactResultsVisbility(data_->component_info, - parent_item->getUUID(), - derived_item->contact_result.getUUID(), - value.value() == Qt::Checked)); + events::ContactResultsVisbility event(data_->component_info, + parent_item->getUUID(), + derived_item->contact_result.getUUID(), + value.value() == Qt::Checked); + QApplication::sendEvent(qApp, &event); } else if (item->type() == static_cast(StandardItemType::COLLISION_CONTACT_RESULT_VECTOR)) { assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); - QApplication::sendEvent(qApp, - new events::ContactResultsVisbility(data_->component_info, - derived_item->getUUID(), - value.value() == Qt::Checked)); + events::ContactResultsVisbility event( + data_->component_info, derived_item->getUUID(), value.value() == Qt::Checked); + QApplication::sendEvent(qApp, &event); } } return QStandardItemModel::setData(index, value, role); diff --git a/collision/src/widgets/contact_results_compute_widget.cpp b/collision/src/widgets/contact_results_compute_widget.cpp index a850530f..bf146c59 100644 --- a/collision/src/widgets/contact_results_compute_widget.cpp +++ b/collision/src/widgets/contact_results_compute_widget.cpp @@ -63,10 +63,9 @@ void ContactResultsComputeWidget::onComputeClicked() config.contact_request.type = static_cast(ui->contact_test_type->currentIndex()); - QApplication::sendEvent( - qApp, - new events::ContactResultsCompute( - getComponentInfo(), config, events::ContactResultsCompute::StateType::CURRENT_STATE, "Contact Results")); + events::ContactResultsCompute event( + getComponentInfo(), config, events::ContactResultsCompute::StateType::CURRENT_STATE, "Contact Results"); + QApplication::sendEvent(qApp, &event); } void ContactResultsComputeWidget::ctor(std::shared_ptr component_info) diff --git a/command_language/demo/command_language_demo.cpp b/command_language/demo/command_language_demo.cpp index ed8cccb4..64dde050 100644 --- a/command_language/demo/command_language_demo.cpp +++ b/command_language/demo/command_language_demo.cpp @@ -105,7 +105,8 @@ int main(int argc, char** argv) tesseract_gui::CompositeInstructionWidget widget(component_info); widget.show(); - QApplication::sendEvent(qApp, new tesseract_gui::events::CompositeInstructionSet(component_info, program, "general")); + tesseract_gui::events::CompositeInstructionSet event(component_info, program, "general"); + QApplication::sendEvent(qApp, &event); return QApplication::exec(); } diff --git a/common/src/environment_wrapper.cpp b/common/src/environment_wrapper.cpp index 45799410..43f2bfc0 100644 --- a/common/src/environment_wrapper.cpp +++ b/common/src/environment_wrapper.cpp @@ -144,8 +144,8 @@ void tesseractEventFilterHelper(const tesseract_environment::Event& event, case tesseract_environment::Events::SCENE_STATE_CHANGED: { const auto& e = static_cast(event); - QApplication::sendEvent(qApp, - new tesseract_gui::events::SceneStateChanged(env_wrapper.getComponentInfo(), e.state)); + tesseract_gui::events::SceneStateChanged event(env_wrapper.getComponentInfo(), e.state); + QApplication::sendEvent(qApp, &event); break; } } @@ -199,8 +199,8 @@ void eventFilterHelper(QObject* /*obj*/, tracked_object[contact.first] = crv; } - QApplication::sendEvent( - qApp, new tesseract_gui::events::ContactResultsSet(component_info, tracked_object, e->getNamespace())); + tesseract_gui::events::ContactResultsSet event(component_info, tracked_object, e->getNamespace()); + QApplication::sendEvent(qApp, &event); } else if (event->type() == tesseract_gui::events::AllowedCollisionMatrixGenerate::kType) { @@ -266,7 +266,8 @@ void eventFilterHelper(QObject* /*obj*/, } } - QApplication::sendEvent(qApp, new tesseract_gui::events::AllowedCollisionMatrixSet(component_info, acm)); + tesseract_gui::events::AllowedCollisionMatrixSet event(component_info, acm); + QApplication::sendEvent(qApp, &event); } else if (event->type() == tesseract_gui::events::EnvironmentApplyCommand::kType) { @@ -288,19 +289,28 @@ void broadcastHelper(const std::shared_ptr& return; // Broadcast environment data - QApplication::sendEvent(qApp, new tesseract_gui::events::SceneGraphSet(component_info, env.getSceneGraph()->clone())); - QApplication::sendEvent(qApp, new tesseract_gui::events::SceneStateChanged(component_info, env.getState())); - QApplication::sendEvent(qApp, - new tesseract_gui::events::EnvironmentCommandsSet(component_info, env.getCommandHistory())); - QApplication::sendEvent( - qApp, new tesseract_gui::events::AllowedCollisionMatrixSet(component_info, *env.getAllowedCollisionMatrix())); + tesseract_gui::events::SceneGraphSet set_scene_graph_event(component_info, env.getSceneGraph()->clone()); + QApplication::sendEvent(qApp, &set_scene_graph_event); + + tesseract_gui::events::SceneStateChanged scene_state_changed_event(component_info, env.getState()); + QApplication::sendEvent(qApp, &scene_state_changed_event); + + tesseract_gui::events::EnvironmentCommandsSet set_environment_commands_event(component_info, env.getCommandHistory()); + QApplication::sendEvent(qApp, &set_environment_commands_event); + + tesseract_gui::events::AllowedCollisionMatrixSet set_acm_event(component_info, *env.getAllowedCollisionMatrix()); + QApplication::sendEvent(qApp, &set_acm_event); auto kin_info = env.getKinematicsInformation(); - QApplication::sendEvent(qApp, - new tesseract_gui::events::KinematicGroupsSet( - component_info, kin_info.chain_groups, kin_info.joint_groups, kin_info.link_groups)); - QApplication::sendEvent(qApp, new tesseract_gui::events::GroupJointStatesSet(component_info, kin_info.group_states)); - QApplication::sendEvent(qApp, new tesseract_gui::events::GroupTCPsSet(component_info, kin_info.group_tcps)); + tesseract_gui::events::KinematicGroupsSet set_kin_groups_event( + component_info, kin_info.chain_groups, kin_info.joint_groups, kin_info.link_groups); + QApplication::sendEvent(qApp, &set_kin_groups_event); + + tesseract_gui::events::GroupJointStatesSet set_group_joint_states_event(component_info, kin_info.group_states); + QApplication::sendEvent(qApp, &set_group_joint_states_event); + + tesseract_gui::events::GroupTCPsSet set_group_tcps_event(component_info, kin_info.group_tcps); + QApplication::sendEvent(qApp, &set_group_tcps_event); } namespace tesseract_gui @@ -313,12 +323,23 @@ EnvironmentWrapper::EnvironmentWrapper(std::shared_ptr comp EnvironmentWrapper::~EnvironmentWrapper() { // clear environment data - QApplication::sendEvent(qApp, new events::SceneGraphClear(component_info_)); - QApplication::sendEvent(qApp, new events::EnvironmentCommandsClear(component_info_)); - QApplication::sendEvent(qApp, new events::AllowedCollisionMatrixClear(component_info_)); - QApplication::sendEvent(qApp, new events::KinematicGroupsClear(component_info_)); - QApplication::sendEvent(qApp, new events::GroupJointStatesClear(component_info_)); - QApplication::sendEvent(qApp, new events::GroupTCPsClear(component_info_)); + events::SceneGraphClear clear_scene_graph_event(component_info_); + QApplication::sendEvent(qApp, &clear_scene_graph_event); + + events::EnvironmentCommandsClear clear_environment_commands_event(component_info_); + QApplication::sendEvent(qApp, &clear_environment_commands_event); + + events::AllowedCollisionMatrixClear clear_acm_event(component_info_); + QApplication::sendEvent(qApp, &clear_acm_event); + + events::KinematicGroupsClear clear_kin_groups_event(component_info_); + QApplication::sendEvent(qApp, &clear_kin_groups_event); + + events::GroupJointStatesClear clear_group_joint_states_event(component_info_); + QApplication::sendEvent(qApp, &clear_group_joint_states_event); + + events::GroupTCPsClear clear_group_tcps_event(component_info_); + QApplication::sendEvent(qApp, &clear_group_tcps_event); } std::shared_ptr EnvironmentWrapper::getComponentInfo() const { return component_info_; } diff --git a/joint_trajectory/demo/joint_trajectory_demo.cpp b/joint_trajectory/demo/joint_trajectory_demo.cpp index 5a553c5e..e87904dc 100644 --- a/joint_trajectory/demo/joint_trajectory_demo.cpp +++ b/joint_trajectory/demo/joint_trajectory_demo.cpp @@ -91,12 +91,20 @@ int main(int argc, char** argv) window.setCentralWidget(new tesseract_gui::JointTrajectoryWidget(component_info)); window.show(); - QApplication::sendEvent(qApp, new tesseract_gui::events::JointTrajectoryAdd(component_info, trajectory_set)); - QApplication::sendEvent(qApp, new tesseract_gui::events::JointTrajectoryAdd(component_info, trajectory_set1)); - QApplication::sendEvent(qApp, new tesseract_gui::events::JointTrajectoryAdd(component_info, trajectory_set2)); - QApplication::sendEvent(qApp, new tesseract_gui::events::JointTrajectoryAdd(component_info, trajectory_set3)); - QApplication::sendEvent(qApp, - new tesseract_gui::events::JointTrajectoryRemove(component_info, trajectory_set2.getUUID())); + tesseract_gui::events::JointTrajectoryAdd event(component_info, trajectory_set); + QApplication::sendEvent(qApp, &event); + + tesseract_gui::events::JointTrajectoryAdd event1(component_info, trajectory_set1); + QApplication::sendEvent(qApp, &event1); + + tesseract_gui::events::JointTrajectoryAdd event2(component_info, trajectory_set2); + QApplication::sendEvent(qApp, &event2); + + tesseract_gui::events::JointTrajectoryAdd event3(component_info, trajectory_set3); + QApplication::sendEvent(qApp, &event3); + + tesseract_gui::events::JointTrajectoryRemove event4(component_info, trajectory_set2.getUUID()); + QApplication::sendEvent(qApp, &event4); return QApplication::exec(); } diff --git a/joint_trajectory/src/models/joint_trajectory_utils.cpp b/joint_trajectory/src/models/joint_trajectory_utils.cpp index 9194e466..df93c253 100644 --- a/joint_trajectory/src/models/joint_trajectory_utils.cpp +++ b/joint_trajectory/src/models/joint_trajectory_utils.cpp @@ -49,7 +49,9 @@ bool openJointTrajectorySet(const std::shared_ptr& componen { auto jts = tesseract_common::Serialization::fromArchiveFileXML( filename.toStdString()); - QApplication::sendEvent(qApp, new events::JointTrajectoryAdd(component_info, std::move(jts))); + + events::JointTrajectoryAdd event(component_info, std::move(jts)); + QApplication::sendEvent(qApp, &event); return true; } @@ -57,7 +59,8 @@ bool openJointTrajectorySet(const std::shared_ptr& componen { auto jts = tesseract_common::Serialization::fromArchiveFileBinary( filename.toStdString()); - QApplication::sendEvent(qApp, new events::JointTrajectoryAdd(component_info, std::move(jts))); + events::JointTrajectoryAdd event(component_info, std::move(jts)); + QApplication::sendEvent(qApp, &event); return true; } @@ -77,7 +80,8 @@ bool openJointTrajectorySet(const std::shared_ptr& componen tesseract_common::JointTrajectorySet jts(initial_state, jt.description); jts.appendJointTrajectory(jt); - QApplication::sendEvent(qApp, new events::JointTrajectoryAdd(component_info, std::move(jts))); + events::JointTrajectoryAdd event(component_info, std::move(jts)); + QApplication::sendEvent(qApp, &event); return true; } @@ -95,7 +99,8 @@ bool openJointTrajectorySet(const std::shared_ptr& componen initial_state[jt.states.front().joint_names[i]] = jt.states.front().position[i]; tesseract_common::JointTrajectorySet jts(initial_state, jt.description); - QApplication::sendEvent(qApp, new events::JointTrajectoryAdd(component_info, std::move(jts))); + events::JointTrajectoryAdd event(component_info, std::move(jts)); + QApplication::sendEvent(qApp, &event); return true; } diff --git a/joint_trajectory/src/widgets/joint_trajectory_tool_bar.cpp b/joint_trajectory/src/widgets/joint_trajectory_tool_bar.cpp index 684d5ac2..85122a6b 100644 --- a/joint_trajectory/src/widgets/joint_trajectory_tool_bar.cpp +++ b/joint_trajectory/src/widgets/joint_trajectory_tool_bar.cpp @@ -47,21 +47,26 @@ JointTrajectoryToolBar::JointTrajectoryToolBar(std::shared_ptrcomponent_info = std::move(component_info); data_->remove_all_action = addAction(icons::getClearIcon(), "Remove All", [this]() { - QApplication::sendEvent(qApp, new events::JointTrajectoryRemoveAll(data_->component_info)); + events::JointTrajectoryRemoveAll event(data_->component_info); + QApplication::sendEvent(qApp, &event); }); data_->remove_action = addAction(icons::getTrashIcon(), "Remove All", [this]() { - QApplication::sendEvent(qApp, new events::JointTrajectoryRemoveSelected(data_->component_info)); + events::JointTrajectoryRemoveSelected event(data_->component_info); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->open_action = addAction(icons::getImportIcon(), "Open", [this]() { - QApplication::sendEvent(qApp, new events::JointTrajectoryOpen(data_->component_info)); + events::JointTrajectoryOpen event(data_->component_info); + QApplication::sendEvent(qApp, &event); }); data_->save_action = addAction(icons::getSaveIcon(), "Save", [this]() { - QApplication::sendEvent(qApp, new events::JointTrajectorySave(data_->component_info)); + events::JointTrajectorySave event(data_->component_info); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->plot_action = addAction(icons::getPlotIcon(), "Plot Joint Trajectory", [this]() { - QApplication::sendEvent(qApp, new events::JointTrajectoryPlot(data_->component_info)); + events::JointTrajectoryPlot event(data_->component_info); + QApplication::sendEvent(qApp, &event); }); data_->save_action->setDisabled(true); diff --git a/joint_trajectory/src/widgets/joint_trajectory_widget.cpp b/joint_trajectory/src/widgets/joint_trajectory_widget.cpp index e4d33716..ae741894 100644 --- a/joint_trajectory/src/widgets/joint_trajectory_widget.cpp +++ b/joint_trajectory/src/widgets/joint_trajectory_widget.cpp @@ -230,7 +230,8 @@ void JointTrajectoryWidget::onRemove() data_->selected_item->type() == static_cast(StandardItemType::JOINT_TRAJECTORY_SET)) { boost::uuids::uuid uuid = dynamic_cast(data_->selected_item)->trajectory_set.getUUID(); - QApplication::sendEvent(qApp, new events::JointTrajectoryRemove(data_->model->getComponentInfo(), uuid)); + events::JointTrajectoryRemove event(data_->model->getComponentInfo(), uuid); + QApplication::sendEvent(qApp, &event); data_->selected_item = nullptr; onDisablePlayer(); } @@ -256,21 +257,21 @@ void JointTrajectoryWidget::onCurrentRowChanged(const QModelIndex& current, cons { case static_cast(StandardItemType::COMMON_NAMESPACE): { - auto* event = new events::JointTrajectoryToolbarState(data_->model->getComponentInfo()); - event->save_enabled = false; - event->remove_enabled = false; - event->plot_enabled = false; - QApplication::sendEvent(qApp, event); + events::JointTrajectoryToolbarState event(data_->model->getComponentInfo()); + event.save_enabled = false; + event.remove_enabled = false; + event.plot_enabled = false; + QApplication::sendEvent(qApp, &event); break; } case static_cast(StandardItemType::JOINT_TRAJECTORY_SET_TRAJECTORY): { - auto* event = new events::JointTrajectoryToolbarState(data_->model->getComponentInfo()); - event->save_enabled = false; - event->remove_enabled = false; - event->plot_enabled = true; - QApplication::sendEvent(qApp, event); + events::JointTrajectoryToolbarState event(data_->model->getComponentInfo()); + event.save_enabled = false; + event.remove_enabled = false; + event.plot_enabled = true; + QApplication::sendEvent(qApp, &event); data_->current_trajectory = data_->model->getJointTrajectory(current_index); @@ -299,11 +300,11 @@ void JointTrajectoryWidget::onCurrentRowChanged(const QModelIndex& current, cons } case static_cast(StandardItemType::JOINT_TRAJECTORY_SET): { - auto* event = new events::JointTrajectoryToolbarState(data_->model->getComponentInfo()); - event->save_enabled = true; - event->remove_enabled = true; - event->plot_enabled = true; - QApplication::sendEvent(qApp, event); + events::JointTrajectoryToolbarState event(data_->model->getComponentInfo()); + event.save_enabled = true; + event.remove_enabled = true; + event.plot_enabled = true; + QApplication::sendEvent(qApp, &event); auto jts = data_->model->getJointTrajectorySet(current_index); @@ -336,11 +337,11 @@ void JointTrajectoryWidget::onCurrentRowChanged(const QModelIndex& current, cons } default: { - auto* event = new events::JointTrajectoryToolbarState(data_->model->getComponentInfo()); - event->save_enabled = false; - event->remove_enabled = false; - event->plot_enabled = false; - QApplication::sendEvent(qApp, event); + events::JointTrajectoryToolbarState event(data_->model->getComponentInfo()); + event.save_enabled = false; + event.remove_enabled = false; + event.plot_enabled = false; + QApplication::sendEvent(qApp, &event); const tesseract_common::JointState& state = data_->model->getJointState(current_index); auto jts = data_->model->getJointTrajectorySet(current_index); diff --git a/kinematic_groups/src/models/group_joint_states_model.cpp b/kinematic_groups/src/models/group_joint_states_model.cpp index fa49b609..59074738 100644 --- a/kinematic_groups/src/models/group_joint_states_model.cpp +++ b/kinematic_groups/src/models/group_joint_states_model.cpp @@ -79,18 +79,17 @@ bool GroupJointStatesModel::setData(const QModelIndex& index, const QVariant& va if (value.value() == Qt::Checked) { - QApplication::sendEvent(qApp, - new events::GroupJointStatesShow(component_info_, - parent_item->text().toStdString(), - derived_item->getName().toStdString(), - derived_item->getState())); + events::GroupJointStatesShow event(component_info_, + parent_item->text().toStdString(), + derived_item->getName().toStdString(), + derived_item->getState()); + QApplication::sendEvent(qApp, &event); } else { - QApplication::sendEvent(qApp, - new events::GroupJointStatesHide(component_info_, - parent_item->text().toStdString(), - derived_item->getName().toStdString())); + events::GroupJointStatesHide event( + component_info_, parent_item->text().toStdString(), derived_item->getName().toStdString()); + QApplication::sendEvent(qApp, &event); } } } diff --git a/kinematic_groups/src/widgets/group_joint_states_editor_widget.cpp b/kinematic_groups/src/widgets/group_joint_states_editor_widget.cpp index 78bf1fc2..748e58c9 100644 --- a/kinematic_groups/src/widgets/group_joint_states_editor_widget.cpp +++ b/kinematic_groups/src/widgets/group_joint_states_editor_widget.cpp @@ -134,12 +134,9 @@ void GroupJointStatesEditorWidget::onAddJointState() if (state_name.empty()) return; - QApplication::sendEvent( - qApp, - new tesseract_gui::events::GroupJointStatesAdd(ui_->groupJointStatesWidget->getComponentInfo(), - group_name, - state_name, - ui_->jointSliderWidget->getJointState())); + tesseract_gui::events::GroupJointStatesAdd event( + ui_->groupJointStatesWidget->getComponentInfo(), group_name, state_name, ui_->jointSliderWidget->getJointState()); + QApplication::sendEvent(qApp, &event); ui_->jointStateNameLineEdit->clear(); } @@ -160,8 +157,10 @@ void GroupJointStatesEditorWidget::onRemoveJointState() } if (!remove_items.empty()) - QApplication::sendEvent(qApp, - new tesseract_gui::events::GroupJointStatesRemove(model->getComponentInfo(), remove_items)); + { + tesseract_gui::events::GroupJointStatesRemove event(model->getComponentInfo(), remove_items); + QApplication::sendEvent(qApp, &event); + } } void GroupJointStatesEditorWidget::onApply() @@ -170,7 +169,8 @@ void GroupJointStatesEditorWidget::onApply() info.group_states = ui_->groupJointStatesWidget->getModel()->getGroupsJointStates(); auto cmd = std::make_shared(info); - QApplication::sendEvent(qApp, new events::EnvironmentApplyCommand(getComponentInfo(), { cmd })); + events::EnvironmentApplyCommand event(getComponentInfo(), { cmd }); + QApplication::sendEvent(qApp, &event); } void GroupJointStatesEditorWidget::onUpdateModels() diff --git a/kinematic_groups/src/widgets/kinematic_groups_editor_widget.cpp b/kinematic_groups/src/widgets/kinematic_groups_editor_widget.cpp index a52c9af0..f792e24a 100644 --- a/kinematic_groups/src/widgets/kinematic_groups_editor_widget.cpp +++ b/kinematic_groups/src/widgets/kinematic_groups_editor_widget.cpp @@ -133,7 +133,8 @@ void KinematicGroupsEditorWidget::onAddGroup() tesseract_srdf::ChainGroup group{ { base_link.toStdString(), tip_link.toStdString() } }; - QApplication::sendEvent(qApp, new events::KinematicGroupsAddChain(getComponentInfo(), group_name, group)); + events::KinematicGroupsAddChain event(getComponentInfo(), group_name, group); + QApplication::sendEvent(qApp, &event); ui_->groupNameLineEdit->clear(); return; @@ -151,7 +152,8 @@ void KinematicGroupsEditorWidget::onAddGroup() for (auto& joint : joints) group.push_back(joint.toStdString()); - QApplication::sendEvent(qApp, new events::KinematicGroupsAddJoint(getComponentInfo(), group_name, group)); + events::KinematicGroupsAddJoint event(getComponentInfo(), group_name, group); + QApplication::sendEvent(qApp, &event); ui_->groupNameLineEdit->clear(); ui_->jointListWidget->clear(); @@ -170,7 +172,8 @@ void KinematicGroupsEditorWidget::onAddGroup() for (auto& link : links) group.push_back(link.toStdString()); - QApplication::sendEvent(qApp, new events::KinematicGroupsAddLink(getComponentInfo(), group_name, group)); + events::KinematicGroupsAddLink event(getComponentInfo(), group_name, group); + QApplication::sendEvent(qApp, &event); ui_->groupNameLineEdit->clear(); ui_->linkListWidget->clear(); @@ -196,7 +199,8 @@ void KinematicGroupsEditorWidget::onRemoveGroup() } } - QApplication::sendEvent(qApp, new events::KinematicGroupsRemove(getComponentInfo(), remove_groups)); + events::KinematicGroupsRemove event(getComponentInfo(), remove_groups); + QApplication::sendEvent(qApp, &event); } void KinematicGroupsEditorWidget::onAddJoint() { ui_->jointListWidget->addItem(ui_->jointComboBox->currentText()); } @@ -232,7 +236,8 @@ void KinematicGroupsEditorWidget::onApply() info.link_groups = ui_->kinGroupsWidget->getModel()->getLinkGroups(); auto cmd = std::make_shared(info); - QApplication::sendEvent(qApp, new events::EnvironmentApplyCommand(getComponentInfo(), { cmd })); + events::EnvironmentApplyCommand event(getComponentInfo(), { cmd }); + QApplication::sendEvent(qApp, &event); } void KinematicGroupsEditorWidget::onUpdateLinkNamesModel() diff --git a/manipulation/src/manipulation_tool_bar.cpp b/manipulation/src/manipulation_tool_bar.cpp index bda333c7..d2ee97cd 100644 --- a/manipulation/src/manipulation_tool_bar.cpp +++ b/manipulation/src/manipulation_tool_bar.cpp @@ -80,16 +80,16 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::LINK, true)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::LINK, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_all_links_action = addAction(icons::getHideAllLinksIcon(), "Hide All Links", [this]() { auto it = data_->state_component_infos.find(data_->state_name); if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::LINK, false)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::LINK, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->show_visual_all_links_action = @@ -98,8 +98,8 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::VISUAL, true)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::VISUAL, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_visual_all_links_action = addAction(icons::getHideVisualAllLinksIcon(), "Hide Visual All Links", [this]() { @@ -107,8 +107,8 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::VISUAL, false)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::VISUAL, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->show_collision_all_links_action = @@ -117,8 +117,8 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::COLLISION, true)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::COLLISION, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_collision_all_links_action = addAction(icons::getHideCollisionAllLinksIcon(), "Hide Collision All Links", [this]() { @@ -126,8 +126,8 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::COLLISION, false)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::COLLISION, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->select_all_links_action = addAction(icons::getSelectAllLinksIcon(), "Select All Links", [this]() { @@ -135,16 +135,16 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::WIREBOX, true)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::WIREBOX, true); + QApplication::sendEvent(qApp, &event); }); data_->deselect_all_links_action = addAction(icons::getDeselectAllLinksIcon(), "Deselect All Links", [this]() { auto it = data_->state_component_infos.find(data_->state_name); if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::WIREBOX, false)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::WIREBOX, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->show_axis_all_links_action = addAction(icons::getShowAxisAllLinksIcon(), "Show Axis All Links", [this]() { @@ -152,16 +152,16 @@ ManipulationToolBar::ManipulationToolBar(std::shared_ptr pa if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::AXIS, true)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::AXIS, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_axis_all_links_action = addAction(icons::getHideAxisAllLinksIcon(), "Hide Axis All Links", [this]() { auto it = data_->state_component_infos.find(data_->state_name); if (it == data_->state_component_infos.end()) return; - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(it->second, LinkVisibilityFlags::AXIS, false)); + events::SceneGraphModifyLinkVisibilityALL event(it->second, LinkVisibilityFlags::AXIS, false); + QApplication::sendEvent(qApp, &event); }); // Install event filter diff --git a/manipulation/src/manipulation_widget.cpp b/manipulation/src/manipulation_widget.cpp index 4d4323ee..ff69b938 100644 --- a/manipulation/src/manipulation_widget.cpp +++ b/manipulation/src/manipulation_widget.cpp @@ -132,9 +132,9 @@ void ManipulationWidget::addStateHelper(const std::string& state_name) std::unordered_map> state_component_infos; for (const auto& it : data_->state_models) state_component_infos[it.first] = it.second->getComponentInfo(); - QApplication::sendEvent(qApp, - new events::ManipulationChanged( - data_->parent_component_info, current_state_name.toStdString(), state_component_infos)); + events::ManipulationChanged event( + data_->parent_component_info, current_state_name.toStdString(), state_component_infos); + QApplication::sendEvent(qApp, &event); } if (!data_->use_parent_component_info) @@ -186,10 +186,9 @@ void ManipulationWidget::removeStateHelper(const std::string& state_name) std::unordered_map> state_component_infos; for (const auto& it : data_->state_models) state_component_infos[it.first] = it.second->getComponentInfo(); - QApplication::sendEvent(qApp, - new events::ManipulationChanged(data_->parent_component_info, - ui->state_combo_box->currentText().toStdString(), - state_component_infos)); + events::ManipulationChanged event( + data_->parent_component_info, ui->state_combo_box->currentText().toStdString(), state_component_infos); + QApplication::sendEvent(qApp, &event); } void ManipulationWidget::setComponentInfo(std::shared_ptr component_info) @@ -318,10 +317,9 @@ void ManipulationWidget::onGroupNameChanged() for (const auto& state_name : data_->state_names) { - QApplication::sendEvent( - qApp, - new events::SceneStateChanged(data_->state_models.at(state_name.toStdString())->getComponentInfo(), - env->getState())); + events::SceneStateChanged event(data_->state_models.at(state_name.toStdString())->getComponentInfo(), + env->getState()); + QApplication::sendEvent(qApp, &event); data_->states[state_name.toStdString()].clear(); } @@ -577,9 +575,9 @@ void ManipulationWidget::onReset() for (const auto& state_name : data_->state_names) { - QApplication::sendEvent(qApp, - new events::SceneStateChanged( - data_->state_models.at(state_name.toStdString())->getComponentInfo(), env->getState())); + events::SceneStateChanged event(data_->state_models.at(state_name.toStdString())->getComponentInfo(), + env->getState()); + QApplication::sendEvent(qApp, &event); data_->states[state_name.toStdString()].clear(); } @@ -640,10 +638,9 @@ void ManipulationWidget::onReset() std::unordered_map> state_component_infos; for (const auto& it : data_->state_models) state_component_infos[it.first] = it.second->getComponentInfo(); - QApplication::sendEvent(qApp, - new events::ManipulationChanged(data_->parent_component_info, - ui->state_combo_box->currentText().toStdString(), - state_component_infos)); + events::ManipulationChanged event( + data_->parent_component_info, ui->state_combo_box->currentText().toStdString(), state_component_infos); + QApplication::sendEvent(qApp, &event); } } // namespace tesseract_gui diff --git a/rendering/demo/render_environment_widget_demo.cpp b/rendering/demo/render_environment_widget_demo.cpp index 01924c21..5c5ce463 100644 --- a/rendering/demo/render_environment_widget_demo.cpp +++ b/rendering/demo/render_environment_widget_demo.cpp @@ -175,10 +175,12 @@ int main(int argc, char** argv) std::make_shared(component_info, env)); tesseract_gui::ToolPath tool_path = getToolPath(); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathAdd(component_info, tool_path)); + tesseract_gui::events::ToolPathAdd event1(component_info, tool_path); + QApplication::sendEvent(qApp, &event1); tesseract_common::JointTrajectorySet trajectory_set = getJointTrajectorySet(); - QApplication::sendEvent(qApp, new tesseract_gui::events::JointTrajectoryAdd(jt_component_info, trajectory_set)); + tesseract_gui::events::JointTrajectoryAdd event2(jt_component_info, trajectory_set); + QApplication::sendEvent(qApp, &event2); return app.exec(); } diff --git a/rendering/src/render_widget.cpp b/rendering/src/render_widget.cpp index 2ffcc928..530a9370 100644 --- a/rendering/src/render_widget.cpp +++ b/rendering/src/render_widget.cpp @@ -358,7 +358,8 @@ void Renderer::render() if (qApp != nullptr) { - QApplication::sendEvent(qApp, new events::PreRender(data_->scene_name)); + events::PreRender event(data_->scene_name); + QApplication::sendEvent(qApp, &event); } { @@ -369,7 +370,8 @@ void Renderer::render() if (qApp != nullptr) { - QApplication::sendEvent(qApp, new events::Render(data_->scene_name)); + events::Render event(data_->scene_name); + QApplication::sendEvent(qApp, &event); } return; diff --git a/scene_graph/demo/scene_graph_demo.cpp b/scene_graph/demo/scene_graph_demo.cpp index 30a430b5..8c9ee941 100644 --- a/scene_graph/demo/scene_graph_demo.cpp +++ b/scene_graph/demo/scene_graph_demo.cpp @@ -62,7 +62,8 @@ int main(int argc, char** argv) widget.setLayout(layout); widget.show(); - QApplication::sendEvent(qApp, new tesseract_gui::events::SceneGraphSet(component_info, std::move(scene_graph))); + tesseract_gui::events::SceneGraphSet event(component_info, std::move(scene_graph)); + QApplication::sendEvent(qApp, &event); return app.exec(); } diff --git a/scene_graph/src/models/scene_graph_model.cpp b/scene_graph/src/models/scene_graph_model.cpp index d5008720..87e2f168 100644 --- a/scene_graph/src/models/scene_graph_model.cpp +++ b/scene_graph/src/models/scene_graph_model.cpp @@ -110,31 +110,31 @@ bool SceneGraphModel::setData(const QModelIndex& index, const QVariant& value, i { assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibility(data_->component_info, - { derived_item->link->getName() }, - LinkVisibilityFlags::LINK, - value.value() == Qt::Checked)); + events::SceneGraphModifyLinkVisibility event(data_->component_info, + { derived_item->link->getName() }, + LinkVisibilityFlags::LINK, + value.value() == Qt::Checked); + QApplication::sendEvent(qApp, &event); } else if (item->type() == static_cast(StandardItemType::SG_VISUALS)) { assert(dynamic_cast(item->parent()) != nullptr); auto* derived_item = static_cast(item->parent()); - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibility(data_->component_info, - { derived_item->link->getName() }, - LinkVisibilityFlags::VISUAL, - value.value() == Qt::Checked)); + events::SceneGraphModifyLinkVisibility event(data_->component_info, + { derived_item->link->getName() }, + LinkVisibilityFlags::VISUAL, + value.value() == Qt::Checked); + QApplication::sendEvent(qApp, &event); } else if (item->type() == static_cast(StandardItemType::SG_COLLISIONS)) { assert(dynamic_cast(item->parent()) != nullptr); auto* derived_item = static_cast(item->parent()); - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibility(data_->component_info, - { derived_item->link->getName() }, - LinkVisibilityFlags::COLLISION, - value.value() == Qt::Checked)); + events::SceneGraphModifyLinkVisibility event(data_->component_info, + { derived_item->link->getName() }, + LinkVisibilityFlags::COLLISION, + value.value() == Qt::Checked); + QApplication::sendEvent(qApp, &event); } } return QStandardItemModel::setData(index, value, role); diff --git a/scene_graph/src/models/scene_state_model.cpp b/scene_graph/src/models/scene_state_model.cpp index caebf938..75544759 100644 --- a/scene_graph/src/models/scene_state_model.cpp +++ b/scene_graph/src/models/scene_state_model.cpp @@ -239,11 +239,11 @@ bool SceneStateModel::setData(const QModelIndex& index, const QVariant& value, i { assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibility(data_->component_info, - { derived_item->text().toStdString() }, - LinkVisibilityFlags::AXIS, - value.value() == Qt::Checked)); + events::SceneGraphModifyLinkVisibility event(data_->component_info, + { derived_item->text().toStdString() }, + LinkVisibilityFlags::AXIS, + value.value() == Qt::Checked); + QApplication::sendEvent(qApp, &event); } } return QStandardItemModel::setData(index, value, role); diff --git a/scene_graph/src/widgets/scene_graph_tool_bar.cpp b/scene_graph/src/widgets/scene_graph_tool_bar.cpp index 4b6e0c08..08bbb881 100644 --- a/scene_graph/src/widgets/scene_graph_tool_bar.cpp +++ b/scene_graph/src/widgets/scene_graph_tool_bar.cpp @@ -59,61 +59,57 @@ SceneGraphToolBar::SceneGraphToolBar(std::shared_ptr compon { data_->component_info = std::move(component_info); data_->show_all_links_action = addAction(icons::getShowAllLinksIcon(), "Show All Links", [this]() { - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::LINK, true)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::LINK, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_all_links_action = addAction(icons::getHideAllLinksIcon(), "Hide All Links", [this]() { - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::LINK, false)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::LINK, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->show_visual_all_links_action = addAction(icons::getShowVisualAllLinksIcon(), "Show Visual All Links", [this]() { - QApplication::sendEvent( - qApp, - new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::VISUAL, true)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::VISUAL, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_visual_all_links_action = addAction(icons::getHideVisualAllLinksIcon(), "Hide Visual All Links", [this]() { - QApplication::sendEvent( - qApp, - new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::VISUAL, false)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::VISUAL, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->show_collision_all_links_action = addAction(icons::getShowCollisionAllLinksIcon(), "Show Collision All Links", [this]() { - QApplication::sendEvent( - qApp, - new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::COLLISION, true)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::COLLISION, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_collision_all_links_action = addAction(icons::getHideCollisionAllLinksIcon(), "Hide Collision All Links", [this]() { - QApplication::sendEvent(qApp, - new events::SceneGraphModifyLinkVisibilityALL( - data_->component_info, LinkVisibilityFlags::COLLISION, false)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::COLLISION, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->select_all_links_action = addAction(icons::getSelectAllLinksIcon(), "Select All Links", [this]() { - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::WIREBOX, true)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::WIREBOX, true); + QApplication::sendEvent(qApp, &event); }); data_->deselect_all_links_action = addAction(icons::getDeselectAllLinksIcon(), "Deselect All Links", [this]() { - QApplication::sendEvent( - qApp, - new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::WIREBOX, false)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::WIREBOX, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->show_axis_all_links_action = addAction(icons::getShowAxisAllLinksIcon(), "Show Axis All Links", [this]() { - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::AXIS, true)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::AXIS, true); + QApplication::sendEvent(qApp, &event); }); data_->hide_axis_all_links_action = addAction(icons::getHideAxisAllLinksIcon(), "Hide Axis All Links", [this]() { - QApplication::sendEvent( - qApp, new events::SceneGraphModifyLinkVisibilityALL(data_->component_info, LinkVisibilityFlags::AXIS, false)); + events::SceneGraphModifyLinkVisibilityALL event(data_->component_info, LinkVisibilityFlags::AXIS, false); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->plot_scene_graph_action = addAction(icons::getPlotIcon(), "Plot Scene Graph", [this]() { - QApplication::sendEvent(qApp, new events::SceneGraphPlot(data_->component_info)); + events::SceneGraphPlot event(data_->component_info); + QApplication::sendEvent(qApp, &event); }); } @@ -121,7 +117,7 @@ SceneGraphToolBar::~SceneGraphToolBar() = default; void SceneGraphToolBar::setComponentInfo(std::shared_ptr component_info) { - data_->component_info = component_info; + data_->component_info = std::move(component_info); } std::shared_ptr SceneGraphToolBar::getComponentInfo() const { return data_->component_info; } diff --git a/srdf/src/srdf_editor_widget.cpp b/srdf/src/srdf_editor_widget.cpp index d34fc9d0..92a27ed4 100644 --- a/srdf/src/srdf_editor_widget.cpp +++ b/srdf/src/srdf_editor_widget.cpp @@ -143,9 +143,14 @@ void SRDFEditorWidget::onLoad(const QString& urdf_filepath, const QString& srdf_ // Remove existing environment wrapper EnvironmentManager::remove(data_->component_info); - QApplication::sendEvent(qApp, new events::AllowedCollisionMatrixClear(data_->component_info)); - QApplication::sendEvent(qApp, new events::KinematicGroupsClear(data_->component_info)); - QApplication::sendEvent(qApp, new events::GroupJointStatesClear(data_->component_info)); + events::AllowedCollisionMatrixClear clear_acm_event(data_->component_info); + QApplication::sendEvent(qApp, &clear_acm_event); + + events::KinematicGroupsClear clear_kin_groups_event(data_->component_info); + QApplication::sendEvent(qApp, &clear_kin_groups_event); + + events::GroupJointStatesClear clear_group_joint_states_event(data_->component_info); + QApplication::sendEvent(qApp, &clear_group_joint_states_event); // this->data_->user_tcp_model.clear(); // this->data_->opw_kinematics_model.clear(); diff --git a/tool_path/demo/tool_path_demo.cpp b/tool_path/demo/tool_path_demo.cpp index cad6fb51..37cd05c6 100644 --- a/tool_path/demo/tool_path_demo.cpp +++ b/tool_path/demo/tool_path_demo.cpp @@ -85,12 +85,23 @@ int main(int argc, char** argv) widget.setLayout(layout); widget.show(); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathAdd(component_info, tool_path)); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathAdd(component_info, tool_path1)); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathAdd(component_info, tool_path2)); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathAdd(component_info, tool_path3)); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathAdd(component_info, tool_path4)); - QApplication::sendEvent(qApp, new tesseract_gui::events::ToolPathRemove(component_info, tool_path3.getUUID())); + tesseract_gui::events::ToolPathAdd event(component_info, tool_path); + QApplication::sendEvent(qApp, &event); + + tesseract_gui::events::ToolPathAdd event1(component_info, tool_path1); + QApplication::sendEvent(qApp, &event1); + + tesseract_gui::events::ToolPathAdd event2(component_info, tool_path2); + QApplication::sendEvent(qApp, &event2); + + tesseract_gui::events::ToolPathAdd event3(component_info, tool_path3); + QApplication::sendEvent(qApp, &event3); + + tesseract_gui::events::ToolPathAdd event4(component_info, tool_path4); + QApplication::sendEvent(qApp, &event4); + + tesseract_gui::events::ToolPathRemove event5(component_info, tool_path3.getUUID()); + QApplication::sendEvent(qApp, &event5); return QApplication::exec(); } diff --git a/tool_path/src/models/tool_path_model.cpp b/tool_path/src/models/tool_path_model.cpp index 20d870ed..3349769a 100644 --- a/tool_path/src/models/tool_path_model.cpp +++ b/tool_path/src/models/tool_path_model.cpp @@ -140,35 +140,45 @@ bool ToolPathModel::setData(const QModelIndex& index, const QVariant& value, int assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); if (value.value() == Qt::Checked) - QApplication::sendEvent(qApp, new events::ToolPathShow(data_->component_info, derived_item->getUUID())); + { + events::ToolPathShow event(data_->component_info, derived_item->getUUID()); + QApplication::sendEvent(qApp, &event); + } else - QApplication::sendEvent(qApp, new events::ToolPathHide(data_->component_info, derived_item->getUUID())); + { + events::ToolPathHide event(data_->component_info, derived_item->getUUID()); + QApplication::sendEvent(qApp, &event); + } } else if (item->type() == static_cast(StandardItemType::COMMON_TOOL_PATH_SEGMENT)) { assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); if (value.value() == Qt::Checked) - QApplication::sendEvent(qApp, - new events::ToolPathShow( - data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID())); + { + events::ToolPathShow event(data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID()); + QApplication::sendEvent(qApp, &event); + } else - QApplication::sendEvent(qApp, - new events::ToolPathHide( - data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID())); + { + events::ToolPathHide event(data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID()); + QApplication::sendEvent(qApp, &event); + } } else if (item->type() == static_cast(StandardItemType::COMMON_TRANSFORM)) { assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); if (value.value() == Qt::Checked) - QApplication::sendEvent(qApp, - new events::ToolPathShow( - data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID())); + { + events::ToolPathShow event(data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID()); + QApplication::sendEvent(qApp, &event); + } else - QApplication::sendEvent(qApp, - new events::ToolPathHide( - data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID())); + { + events::ToolPathHide event(data_->component_info, findToolPathItem(item)->getUUID(), derived_item->getUUID()); + QApplication::sendEvent(qApp, &event); + } } } return QStandardItemModel::setData(index, value, role); diff --git a/tool_path/src/models/tool_path_selection_model.cpp b/tool_path/src/models/tool_path_selection_model.cpp index a8dc5e82..5933398f 100644 --- a/tool_path/src/models/tool_path_selection_model.cpp +++ b/tool_path/src/models/tool_path_selection_model.cpp @@ -83,7 +83,8 @@ bool ToolPathSelectionModel::eventFilter(QObject* obj, QEvent* event) { assert(dynamic_cast(item) != nullptr); auto* derived_item = static_cast(item); - QGuiApplication::sendEvent(qApp, new events::ToolPathRemove(component_info_, derived_item->getUUID())); + events::ToolPathRemove event(component_info_, derived_item->getUUID()); + QGuiApplication::sendEvent(qApp, &event); } else if (item->type() == static_cast(StandardItemType::COMMON_TOOL_PATH_SEGMENT)) { diff --git a/tool_path/src/models/tool_path_utils.cpp b/tool_path/src/models/tool_path_utils.cpp index cd13a561..0282464e 100644 --- a/tool_path/src/models/tool_path_utils.cpp +++ b/tool_path/src/models/tool_path_utils.cpp @@ -84,7 +84,8 @@ bool openToolPath(const std::shared_ptr& component_info, auto tool_path = tesseract_common::Serialization::fromArchiveFileXML(filename.toStdString()); ToolPath qt_tool_path(tool_path, link_name.toStdString()); - QApplication::sendEvent(qApp, new events::ToolPathAdd(component_info, std::move(qt_tool_path))); + events::ToolPathAdd event(component_info, std::move(qt_tool_path)); + QApplication::sendEvent(qApp, &event); return true; } @@ -93,7 +94,8 @@ bool openToolPath(const std::shared_ptr& component_info, auto tool_path = tesseract_common::Serialization::fromArchiveFileBinary(filename.toStdString()); ToolPath qt_tool_path(tool_path, link_name.toStdString()); - QApplication::sendEvent(qApp, new events::ToolPathAdd(component_info, std::move(qt_tool_path))); + events::ToolPathAdd event(component_info, std::move(qt_tool_path)); + QApplication::sendEvent(qApp, &event); return true; } @@ -102,7 +104,8 @@ bool openToolPath(const std::shared_ptr& component_info, YAML::Node node = YAML::LoadFile(filename.toStdString()); auto tool_path = node.as(); ToolPath qt_tool_path(tool_path, link_name.toStdString()); - QApplication::sendEvent(qApp, new events::ToolPathAdd(component_info, std::move(qt_tool_path))); + events::ToolPathAdd event(component_info, std::move(qt_tool_path)); + QApplication::sendEvent(qApp, &event); return true; } diff --git a/tool_path/src/widgets/tool_path_tool_bar.cpp b/tool_path/src/widgets/tool_path_tool_bar.cpp index e1ab98ab..717e2e81 100644 --- a/tool_path/src/widgets/tool_path_tool_bar.cpp +++ b/tool_path/src/widgets/tool_path_tool_bar.cpp @@ -48,24 +48,30 @@ ToolPathToolBar::ToolPathToolBar(std::shared_ptr component_ { data_->component_info = component_info; data_->remove_all = addAction(icons::getClearIcon(), "Remove All", [component_info]() { - QApplication::sendEvent(qApp, new events::ToolPathRemoveAll(component_info)); + events::ToolPathRemoveAll event(component_info); + QApplication::sendEvent(qApp, &event); }); data_->remove_selected = addAction(icons::getTrashIcon(), "Remove Selected", [component_info]() { - QApplication::sendEvent(qApp, new events::ToolPathRemoveSelected(component_info)); + events::ToolPathRemoveSelected event(component_info); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->hide_all = addAction(icons::getToolPathHideIcon(), "Hide All", [component_info]() { - QApplication::sendEvent(qApp, new events::ToolPathHideAll(component_info)); + events::ToolPathHideAll event(component_info); + QApplication::sendEvent(qApp, &event); }); data_->show_all = addAction(icons::getToolPathShowIcon(), "Show All", [component_info]() { - QApplication::sendEvent(qApp, new events::ToolPathShowAll(component_info)); + events::ToolPathShowAll event(component_info); + QApplication::sendEvent(qApp, &event); }); addSeparator(); data_->open_action = addAction(icons::getImportIcon(), "Open", [component_info]() { - QApplication::sendEvent(qApp, new events::ToolPathOpen(component_info)); + events::ToolPathOpen event(component_info); + QApplication::sendEvent(qApp, &event); }); data_->save_action = addAction(icons::getSaveIcon(), "Save", [component_info]() { - QApplication::sendEvent(qApp, new events::ToolPathSave(component_info)); + events::ToolPathSave event(component_info); + QApplication::sendEvent(qApp, &event); }); }