diff --git a/CMakeLists.txt b/CMakeLists.txt index c02a1a7a1..f6a708fe3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,10 +227,6 @@ option(SLS_USE_DETECTOR "Detector libs" ON) option(SLS_USE_RECEIVER "Receiver" ON) option(SLS_USE_RECEIVER_BINARIES "Receiver binaries" ON) option(SLS_USE_GUI "GUI" OFF) -# Qt major version used by slsDetectorGui when SLS_USE_GUI=ON. Qt 5 is kept -# for older distributions (e.g. RHEL 7); Qt 6 is the default. -set(SLS_GUI_QT_MAJOR "6" CACHE STRING "Qt major version for slsDetectorGui (5 or 6)") -set_property(CACHE SLS_GUI_QT_MAJOR PROPERTY STRINGS 5 6) option(SLS_USE_SIMULATOR "Simulator" OFF) option(SLS_USE_TESTS "TESTS" OFF) option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF) @@ -542,15 +538,9 @@ set(CPACK_RPM_PACKAGE_RELEASE_DIST ON) set(CPACK_RPM_COMPONENT_INSTALL ON) -if(SLS_GUI_QT_MAJOR STREQUAL "5") - set(CPACK_RPM_GUI_PACKAGE_REQUIRES - "qt5-qtbase, qt5-qtbase-gui" - ) -else() - set(CPACK_RPM_GUI_PACKAGE_REQUIRES - "qt6-qtbase, qt6-qtbase-gui" - ) -endif() +set(CPACK_RPM_GUI_PACKAGE_REQUIRES + "qt6-qtbase, qt6-qtbase-gui" +) #control which RPMs are generated set(CPACK_COMPONENTS_ALL cli receiver zmq gui) diff --git a/cmk.sh b/cmk.sh index 472609b44..498d590bd 100755 --- a/cmk.sh +++ b/cmk.sh @@ -1,16 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: LGPL-3.0-or-other # Copyright (C) 2021 Contributors to the SLS Detector Package -# Stop at the first failing configure/build step so a failed GUI build is not -# reported as success by the final (possibly skipped) install step. -set -e -# Prefer cmake3 when the distribution provides it (RHEL/CentOS), otherwise -# use the default cmake. -k still overrides this. -if command -v cmake3 >/dev/null 2>&1; then - CMAKE="cmake3" -else - CMAKE="cmake" -fi +CMAKE="cmake3" BUILDDIR="build" INSTALLDIR="" HDF5DIR="/opt/hdf5v1.10.0" @@ -19,8 +10,6 @@ COMPILERTHREADS=0 TEXTCLIENT=0 RECEIVER=0 GUI=0 -QT5=0 -QT6=0 DEBUG=0 PYTHON=0 TESTS=0 @@ -37,14 +26,13 @@ CMAKE_PRE="" CMAKE_POST="" usage() { echo -e " -Usage: $0 [-b] [-c] [-d ] [-e] [-g] [-G] [-h] [-i] [-j ] [-k ] [-l ] [-m] [-n] [-p] [-r] [-s] [-t] [-u] [-z] +Usage: $0 [-b] [-c] [-d ] [-e] [-g] [-h] [-i] [-j ] [-k ] [-l ] [-m] [-n] [-p] [-r] [-s] [-t] [-u] [-z] -[no option]: only make -b: Builds/Rebuilds CMake files normal mode -c: Clean -d: HDF5 Custom Directory -e: Debug mode - -g: Build/Rebuilds gui with Qt5 - -G: Build/Rebuilds gui with Qt6 + -g: Build/Rebuilds gui -h: Builds/Rebuilds Cmake files with HDF5 package -i: Builds tests -j: Number of threads to compile through @@ -88,16 +76,12 @@ For using multiple cores to compile faster: ./cmk.sh -j9 -h #with hdf For rebuilding only certain sections -./cmk.sh -tg #text client and Qt5 gui -./cmk.sh -tG #text client and Qt6 gui +./cmk.sh -tg #only text client and gui ./cmk.sh -r #only receiver - -Switching between -g and -G removes the build tree automatically -(no extra -c needed). " ; exit 1; } -while getopts ":bcd:eghij:k:l:mnpGq:rstuz" opt ; do +while getopts ":bcd:eghij:k:l:mnpq:rstuz" opt ; do case $opt in b) echo "Building of CMake files Required" @@ -116,15 +100,8 @@ while getopts ":bcd:eghij:k:l:mnpGq:rstuz" opt ; do DEBUG=1 ;; g) - echo "Compiling Options: GUI (Qt5)" + echo "Compiling Options: GUI" GUI=1 - QT5=1 - REBUILD=1 - ;; - G) - echo "Compiling Options: GUI (Qt6)" - GUI=1 - QT6=1 REBUILD=1 ;; h) @@ -197,11 +174,6 @@ while getopts ":bcd:eghij:k:l:mnpGq:rstuz" opt ; do done -if [ $QT5 -eq 1 ] && [ $QT6 -eq 1 ]; then - echo "Invalid options: -g (Qt5 GUI) and -G (Qt6 GUI) are mutually exclusive" >&2 - exit 1 -fi - #python if [ $PYTHON -eq 1 ]; then CMAKE_POST+=" -DSLS_USE_PYTHON=ON " @@ -210,8 +182,9 @@ fi if [ $TEXTCLIENT -eq 0 ] && [ $RECEIVER -eq 0 ] && [ $GUI -eq 0 ]; then + #CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=ON -DSLS_USE_GUI=ON " CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=ON -DSLS_USE_GUI=OFF " - echo "Enabling Compile Option: TextClient and Receiver (GUI off; use -g)" + echo "Enabling Compile Option: TextClient, Receiver and GUI" else if [ $TEXTCLIENT -eq 1 ]; then CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=OFF " @@ -222,13 +195,8 @@ else echo "Enabling Compile Option: Receiver" fi if [ $GUI -eq 1 ]; then - if [ $QT6 -eq 1 ]; then - CMAKE_POST+=" -DSLS_USE_GUI=ON -DSLS_GUI_QT_MAJOR=6 " - echo "Enabling Compile Option: GUI (Qt6)" - else - CMAKE_POST+=" -DSLS_USE_GUI=ON -DSLS_GUI_QT_MAJOR=5 " - echo "Enabling Compile Option: GUI (Qt5)" - fi + CMAKE_POST+=" -DSLS_USE_GUI=ON " + echo "Enabling Compile Option: GUI" fi fi @@ -236,26 +204,6 @@ fi -# Switching the GUI between Qt5 and Qt6 in an existing build tree leaves -# generated Qt/moc/ui files and objects from the other major behind; even -# make clean after a reconfigure can race with stale targets, so remove the -# whole build tree. Read the cache before -b removes it. -if [ $GUI -eq 1 ] && [ -f "$BUILDDIR/CMakeCache.txt" ]; then - requested_qt=5 - [ $QT6 -eq 1 ] && requested_qt=6 - cached_gui=$(grep -E '^SLS_USE_GUI:BOOL=' "$BUILDDIR/CMakeCache.txt" | head -1 | cut -d= -f2 || true) - cached_qt=$(grep -E '^SLS_GUI_QT_MAJOR:STRING=' "$BUILDDIR/CMakeCache.txt" | head -1 | cut -d= -f2 || true) - # Cache from before SLS_GUI_QT_MAJOR existed: that build was Qt6. - if [ "$cached_gui" = "ON" ] && [ -z "$cached_qt" ]; then - cached_qt=6 - fi - if [ "$cached_gui" = "ON" ] && [ -n "$cached_qt" ] && [ "$cached_qt" != "$requested_qt" ]; then - echo "Qt major changed from $cached_qt to $requested_qt: removing the build directory" - rm -rf -- "$BUILDDIR" - CLEAN=0 - fi -fi - #build dir doesnt exist if [ ! -d "$BUILDDIR" ] ; then echo "No Build Directory. Building of Cmake files required" @@ -317,14 +265,6 @@ else fi -# Qt from conda-forge: cmake does not search $CONDA_PREFIX by itself when -# the environment does not export CMAKE_PREFIX_PATH. Only add the hint for -# the GUI build so a plain `./cmk.sh -cbgjN` / `-cbGjN` works in a conda env. -if [ $GUI -eq 1 ] && [ -n "${CONDA_PREFIX:-}" ] && [ -z "${CMAKE_PREFIX_PATH:-}" ]; then - CMAKE_POST+=" -DCMAKE_PREFIX_PATH=$CONDA_PREFIX" - echo "Using CMAKE_PREFIX_PATH from CONDA_PREFIX: $CONDA_PREFIX" -fi - #install if [ -n "$INSTALLDIR" ]; then CMAKE_POST+=" -DCMAKE_INSTALL_PREFIX=$INSTALLDIR" diff --git a/docs/src/gui_plotting.rst b/docs/src/gui_plotting.rst index 92c65c50f..7aa1b1042 100644 --- a/docs/src/gui_plotting.rst +++ b/docs/src/gui_plotting.rst @@ -1,14 +1,12 @@ -Plotting in slsDetectorGui (Qt 5 / Qt 6) -======================================= +Plotting in slsDetectorGui +========================== The detector GUI used to draw every plot with the bundled **Qwt 6.1.5** library. That dependency has been removed together with its build rules and sources. All plots in `slsDetectorGui` are now painted by a small, self-contained stack that needs only **Qt Widgets / Gui / Core** (plus the -Qt `Concurrent` module for the acquisition thread). It builds against **Qt 5 -(>= 5.9) or Qt 6 (>= 6.2)**; Qt 6 is the default, while Qt 5 keeps older -distributions such as RHEL 7 usable. There is no ROOT, Qwt, Qt Charts or -OpenGL dependency. +Qt `Concurrent` module for the acquisition thread). It needs **Qt 6 +(>= 6.2)**. There is no ROOT, Qwt, Qt Charts or OpenGL dependency. The stack lives in `slsDetectorGui/slsDetectorPlotting` and is compiled once into the static library `slsDetectorPlotting`, which is linked by the GUI @@ -102,19 +100,18 @@ stopping an acquisition. Selecting the action again reattaches the tab. Demo and tests -------------- -The demo application and the QtTest suite are built automatically by the GUI -CMake file (they are enabled by the presence of `slsDetectorGui/demo` and -`slsDetectorGui/tests`):: +The demo application and the QtTest suite are built together with the GUI +when the tests are enabled:: cmake -S slsDetectorPackage -B build -DSLS_USE_GUI=ON \ - -DSLS_GUI_QT_MAJOR=6 -DCMAKE_BUILD_TYPE=Release + -DSLS_USE_TESTS=ON -DCMAKE_BUILD_TYPE=Release cmake --build build --target plot_demo plotting_test -j # standalone demo / offline benchmark (1024x512 synthetic frame, 20 Hz) QT_QPA_PLATFORM=offscreen ./build/bin/plot_demo --frames 100 QT_QPA_PLATFORM=offscreen ./build/bin/plot_demo --shot 2d-zoom-roi --png shot.png - # QtTest suite (also registered with CTest when -DSLS_USE_TESTS=ON) + # QtTest suite (also registered with CTest) QT_QPA_PLATFORM=offscreen ./build/bin/plotting_test `plot_demo` prints the unthrottled render throughput and the measured timer @@ -131,8 +128,5 @@ Removing Qwt `libs/qwt` is gone from the source tree and the build; `slsDetectorGui` no longer finds or links Qwt, and no source under `slsDetectorPlotting` includes a `qwt_*` header. The package metadata and documentation refer to the Qt -runtime packages instead (`qt6-qtbase`/`qt5-qtbase` on RPM based systems, -`qt6-base-dev`/`qtbase5-dev` on Debian/Ubuntu, `qt6-main`/`qt-main` in -conda), selected by `SLS_GUI_QT_MAJOR` (or `cmk.sh -G` for Qt 6 and `-g` for -Qt 5). Switching between the two cmk flags removes the build tree -automatically, so no extra `-c` is needed. +runtime packages instead (`qt6-qtbase` on RPM based systems, `qt6-base-dev` +on Debian/Ubuntu, `qt6-main` in conda). diff --git a/slsDetectorGui/CMakeLists.txt b/slsDetectorGui/CMakeLists.txt index 04ac38b0e..680922825 100755 --- a/slsDetectorGui/CMakeLists.txt +++ b/slsDetectorGui/CMakeLists.txt @@ -5,27 +5,15 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -# Qt 5 or 6 (Widgets/Gui/Core). Concurrent is needed for the acquisition -# thread in qDrawPlot.cpp. No Qwt. SLS_GUI_QT_MAJOR selects the Qt major -# version; Qt 5 is needed on older distributions such as RHEL 7. -if(SLS_GUI_QT_MAJOR STREQUAL "6") - find_package(Qt6 6.2 REQUIRED COMPONENTS Widgets Gui Core Concurrent) - set(SLS_QT_LIBS Qt6::Widgets Qt6::Gui Qt6::Core) - set(SLS_QT_CONCURRENT Qt6::Concurrent) -elseif(SLS_GUI_QT_MAJOR STREQUAL "5") - find_package(Qt5 5.9 REQUIRED COMPONENTS Widgets Gui Core Concurrent) - set(SLS_QT_LIBS Qt5::Widgets Qt5::Gui Qt5::Core) - set(SLS_QT_CONCURRENT Qt5::Concurrent) -else() - message(FATAL_ERROR "SLS_GUI_QT_MAJOR must be 5 or 6 (got ${SLS_GUI_QT_MAJOR})") -endif() +# Concurrent is needed for the acquisition thread in qDrawPlot.cpp +find_package(Qt6 6.2 REQUIRED COMPONENTS Widgets Gui Core Concurrent) find_package(PNG REQUIRED) find_package(ZLIB REQUIRED) -# The Qt-only plotting stack is built once as a static library and linked by -# the GUI executable as well as by the plotting demo and the QtTest suite. +# The plotting widgets are a static library so that the gui, the tests and +# the demo share them. set(PLOTTING_SOURCES slsDetectorPlotting/src/SlsQtPlotCommon.cpp slsDetectorPlotting/src/SlsQtFastImage.cpp @@ -47,11 +35,6 @@ add_library(slsDetectorPlotting STATIC ${PLOTTING_SOURCES} ${PLOTTING_HEADERS} ) -set_target_properties(slsDetectorPlotting PROPERTIES - # plotting widgets are Q_OBJECT classes; moc them in the library - AUTOMOC ON - AUTOUIC OFF -) target_include_directories(slsDetectorPlotting PUBLIC "$" "$" @@ -59,9 +42,10 @@ target_include_directories(slsDetectorPlotting PUBLIC target_link_libraries(slsDetectorPlotting PUBLIC slsProjectOptions - # sls/ansi.h, sls/sls_detector_defs.h and the logger symbols slsSupportStatic - ${SLS_QT_LIBS} + Qt6::Widgets + Qt6::Gui + Qt6::Core PRIVATE slsProjectWarnings ) @@ -80,7 +64,6 @@ set(SOURCES src/qTabDeveloper.cpp src/qTabMessages.cpp src/qDacWidget.cpp - src/qVersionResolve.cpp ) set(FORMS @@ -98,11 +81,7 @@ set(FORMS forms/form_cloneplot.ui ) -if(SLS_GUI_QT_MAJOR STREQUAL "6") - qt6_wrap_ui(FORMS_H ${FORMS}) -else() - qt5_wrap_ui(FORMS_H ${FORMS}) -endif() +qt_wrap_ui(FORMS_H ${FORMS}) set(HEADERS include/qDefs.h @@ -118,16 +97,11 @@ set(HEADERS include/qTabDeveloper.h include/qTabMessages.h include/qDacWidget.h - include/qVersionResolve.h ) set(RESOURCES include/icons.qrc ) -if(SLS_GUI_QT_MAJOR STREQUAL "6") - qt6_add_resources(RESOURCES_SRCS ${RESOURCES}) -else() - qt5_add_resources(RESOURCES_SRCS ${RESOURCES}) -endif() +qt_add_resources(RESOURCES_SRCS ${RESOURCES}) add_executable(slsDetectorGui @@ -151,9 +125,8 @@ target_link_libraries(slsDetectorGui PUBLIC slsDetectorPlotting PNG::PNG ZLIB::ZLIB - ${SLS_QT_LIBS} - ${SLS_QT_CONCURRENT} - + Qt6::Concurrent + PRIVATE slsProjectWarnings ) @@ -167,13 +140,8 @@ if((CMAKE_BUILD_TYPE STREQUAL "Release") AND SLS_LTO_AVAILABLE) set_property(TARGET slsDetectorGui PROPERTY INTERPROCEDURAL_OPTIMIZATION True) endif() -# Demo application and QtTest based tests for the plotting widgets. -# These are provided by the verification task; wire them in when present so -# they do not have to touch this file. Both link slsDetectorPlotting. -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt") +if(SLS_USE_TESTS) add_subdirectory(tests) -endif() -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/demo/CMakeLists.txt") add_subdirectory(demo) endif() diff --git a/slsDetectorGui/demo/CMakeLists.txt b/slsDetectorGui/demo/CMakeLists.txt index a6544c9ee..91f2a26a1 100644 --- a/slsDetectorGui/demo/CMakeLists.txt +++ b/slsDetectorGui/demo/CMakeLists.txt @@ -1,29 +1,13 @@ # SPDX-License-Identifier: LGPL-3.0-or-other # Copyright (C) 2026 Contributors to the SLS Detector Package -# -# Standalone Qt Widgets demo / benchmark for the Qt5/Qt6 plotting stack. -# Wired in from slsDetectorGui/CMakeLists.txt by an EXISTS guard; links the -# shared slsDetectorPlotting static library built by the GUI CMake file. -# -# Build: cmake --build --target plot_demo -# Run: QT_QPA_PLATFORM=offscreen /bin/plot_demo --frames 120 -if(SLS_GUI_QT_MAJOR STREQUAL "5") - find_package(Qt5 5.9 REQUIRED COMPONENTS Widgets Gui Core) -else() - find_package(Qt6 6.2 REQUIRED COMPONENTS Widgets Gui Core) -endif() - -if(NOT TARGET slsDetectorPlotting) - message(FATAL_ERROR - "plot_demo needs the slsDetectorPlotting target defined in " - "slsDetectorGui/CMakeLists.txt") -endif() +# Shows the plotting widgets with synthetic frames, no detector needed. +# Also renders screenshots and benchmarks offscreen, see plot_demo --help add_executable(plot_demo plot_demo.cpp ) target_link_libraries(plot_demo PRIVATE slsDetectorPlotting) set_target_properties(plot_demo PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) diff --git a/slsDetectorGui/demo/plot_demo.cpp b/slsDetectorGui/demo/plot_demo.cpp index a7aafdcda..019750f70 100644 --- a/slsDetectorGui/demo/plot_demo.cpp +++ b/slsDetectorGui/demo/plot_demo.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2026 Contributors to the SLS Detector Package // -// Standalone offscreen demo / benchmark for the Qt5/Qt6 plotting stack. +// Standalone offscreen demo / benchmark for the plotting stack. // // It builds a synthetic 1024x512 float frame (sin(x/40)+cos(y/30) plus a moving // hotspot) at ~20 Hz, feeds it to SlsQtFastImage, keeps SlsQtScalePanel in sync @@ -438,7 +438,7 @@ int main(int argc, char **argv) { QCommandLineParser parser; parser.setApplicationDescription( - QStringLiteral("Qt5/Qt6 plotting stack demo / offline benchmark")); + QStringLiteral("Plotting stack demo / offline benchmark")); parser.addHelpOption(); parser.addVersionOption(); const QCommandLineOption framesOpt( diff --git a/slsDetectorGui/include/qVersionResolve.h b/slsDetectorGui/include/qVersionResolve.h deleted file mode 100644 index 9c753b36e..000000000 --- a/slsDetectorGui/include/qVersionResolve.h +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-other -// Copyright (C) 2021 Contributors to the SLS Detector Package -#pragma once - -#include -#include - -namespace sls { - -int qResolve_GetQFontWidth(const QFontMetrics fm, const QString &text, - int len = -1); - -} // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h index 66ed168e1..be5b9e22a 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h @@ -3,7 +3,7 @@ #ifndef SLSQT1DPLOT_H #define SLSQT1DPLOT_H -// Qt5/Qt6 replacement for the qwt based 1D plotting layer of slsDetectorGui. +// Replacement for the qwt based 1D plotting layer of slsDetectorGui. // // SlsQt1DPlot is a plain QWidget that paints its own frame, ticks, grid, // clipped curves, legend, ROI boxes and tracker and implements the zoom / pan diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h index bb66458d2..c1ec8ae23 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h @@ -2,7 +2,7 @@ // Copyright (C) 2026 Contributors to the SLS Detector Package #pragma once -// Shared plotting primitives for the Qt5/Qt6 plotting stack used by +// Shared plotting primitives for the plotting stack used by // slsDetectorGui. Nothing here depends on qwt, ROOT or OpenGL. // // The palettes and the 1/2/5 tick rules are the ones the previous @@ -27,39 +27,6 @@ namespace sls { namespace plot { -// Qt5/Qt6 compatibility helpers. The GUI and the plotting stack are built -// against whichever Qt major version the distribution provides (see the -// SLS_GUI_QT_MAJOR CMake option); keep the version-specific calls in one place. -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -inline QPointF eventPosition(const QMouseEvent *event) { - return event->position(); -} -inline QPointF eventPosition(const QWheelEvent *event) { - return event->position(); -} -#else -inline QPointF eventPosition(const QMouseEvent *event) { - return event->localPos(); -} -inline QPointF eventPosition(const QWheelEvent *event) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - return event->position(); -#else - return event->posF(); -#endif -} -#endif - -// QFontMetrics::horizontalAdvance() arrived in Qt 5.11; Qt 5.9 (RHEL 7) -// still needs width(). -inline int textWidth(const QFontMetrics &metrics, const QString &text) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) - return metrics.horizontalAdvance(text); -#else - return metrics.width(text); -#endif -} - // Palettes offered by the image scale panel. Color / BW1 / BW2 are the // original three and stay first (the b / B / c shortcuts use those indices). // Gain4 is the fixed, muted palette for the 0..3 gain bits and is *not* in the diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQtScalePanel.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQtScalePanel.h index 616fc5918..c236685c7 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQtScalePanel.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQtScalePanel.h @@ -2,7 +2,7 @@ // Copyright (C) 2026 Contributors to the SLS Detector Package #pragma once -// Thin histogram strip + scale panel of the Qt5/Qt6 plotting stack: the +// Thin histogram strip + scale panel of the plotting stack: the // strip shows the distribution of the last frame over the window the colour // mapping currently shows and carries the two draggable range ends; the panel // owns the palette chooser and the image/histogram lin-log switches. The diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp index c164b59a7..eaf5f703e 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp @@ -989,7 +989,7 @@ SlsQt1DPlot::Geometry SlsQt1DPlot::computeGeometry() const { const int w = 20 + (h->title().isEmpty() ? 0 - : sls::plot::textWidth(fmTick, h->title()) + 4); + : fmTick.horizontalAdvance(h->title()) + 4); if (used > 0 && used + w > avail) { ++rows; used = 0; @@ -1020,7 +1020,7 @@ SlsQt1DPlot::Geometry SlsQt1DPlot::computeGeometry() const { } int yLabelW = 0; for (const QString &s : g.yLabels) - yLabelW = std::max(yLabelW, sls::plot::textWidth(fmTick, s)); + yLabelW = std::max(yLabelW, fmTick.horizontalAdvance(s)); int left = 3 + yTitleW + yLabelW + kTickLen + 2; const int right = 8; @@ -1035,7 +1035,7 @@ SlsQt1DPlot::Geometry SlsQt1DPlot::computeGeometry() const { std::vector xl = tickLabels(xt, m_xLo, m_xHi, m_logX); int maxXLabelW = 12; for (const QString &s : xl) - maxXLabelW = std::max(maxXLabelW, sls::plot::textWidth(fmTick, s)); + maxXLabelW = std::max(maxXLabelW, fmTick.horizontalAdvance(s)); int maxXT = std::max(2, std::min(8, plotW / (maxXLabelW + 12))); g.xTicks = tickValues(m_xLo, m_xHi, m_logX, maxXT); g.xLabels = tickLabels(g.xTicks, m_xLo, m_xHi, m_logX); @@ -1246,7 +1246,7 @@ void SlsQt1DPlot::paintFrame(QPainter &p, const Geometry &g) const { if (i < static_cast(g.xLabels.size())) { const QString &lab = g.xLabels[static_cast(i)]; p.setPen(m_theme.text); - int w = sls::plot::textWidth(fmTick, lab) + 8; + int w = fmTick.horizontalAdvance(lab) + 8; int lx = x - w / 2; if (lx < 0) lx = 0; @@ -1269,7 +1269,7 @@ void SlsQt1DPlot::paintFrame(QPainter &p, const Geometry &g) const { if (i < static_cast(g.yLabels.size())) { const QString &lab = g.yLabels[static_cast(i)]; p.setPen(m_theme.text); - const int w = sls::plot::textWidth(fmTick, lab) + 4; + const int w = fmTick.horizontalAdvance(lab) + 4; int lx = r.left() - kTickLen - 2 - w; if (lx < 0) lx = 0; @@ -1326,7 +1326,7 @@ void SlsQt1DPlot::paintLegend(QPainter &p, const Geometry &g) const { const int w = 20 + (h->title().isEmpty() ? 0 - : sls::plot::textWidth(fm, h->title()) + 4); + : fm.horizontalAdvance(h->title()) + 4); if (!current.empty() && curW + w > avail) { rows.push_back(current); rowW.push_back(curW); @@ -1362,7 +1362,7 @@ void SlsQt1DPlot::paintLegend(QPainter &p, const Geometry &g) const { x += 20; if (!h->title().isEmpty()) { p.setPen(m_theme.text); - const int tw = sls::plot::textWidth(fm, h->title()); + const int tw = fm.horizontalAdvance(h->title()); p.drawText(QRect(x, y, tw + 2, rowH), Qt::AlignLeft | Qt::AlignVCenter, h->title()); x += tw + 4; @@ -1461,7 +1461,7 @@ void SlsQt1DPlot::paintEvent(QPaintEvent *event) { // --------------------------------------------------------------------------- void SlsQt1DPlot::mousePressEvent(QMouseEvent *event) { - const QPointF pos = sls::plot::eventPosition(event); + const QPointF pos = event->position(); const Geometry g = computeGeometry(); if (zoomAllowed()) { if (event->button() == Qt::LeftButton && @@ -1498,7 +1498,7 @@ void SlsQt1DPlot::mousePressEvent(QMouseEvent *event) { } void SlsQt1DPlot::mouseMoveEvent(QMouseEvent *event) { - const QPointF pos = sls::plot::eventPosition(event); + const QPointF pos = event->position(); const Geometry g = computeGeometry(); const bool inside = g.plot.contains(pos.toPoint()); if (inside != m_trackValid || pos != m_trackPos) { @@ -1578,7 +1578,7 @@ void SlsQt1DPlot::wheelEvent(QWheelEvent *event) { event->ignore(); return; } - const QPointF pos = sls::plot::eventPosition(event); + const QPointF pos = event->position(); const Geometry g = computeGeometry(); if (!g.plot.contains(pos.toPoint())) { event->ignore(); diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp index 012800106..fc35992ed 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp @@ -930,7 +930,7 @@ double SlsQtFastImage::valueAt(const QPoint &pos) const { void SlsQtFastImage::mousePressEvent(QMouseEvent *e) { if (e->button() != Qt::LeftButton) return; - const QPoint ip = sls::plot::eventPosition(e).toPoint(); + const QPoint ip = e->position().toPoint(); if (m_roiEdit && hasImage()) { // which part of the yellow rectangle was grabbed? const QPointF d = widgetToData(QPointF(ip)); @@ -996,7 +996,7 @@ void SlsQtFastImage::mousePressEvent(QMouseEvent *e) { } void SlsQtFastImage::mouseMoveEvent(QMouseEvent *e) { - const QPointF pos = sls::plot::eventPosition(e); + const QPointF pos = e->position(); if (m_roiEdit && hasImage()) { const QPointF d = widgetToData(pos); const double x = std::max(0.0, std::min(double(m_nx), d.x())); @@ -1087,7 +1087,7 @@ void SlsQtFastImage::mouseMoveEvent(QMouseEvent *e) { const QRect sr = scaleRect(); if (sr.height() <= 0) return; - const double delta = double(sls::plot::eventPosition(e).toPoint().y() - m_dragScaleY) / + const double delta = double(e->position().toPoint().y() - m_dragScaleY) / double(sr.height()) * (m_dragChi - m_dragClo); if (m_dragMax) { m_chi = m_dragChi - delta; @@ -1165,7 +1165,7 @@ void SlsQtFastImage::mouseReleaseEvent(QMouseEvent *e) { void SlsQtFastImage::wheelEvent(QWheelEvent *e) { if (!hasImage() || !m_zoomEnabled) return; - const QPointF imgPt = widgetToData(sls::plot::eventPosition(e)); + const QPointF imgPt = widgetToData(e->position()); const double mx = imgPt.x(), my = imgPt.y(); const double factor = (e->angleDelta().y() > 0) ? 1.0 / 1.18 : 1.18; @@ -1198,7 +1198,7 @@ void SlsQtFastImage::wheelEvent(QWheelEvent *e) { void SlsQtFastImage::mouseDoubleClickEvent(QMouseEvent *e) { const QRect sr = scaleRect(); - if (sr.height() > 0 && sr.contains(sls::plot::eventPosition(e).toPoint())) { + if (sr.height() > 0 && sr.contains(e->position().toPoint())) { m_clo = m_defClo; m_chi = m_defChi; m_histMs = 0; diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp index 57dda1948..875e02302 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp @@ -180,8 +180,8 @@ void SlsQtScaleHisto::paintEvent(QPaintEvent *) { void SlsQtScaleHisto::mousePressEvent(QMouseEvent *e) { const double xa = 0.25 * width(), xb = 0.75 * width(); - const double d = std::abs(sls::plot::eventPosition(e).x() - xa); - const double d2 = std::abs(sls::plot::eventPosition(e).x() - xb); + const double d = std::abs(e->position().x() - xa); + const double d2 = std::abs(e->position().x() - xb); if (std::min(d, d2) > 10) { m_dragMin = -1; // too far from either marker: ignore return; @@ -196,7 +196,7 @@ void SlsQtScaleHisto::mousePressEvent(QMouseEvent *e) { m_snap = *m_hist; // the bars: frozen as well (the image keeps updating) m_preClo = m_clo; // the axis basis: frozen until the button is released m_preChi = m_chi; - m_previewX = sls::plot::eventPosition(e).toPoint().x(); + m_previewX = e->position().toPoint().x(); mouseMoveEvent(e); } @@ -212,14 +212,14 @@ void SlsQtScaleHisto::mouseMoveEvent(QMouseEvent *e) { // mapped to a different value, so the marker chased itself. double wlo = 0.0, whi = 1.0; windowFor(m_preClo, m_preChi, wlo, whi); - const double t = std::max(0.0, std::min(1.0, double(sls::plot::eventPosition(e).x()) / W)); + const double t = std::max(0.0, std::min(1.0, double(e->position().x()) / W)); const double vBin = wlo + t * (whi - wlo); const double v = m_logX ? std::pow(10.0, vBin) : vBin; if (m_dragMin == 1) m_clo = std::min(v, m_chi - 1e-9); else m_chi = std::max(v, m_clo + 1e-9); - m_previewX = sls::plot::eventPosition(e).toPoint().x(); + m_previewX = e->position().toPoint().x(); update(); // only the preview line moves; bars and axis stay frozen } diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index 60e429020..237f362b5 100644 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -3,15 +3,6 @@ #include "qTabDataOutput.h" #include "qDefs.h" -// QButtonGroup::idClicked arrived in Qt 5.15; older Qt5 releases (RHEL 7 has -// Qt 5.9) only provide the deprecated buttonClicked(int) overload, and Qt6 -// removed that overload. Keep the three connect/disconnect sites in sync. -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) -#define SLS_RATE_GROUP_SIGNAL &QButtonGroup::idClicked -#else -#define SLS_RATE_GROUP_SIGNAL QOverload::of(&QButtonGroup::buttonClicked) -#endif - #include #include #include @@ -88,7 +79,7 @@ void qTabDataOutput::Initialization() { if (chkRate->isEnabled()) { connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection())); - connect(btnGroupRate, SLS_RATE_GROUP_SIGNAL, this, + connect(btnGroupRate, &QButtonGroup::idClicked, this, &qTabDataOutput::SetRateCorrection); connect(spinCustomDeadTime, SIGNAL(valueChanged(int)), this, SLOT(SetRateCorrection())); @@ -318,7 +309,7 @@ void qTabDataOutput::GetRateCorrection() { LOG(logDEBUG) << "Getting Rate Correction"; disconnect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection())); - disconnect(btnGroupRate, SLS_RATE_GROUP_SIGNAL, this, + disconnect(btnGroupRate, &QButtonGroup::idClicked, this, &qTabDataOutput::SetRateCorrection); disconnect(spinCustomDeadTime, SIGNAL(valueChanged(int)), this, SLOT(SetRateCorrection())); @@ -335,7 +326,7 @@ void qTabDataOutput::GetRateCorrection() { CATCH_DISPLAY("Could not get rate correction.", "qTabDataOutput::GetRateCorrection") connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection())); - connect(btnGroupRate, SLS_RATE_GROUP_SIGNAL, this, + connect(btnGroupRate, &QButtonGroup::idClicked, this, &qTabDataOutput::SetRateCorrection); connect(spinCustomDeadTime, SIGNAL(valueChanged(int)), this, SLOT(SetRateCorrection())); diff --git a/slsDetectorGui/src/qVersionResolve.cpp b/slsDetectorGui/src/qVersionResolve.cpp deleted file mode 100644 index 42a2c7d09..000000000 --- a/slsDetectorGui/src/qVersionResolve.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-other -// Copyright (C) 2021 Contributors to the SLS Detector Package -#include "qVersionResolve.h" - -namespace sls { - -int qResolve_GetQFontWidth(const QFontMetrics fm, const QString &text, - int len) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) - return fm.horizontalAdvance(text, len); -#else - // RHEL 7 still ships Qt 5.9, where QFontMetrics::width() is the only - // available overload for this. - return fm.width(text, len); -#endif -} - -} // namespace sls diff --git a/slsDetectorGui/tests/CMakeLists.txt b/slsDetectorGui/tests/CMakeLists.txt index 554d37215..5e322be38 100644 --- a/slsDetectorGui/tests/CMakeLists.txt +++ b/slsDetectorGui/tests/CMakeLists.txt @@ -1,46 +1,23 @@ # SPDX-License-Identifier: LGPL-3.0-or-other # Copyright (C) 2026 Contributors to the SLS Detector Package -# -# QtTest suite for the Qt5/Qt6 plotting stack. -# -# Wired in from slsDetectorGui/CMakeLists.txt by an EXISTS guard; the plotting -# sources are compiled once into the slsDetectorPlotting static library there -# and shared by the GUI executable, this suite and the demo. -# -# Build: cmake --build --target plotting_test -# Run: QT_QPA_PLATFORM=offscreen /bin/plotting_test -# (or "ctest -R plotting" when the project is configured with -# -DSLS_USE_TESTS=ON) -if(SLS_GUI_QT_MAJOR STREQUAL "5") - find_package(Qt5 5.9 REQUIRED COMPONENTS Test) - set(SLS_QT_TEST Qt5::Test) -else() - find_package(Qt6 6.2 REQUIRED COMPONENTS Test) - set(SLS_QT_TEST Qt6::Test) -endif() +# QtTest suite for the plotting widgets. Needs no display: +# QT_QPA_PLATFORM=offscreen bin/plotting_test -if(NOT TARGET slsDetectorPlotting) - message(FATAL_ERROR - "plotting_test needs the slsDetectorPlotting target defined in " - "slsDetectorGui/CMakeLists.txt") -endif() +find_package(Qt6 6.2 REQUIRED COMPONENTS Test) add_executable(plotting_test plotting_test.cpp ) target_link_libraries(plotting_test PRIVATE slsDetectorPlotting - ${SLS_QT_TEST} + Qt6::Test ) set_target_properties(plotting_test PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -if(SLS_USE_TESTS) - add_test(NAME plotting_test COMMAND plotting_test) - set_tests_properties(plotting_test PROPERTIES - ENVIRONMENT "QT_QPA_PLATFORM=offscreen" - TIMEOUT 300 - ) -endif() +add_test(NAME plotting_test COMMAND plotting_test) +set_tests_properties(plotting_test PROPERTIES + ENVIRONMENT "QT_QPA_PLATFORM=offscreen" +) diff --git a/slsDetectorGui/tests/plotting_test.cpp b/slsDetectorGui/tests/plotting_test.cpp index 26d0e052a..0eb88ea75 100644 --- a/slsDetectorGui/tests/plotting_test.cpp +++ b/slsDetectorGui/tests/plotting_test.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2026 Contributors to the SLS Detector Package // -// QtTest suite for the Qt5/Qt6 plotting stack (verification task). +// QtTest suite for the plotting stack (verification task). // // Everything is checked through the public API or through rendered pixels; the // widgets are shown on the offscreen QPA platform and rendered synchronously @@ -91,16 +91,9 @@ void sendMouse(QWidget &w, QEvent::Type type, const QPointF &pos, } void sendWheel(QWidget &w, const QPointF &pos, int deltaY) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) QWheelEvent e(pos, QPointF(w.mapToGlobal(pos.toPoint())), QPoint(), QPoint(0, deltaY), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); -#else - // Qt 5.9 (RHEL 7): the scroll-phase constructor does not exist yet. - QWheelEvent e(pos, QPointF(w.mapToGlobal(pos.toPoint())), QPoint(), - QPoint(0, deltaY), 0, Qt::Vertical, Qt::NoButton, - Qt::NoModifier); -#endif QCoreApplication::sendEvent(&w, &e); }