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

Qt6 CMake Migration #2305

Draft
wants to merge 9 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
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,26 @@ set(GZ_FUEL_TOOLS_VER ${gz-fuel_tools10_VERSION_MAJOR})
# Find gz-gui
gz_find_package(gz-gui9 REQUIRED)
set(GZ_GUI_VER ${gz-gui9_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()

qt_standard_project_setup()

#--------------------------------------
# Find gz-physics
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/gui_system_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(CMAKE_AUTOMOC ON)

find_package(gz-sim9 REQUIRED COMPONENTS gui)

QT5_ADD_RESOURCES(resources_RCC ${PROJECT_NAME}.qrc)
qt_add_resources(resources_RCC ${PROJECT_NAME}.qrc)

add_library(${PROJECT_NAME} SHARED
${PROJECT_NAME}.cc
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/rendering_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_AUTOMOC ON)

find_package(gz-gui9 REQUIRED)

QT5_ADD_RESOURCES(resources_RCC ${GUI_PLUGIN}.qrc)
qt_add_resources(resources_RCC ${GUI_PLUGIN}.qrc)

add_library(${GUI_PLUGIN} SHARED
${GUI_PLUGIN}.cc
Expand Down
4 changes: 1 addition & 3 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set(CMAKE_AUTORCC ON)
# 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
# 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,6 @@ 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}
)

set(CMAKE_AUTOMOC OFF)
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
11 changes: 5 additions & 6 deletions src/gui/plugins/align_tool/AlignTool.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
* limitations under the License.
*
*/
import QtQuick 2.9
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
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Controls.Material.impl
import QtQuick.Layouts

ToolBar {
Layout.minimumWidth: 280
Expand Down
8 changes: 4 additions & 4 deletions src/gui/plugins/apply_force_torque/ApplyForceTorque.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*
*/
import QtQuick 2.9
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import "qrc:/qml"
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "qrc:/gz/gui/qml"

GridLayout {
columns: 8
Expand Down
13 changes: 6 additions & 7 deletions src/gui/plugins/banana_for_scale/BananaForScale.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*
*/
import QtQuick 2.9
import QtQuick.Window 2.2
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
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Controls.Material.impl
import QtQuick.Layouts

ToolBar {
id: bananaForScale
Expand Down
10 changes: 4 additions & 6 deletions src/gui/plugins/component_inspector/Boolean.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* limitations under the License.
*
*/
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 QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
import "qrc:/ComponentInspector"

Rectangle {
Expand Down
13 changes: 6 additions & 7 deletions src/gui/plugins/component_inspector/ComponentInspector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
* limitations under the License.
*
*/
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Dialogs
import QtQuick.Layouts
import GzSim 1.0 as GzSim

Rectangle {
Expand Down Expand Up @@ -72,7 +71,7 @@ Rectangle {
Material.accent.b, 0.3)

function delegateQml(_model) {
if (_model === null || _model.dataType == undefined)
if (_model === null || _model.dataType === undefined)
return 'NoData.qml'

return _model.dataType + '.qml'
Expand Down
10 changes: 4 additions & 6 deletions src/gui/plugins/component_inspector/ExpandingTypeHeader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* limitations under the License.
*
*/
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 QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts

// Header
Rectangle {
Expand Down
14 changes: 6 additions & 8 deletions src/gui/plugins/component_inspector/Float.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
* limitations under the License.
*
*/
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 QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
import "qrc:/ComponentInspector"
import "qrc:/qml"
import "qrc:/gz/gui/qml"

Rectangle {
id: numberComponent
Expand All @@ -39,7 +37,7 @@ Rectangle {
property double spinMax: 1000000

// Unit
property string unit: model && model.unit != undefined ? model.unit : ''
property string unit: model && model.unit !== undefined ? model.unit : ''

RowLayout {
anchors.fill: parent
Expand Down
10 changes: 4 additions & 6 deletions src/gui/plugins/component_inspector/Inertial.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* limitations under the License.
*
*/
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 QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
import "qrc:/ComponentInspector"

// TODO
Expand Down
14 changes: 6 additions & 8 deletions src/gui/plugins/component_inspector/Integer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
* limitations under the License.
*
*/
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 QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
import "qrc:/ComponentInspector"
import "qrc:/qml"
import "qrc:/gz/gui/qml"

Rectangle {
id: numberComponent
Expand All @@ -39,7 +37,7 @@ Rectangle {
property double spinMax: 1000000

// Unit
property string unit: model && model.unit != undefined ? model.unit : ''
property string unit: model && model.unit !== undefined ? model.unit : ''

RowLayout {
anchors.fill: parent
Expand Down
Loading
Loading