Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CMakeExternals/QtTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)

#-----------------------------------------------------------------------------
Expand Down
16 changes: 11 additions & 5 deletions Libs/QtTesting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
11 changes: 8 additions & 3 deletions Libs/QtTesting/ctkXMLEventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <QFile>
#include <QMap>
#include <QMessageBox>
#include <QtXmlPatterns/QXmlSchema>
#include <QtXmlPatterns/QXmlSchemaValidator>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
# include <QtXmlPatterns/QXmlSchema>
# include <QtXmlPatterns/QXmlSchemaValidator>
#endif
#include <QVariant>

// CTKQtTesting includes
Expand Down Expand Up @@ -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())
Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion Libs/Visualization/VTK/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 23 additions & 27 deletions Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
}

Expand Down Expand Up @@ -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;
Expand All @@ -144,15 +143,14 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object,
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(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();
Expand Down Expand Up @@ -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();
Expand All @@ -195,9 +193,9 @@ bool ctkVTKRenderViewEventTranslator::translateEvent(QObject *Object,
double x_norm = (x_center - x)/static_cast<double>(size.width()/2.0);
double y_norm = (y_center - y)/static_cast<double>(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)
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions Libs/Visualization/VTK/Widgets/ctkVTKRenderViewEventTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
// QT includes
#include <QMouseEvent>

// STD includes
#include <optional>

// QtTesting includes
#include <pqWidgetEventTranslator.h>

Expand All @@ -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<QMouseEvent> lastMoveEvent;
std::optional<QMouseEvent> oldMoveEvent;
std::optional<QMouseEvent> lastMouseEvent;

private:
Q_DISABLE_COPY(ctkVTKRenderViewEventTranslator);
Expand Down
8 changes: 7 additions & 1 deletion Libs/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading