From 406ac82c80944b93316c5dcd3abfba34bdc42c2e Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Thu, 16 Jun 2022 14:25:33 +0200 Subject: [PATCH 1/5] make CVV module work with Qt6 --- modules/cvv/CMakeLists.txt | 16 ++++--- .../cvv/src/qtutil/matchview/matchscene.cpp | 2 +- .../matchview/singlecolorkeypointpen.cpp | 2 +- .../qtutil/matchview/singlecolormatchpen.cpp | 2 +- .../qtutil/matchview/zoomableproxyobject.cpp | 4 +- modules/cvv/src/qtutil/zoomableimage.cpp | 4 +- modules/cvv/src/qtutil/zoomableimage.hpp | 2 +- modules/cvv/src/stfl/stfl_engine.hpp | 42 +++++++++---------- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/modules/cvv/CMakeLists.txt b/modules/cvv/CMakeLists.txt index c264ef1ead..645e7b3944 100644 --- a/modules/cvv/CMakeLists.txt +++ b/modules/cvv/CMakeLists.txt @@ -5,16 +5,20 @@ endif() set(the_description "Debug visualization framework") ocv_add_module(cvv opencv_core opencv_imgproc opencv_features2d WRAP python) - ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow -Wmissing-declarations) -# Qt5 +# Qt +set(CVV_QT_MODULES Core Gui Widgets) +if(QT_VERSION_MAJOR EQUAL 6) + list(APPEND CVV_QT_MODULES Core5Compat) +endif() + +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${CVV_QT_MODULES}) + set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -foreach(dt5_dep Core Gui Widgets) - add_definitions(${Qt5${dt5_dep}_DEFINITIONS}) - include_directories(${Qt5${dt5_dep}_INCLUDE_DIRS}) - list(APPEND CVV_LIBRARIES ${Qt5${dt5_dep}_LIBRARIES}) +foreach(module ${CVV_QT_MODULES}) + list(APPEND CVV_LIBRARIES ${Qt${QT_VERSION_MAJOR}${module}_LIBRARIES}) endforeach() ocv_glob_module_sources() diff --git a/modules/cvv/src/qtutil/matchview/matchscene.cpp b/modules/cvv/src/qtutil/matchview/matchscene.cpp index bc68fcd62b..5d2a983444 100644 --- a/modules/cvv/src/qtutil/matchview/matchscene.cpp +++ b/modules/cvv/src/qtutil/matchview/matchscene.cpp @@ -153,7 +153,7 @@ void MatchScene::rightClick(const QPoint &pos) pmap = rightImage_->visibleImage(); } }else{ - pmap = QPixmap::grabWidget(graphicView_->viewport()); + pmap = graphicView_->viewport()->grab(); } pmap.save(fileName, 0, 100); } diff --git a/modules/cvv/src/qtutil/matchview/singlecolorkeypointpen.cpp b/modules/cvv/src/qtutil/matchview/singlecolorkeypointpen.cpp index 0c994ff697..0dd17c4730 100644 --- a/modules/cvv/src/qtutil/matchview/singlecolorkeypointpen.cpp +++ b/modules/cvv/src/qtutil/matchview/singlecolorkeypointpen.cpp @@ -15,7 +15,7 @@ SingleColorKeyPen::SingleColorKeyPen(std::vector, QWidget *parent) auto layout = util::make_unique(); auto button = util::make_unique("Color Dialog"); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); connect(colordia_, SIGNAL(currentColorChanged(const QColor &)), this, SLOT(updateColor(const QColor &))); diff --git a/modules/cvv/src/qtutil/matchview/singlecolormatchpen.cpp b/modules/cvv/src/qtutil/matchview/singlecolormatchpen.cpp index 28dfc5b2ac..a847050ba2 100644 --- a/modules/cvv/src/qtutil/matchview/singlecolormatchpen.cpp +++ b/modules/cvv/src/qtutil/matchview/singlecolormatchpen.cpp @@ -23,7 +23,7 @@ SingleColorMatchPen::SingleColorMatchPen(std::vector, QWidget *paren connect(button.get(), SIGNAL(clicked(bool)), this, SLOT(colorButtonClicked())); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); layout->addWidget(button.release()); setLayout(layout.release()); diff --git a/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp b/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp index f314497bae..06c65c92d8 100644 --- a/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp +++ b/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp @@ -21,8 +21,8 @@ void ZoomableProxyObject::wheelEvent(QGraphicsSceneWheelEvent *event) QPoint delta{ event->delta(), 0 }; QWheelEvent newEvent{ event->pos(), event->screenPos(), delta, delta, - event->delta(), event->orientation(), - event->buttons(), event->modifiers() }; + event->buttons(), event->modifiers(), + Qt::NoScrollPhase, true }; image_->wheelEvent(&newEvent); } diff --git a/modules/cvv/src/qtutil/zoomableimage.cpp b/modules/cvv/src/qtutil/zoomableimage.cpp index ce62daab61..64abef1ea7 100644 --- a/modules/cvv/src/qtutil/zoomableimage.cpp +++ b/modules/cvv/src/qtutil/zoomableimage.cpp @@ -205,7 +205,7 @@ ZoomableImage::ZoomableImage(const cv::Mat &mat, QWidget *parent) view_->setFocusPolicy(Qt::NoFocus); auto layout = util::make_unique(); layout->addWidget(view.release()); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); setLayout(layout.release()); setMat(mat_); // rightklick @@ -398,7 +398,7 @@ QPointF ZoomableImage::mapImagePointToParent(QPointF point) const void ZoomableImage::mouseMoveEvent(QMouseEvent * event) { - QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(event->globalPos())); + QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(event->globalPosition().toPoint())); bool inImage=(imgPos.x()>=0) &&(imgPos.y()>=0) &&(imgPos.x()<=imageWidth()) diff --git a/modules/cvv/src/qtutil/zoomableimage.hpp b/modules/cvv/src/qtutil/zoomableimage.hpp index 785a238ab6..1340b626e7 100644 --- a/modules/cvv/src/qtutil/zoomableimage.hpp +++ b/modules/cvv/src/qtutil/zoomableimage.hpp @@ -208,7 +208,7 @@ class ZoomableImage : public QWidget */ QPixmap visibleImage() const { - return QPixmap::grabWidget(view_->viewport()); + return view_->viewport()->grab(); } /** diff --git a/modules/cvv/src/stfl/stfl_engine.hpp b/modules/cvv/src/stfl/stfl_engine.hpp index bb1dc04be5..49b8af78c5 100644 --- a/modules/cvv/src/stfl/stfl_engine.hpp +++ b/modules/cvv/src/stfl/stfl_engine.hpp @@ -162,7 +162,7 @@ template class STFLEngine } QList elemList; QStringList cmdStrings = - query.split("#", QString::SkipEmptyParts); + query.split("#", Qt::SkipEmptyParts); elemList = executeFilters(elements, cmdStrings); elemList = executeSortCmds(elemList, cmdStrings); auto groups = executeGroupCmds(elemList, cmdStrings); @@ -549,7 +549,7 @@ template class STFLEngine { using namespace std::placeholders; QStringList arr = - cmdString.split(" ", QString::SkipEmptyParts); + cmdString.split(" ", Qt::SkipEmptyParts); QString cmd; if (arr.empty()) { @@ -570,7 +570,7 @@ template class STFLEngine else if (isFilterCSCmd(cmd)) { QStringList arguments = arr.join("").split( - ",", QString::SkipEmptyParts); + ",", Qt::SkipEmptyParts); std::for_each(arguments.begin(), arguments.end(), [](QString &str) { str.replace("\\,", ","); }); @@ -609,7 +609,7 @@ template class STFLEngine for (QString cmdString : cmdStrings) { QStringList arr = - cmdString.split(" ", QString::SkipEmptyParts); + cmdString.split(" ", Qt::SkipEmptyParts); if (arr.size() < 2) { continue; @@ -619,7 +619,7 @@ template class STFLEngine { arr.removeFirst(); } - arr = arr.join(" ").split(",", QString::SkipEmptyParts); + arr = arr.join(" ").split(",", Qt::SkipEmptyParts); for (QString cmdPart : arr) { cmdPart = cmdPart.trimmed(); @@ -647,7 +647,7 @@ template class STFLEngine if (sortCmd.second) { auto sortFunc = sortFuncs[sortCmd.first]; - qStableSort(resList.begin(), resList.end(), + std::stable_sort(resList.begin(), resList.end(), [&](const Element &elem1, const Element &elem2) { return sortFunc(elem1, elem2); }); @@ -655,7 +655,7 @@ template class STFLEngine else { auto sortFunc = sortFuncs[sortCmd.first]; - qStableSort(resList.begin(), resList.end(), + std::stable_sort(resList.begin(), resList.end(), [&](const Element &elem1, const Element &elem2) { return sortFunc(elem2, elem1); }); @@ -675,7 +675,7 @@ template class STFLEngine for (QString cmdString : cmdStrings) { QStringList arr = - cmdString.split(" ", QString::SkipEmptyParts); + cmdString.split(" ", Qt::SkipEmptyParts); if (arr.size() < 2) { continue; @@ -689,7 +689,7 @@ template class STFLEngine { arr.removeFirst(); } - arr = arr.join("").split(",", QString::SkipEmptyParts); + arr = arr.join("").split(",", Qt::SkipEmptyParts); for (QString cmdPart : arr) { QStringList cmdPartList = cmdPart.split(" "); @@ -720,7 +720,7 @@ template class STFLEngine for (auto it = groups.begin(); it != groups.end(); ++it) { ElementGroup elementGroup( - it->first.split("\\|", QString::SkipEmptyParts), + it->first.split("\\|", Qt::SkipEmptyParts), it->second); groupList.push_back(elementGroup); } @@ -733,7 +733,7 @@ template class STFLEngine for (QString cmdString : cmdStrings) { QStringList arr = - cmdString.split(" ", QString::SkipEmptyParts); + cmdString.split(" ", Qt::SkipEmptyParts); if (arr.isEmpty()) { continue; @@ -743,7 +743,7 @@ template class STFLEngine { continue; } - arr = arr.join("").split(",", QString::SkipEmptyParts); + arr = arr.join("").split(",", Qt::SkipEmptyParts); additionalCommandFuncs[cmd](arr, groups); } } @@ -762,11 +762,11 @@ template class STFLEngine if (cmd == "group" || cmd == "sort") { int frontCut = - std::min(1 + (hasByString ? 1 : 0), tokens.size()); - tokens = cmdQuery.split(" ", QString::SkipEmptyParts) + std::min(qsizetype(hasByString ? 2 : 1), tokens.size()); + tokens = cmdQuery.split(" ", Qt::SkipEmptyParts) .mid(frontCut, tokens.size()); QStringList args = tokens.join(" ").split( - ",", QString::SkipEmptyParts); + ",", Qt::SkipEmptyParts); args.removeDuplicates(); for (auto &arg : args) { @@ -806,7 +806,7 @@ template class STFLEngine else { QStringList args = rejoined.split( - ",", QString::SkipEmptyParts); + ",", Qt::SkipEmptyParts); if (isFilterCmd(cmd)) { suggs = getSuggestionsForFilterCSCmd(cmd, args); @@ -902,7 +902,7 @@ template class STFLEngine QStringList getSuggestionsForFilterCmd(const QString &cmd, const QString &argument) { - QStringList pool(filterPool[cmd].toList()); + QStringList pool(filterPool[cmd].values()); return sortStringsByStringEquality(pool, argument); } @@ -918,7 +918,7 @@ template class STFLEngine { last = args[args.size() - 1]; } - QStringList pool(filterCSPool[cmd].toList()); + QStringList pool(filterCSPool[cmd].values()); QStringList list = sortStringsByStringEquality(pool, last); for (QString &item : list) { @@ -1022,7 +1022,7 @@ template class STFLEngine void addQueryToStore(QString query) { QStringList storedCmds = getStoredCmds(); - QStringList cmds = query.split("#", QString::SkipEmptyParts); + QStringList cmds = query.split("#", Qt::SkipEmptyParts); cmds.removeDuplicates(); for (QString cmd : cmds) { @@ -1082,12 +1082,12 @@ template class STFLEngine { QMap weightedStrings; auto compareWithWords = - compareWith.split(" ", QString::SkipEmptyParts); + compareWith.split(" ", Qt::SkipEmptyParts); for (const QString &str : strings) { int strEqu = 0xFFFFFF; // infinity... for (auto word : - str.split(" ", QString::SkipEmptyParts)) + str.split(" ", Qt::SkipEmptyParts)) { auto wordA = word.leftJustified(15, ' '); for (const auto &word2 : compareWithWords) From d2f3ef229b9a9b8c79d168a3b39c7bf4e5383032 Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Tue, 6 Sep 2022 14:09:07 +0200 Subject: [PATCH 2/5] workaround non-existence of Qt::SplitBehavior for Qt versions less 5.15 --- modules/cvv/src/stfl/stfl_engine.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/cvv/src/stfl/stfl_engine.hpp b/modules/cvv/src/stfl/stfl_engine.hpp index 49b8af78c5..c361c93e97 100644 --- a/modules/cvv/src/stfl/stfl_engine.hpp +++ b/modules/cvv/src/stfl/stfl_engine.hpp @@ -22,6 +22,17 @@ #include "element_group.hpp" #include "../qtutil/util.hpp" + +// WORKAROUND: +// - Qt::SplitBehavior introduced in 5.14, QString::SplitBehavior was removed in Qt6 +// - Support required part of Qt::SplitBehavior from 5.15 for older Qt versions +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +namespace Qt { + static constexpr QString::SplitBehavior SkipEmptyParts = QString::SkipEmptyParts; +} +#endif + + namespace cvv { namespace stfl From 4e2846006450747875b0e156f6aaa53958ca4c5f Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Tue, 6 Sep 2022 14:18:25 +0200 Subject: [PATCH 3/5] workaround Qt5/Qt6 differences --- modules/cvv/src/qtutil/zoomableimage.cpp | 8 +++++++- modules/cvv/src/stfl/stfl_engine.hpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/cvv/src/qtutil/zoomableimage.cpp b/modules/cvv/src/qtutil/zoomableimage.cpp index 64abef1ea7..634fb88f48 100644 --- a/modules/cvv/src/qtutil/zoomableimage.cpp +++ b/modules/cvv/src/qtutil/zoomableimage.cpp @@ -398,7 +398,13 @@ QPointF ZoomableImage::mapImagePointToParent(QPointF point) const void ZoomableImage::mouseMoveEvent(QMouseEvent * event) { - QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(event->globalPosition().toPoint())); +#if QT_VERSION >= 0x060000 + QPoint pos = event->globalPosition().toPoint(); +#else + QPoint pos = event->globalPos(); +#endif + + QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(pos)); bool inImage=(imgPos.x()>=0) &&(imgPos.y()>=0) &&(imgPos.x()<=imageWidth()) diff --git a/modules/cvv/src/stfl/stfl_engine.hpp b/modules/cvv/src/stfl/stfl_engine.hpp index c361c93e97..1dc6167f7f 100644 --- a/modules/cvv/src/stfl/stfl_engine.hpp +++ b/modules/cvv/src/stfl/stfl_engine.hpp @@ -773,7 +773,7 @@ template class STFLEngine if (cmd == "group" || cmd == "sort") { int frontCut = - std::min(qsizetype(hasByString ? 2 : 1), tokens.size()); + std::min(qsizetype(hasByString ? 2 : 1), qsizetype(tokens.size())); tokens = cmdQuery.split(" ", Qt::SkipEmptyParts) .mid(frontCut, tokens.size()); QStringList args = tokens.join(" ").split( From 27132ad996874cbab949da9d8bc878ad1555c929 Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Tue, 6 Sep 2022 14:56:53 +0200 Subject: [PATCH 4/5] workaround differences between Qt 5.11 and later versions --- modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp b/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp index 06c65c92d8..60b1b11839 100644 --- a/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp +++ b/modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp @@ -19,10 +19,16 @@ ZoomableProxyObject::ZoomableProxyObject(ZoomableImage *zoom) void ZoomableProxyObject::wheelEvent(QGraphicsSceneWheelEvent *event) { QPoint delta{ event->delta(), 0 }; + QWheelEvent newEvent{ event->pos(), event->screenPos(), delta, delta, +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) event->buttons(), event->modifiers(), Qt::NoScrollPhase, true }; +#else + event->delta(), event->orientation(), + event->buttons(), event->modifiers() }; +#endif image_->wheelEvent(&newEvent); } From 7bfb4f7db1858d2e1de82a19a3a935ca108cf63f Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Wed, 16 Nov 2022 11:02:11 +0100 Subject: [PATCH 5/5] fix regressions for Qt 5.5 --- modules/cvv/src/qtutil/zoomableimage.cpp | 2 +- modules/cvv/src/stfl/stfl_engine.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cvv/src/qtutil/zoomableimage.cpp b/modules/cvv/src/qtutil/zoomableimage.cpp index 634fb88f48..ffc7e6f55d 100644 --- a/modules/cvv/src/qtutil/zoomableimage.cpp +++ b/modules/cvv/src/qtutil/zoomableimage.cpp @@ -398,7 +398,7 @@ QPointF ZoomableImage::mapImagePointToParent(QPointF point) const void ZoomableImage::mouseMoveEvent(QMouseEvent * event) { -#if QT_VERSION >= 0x060000 +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QPoint pos = event->globalPosition().toPoint(); #else QPoint pos = event->globalPos(); diff --git a/modules/cvv/src/stfl/stfl_engine.hpp b/modules/cvv/src/stfl/stfl_engine.hpp index 1dc6167f7f..1d1139c24d 100644 --- a/modules/cvv/src/stfl/stfl_engine.hpp +++ b/modules/cvv/src/stfl/stfl_engine.hpp @@ -773,7 +773,7 @@ template class STFLEngine if (cmd == "group" || cmd == "sort") { int frontCut = - std::min(qsizetype(hasByString ? 2 : 1), qsizetype(tokens.size())); + std::min(size_t(hasByString ? 2 : 1), size_t(tokens.size())); tokens = cmdQuery.split(" ", Qt::SkipEmptyParts) .mid(frontCut, tokens.size()); QStringList args = tokens.join(" ").split(