diff --git a/CMakeLists.txt b/CMakeLists.txt
index a20b96fbb..37613cc2f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -81,8 +81,8 @@ set(GZ_TOOLS_VER 2)
#--------------------------------------
# Find QT
-set(QT_MAJOR_VERSION 5)
-set(QT_MINOR_VERSION 15)
+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
@@ -94,7 +94,16 @@ gz_find_package (Qt${QT_MAJOR_VERSION}
REQUIRED
PKGCONFIG_VER_COMPARISON >=
PKGCONFIG "Qt${QT_MAJOR_VERSION}Core Qt${QT_MAJOR_VERSION}Quick Qt${QT_MAJOR_VERSION}QuickControls2 Qt${QT_MAJOR_VERSION}Widgets")
+
add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x050F00)
+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()
set(GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR
${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins
diff --git a/examples/config/scene3d.config b/examples/config/scene3d.config
index 26719cb40..119d1a90e 100644
--- a/examples/config/scene3d.config
+++ b/examples/config/scene3d.config
@@ -72,46 +72,3 @@
false
-
-
- Controls
- false
- false
- 72
- 121
- 1
-
- floating
-
-
-
-
-
- true
- true
- false
- /world_control
- /world_stats
-
-
-
-
- Stats
- false
- false
- 110
- 290
- 1
-
- floating
-
-
-
-
-
- true
- true
- true
- true
- /world_stats
-
diff --git a/examples/plugin/custom_context_menu/CustomContext.qml b/examples/plugin/custom_context_menu/CustomContext.qml
index bf0f0d15a..9bdcd9b8e 100644
--- a/examples/plugin/custom_context_menu/CustomContext.qml
+++ b/examples/plugin/custom_context_menu/CustomContext.qml
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.0
-import QtQuick.Controls 2.0
+import QtQuick
+import QtQuick.Controls
Rectangle {
id: customContext
diff --git a/examples/plugin/dialog_from_plugin/DialogFromPlugin.qml b/examples/plugin/dialog_from_plugin/DialogFromPlugin.qml
index f1bd575b9..5ca8aa72f 100644
--- a/examples/plugin/dialog_from_plugin/DialogFromPlugin.qml
+++ b/examples/plugin/dialog_from_plugin/DialogFromPlugin.qml
@@ -14,10 +14,10 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Dialogs 1.0
-import QtQuick.Window 2.2
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Dialogs
+import QtQuick.Window
Rectangle {
id: customPlugin
diff --git a/examples/plugin/gz_components/GzComponents.qml b/examples/plugin/gz_components/GzComponents.qml
index 7a7fd7997..73c22f5e1 100644
--- a/examples/plugin/gz_components/GzComponents.qml
+++ b/examples/plugin/gz_components/GzComponents.qml
@@ -14,9 +14,9 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.0
-import gz.gui 1.0
+import QtQuick
+import QtQuick.Controls
+import gz.gui
Column {
anchors.fill: parent
diff --git a/examples/plugin/hello_plugin/HelloPlugin.qml b/examples/plugin/hello_plugin/HelloPlugin.qml
index 4d4dafc7a..acaf6629d 100644
--- a/examples/plugin/hello_plugin/HelloPlugin.qml
+++ b/examples/plugin/hello_plugin/HelloPlugin.qml
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.0
-import QtQuick.Controls 2.0
+import QtQuick
+import QtQuick.Controls
Rectangle {
color: "transparent"
anchors.fill: parent
diff --git a/examples/plugin/multiple_qml/MultipleQml.qml b/examples/plugin/multiple_qml/MultipleQml.qml
index 2063565c2..2d9892485 100644
--- a/examples/plugin/multiple_qml/MultipleQml.qml
+++ b/examples/plugin/multiple_qml/MultipleQml.qml
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.0
-import QtQuick.Controls 2.0
+import QtQuick
+import QtQuick.Controls
import "qrc:/MultipleQml_qml"
Column {
diff --git a/examples/standalone/custom_drawer/CustomDrawer.qml b/examples/standalone/custom_drawer/CustomDrawer.qml
index dcbf089a5..e6d2b05b0 100644
--- a/examples/standalone/custom_drawer/CustomDrawer.qml
+++ b/examples/standalone/custom_drawer/CustomDrawer.qml
@@ -14,9 +14,9 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.1
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
/**
* Custom drawer
diff --git a/examples/standalone/start_dialog/start_dialog.qml b/examples/standalone/start_dialog/start_dialog.qml
index a07f4ff52..645a0c5b4 100644
--- a/examples/standalone/start_dialog/start_dialog.qml
+++ b/examples/standalone/start_dialog/start_dialog.qml
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.0
-import QtQuick.Controls 2.0
+import QtQuick
+import QtQuick.Controls
Rectangle {
color: "green"
anchors.fill: parent
diff --git a/include/gz/gui/CMakeLists.txt b/include/gz/gui/CMakeLists.txt
index 5e15317d6..e291ea1a5 100644
--- a/include/gz/gui/CMakeLists.txt
+++ b/include/gz/gui/CMakeLists.txt
@@ -1,9 +1,3 @@
-if(POLICY CMP0100)
- cmake_policy(SET CMP0100 NEW)
-endif()
-
-set (CMAKE_AUTOMOC ON)
-
set (qt_headers
Application.hh
Dialog.hh
@@ -20,19 +14,101 @@ set (headers
gz.hh
qt.h
SearchModel.hh
- System.hh
)
-set (resources resources.qrc)
-
-qt_wrap_cpp(headers_MOC ${qt_headers})
-qt_add_resources(resources_RCC ${resources})
+set(qml_files
+ qml/Chart.qml
+ qml/GzCard.qml
+ qml/GzCardSettings.qml
+ qml/GzColor.qml
+ qml/GzHelpers.qml
+ qml/GzPlotIcon.qml
+ qml/GzPose.qml
+ qml/GzRulers.qml
+ qml/GzSnackBar.qml
+ qml/GzSortFilterModel.qml
+ qml/GzSpinBox.qml
+ qml/GzSplit.qml
+ qml/GzVector3.qml
+ qml/Main.qml
+ qml/PlottingInterface.qml
+ qml/PluginMenu.qml
+ qml/SideDrawer.qml
+ qml/StandaloneDialog.qml
+ qml/StyleDialog.qml
+)
-gz_create_core_library(SOURCES
- ${sources}
- ${headers_MOC}
- ${resources_RCC}
+set(resources
+ qml/images/drawer.png
+ qml/images/export_icon.png
+ qml/images/gazebo_logo.png
+ qml/images/menu.png
+ qml/images/plottable_icon.svg
+ qml/images/search.svg
)
+
+if (QT_MAJOR_VERSION EQUAL 6)
+ qt_add_qml_module(${PROJECT_LIBRARY_TARGET_NAME}
+ URI gz.gui
+ VERSION 9.0.0
+ SOURCES ${sources} ${qt_headers} ${headers}
+ QML_FILES ${qml_files}
+ RESOURCES ${resources}
+ )
+
+ include(GenerateExportHeader)
+ generate_export_header(${PROJECT_LIBRARY_TARGET_NAME}
+ BASE_NAME GZ_GUI
+ EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/gz/gui/detail/Export.hh
+ EXPORT_MACRO_NAME DETAIL_GZ_GUI_VISIBLE
+ NO_EXPORT_MACRO_NAME DETAIL_GZ_GUI_HIDDEN
+ DEPRECATED_MACRO_NAME GZ_DEPRECATED_ALL_VERSIONS)
+
+ set(include_dir "gz/gui")
+ set(export_base "GZ_GUI")
+ configure_file(
+ "${GZ_CMAKE_DIR}/Export.hh.in"
+ "${PROJECT_BINARY_DIR}/include/gz/gui/Export.hh")
+
+ install(
+ FILES "${PROJECT_BINARY_DIR}/include/gz/gui/Export.hh"
+ DESTINATION ${GZ_INCLUDE_INSTALL_DIR_FULL}/gz/gui/
+ COMPONENT headers)
+
+ install(
+ FILES "${PROJECT_BINARY_DIR}/include/gz/gui/detail/Export.hh"
+ DESTINATION ${GZ_INCLUDE_INSTALL_DIR_FULL}/gz/gui/detail/
+ COMPONENT headers)
+
+ target_include_directories(${PROJECT_LIBRARY_TARGET_NAME}
+ PUBLIC
+ $
+ $
+ )
+
+ install(
+ TARGETS ${PROJECT_LIBRARY_TARGET_NAME}
+ EXPORT ${PROJECT_LIBRARY_TARGET_NAME}
+ LIBRARY DESTINATION ${GZ_LIB_INSTALL_DIR}
+ ARCHIVE DESTINATION ${GZ_LIB_INSTALL_DIR}
+ RUNTIME DESTINATION ${GZ_BIN_INSTALL_DIR}
+ COMPONENT libraries)
+
+ _gz_create_cmake_package()
+ _gz_create_pkgconfig()
+
+else()
+ set (resources resources.qrc)
+ qt_wrap_cpp(headers_MOC ${qt_headers})
+ qt_add_resources(resources_RCC ${resources})
+
+ gz_create_core_library(SOURCES
+ ${sources}
+ ${headers_MOC}
+ ${resources_RCC}
+ )
+endif()
+
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION gz::gui::getInstallPrefix
GET_INSTALL_PREFIX_HEADER gz/gui/InstallationDirectories.hh
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GZ_GUI_INSTALL_PREFIX)
diff --git a/include/gz/gui/Plugin.hh b/include/gz/gui/Plugin.hh
index f4066ea8b..34c99ec31 100644
--- a/include/gz/gui/Plugin.hh
+++ b/include/gz/gui/Plugin.hh
@@ -49,7 +49,7 @@ namespace gz::gui
Q_OBJECT
/// \brief Constructor
- public: Plugin();
+ public: Plugin(QObject *_parent=nullptr);
/// \brief Destructor
public: virtual ~Plugin();
diff --git a/include/gz/gui/qml/Chart.qml b/include/gz/gui/qml/Chart.qml
index cd3a259d7..a0506e9ff 100644
--- a/include/gz/gui/qml/Chart.qml
+++ b/include/gz/gui/qml/Chart.qml
@@ -14,12 +14,11 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtCharts 2.2
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Styles 1.4
-import QtQuick.Controls.Material 2.1
-import QtQuick.Layouts 1.3
+import QtQuick
+import QtCharts
+import QtQuick.Controls
+import QtQuick.Controls.Style
+import QtQuick.Layouts
Rectangle {
id: main
diff --git a/include/gz/gui/qml/GzCard.qml b/include/gz/gui/qml/GzCard.qml
index c6c4464e6..ef96527d1 100644
--- a/include/gz/gui/qml/GzCard.qml
+++ b/include/gz/gui/qml/GzCard.qml
@@ -14,16 +14,16 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 1.4 as QQC1
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.1
-import QtQuick.Layouts 1.3
-import QtQuick.Window 2.2
-import "qrc:/qml"
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Layouts
+import QtQuick.Window
+import "qrc:/gz/gui/qml"
// TODO: don't use "parent"
Pane {
+ clip: true
/**
* Minimum length of each dimension
*/
@@ -158,6 +158,8 @@ Pane {
*/
objectName: "plugin" + Math.floor(Math.random() * 100000);
+ anchors.fill: parent
+
// Stop scroll propagation to widgets below
MouseArea {
anchors.fill: parent
@@ -174,9 +176,9 @@ Pane {
return;
// Bind anchors
- anchors.fill = Qt.binding(function() {return parent})
- parent.height = Qt.binding(function() {return height})
- parent.width = Qt.binding(function() {return width})
+ // anchors.fill = Qt.binding(function() {return parent})
+ // parent.height = Qt.binding(function() {return height})
+ // parent.width = Qt.binding(function() {return width})
// Keep a reference to the background
// TODO(louise) This feels hacky, the card shouldn't care about the background,
@@ -196,16 +198,16 @@ Pane {
* any knowledge of splits
*/
function syncTheFamily() {
- var parentSplit = helpers.ancestorByName(cardPane, /^split_item/);
-
- if (undefined == parentSplit)
- return;
-
- if (content.children.length != 1)
- return;
-
- parentSplit.Layout.minimumWidth = content.children[0].Layout.minimumWidth;
- parentSplit.Layout.minimumHeight = content.children[0].Layout.minimumHeight;
+ // var parentSplit = helpers.ancestorByName(cardPane, /^split_item/);
+ //
+ // if (undefined == parentSplit)
+ // return;
+ //
+ // if (content.children.length != 1)
+ // return;
+ //
+ // parentSplit.Layout.minimumWidth = content.children[0].Layout.minimumWidth;
+ // parentSplit.Layout.minimumHeight = content.children[0].Layout.minimumHeight;
}
/**
@@ -416,7 +418,7 @@ Pane {
{
const collapsed = cardPane.parent.Layout.minimumHeight === 50;
// Reparent to main window's background
- cardPane.parent = backgroundItem
+ cardPane.parent = backgroundItem.contentChildren[0]
// Resize to minimum size
cardPane.clearAnchors();
@@ -450,7 +452,7 @@ Pane {
*/
function recalculateSplitSizes()
{
- backgroundItem.recalculateMinimumSizes();
+ // backgroundItem.recalculateMinimumSizes();
}
// TODO(louise): re-enable window state support
@@ -670,21 +672,31 @@ Pane {
Rectangle {
objectName: "content"
id: content
+ // anchors.horizontalCenter: parent.horizontalCenter
+
anchors.fill: parent
anchors.topMargin: cardPane.showTitleBar ? 50 : 0
+ // height: 100
+ // implicitHeight: 123
clip: true
color: cardBackground
onChildrenChanged: {
// Set the height and width of the cardPane when child plugin is attached
+ // if (children.length > 0) {
+ // cardMinimumWidth = content.children[0].Layout.minimumWidth;
+ // cardMinimumHeight = content.children[0].Layout.minimumHeight;
+ // cardPane.width = cardMinimumWidth
+ // cardPane.height = cardMinimumHeight
+ // }
+ //
+ // cardPane.syncTheFamily()
if (children.length > 0) {
cardMinimumWidth = content.children[0].Layout.minimumWidth;
cardMinimumHeight = content.children[0].Layout.minimumHeight;
- cardPane.width = cardMinimumWidth
- cardPane.height = cardMinimumHeight
+ cardPane.Layout.minimumWidth = cardMinimumWidth
+ cardPane.Layout.minimumHeight = cardMinimumHeight
}
-
- cardPane.syncTheFamily()
}
/**
diff --git a/include/gz/gui/qml/GzCardSettings.qml b/include/gz/gui/qml/GzCardSettings.qml
index 0bf9423d9..cde4c4bbf 100644
--- a/include/gz/gui/qml/GzCardSettings.qml
+++ b/include/gz/gui/qml/GzCardSettings.qml
@@ -14,12 +14,12 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Layouts 1.3
-import QtQuick.Window 2.2
-import QtQuick.Dialogs 1.0
-import "qrc:/qml"
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtQuick.Window
+import QtQuick.Dialogs
+import "qrc:/gz/gui/qml"
Dialog {
id: settingsDialog
@@ -208,7 +208,7 @@ Dialog {
ColorDialog {
id: colorDialog
title: "Please choose a color"
- showAlphaChannel : true
+ options: ColorDialog.ShowAlphaChannel
onAccepted: {
content.color = colorDialog.color
bgColor.color = colorDialog.color
diff --git a/include/gz/gui/qml/GzColor.qml b/include/gz/gui/qml/GzColor.qml
index a04162d22..327ebd1eb 100644
--- a/include/gz/gui/qml/GzColor.qml
+++ b/include/gz/gui/qml/GzColor.qml
@@ -14,11 +14,10 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.1
-import QtQuick.Dialogs 1.0
-import QtQuick.Layouts 1.3
-import QtQuick.Controls.Material 2.1
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Dialogs
+import QtQuick.Layouts
// RGBA using range 0 - 1.0
@@ -56,7 +55,9 @@ Item {
id: gzColorDialog
title: "Choose a color"
visible: false
- showAlphaChannel: true
+ options: {
+ ShowAlphaChannel: true
+ }
onAccepted: {
r = gzColorDialog.color.r
g = gzColorDialog.color.g
@@ -70,4 +71,3 @@ Item {
}
}
}
-
diff --git a/include/gz/gui/qml/GzHelpers.qml b/include/gz/gui/qml/GzHelpers.qml
index 9938872f8..991c44f44 100644
--- a/include/gz/gui/qml/GzHelpers.qml
+++ b/include/gz/gui/qml/GzHelpers.qml
@@ -14,9 +14,10 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
+import QtQuick
Item {
+ visible: false
/**
* Helper function to get an item's ancestor by name.
* @param _item Item whose parent we're looking for.
@@ -56,4 +57,12 @@ Item {
return 4
}
+ function dump(object, indent, depth) {
+ console.log(indent + object)
+ if (depth > 0) {
+ for (const i in object.children)
+ dump(object.children[i], indent + " ", depth - 1)
+ }
+ }
+
}
diff --git a/include/gz/gui/qml/GzPlotIcon.qml b/include/gz/gui/qml/GzPlotIcon.qml
index 3167d20ae..72d36b00a 100644
--- a/include/gz/gui/qml/GzPlotIcon.qml
+++ b/include/gz/gui/qml/GzPlotIcon.qml
@@ -14,7 +14,7 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
+import QtQuick
/**
* Item for a draggable plotting icon
@@ -32,7 +32,7 @@ import QtQuick 2.9
* sourceComponent: gzploticon
* }
* Component.onCompleted: {
- * plotLoader.item.gzMimeData = {"text/plain" : "Component," + entityFromCpp + "," + typeIdFromCpp + ",x," + typeNameFromCpp}
+ * plotLoader.item.gzMimeData = {"text/plain" : "Component," + entityFromCpp + "," + typeIdFromCpp + ",x," + typeNameFromCpp}
* }
* }
* }
diff --git a/include/gz/gui/qml/GzPose.qml b/include/gz/gui/qml/GzPose.qml
index 63112fdec..5037258b0 100644
--- a/include/gz/gui/qml/GzPose.qml
+++ b/include/gz/gui/qml/GzPose.qml
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-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.Layouts
/**
* Item displaying 3D pose information.
diff --git a/include/gz/gui/qml/GzRulers.qml b/include/gz/gui/qml/GzRulers.qml
index 1595389cd..2b129f0bb 100644
--- a/include/gz/gui/qml/GzRulers.qml
+++ b/include/gz/gui/qml/GzRulers.qml
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
+import QtQuick
+import QtQuick.Controls
/**
* Rulers which can be dragged to resize a target.
diff --git a/include/gz/gui/qml/GzSnackBar.qml b/include/gz/gui/qml/GzSnackBar.qml
index f4f2dc3c8..de5f75863 100644
--- a/include/gz/gui/qml/GzSnackBar.qml
+++ b/include/gz/gui/qml/GzSnackBar.qml
@@ -15,13 +15,14 @@
*
*/
-import QtGraphicalEffects 1.0
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.2
-import QtQuick.Dialogs 1.0
-import QtQuick.Layouts 1.3
-import QtQuick.Window 2.2
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Dialogs
+import QtQuick.Layouts
+import QtQuick.Window
+
+import Qt5Compat.GraphicalEffects as Effects
/*
To use the snackbar you need to call the methods in the MainWindow class:
@@ -70,7 +71,7 @@ Popup {
background: Rectangle {
color: Material.background
layer.enabled: true
- layer.effect: DropShadow {
+ layer.effect: Effects.DropShadow {
color: "#aa000000"
samples: 9
spread: 0
diff --git a/include/gz/gui/qml/GzSortFilterModel.qml b/include/gz/gui/qml/GzSortFilterModel.qml
index f127d27ab..e60f6f094 100644
--- a/include/gz/gui/qml/GzSortFilterModel.qml
+++ b/include/gz/gui/qml/GzSortFilterModel.qml
@@ -18,8 +18,8 @@
// Borrowed from
// https://martin.rpdev.net/2019/01/15/using-delegatemodel-in-qml-for-sorting-and-filtering.html
-import QtQuick 2.9
-import QtQml.Models 2.3
+import QtQuick
+import QtQml.Models
DelegateModel {
/**
@@ -83,4 +83,3 @@ DelegateModel {
filterOnGroup: "visible"
}
-
diff --git a/include/gz/gui/qml/GzSpinBox.qml b/include/gz/gui/qml/GzSpinBox.qml
index 800db5e11..1ee4f6314 100644
--- a/include/gz/gui/qml/GzSpinBox.qml
+++ b/include/gz/gui/qml/GzSpinBox.qml
@@ -14,16 +14,72 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 1.4
-import QtQuick.Controls.Styles 1.4
+import QtQuick
+import QtQuick.Controls
+
+Item {
+ id: root
+ property int decimals: 2
+ property real value: 0.0
+ property real from: 0.0
+ property real to: 100.0
+ property alias minimumValue: root.from
+ property alias maximumValue: root.to
+ property real stepSize: 1.0
+ signal editingFinished(real _value)
+ implicitWidth: spinbox.implicitWidth
+ implicitHeight: spinbox.implicitHeight
+ // Timer {
+ // interval: 50; running: true; repeat: true
+ // onTriggered: {
+ // console.log("root. w: ", root.parent.objectName, spinbox.objectName, " = ", root.width, root.height, root.implicitWidth, root.implicitHeight)
+ // }
+ // }
+
+
+ function decimalToInt(decimal) {
+ return Math.round(decimal * spinbox.factor)
+ }
+
+ readonly property int maxInt32: Math.pow( 2, 31 ) - 1;
+ clip: true
+
+ SpinBox{
+ id: spinbox
+ anchors.fill: parent
+ property real factor: Math.pow(10, root.decimals)
+ stepSize: decimalToInt(root.stepSize)
+ value: decimalToInt(root.value)
+ to : Math.min(decimalToInt(root.to), maxInt32)
+ from : Math.max(decimalToInt(root.from), -maxInt32)
+ editable: true
+ clip: true
+ topPadding: 0
+ bottomPadding: 0
+
+ validator: DoubleValidator {
+ bottom: Math.min(spinbox.from, spinbox.to)
+ top: Math.max(spinbox.from, spinbox.to)
+ }
+
+ textFromValue: function(value, locale) {
+ return Number(value / factor).toLocaleString(locale, 'f', root.decimals)
+ }
+
+ valueFromText: function(text, locale) {
+ return decimalToInt(Number.fromLocaleString(locale, text))
+ }
+
+ onValueModified: {
+ root.value = spinbox.value / spinbox.factor
+ // console.log("val mod: ", root.value)
+ root.editingFinished(root.value)
+ }
-SpinBox {
- style: SpinBoxStyle{
background: Rectangle {
- implicitWidth: 70
- implicitHeight: 40
- border.color: "gray"
+ implicitWidth: 80
+ implicitHeight: 80
+ border.color: "red"
}
}
}
diff --git a/include/gz/gui/qml/GzSplit.qml b/include/gz/gui/qml/GzSplit.qml
index 87e521a71..a5fd00915 100644
--- a/include/gz/gui/qml/GzSplit.qml
+++ b/include/gz/gui/qml/GzSplit.qml
@@ -14,11 +14,10 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 1.1
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.1
-import QtQuick.Layouts 1.3
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Layouts
/**
* Main split view, which provides functions to add and remove child items
@@ -28,6 +27,7 @@ SplitView {
id: background
objectName: "background"
+ clip: true
GzHelpers {
id: helpers
@@ -43,19 +43,11 @@ SplitView {
*/
property variant childSplits: new Object()
- /**
- * Callback when the height changed.
- */
- onHeightChanged:
- {
- background.recalculateMinimumSizes();
- }
-
Rectangle {
id: startLabel;
- visible: MainWindow.pluginCount === 0
+ visible: false; //MainWindow.pluginCount === 0
anchors.fill: parent
- color: Material.background
+ color: "red" //Material.background
Label {
text: "Insert plugins to start!"
anchors.fill: parent
@@ -64,6 +56,7 @@ SplitView {
verticalAlignment: Label.AlignVCenter
wrapMode: Label.Wrap
}
+ SplitView.fillWidth: true
}
/**
@@ -89,35 +82,40 @@ SplitView {
*/
function addSplitItem()
{
- var itemName = "";
-
+ var addedItem = "";
// First section goes in the top level SplitView, which is Qt.Horizontal
// 2 for helpers and startLabel
- if (background.__items.length <= 2)
+ console.log("bg count:", background.count, background.contentChildren.length, Object.keys(childSplits).length)
+ if (background.contentChildren.length <= 2)
{
- itemName = _addNewItem(background);
+ console.log("Add to bg split")
+ addedItem = _addNewItem(background);
}
// The next one adds a Qt.Vertical split to the right
else if (Object.keys(childSplits).length === 0)
{
+ console.log("Creating side split")
// Add the split
var split = _addNewSplit(background);
- split.split.orientation = Qt.Vertical;
+ console.log("Created ", split.objectName)
+
// Then add a new item to the newly created split
- itemName = _addNewItem(split);
+ addedItem = _addNewItem(split);
}
// All subsequent ones are added to the vertical child split on the right
else
{
+ console.log("Adding side split")
// Get desired split (for now we have only one)
var firstChildSplit = childSplits[Object.keys(childSplits)[0]];
// Then add a new item to it
- itemName = _addNewItem(firstChildSplit);
+ addedItem = _addNewItem(firstChildSplit);
}
- return itemName
+ helpers.dump(background, "", 5)
+ return addedItem
}
/**
@@ -126,6 +124,7 @@ SplitView {
*/
function removeSplitItem(_name)
{
+ console.log("Removing ", _name)
// Remove from split
_removeFromSplits(childItems[_name]);
@@ -155,18 +154,15 @@ SplitView {
if (_split === background)
{
_split.addItem(item);
+ item.SplitView.fillWidth = true;
}
else
{
- _split.split.addItem(item);
-
- // Make sure that changes to the item's minimum size get propagated to the
- // split.
- item.minimumSizeChanged.connect(function(){
- _split.split.recalculateMinimumSize()
- });
+ _split.addItem(item);
}
+ console.log(itemName, item.objectName, "size: ", item.width, item.height)
+ // return childItems[itemName];
return itemName;
}
@@ -189,7 +185,7 @@ SplitView {
childSplits[splitName] = splitWrapper;
// Add to parent
- _parentSplit.addItem(splitWrapper);
+ // _parentSplit.addItem(splitWrapper);
return splitWrapper;
}
@@ -206,6 +202,7 @@ SplitView {
return;
var split = helpers.ancestorByName(_item, /^split_|^background$/);
+ console.log("Ancestor ", split.objectName)
if (!split)
{
@@ -215,15 +212,21 @@ SplitView {
if (split === background)
{
+ console.log("Final remove ", _item.objectName, " from bg")
split.removeItem(_item);
+ for (var i in split.contentChildren)
+ {
+ console.log(" ", split.contentChildren[i])
+ }
}
else
{
- split.split.removeItem(_item);
+ split.removeItem(_item);
// If split is now empty, remove split
- if (split.split.__items.length === 0)
- {
+ // if (split.contentChildren.length === 0)
+ // {
+ console.log("Removing side split from bg", split.objectName)
// Remove from array
delete childSplits[split.objectName]
@@ -232,11 +235,12 @@ SplitView {
// Destroy
split.destroy();
- }
- else
- {
- split.split.recalculateMinimumSize();
- }
+ helpers.dump(background, "", 5)
+ // }
+ // else
+ // {
+ // split.recalculateMinimumSize();
+ // }
}
}
@@ -246,48 +250,11 @@ SplitView {
Component {
id: newItem
- Rectangle {
- Layout.minimumWidth: 100
- Layout.minimumHeight: 100
- Layout.fillHeight: false
- Layout.fillWidth: true
- color: Material.background
-
- /**
- * Notifies that its minimum size has changed.
- */
- signal minimumSizeChanged();
-
- /**
- * Callback when the layout's minimum width changes.
- */
- Layout.onMinimumWidthChanged: {
- minimumSizeChanged();
- }
-
- /**
- * Callback when the layout's minimum height changes.
- */
- Layout.onMinimumHeightChanged: {
- minimumSizeChanged();
- }
-
- /**
- * Callback when the children array has been changed.
- */
- onChildrenChanged: {
- // Propagate child's minimum size changes to the item.
- newItem.Layout.minimumWidth = Qt.binding(function() {
- if (children.length === 0 || children[0] === undefined)
- return 0;
- return children[0].Layout.minimumWidth
- });
- newItem.Layout.minimumHeight = Qt.binding(function() {
- if (children.length === 0 || children[0] === undefined)
- return 0;
- return children[0].Layout.minimumHeight
- });
- }
+ ColumnLayout {
+ id: rectContainer
+ SplitView.minimumWidth: children[0]? children[0].Layout.minimumWidth : 0
+ SplitView.minimumHeight: children[0]? children[0].Layout.minimumHeight : 0
+ clip: true
}
}
@@ -296,90 +263,11 @@ SplitView {
*/
Component {
id: newSplit
-
- /**
- * For some reason, the scroll view doesn't work well within a split view,
- * so we wrap it in a rectangle.
- */
- Rectangle {
- id: splitWrapper
- color: "transparent"
-
- /**
- * Expose the split view.
- */
- property var split: split
-
- /**
- * Offset of 17 to accommodate for ScrollView scroll bar
- */
- property var scrollBarWidth: 17
-
- Layout.minimumWidth: split.Layout.minimumWidth + scrollBarWidth
- Layout.minimumHeight: split.Layout.minimumHeight
-
- ScrollView {
- contentHeight: split.height
- contentWidth: split.width + scrollBarWidth
-
- ScrollBar.vertical.policy: ScrollBar.AlwaysOn
-
- // TODO(louise) This only works for a very specific split
- height: window.height - window.header.height
-
- SplitView {
- id: split
- width: splitWrapper.width - scrollBarWidth
- height: Math.max(childItems[Object.keys(childItems)[0]].height,
- split.Layout.minimumHeight)
-
- /**
- * Iterate over all current child items and update the split's minimum
- * width accordingly.
- */
- function recalculateMinimumSize()
- {
- // TODO(louise): generalize to support horizontal splits
- if (orientation === Qt.Horizontal)
- {
- return;
- }
-
- // Sync minimum sizes
- var heightSum = 0;
- var minHeightSum = 0;
- for (var i = 0; i < __items.length; i++)
- {
- var child = __items[i];
-
- // Minimum width matches the largest minimum width among children
- if (child.Layout.minimumWidth > Layout.minimumWidth)
- {
- Layout.minimumWidth = child.Layout.minimumWidth;
- }
- heightSum += child.height;
-
- var collapsed = child.Layout.maximumHeight == 50
- minHeightSum += collapsed ? child.height : child.Layout.minimumHeight
- }
-
- // Minimum height to show all children
- Layout.minimumHeight = minHeightSum;
- split.height = Math.max(minHeightSum, background.height);
-
- // Squish all children if there's no slack
- if (heightSum > background.height)
- {
- for (var i = 0; i < __items.length; i++)
- {
- var child = __items[i];
- child.height = child.Layout.minimumHeight;
- }
- }
- }
- }
- }
+ SplitView {
+ id: __split
+ orientation: Qt.Vertical
+ clip: true
+ SplitView.minimumWidth: __split.contentChildren[0]? __split.contentChildren[0].SplitView.minimumWidth : 0
}
}
}
-
diff --git a/include/gz/gui/qml/GzVector3.qml b/include/gz/gui/qml/GzVector3.qml
index 94752f4c5..e0c5b9e40 100644
--- a/include/gz/gui/qml/GzVector3.qml
+++ b/include/gz/gui/qml/GzVector3.qml
@@ -14,9 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls.Material 2.1
-import QtQuick.Layouts 1.3
+import QtQuick
+import QtQuick.Layouts
/**
* Item displaying a 3D vector
diff --git a/include/gz/gui/qml/Main.qml b/include/gz/gui/qml/Main.qml
index c18154f29..651335971 100644
--- a/include/gz/gui/qml/Main.qml
+++ b/include/gz/gui/qml/Main.qml
@@ -14,13 +14,14 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.1
-import QtQuick.Dialogs 1.0
-import QtQuick.Layouts 1.3
-import ExitAction 1.0
-import "qrc:/qml"
+import QtCore
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Dialogs
+import QtQuick.Layouts
+import ExitAction
+import "qrc:/gz/gui/qml/"
ApplicationWindow
{
@@ -85,7 +86,7 @@ ApplicationWindow
}
// Handler for window closing
- onClosing: {
+ onClosing: (close) => {
close.accepted = !showDialogOnExit
if(showDialogOnExit){
if (closingFromDialog) {
@@ -295,10 +296,9 @@ ApplicationWindow
FileDialog {
id: loadFileDialog
title: "Load configuration"
- folder: shortcuts.home
+ fileMode: FileDialog.OpenFile
+ currentFolder: StandardPaths.writableLocation(StandardPaths.HomeLocation)
nameFilters: [ "Config files (*.config)" ]
- selectMultiple: false
- selectExisting: true
onAccepted: {
MainWindow.OnLoadConfig(fileUrl)
}
@@ -310,10 +310,9 @@ ApplicationWindow
FileDialog {
id: saveFileDialog
title: "Save configuration"
- folder: shortcuts.home
+ fileMode: FileDialog.SaveFile
+ currentFolder: StandardPaths.writableLocation(StandardPaths.HomeLocation)
nameFilters: [ "Config files (*.config)" ]
- selectMultiple: false
- selectExisting: false
onAccepted: {
var selected = fileUrl.toString();
diff --git a/include/gz/gui/qml/PlottingInterface.qml b/include/gz/gui/qml/PlottingInterface.qml
index 168d3a862..c3e834909 100644
--- a/include/gz/gui/qml/PlottingInterface.qml
+++ b/include/gz/gui/qml/PlottingInterface.qml
@@ -14,14 +14,13 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtCharts 2.2
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Styles 1.4
-import QtQuick.Controls.Material 2.1
-import QtQuick.Layouts 1.3
-import Qt.labs.platform 1.0
-import "qrc:/qml"
+import QtQuick
+import QtCharts
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Layouts
+import Qt.labs.platform
+import "qrc:/gz/gui/qml"
Rectangle
{
diff --git a/include/gz/gui/qml/PluginMenu.qml b/include/gz/gui/qml/PluginMenu.qml
index 890a7e7d4..7f393b3a0 100644
--- a/include/gz/gui/qml/PluginMenu.qml
+++ b/include/gz/gui/qml/PluginMenu.qml
@@ -14,11 +14,10 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.2
-import QtQuick.Controls.Material.impl 2.2
-import QtQuick.Layouts 1.3
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Layouts
Popup {
id: pluginMenu
@@ -87,7 +86,7 @@ Popup {
}
Keys.onUpPressed: {
pluginMenuListView.decrementCurrentIndex();
- }
+ }
}
}
}
@@ -138,4 +137,3 @@ Popup {
}
}
}
-
diff --git a/include/gz/gui/qml/SideDrawer.qml b/include/gz/gui/qml/SideDrawer.qml
index 3b6c63c9f..66eb8653e 100644
--- a/include/gz/gui/qml/SideDrawer.qml
+++ b/include/gz/gui/qml/SideDrawer.qml
@@ -14,9 +14,9 @@
* limitations under the License.
*
*/
-import QtQuick 2.9
-import QtQuick.Controls 2.2
-import QtQuick.Controls.Material 2.1
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
/**
* Side menu
diff --git a/include/gz/gui/qml/StandaloneDialog.qml b/include/gz/gui/qml/StandaloneDialog.qml
index a55864499..a9cb0ed9f 100644
--- a/include/gz/gui/qml/StandaloneDialog.qml
+++ b/include/gz/gui/qml/StandaloneDialog.qml
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-import QtQuick 2.3
-import QtQuick.Controls 1.2
+import QtQuick
+import QtQuick.Controls
ApplicationWindow {
id: dialog
diff --git a/include/gz/gui/qml/StyleDialog.qml b/include/gz/gui/qml/StyleDialog.qml
index f8566b0ca..2c2447a64 100644
--- a/include/gz/gui/qml/StyleDialog.qml
+++ b/include/gz/gui/qml/StyleDialog.qml
@@ -14,10 +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.0
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import QtQuick.Dialogs
+import Qt.labs.platform as Platform
/**
* Style dialog
@@ -309,28 +310,16 @@ Dialog {
text: modelData
width: parent.width
}
- onCurrentTextChanged: {
- updateTheme();
- }
}
Label {
text: "Primary"
}
- ColorDialog {
+ Platform.ColorDialog {
id: materialPrimaryDialog
title: "Primary color"
// options: ColorDialog.NoButtons
- onCurrentColorChanged: {
-
- // Avoiding pure black because for some reason it is set to that as the
- // dialog opens
- if (currentColor == "#000000")
- return;
-
- updatePrimary(colorToHex(currentColor))
- }
}
Row {
@@ -364,19 +353,10 @@ Dialog {
text: "Accent"
}
- ColorDialog {
+ Platform.ColorDialog {
id: materialAccentDialog
title: "Accent color"
// options: ColorDialog.NoButtons
- onCurrentColorChanged: {
-
- // Avoiding pure black because for some reason it is set to that as the
- // dialog opens
- if (currentColor == "#000000")
- return;
-
- updateAccent(colorToHex(currentColor))
- }
}
Row {
diff --git a/src/Application.cc b/src/Application.cc
index 5427a67c3..a767286e9 100644
--- a/src/Application.cc
+++ b/src/Application.cc
@@ -81,7 +81,7 @@ class Application::Implementation
const QMessageLogContext &_context, const QString &_msg);
};
-enum class GZ_COMMON_HIDDEN AvailableAPIs
+enum class GZ_COMMON_HIDDEN AvailableAPIs
{
OpenGL,
Vulkan,
@@ -153,8 +153,6 @@ Application::Application(int &_argc, char **_argv, const WindowType _type,
if (api == AvailableAPIs::Vulkan)
{
- gzdbg << "Qt using Vulkan graphics interface" << std::endl;
-
# ifdef GZ_USE_VULKAN_DEBUG_EXT
qputenv("QT_VULKAN_INSTANCE_EXTENSIONS",
"VK_EXT_debug_report;VK_EXT_debug_utils");
@@ -172,6 +170,7 @@ Application::Application(int &_argc, char **_argv, const WindowType _type,
#else
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
#endif
+ gzdbg << "Qt using Vulkan graphics interface" << std::endl;
}
else
{
@@ -214,14 +213,14 @@ Application::Application(int &_argc, char **_argv, const WindowType _type,
switch (api)
{
default:
- case AvailableAPIs::OpenGL:
- this->dataPtr->mainWin->setProperty("renderEngineBackendApiName",
- "opengl");
- break;
case AvailableAPIs::Vulkan:
this->dataPtr->mainWin->setProperty("renderEngineBackendApiName",
"vulkan");
break;
+ case AvailableAPIs::OpenGL:
+ this->dataPtr->mainWin->setProperty("renderEngineBackendApiName",
+ "opengl");
+ break;
case AvailableAPIs::Metal:
this->dataPtr->mainWin->setProperty("renderEngineBackendApiName",
"metal");
@@ -266,6 +265,9 @@ Application::~Application()
}
this->dataPtr->dialogs.clear();
+ this->dataPtr->engine->clearComponentCache();
+ this->dataPtr->engine->clearSingletons();
+
delete this->dataPtr->engine;
std::queue> empty;
@@ -890,6 +892,8 @@ void Application::Implementation::MessageHandler(QtMsgType _type,
const QMessageLogContext &_context, const QString &_msg)
{
std::string msg = "[QT] " + _msg.toStdString();
+ if (_context.file)
+ msg += std::string("[") + _context.file + ":" + std::to_string(_context.line) + "]";
if (_context.function)
msg += std::string("(") + _context.function + ")";
@@ -915,3 +919,5 @@ void Application::Implementation::MessageHandler(QtMsgType _type,
}
}
} // namespace gz::gui
+
+#include "moc_Application.cpp"
diff --git a/src/Application_TEST.cc b/src/Application_TEST.cc
index f23ce8ab0..1344bf322 100644
--- a/src/Application_TEST.cc
+++ b/src/Application_TEST.cc
@@ -17,6 +17,7 @@
#include
#include
+#include
#include
#include
@@ -35,15 +36,28 @@ char* g_argv[] =
using namespace gz;
using namespace gui;
+class ApplicationTest: public ::testing::Test
+{
+ protected:
+ void SetUp() override
+ {
+ common::Console::SetVerbosity(4);
+ // No Qt app
+ ASSERT_EQ(nullptr, qGuiApp);
+ ASSERT_EQ(nullptr, App());
+ }
+};
+
+
// See https://github.com/gazebosim/gz-gui/issues/75
//////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor))
{
- common::Console::SetVerbosity(4);
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
- ASSERT_EQ(nullptr, App());
+ QDirIterator it(":", QDirIterator::Subdirectories);
+ while (it.hasNext()) {
+ std::cout << it.next().toStdString() << "\n";
+ }
// One app construct - destruct
{
@@ -63,23 +77,16 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor))
}
//////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadPlugin))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadPlugin))
{
- gz::common::Console::SetVerbosity(4);
-
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
EXPECT_TRUE(app.LoadPlugin("Publisher"));
}
//////////////////////////////////////////////////
-TEST(ApplicationTest,
+TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadNonexistantPlugin))
{
- gz::common::Console::SetVerbosity(4);
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
EXPECT_FALSE(app.LoadPlugin("_doesnt_exist"));
@@ -87,12 +94,10 @@ TEST(ApplicationTest,
}
//////////////////////////////////////////////////
-TEST(ApplicationTest,
+TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadProgrammaticPlugin))
{
- gz::common::Console::SetVerbosity(4);
// No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
std::string pluginName;
@@ -117,11 +122,8 @@ TEST(ApplicationTest,
}
//////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadEnvPlugin))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadEnvPlugin))
{
- gz::common::Console::SetVerbosity(4);
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
setenv("TEST_ENV_VAR",
@@ -131,12 +133,9 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadEnvPlugin))
}
//////////////////////////////////////////////////
-TEST(ApplicationTest,
+TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadBadInheritancePlugin))
{
- gz::common::Console::SetVerbosity(4);
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");
@@ -144,12 +143,9 @@ TEST(ApplicationTest,
}
//////////////////////////////////////////////////
-TEST(ApplicationTest,
+TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadNotRegisteredPlugin))
{
- gz::common::Console::SetVerbosity(4);
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");
@@ -157,12 +153,9 @@ TEST(ApplicationTest,
}
//////////////////////////////////////////////////
-TEST(ApplicationTest,
+TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadInvalidQmlPlugin))
{
- gz::common::Console::SetVerbosity(4);
- // No Qt app
- ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);
app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");
@@ -170,12 +163,8 @@ TEST(ApplicationTest,
}
//////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig))
{
- common::Console::SetVerbosity(4);
-
- ASSERT_EQ(nullptr, qGuiApp);
-
// Empty string
{
Application app(g_argc, g_argv);
@@ -220,12 +209,8 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig))
}
//////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig))
{
- common::Console::SetVerbosity(4);
-
- ASSERT_EQ(nullptr, qGuiApp);
-
// Test config file
{
Application app(g_argc, g_argv);
@@ -245,83 +230,89 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig))
}
//////////////////////////////////////////////////
-TEST(ApplicationTest,
- GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindow))
+TEST_F(ApplicationTest,
+ GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindowSimple))
{
- common::Console::SetVerbosity(4);
-
- ASSERT_EQ(nullptr, qGuiApp);
-
// No plugins
- {
- Application app(g_argc, g_argv);
+ Application app(g_argc, g_argv);
- auto wins = app.allWindows();
- ASSERT_EQ(wins.size(), 1);
+ auto wins = app.allWindows();
+ ASSERT_EQ(wins.size(), 1);
- // Close window after some time
- QTimer::singleShot(300, wins[0], SLOT(close()));
+ // Close window after some time
+ QObject::connect(&app, &QGuiApplication::applicationStateChanged,
+ [&wins](auto /*state*/){
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ wins[0]->close();
+ });
- // Show window
- app.exec();
- }
+ // Show window
+ gz::gui::Application::exec();
+}
- // Load plugin
- {
- Application app(g_argc, g_argv);
+//////////////////////////////////////////////////
+TEST_F(ApplicationTest,
+ GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindowPlugin))
+{
+ Application app(g_argc, g_argv);
- EXPECT_TRUE(app.LoadPlugin("Publisher"));
+ EXPECT_TRUE(app.LoadPlugin("Publisher"));
- auto win = App()->findChild();
- ASSERT_NE(nullptr, win);
+ auto *win = App()->findChild();
+ ASSERT_NE(nullptr, win);
- // Check plugin count
- auto plugins = win->findChildren();
- EXPECT_EQ(1, plugins.count());
+ // Check plugin count
+ auto plugins = win->findChildren();
+ EXPECT_EQ(1, plugins.count());
- // Close window after some time
- QTimer::singleShot(300, win->QuickWindow(), SLOT(close()));
+ QObject::connect(&app, &QGuiApplication::applicationStateChanged,
+ [&win](auto /*state*/){
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ win->QuickWindow()->close();
+ });
- // Show window
- app.exec();
- }
+ // Show window
+ gz::gui::Application::exec();
+}
+//////////////////////////////////////////////////
+TEST_F(ApplicationTest,
+ GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindowConfig))
+{
// Test config
auto testBuildPath = std::string(PROJECT_BINARY_PATH) + "/lib/";
auto testSourcePath = std::string(PROJECT_SOURCE_PATH) + "/test/";
// Load config
- {
- Application app(g_argc, g_argv);
+ Application app(g_argc, g_argv);
- // Add test plugin to path (referenced in config)
- app.AddPluginPath(testBuildPath);
+ // Add test plugin to path (referenced in config)
+ app.AddPluginPath(testBuildPath);
- // Load test config file
- EXPECT_TRUE(app.LoadConfig(testSourcePath + "config/test.config"));
+ // Load test config file
+ EXPECT_TRUE(app.LoadConfig(testSourcePath + "config/test.config"));
- auto win = App()->findChild();
- ASSERT_NE(nullptr, win);
+ auto *win = App()->findChild();
+ ASSERT_NE(nullptr, win);
- // Check plugin count
- auto plugins = win->findChildren();
- EXPECT_EQ(1, plugins.count());
+ // Check plugin count
+ auto plugins = win->findChildren();
+ EXPECT_EQ(1, plugins.count());
- // Close window after some time
- QTimer::singleShot(300, win->QuickWindow(), SLOT(close()));
+ // Close window after some time
+ QObject::connect(&app, &QGuiApplication::applicationStateChanged,
+ [&win](auto /*state*/){
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ win->QuickWindow()->close();
+ });
- // Show window
- app.exec();
- }
+ // Show window
+ gz::gui::Application::exec();
}
//////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
{
- common::Console::SetVerbosity(4);
-
- ASSERT_EQ(nullptr, qGuiApp);
-
// Single dialog
{
Application app(g_argc, g_argv, WindowType::kDialog);
@@ -336,21 +327,23 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
// Close dialog after some time
auto closed = false;
- QTimer::singleShot(300, &app, [&] {
- auto ds = app.allWindows();
- // The main dialog - some systems return more, not sure why
- ASSERT_GE(ds.size(), 1);
-
- EXPECT_TRUE(qobject_cast(ds[0]));
-
- // Close
- ds[0]->close();
- closed = true;
+ // Close window after some time
+ QObject::connect(&app, &QGuiApplication::applicationStateChanged,
+ [&closed](auto /*state*/){
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ auto ds = gz::gui::Application::allWindows();
+
+ // The main diaog - some systems return more, not sure why
+ ASSERT_GE(ds.size(), 1);
+ EXPECT_TRUE(qobject_cast(ds[0]));
+ // Close
+ ds[0]->close();
+ closed = true;
});
- // Exec dialog
- app.exec();
+ // Show window
+ gz::gui::Application::exec();
// Make sure timer was triggered
EXPECT_TRUE(closed);
@@ -371,19 +364,21 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
// Close dialogs after some time
auto closed = false;
- QTimer::singleShot(300, &app, [&] {
- auto ds = app.allWindows();
+ QObject::connect(&app, &QGuiApplication::applicationStateChanged,
+ [&closed](auto /*state*/){
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ auto ds = gz::gui::Application::allWindows();
- // 2 dialog - some systems return more, not sure why
- EXPECT_GE(ds.size(), 2);
+ // 2 dialog - some systems return more, not sure why
+ ASSERT_GE(ds.size(), 2);
- for (auto dialog : ds)
- dialog->close();
- closed = true;
- });
+ for (auto *dialog : ds)
+ dialog->close();
+ closed = true;
+ });
// Exec dialog
- app.exec();
+ gz::gui::Application::exec();
// Make sure timer was triggered
EXPECT_TRUE(closed);
@@ -391,12 +386,8 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
}
/////////////////////////////////////////////////
-TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(messageHandler))
+TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(messageHandler))
{
- common::Console::SetVerbosity(4);
-
- ASSERT_EQ(nullptr, qGuiApp);
-
Application app(g_argc, g_argv);
// \todo Verify output, see commmon::Console_TEST for example
diff --git a/src/Dialog.cc b/src/Dialog.cc
index 7701c2cfd..2da5a7665 100644
--- a/src/Dialog.cc
+++ b/src/Dialog.cc
@@ -22,6 +22,11 @@
#include "gz/gui/Application.hh"
#include "gz/gui/Dialog.hh"
+namespace
+{
+constexpr const char* kQmlUri ="qrc:gz/gui/qml/StandaloneDialog.qml";
+} // namespace
+
namespace gz::gui
{
class Dialog::Implementation
@@ -35,16 +40,15 @@ Dialog::Dialog()
: dataPtr(gz::utils::MakeUniqueImpl())
{
// Load QML and keep pointer to generated QQuickWindow
- std::string qmlFile("qrc:qml/StandaloneDialog.qml");
- App()->Engine()->load(QUrl(QString::fromStdString(qmlFile)));
+ App()->Engine()->load(QUrl(QString(kQmlUri)));
this->dataPtr->quickWindow = qobject_cast(
App()->Engine()->rootObjects().value(0));
- if (!this->dataPtr->quickWindow)
+ if (this->dataPtr->quickWindow == nullptr)
{
// We'd only get here if the QML file is malformed
// LCOV_EXCL_START
- gzerr << "Internal error: Failed to instantiate QML file [" << qmlFile
+ gzerr << "Internal error: Failed to instantiate QML file [" << kQmlUri
<< "]" << std::endl;
// LCOV_EXCL_STOP
}
@@ -62,8 +66,8 @@ QQuickWindow *Dialog::QuickWindow() const
/////////////////////////////////////////////////
QQuickItem *Dialog::RootItem() const
{
- auto dialogItem = this->dataPtr->quickWindow->findChild();
- if (!dialogItem)
+ auto *dialogItem = this->dataPtr->quickWindow->findChild();
+ if (dialogItem == nullptr)
{
// We'd only get here if the QML file is malformed
// LCOV_EXCL_START
@@ -96,7 +100,7 @@ bool Dialog::UpdateConfigAttribute(const std::string &_path,
// Update attribute value for the correct dialog
bool updated{false};
- for (auto dialogElem = doc.FirstChildElement("dialog");
+ for (auto *dialogElem = doc.FirstChildElement("dialog");
dialogElem != nullptr;
dialogElem = dialogElem->NextSiblingElement("dialog"))
{
@@ -110,7 +114,7 @@ bool Dialog::UpdateConfigAttribute(const std::string &_path,
// Create new