Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Qt6 #2797

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ python3-gz-transport14
python3-pybind11
python3-pytest
python3-sdformat15
qml-module-qt-labs-folderlistmodel
qml-module-qt-labs-settings
qml-module-qtgraphicaleffects
qml-module-qtqml-models2
qml-module-qtquick-controls
qml-module-qtquick-controls2
qml-module-qtquick-dialogs
qml-module-qtquick-layouts
qml-module-qtquick2
qtbase5-dev
qtdeclarative5-dev
qtquickcontrols2-5-dev
qml6-module-qt-labs-folderlistmodel
qml6-module-qt-labs-settings
qml6-module-qt5compat-graphicaleffects
qml6-module-qtqml-models
qml6-module-qtquick-controls
qml6-module-qtquick-dialogs
qml6-module-qtquick-layouts
qml6-module-qtquick
qt6-5compat-dev
qt6-base-dev
qt6-base-private-dev
qt6-declarative-dev
uuid-dev
xvfb
x11-utils
Expand Down
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,25 @@ set(GZ_FUEL_TOOLS_VER ${gz-fuel_tools10_VERSION_MAJOR})
# Find gz-gui
gz_find_package(gz-gui10 REQUIRED)
set(GZ_GUI_VER ${gz-gui10_VERSION_MAJOR})
gz_find_package (Qt5

set(QT_MAJOR_VERSION 6)
set(QT_MINOR_VERSION 4)
gz_find_package (Qt${QT_MAJOR_VERSION}
VERSION ${QT_MAJOR_VERSION}.${QT_MINOR_VERSION}
COMPONENTS
Core
Quick
QuickControls2
REQUIRED
PKGCONFIG "Qt5Core Qt5Quick Qt5QuickControls2")
PKGCONFIG "Qt${QT_MAJOR_VERSION}Core Qt${QT_MAJOR_VERSION}Quick Qt${QT_MAJOR_VERSION}QuickControls2")

set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTORCC TRUE)
if(POLICY CMP0100)
cmake_policy(SET CMP0100 NEW)
endif()


#--------------------------------------
# Find gz-physics
Expand Down
11 changes: 7 additions & 4 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ set(CMAKE_AUTORCC ON)

# CMake AUTOMOC does not generate moc_*.cpp files automatically for headers
# located in different directories than the containing .cc file. For Qt header
# files in `include/gz/sim/gui`, we use qt5_wrap_cpp instead. There is
# files in `include/gz/sim/gui`, we use qt_wrap_cpp instead. There is
# no need to add entries for Qt header files in `src/gui/`.
qt5_wrap_cpp(gui_sources
qt_wrap_cpp(gui_sources
${PROJECT_SOURCE_DIR}/include/gz/sim/gui/GuiSystem.hh
)

Expand All @@ -51,8 +51,11 @@ target_link_libraries(${gui_target}
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER}
gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}
${Qt5Core_LIBRARIES}
${Qt5Widgets_LIBRARIES}
Qt::Core
Qt::Qml
Qt::Quick
Qt::QuickControls2
Qt::Widgets
)

set(CMAKE_AUTOMOC OFF)
Expand Down
8 changes: 6 additions & 2 deletions src/gui/Gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ std::unique_ptr<gz::gui::Application> createGui(

// Let QML files use C++ functions and properties
auto context = new QQmlContext(app->Engine()->rootContext());
context->setContextProperty("AboutDialogHandler", aboutDialogHandler);
context->setContextProperty("GuiFileHandler", guiFileHandler);
context->setContextProperty("_AboutDialogHandler", aboutDialogHandler);
context->setContextProperty("_GuiFileHandler", guiFileHandler);

// Instantiate GazeboDrawer.qml file into a component
QQmlComponent component(app->Engine(), ":/Gazebo/GazeboDrawer.qml");
Expand All @@ -452,6 +452,10 @@ std::unique_ptr<gz::gui::Application> createGui(
}
else
{
if (component.isError())
{
qWarning() << component.errors();
}
gzerr << "Failed to instantiate custom drawer, drawer will be empty"
<< std::endl;
}
Expand Down
48 changes: 25 additions & 23 deletions src/gui/GuiRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*
*/

#include <optional>
#include <memory>
#include <mutex>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -45,10 +47,6 @@
using namespace gz;
using namespace sim;

// Register SerializedStepMap to the Qt meta type system so we can pass objects
// of this type in QMetaObject::invokeMethod
Q_DECLARE_METATYPE(msgs::SerializedStepMap)

/////////////////////////////////////////////////
class gz::sim::GuiRunner::Implementation
{
Expand All @@ -64,15 +62,6 @@ class gz::sim::GuiRunner::Implementation
/// \brief Latest update info
public: UpdateInfo updateInfo;

/// \brief Flag used to end the updateThread.
public: bool running{false};

/// \brief Mutex to protect the plugin update.
public: std::mutex updateMutex;

/// \brief The plugin update thread..
public: std::thread updateThread;

/// \brief True if the initial state has been received and processed.
public: bool receivedInitialState{false};

Expand Down Expand Up @@ -103,14 +92,15 @@ class gz::sim::GuiRunner::Implementation

/// \brief Manager of all events.
public: EventManager eventMgr;

public: std::optional<msgs::SerializedStepMap> lastStateMsg;
public: std::mutex stateMsgMutex;
};

/////////////////////////////////////////////////
GuiRunner::GuiRunner(const std::string &_worldName)
: dataPtr(utils::MakeUniqueImpl<Implementation>())
{
qRegisterMetaType<msgs::SerializedStepMap>();

this->setProperty("worldName", QString::fromStdString(_worldName));

// Allow for creation of entities on GUI side.
Expand Down Expand Up @@ -262,8 +252,11 @@ void GuiRunner::OnStateAsyncService(const msgs::SerializedStepMap &_res)
// OnStateQt function to the queue so that its called from the Qt thread. This
// ensures that only one thread has access to the ecm and updateInfo
// variables.
QMetaObject::invokeMethod(this, "OnStateQt", Qt::QueuedConnection,
Q_ARG(msgs::SerializedStepMap, _res));
{
std::lock_guard<std::mutex> lock(this->dataPtr->stateMsgMutex);
this->dataPtr->lastStateMsg = _res;
}
QMetaObject::invokeMethod(this, "OnStateQt", Qt::QueuedConnection);
this->dataPtr->receivedInitialState = true;

// todo(anyone) store reqSrv string in a member variable and use it here
Expand All @@ -284,23 +277,32 @@ void GuiRunner::OnState(const msgs::SerializedStepMap &_msg)
if (!this->dataPtr->receivedInitialState)
return;

{
std::lock_guard<std::mutex> lock(this->dataPtr->stateMsgMutex);
this->dataPtr->lastStateMsg = _msg;
}
// Since this function may be called from a transport thread, we push the
// OnStateQt function to the queue so that its called from the Qt thread. This
// ensures that only one thread has access to the ecm and updateInfo
// variables.
QMetaObject::invokeMethod(this, "OnStateQt", Qt::QueuedConnection,
Q_ARG(msgs::SerializedStepMap, _msg));
QMetaObject::invokeMethod(this, "OnStateQt", Qt::QueuedConnection);
}

/////////////////////////////////////////////////
void GuiRunner::OnStateQt(const msgs::SerializedStepMap &_msg)
void GuiRunner::OnStateQt()
{
GZ_PROFILE_THREAD_NAME("Qt thread");
GZ_PROFILE("GuiRunner::Update");
this->dataPtr->ecm.SetState(_msg.state());
{
std::lock_guard<std::mutex> lock(this->dataPtr->stateMsgMutex);
if (this->dataPtr->lastStateMsg.has_value())
{
this->dataPtr->ecm.SetState(this->dataPtr->lastStateMsg->state());
}

// Update all plugins
this->dataPtr->updateInfo = convert<UpdateInfo>(_msg.stats());
// Update all plugins
this->dataPtr->updateInfo = convert<UpdateInfo>(this->dataPtr->lastStateMsg->stats());
}
this->UpdatePlugins();
}

Expand Down
4 changes: 3 additions & 1 deletion src/gui/GuiRunner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
#include "gz/sim/EventManager.hh"
#include "gz/sim/gui/Export.hh"


namespace gz
{
namespace sim
{

// Inline bracket to help doxygen filtering.
inline namespace GZ_SIM_VERSION_NAMESPACE {
/// \brief Responsible for running GUI systems as new states are received from
Expand Down Expand Up @@ -67,7 +69,7 @@ class GZ_SIM_GUI_VISIBLE GuiRunner : public QObject

/// \brief Called by the Qt thread to update the ECM with new state
/// \param[in] _msg New state message.
private: Q_INVOKABLE void OnStateQt(const msgs::SerializedStepMap &_msg);
private: Q_INVOKABLE void OnStateQt();

/// \brief Update the plugins.
private: Q_INVOKABLE void UpdatePlugins();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function(gz_add_gui_library library_name)

cmake_parse_arguments(gz_add_gui_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

QT5_WRAP_CPP(${library_name}_headers_MOC ${gz_add_gui_library_QT_HEADERS})
QT5_ADD_RESOURCES(${library_name}_RCC ${library_name}.qrc)
QT_WRAP_CPP(${library_name}_headers_MOC ${gz_add_gui_library_QT_HEADERS})
QT_ADD_RESOURCES(${library_name}_RCC ${library_name}.qrc)

if(MSVC)
# Warning #4251 is the "dll-interface" warning that tells you when types
Expand Down
2 changes: 1 addition & 1 deletion src/gui/plugins/align_tool/AlignTool.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.2
import QtQuick.Controls.Material.impl 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4


ToolBar {
Layout.minimumWidth: 280
Expand Down
2 changes: 1 addition & 1 deletion src/gui/plugins/banana_for_scale/BananaForScale.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.2
import QtQuick.Controls.Material.impl 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4


ToolBar {
id: bananaForScale
Expand Down
4 changes: 2 additions & 2 deletions src/gui/plugins/component_inspector/Boolean.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*
*/
import QtQuick 2.9
import QtQuick.Controls 1.4

import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4

import "qrc:/ComponentInspector"

Rectangle {
Expand Down
Loading
Loading