diff --git a/CMakeExternals/QtTesting.cmake b/CMakeExternals/QtTesting.cmake index e52c556dab..13fff596bd 100644 --- a/CMakeExternals/QtTesting.cmake +++ b/CMakeExternals/QtTesting.cmake @@ -27,7 +27,7 @@ if(NOT DEFINED QtTesting_DIR) if("${CMAKE_CXX_STANDARD}" STREQUAL "98") set(revision_tag c44b32fdea827be737e8c2f5608ffbc2e3bd08b2) else() - set(revision_tag a86bee55104f553a1cb82b9cf0b109d9f1e95dbf) # ctk-2019-03-14-b5324a2 + set(revision_tag cf5fa4156734edb9c3515c7104c19783b17ed0c1) # ctk-2026-03-27 Qt5+Qt6 support endif() if(${proj}_REVISION_TAG) set(revision_tag ${${proj}_REVISION_TAG}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43ca40ba7d..10b94f3c19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,21 @@ if(APPLE) ) endif() +#----------------------------------------------------------------------------- +# Setting C++ Standard +#----------------------------------------------------------------------------- +set(_msg "Setting C++ standard") +message(STATUS "${_msg}") +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +message(STATUS "${_msg} - C++${CMAKE_CXX_STANDARD}") +if(NOT CMAKE_CXX_STANDARD MATCHES "^(17|20)$") + message(FATAL_ERROR "CMAKE_CXX_STANDARD must be set to 17 or 20") +endif() + #----------------------------------------------------------------------------- project(CTK) #----------------------------------------------------------------------------- @@ -329,14 +344,6 @@ endif() # option(CTK_USE_QTTESTING "Enable/Disable QtTesting" OFF) mark_as_advanced(CTK_USE_QTTESTING) -if(NOT CTK_QT_VERSION VERSION_EQUAL "5") - # Forcing to OFF as "QtTesting" depends on XmlPatterns Qt component not available with Qt 6 - if(DEFINED CTK_USE_QTTESTING AND CTK_USE_QTTESTING) - unset(CTK_USE_QTTESTING CACHE) - set(CTK_USE_QTTESTING OFF) - message(WARNING "Forcing option [CTK_USE_QTTESTING] to OFF as QtTesting depends on XmlPatterns Qt component not available with Qt ${CTK_QT_VERSION}") - endif() -endif() mark_as_superbuild(CTK_USE_QTTESTING) #----------------------------------------------------------------------------- diff --git a/Libs/QtTesting/CMakeLists.txt b/Libs/QtTesting/CMakeLists.txt index 0dc0ed5ba0..af3ec83d16 100644 --- a/Libs/QtTesting/CMakeLists.txt +++ b/Libs/QtTesting/CMakeLists.txt @@ -4,7 +4,13 @@ project(CTKQtTesting) # 3rd party dependencies # find_package(QtTesting REQUIRED) -set(QtTesting_LIBRARIES QtTesting) +# The upstream target name changed from "QtTesting" (pre-2024) to "qttesting" +# (lowercase) in newer revisions. Use whichever target the package provides. +if(TARGET qttesting) + set(QtTesting_LIBRARIES qttesting) +else() + set(QtTesting_LIBRARIES QtTesting) +endif() # # See CTK/CMake/ctkMacroBuildLib.cmake for details @@ -135,17 +141,17 @@ set(KIT_resources Resources/ctkQtTesting.qrc ) -# Set QtTesting_LIBRARIES variable -set(QtTesting_LIBRARIES QtTesting) - # Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake # The following macro will read the target libraries from the file 'target_libraries.cmake' ctkFunctionGetTargetLibraries(KIT_target_libraries) list(APPEND KIT_target_libraries Qt${CTK_QT_VERSION}::Xml - Qt${CTK_QT_VERSION}::XmlPatterns ) +if(CTK_QT_VERSION VERSION_LESS "6") + # QtXmlPatterns is Qt 5 only; ctkXMLEventSource guards its usage accordingly + list(APPEND KIT_target_libraries Qt5::XmlPatterns) +endif() ctkMacroBuildLib( NAME ${PROJECT_NAME} diff --git a/Libs/QtTesting/ctkXMLEventSource.cpp b/Libs/QtTesting/ctkXMLEventSource.cpp index b153f77bb6..f1a69eeab6 100644 --- a/Libs/QtTesting/ctkXMLEventSource.cpp +++ b/Libs/QtTesting/ctkXMLEventSource.cpp @@ -25,8 +25,10 @@ #include #include #include -#include -#include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +# include +# include +#endif #include // CTKQtTesting includes @@ -78,7 +80,9 @@ void ctkXMLEventSource::setContent(const QString& xmlfilename) return; } - // Check if the xml file is valid +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + // Check if the xml file is valid (Qt5 only — QXmlSchema/QXmlSchemaValidator + // are from QtXmlPatterns which is not available in Qt 6) QXmlSchema xmlSchema; if (!xmlSchema.load(QUrl::fromLocalFile(":/XML/XMLDescription.xsd")) || !xmlSchema.isValid()) @@ -93,6 +97,7 @@ void ctkXMLEventSource::setContent(const QString& xmlfilename) qCritical() << xmlfilename << "invalid xml file for qtTesting !"; return; } +#endif xml.reset(); QByteArray data = xml.readAll(); diff --git a/Libs/Visualization/VTK/Widgets/CMakeLists.txt b/Libs/Visualization/VTK/Widgets/CMakeLists.txt index c66b32e203..bdfc0b9e9a 100644 --- a/Libs/Visualization/VTK/Widgets/CMakeLists.txt +++ b/Libs/Visualization/VTK/Widgets/CMakeLists.txt @@ -56,6 +56,12 @@ set(KIT_export_directive "CTK_VISUALIZATION_VTK_WIDGETS_EXPORT") # if(CTK_USE_QTTESTING) find_package(QtTesting REQUIRED) + # Target name changed from "QtTesting" (old) to "qttesting" (new upstream) + if(TARGET qttesting) + set(QtTesting_LINK_TARGET qttesting) + else() + set(QtTesting_LINK_TARGET QtTesting) + endif() include_directories( ${QtTesting_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} # For ctkConfig.h @@ -211,7 +217,7 @@ if(CTK_USE_QTTESTING) ctkVTKRenderViewEventPlayer.h ctkVTKRenderViewEventTranslator.h ) - list(APPEND KIT_target_libraries QtTesting) + list(APPEND KIT_target_libraries ${QtTesting_LINK_TARGET}) endif() # Prefer QVTKOpenGLWidget to QVTKWidget when using Qt5 diff --git a/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.cpp b/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.cpp index 45242bc17e..ff459d7163 100644 --- a/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.cpp +++ b/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.cpp @@ -33,12 +33,12 @@ ctkVTKRenderViewEventTranslator::ctkVTKRenderViewEventTranslator(const QByteArray& Classname, QObject* Parent) : pqWidgetEventTranslator(Parent), mClassType(Classname), - lastMoveEvent(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()), - oldMoveEvent(QEvent::MouseMove, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()), - lastMouseEvent(QEvent::MouseButtonRelease, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()) + lastMoveEvent(std::in_place, QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), + Qt::MouseButtons(), Qt::KeyboardModifiers()), + oldMoveEvent(std::in_place, QEvent::MouseMove, QPoint(), Qt::MouseButton(), + Qt::MouseButtons(), Qt::KeyboardModifiers()), + lastMouseEvent(std::in_place, QEvent::MouseButtonRelease, QPoint(), Qt::MouseButton(), + Qt::MouseButtons(), Qt::KeyboardModifiers()) { } @@ -129,12 +129,11 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object, .arg(modifiers)); } - // reset lastMoveEvent - QMouseEvent e(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()); - - lastMoveEvent = e; - lastMouseEvent = e; + // reset lastMoveEvent / lastMouseEvent + lastMoveEvent.emplace(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), + Qt::MouseButtons(), Qt::KeyboardModifiers()); + lastMouseEvent.emplace(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), + Qt::MouseButtons(), Qt::KeyboardModifiers()); } handled = true; break; @@ -144,15 +143,14 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object, QMouseEvent* mouseEvent = dynamic_cast(Event); if (mouseEvent) { - QMouseEvent e(QEvent::MouseMove, QPoint(mouseEvent->x(), mouseEvent->y()), - mouseEvent->button(), mouseEvent->buttons(), - mouseEvent->modifiers()); - - lastMoveEvent = e; + lastMoveEvent.emplace(QEvent::MouseMove, + QPoint(mouseEvent->x(), mouseEvent->y()), + mouseEvent->button(), mouseEvent->buttons(), + mouseEvent->modifiers()); QSize size = widget->size(); - if(lastMouseEvent.type() == QEvent::MouseButtonPress ) + if(lastMouseEvent->type() == QEvent::MouseButtonPress ) { int x = mouseEvent->x(); int y = mouseEvent->y(); @@ -185,7 +183,7 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object, QSize size = widget->size(); // record last move event if it is valid - if(lastMoveEvent.type() == QEvent::MouseMove) + if(lastMoveEvent->type() == QEvent::MouseMove) { int x = mouseEvent->x(); int y = mouseEvent->y(); @@ -195,9 +193,9 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object, double x_norm = (x_center - x)/static_cast(size.width()/2.0); double y_norm = (y_center - y)/static_cast(size.height()/2.0); - int button = lastMoveEvent.button(); - int buttons = lastMoveEvent.buttons(); - int modifiers = lastMoveEvent.modifiers(); + int button = lastMoveEvent->button(); + int buttons = lastMoveEvent->buttons(); + int modifiers = lastMoveEvent->modifiers(); emit recordEvent(Object, "mouseMove", QString("(%1,%2,%3,%4,%5)") .arg(x_norm) @@ -226,11 +224,9 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object, .arg(buttons) .arg(modifiers)); } - // reset lastMoveEvent - QMouseEvent e(QEvent::MouseButtonRelease, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()); - - lastMouseEvent = e; + // reset lastMouseEvent + lastMouseEvent.emplace(QEvent::MouseButtonRelease, QPoint(), Qt::MouseButton(), + Qt::MouseButtons(), Qt::KeyboardModifiers()); } handled = true; diff --git a/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.h b/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.h index 312934bb22..d50487e0a4 100644 --- a/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.h +++ b/Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.h @@ -24,6 +24,9 @@ // QT includes #include +// STD includes +#include + // QtTesting includes #include @@ -46,9 +49,11 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderViewEventTranslator : protected: QByteArray mClassType; - QMouseEvent lastMoveEvent; - QMouseEvent oldMoveEvent; - QMouseEvent lastMouseEvent; + // Qt6: QMouseEvent::operator= is protected (inherited from QInputEvent). + // Use std::optional so .emplace() can construct in-place without copy/assign. + std::optional lastMoveEvent; + std::optional oldMoveEvent; + std::optional lastMouseEvent; private: Q_DISABLE_COPY(ctkVTKRenderViewEventTranslator); diff --git a/Libs/Widgets/CMakeLists.txt b/Libs/Widgets/CMakeLists.txt index 591e2d583a..02c9a50d11 100644 --- a/Libs/Widgets/CMakeLists.txt +++ b/Libs/Widgets/CMakeLists.txt @@ -18,6 +18,12 @@ endif() # if(CTK_USE_QTTESTING) find_package(QtTesting REQUIRED) + # Target name changed from "QtTesting" (old) to "qttesting" (new upstream) + if(TARGET qttesting) + set(QtTesting_LINK_TARGET qttesting) + else() + set(QtTesting_LINK_TARGET QtTesting) + endif() include_directories( ${QtTesting_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} # For ctkConfig.h @@ -311,7 +317,7 @@ if(CTK_USE_QTTESTING) ctkTreeComboBoxEventTranslator.cpp ctkTreeComboBoxEventTranslator.h ) - list(APPEND KIT_target_libraries QtTesting) + list(APPEND KIT_target_libraries ${QtTesting_LINK_TARGET}) endif() ctkMacroBuildLib(