Skip to content

Commit 1754d03

Browse files
authored
Merge pull request #3285 from bebuch:4.x
make CVV module work with Qt6 * make CVV module work with Qt6 * workaround non-existence of Qt::SplitBehavior for Qt versions less 5.15 * workaround Qt5/Qt6 differences * workaround differences between Qt 5.11 and later versions * fix regressions for Qt 5.5
1 parent 9d84eae commit 1754d03

File tree

8 files changed

+60
-33
lines changed

8 files changed

+60
-33
lines changed

modules/cvv/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ endif()
55

66
set(the_description "Debug visualization framework")
77
ocv_add_module(cvv opencv_core opencv_imgproc opencv_features2d WRAP python)
8-
98
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow -Wmissing-declarations)
109

11-
# Qt5
10+
# Qt
11+
set(CVV_QT_MODULES Core Gui Widgets)
12+
if(QT_VERSION_MAJOR EQUAL 6)
13+
list(APPEND CVV_QT_MODULES Core5Compat)
14+
endif()
15+
16+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${CVV_QT_MODULES})
17+
1218
set(CMAKE_AUTOMOC ON)
1319
set(CMAKE_INCLUDE_CURRENT_DIR ON)
14-
foreach(dt5_dep Core Gui Widgets)
15-
add_definitions(${Qt5${dt5_dep}_DEFINITIONS})
16-
include_directories(${Qt5${dt5_dep}_INCLUDE_DIRS})
17-
list(APPEND CVV_LIBRARIES ${Qt5${dt5_dep}_LIBRARIES})
20+
foreach(module ${CVV_QT_MODULES})
21+
list(APPEND CVV_LIBRARIES ${Qt${QT_VERSION_MAJOR}${module}_LIBRARIES})
1822
endforeach()
1923

2024
ocv_glob_module_sources()

modules/cvv/src/qtutil/matchview/matchscene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void MatchScene::rightClick(const QPoint &pos)
153153
pmap = rightImage_->visibleImage();
154154
}
155155
}else{
156-
pmap = QPixmap::grabWidget(graphicView_->viewport());
156+
pmap = graphicView_->viewport()->grab();
157157
}
158158
pmap.save(fileName, 0, 100);
159159
}

modules/cvv/src/qtutil/matchview/singlecolorkeypointpen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SingleColorKeyPen::SingleColorKeyPen(std::vector<cv::KeyPoint>, QWidget *parent)
1515
auto layout = util::make_unique<QVBoxLayout>();
1616
auto button = util::make_unique<QPushButton>("Color Dialog");
1717

18-
layout->setMargin(0);
18+
layout->setContentsMargins(QMargins());
1919

2020
connect(colordia_, SIGNAL(currentColorChanged(const QColor &)), this,
2121
SLOT(updateColor(const QColor &)));

modules/cvv/src/qtutil/matchview/singlecolormatchpen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SingleColorMatchPen::SingleColorMatchPen(std::vector<cv::DMatch>, QWidget *paren
2323
connect(button.get(), SIGNAL(clicked(bool)), this,
2424
SLOT(colorButtonClicked()));
2525

26-
layout->setMargin(0);
26+
layout->setContentsMargins(QMargins());
2727
layout->addWidget(button.release());
2828

2929
setLayout(layout.release());

modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ ZoomableProxyObject::ZoomableProxyObject(ZoomableImage *zoom)
1919
void ZoomableProxyObject::wheelEvent(QGraphicsSceneWheelEvent *event)
2020
{
2121
QPoint delta{ event->delta(), 0 };
22+
2223
QWheelEvent newEvent{ event->pos(), event->screenPos(),
2324
delta, delta,
25+
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
26+
event->buttons(), event->modifiers(),
27+
Qt::NoScrollPhase, true };
28+
#else
2429
event->delta(), event->orientation(),
2530
event->buttons(), event->modifiers() };
31+
#endif
2632
image_->wheelEvent(&newEvent);
2733
}
2834

modules/cvv/src/qtutil/zoomableimage.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ ZoomableImage::ZoomableImage(const cv::Mat &mat, QWidget *parent)
205205
view_->setFocusPolicy(Qt::NoFocus);
206206
auto layout = util::make_unique<QHBoxLayout>();
207207
layout->addWidget(view.release());
208-
layout->setMargin(0);
208+
layout->setContentsMargins(QMargins());
209209
setLayout(layout.release());
210210
setMat(mat_);
211211
// rightklick
@@ -398,7 +398,13 @@ QPointF ZoomableImage::mapImagePointToParent(QPointF point) const
398398

399399
void ZoomableImage::mouseMoveEvent(QMouseEvent * event)
400400
{
401-
QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(event->globalPos()));
401+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
402+
QPoint pos = event->globalPosition().toPoint();
403+
#else
404+
QPoint pos = event->globalPos();
405+
#endif
406+
407+
QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(pos));
402408
bool inImage=(imgPos.x()>=0)
403409
&&(imgPos.y()>=0)
404410
&&(imgPos.x()<=imageWidth())

modules/cvv/src/qtutil/zoomableimage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class ZoomableImage : public QWidget
208208
*/
209209
QPixmap visibleImage() const
210210
{
211-
return QPixmap::grabWidget(view_->viewport());
211+
return view_->viewport()->grab();
212212
}
213213

214214
/**

modules/cvv/src/stfl/stfl_engine.hpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
#include "element_group.hpp"
2323
#include "../qtutil/util.hpp"
2424

25+
26+
// WORKAROUND:
27+
// - Qt::SplitBehavior introduced in 5.14, QString::SplitBehavior was removed in Qt6
28+
// - Support required part of Qt::SplitBehavior from 5.15 for older Qt versions
29+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
30+
namespace Qt {
31+
static constexpr QString::SplitBehavior SkipEmptyParts = QString::SkipEmptyParts;
32+
}
33+
#endif
34+
35+
2536
namespace cvv
2637
{
2738
namespace stfl
@@ -162,7 +173,7 @@ template <typename Element> class STFLEngine
162173
}
163174
QList<Element> elemList;
164175
QStringList cmdStrings =
165-
query.split("#", QString::SkipEmptyParts);
176+
query.split("#", Qt::SkipEmptyParts);
166177
elemList = executeFilters(elements, cmdStrings);
167178
elemList = executeSortCmds(elemList, cmdStrings);
168179
auto groups = executeGroupCmds(elemList, cmdStrings);
@@ -549,7 +560,7 @@ template <typename Element> class STFLEngine
549560
{
550561
using namespace std::placeholders;
551562
QStringList arr =
552-
cmdString.split(" ", QString::SkipEmptyParts);
563+
cmdString.split(" ", Qt::SkipEmptyParts);
553564
QString cmd;
554565
if (arr.empty())
555566
{
@@ -570,7 +581,7 @@ template <typename Element> class STFLEngine
570581
else if (isFilterCSCmd(cmd))
571582
{
572583
QStringList arguments = arr.join("").split(
573-
",", QString::SkipEmptyParts);
584+
",", Qt::SkipEmptyParts);
574585
std::for_each(arguments.begin(),
575586
arguments.end(), [](QString &str)
576587
{ str.replace("\\,", ","); });
@@ -609,7 +620,7 @@ template <typename Element> class STFLEngine
609620
for (QString cmdString : cmdStrings)
610621
{
611622
QStringList arr =
612-
cmdString.split(" ", QString::SkipEmptyParts);
623+
cmdString.split(" ", Qt::SkipEmptyParts);
613624
if (arr.size() < 2)
614625
{
615626
continue;
@@ -619,7 +630,7 @@ template <typename Element> class STFLEngine
619630
{
620631
arr.removeFirst();
621632
}
622-
arr = arr.join(" ").split(",", QString::SkipEmptyParts);
633+
arr = arr.join(" ").split(",", Qt::SkipEmptyParts);
623634
for (QString cmdPart : arr)
624635
{
625636
cmdPart = cmdPart.trimmed();
@@ -647,15 +658,15 @@ template <typename Element> class STFLEngine
647658
if (sortCmd.second)
648659
{
649660
auto sortFunc = sortFuncs[sortCmd.first];
650-
qStableSort(resList.begin(), resList.end(),
661+
std::stable_sort(resList.begin(), resList.end(),
651662
[&](const Element &elem1,
652663
const Element &elem2)
653664
{ return sortFunc(elem1, elem2); });
654665
}
655666
else
656667
{
657668
auto sortFunc = sortFuncs[sortCmd.first];
658-
qStableSort(resList.begin(), resList.end(),
669+
std::stable_sort(resList.begin(), resList.end(),
659670
[&](const Element &elem1,
660671
const Element &elem2)
661672
{ return sortFunc(elem2, elem1); });
@@ -675,7 +686,7 @@ template <typename Element> class STFLEngine
675686
for (QString cmdString : cmdStrings)
676687
{
677688
QStringList arr =
678-
cmdString.split(" ", QString::SkipEmptyParts);
689+
cmdString.split(" ", Qt::SkipEmptyParts);
679690
if (arr.size() < 2)
680691
{
681692
continue;
@@ -689,7 +700,7 @@ template <typename Element> class STFLEngine
689700
{
690701
arr.removeFirst();
691702
}
692-
arr = arr.join("").split(",", QString::SkipEmptyParts);
703+
arr = arr.join("").split(",", Qt::SkipEmptyParts);
693704
for (QString cmdPart : arr)
694705
{
695706
QStringList cmdPartList = cmdPart.split(" ");
@@ -720,7 +731,7 @@ template <typename Element> class STFLEngine
720731
for (auto it = groups.begin(); it != groups.end(); ++it)
721732
{
722733
ElementGroup<Element> elementGroup(
723-
it->first.split("\\|", QString::SkipEmptyParts),
734+
it->first.split("\\|", Qt::SkipEmptyParts),
724735
it->second);
725736
groupList.push_back(elementGroup);
726737
}
@@ -733,7 +744,7 @@ template <typename Element> class STFLEngine
733744
for (QString cmdString : cmdStrings)
734745
{
735746
QStringList arr =
736-
cmdString.split(" ", QString::SkipEmptyParts);
747+
cmdString.split(" ", Qt::SkipEmptyParts);
737748
if (arr.isEmpty())
738749
{
739750
continue;
@@ -743,7 +754,7 @@ template <typename Element> class STFLEngine
743754
{
744755
continue;
745756
}
746-
arr = arr.join("").split(",", QString::SkipEmptyParts);
757+
arr = arr.join("").split(",", Qt::SkipEmptyParts);
747758
additionalCommandFuncs[cmd](arr, groups);
748759
}
749760
}
@@ -762,11 +773,11 @@ template <typename Element> class STFLEngine
762773
if (cmd == "group" || cmd == "sort")
763774
{
764775
int frontCut =
765-
std::min(1 + (hasByString ? 1 : 0), tokens.size());
766-
tokens = cmdQuery.split(" ", QString::SkipEmptyParts)
776+
std::min(size_t(hasByString ? 2 : 1), size_t(tokens.size()));
777+
tokens = cmdQuery.split(" ", Qt::SkipEmptyParts)
767778
.mid(frontCut, tokens.size());
768779
QStringList args = tokens.join(" ").split(
769-
",", QString::SkipEmptyParts);
780+
",", Qt::SkipEmptyParts);
770781
args.removeDuplicates();
771782
for (auto &arg : args)
772783
{
@@ -806,7 +817,7 @@ template <typename Element> class STFLEngine
806817
else
807818
{
808819
QStringList args = rejoined.split(
809-
",", QString::SkipEmptyParts);
820+
",", Qt::SkipEmptyParts);
810821
if (isFilterCmd(cmd))
811822
{
812823
suggs = getSuggestionsForFilterCSCmd(cmd, args);
@@ -902,7 +913,7 @@ template <typename Element> class STFLEngine
902913
QStringList getSuggestionsForFilterCmd(const QString &cmd,
903914
const QString &argument)
904915
{
905-
QStringList pool(filterPool[cmd].toList());
916+
QStringList pool(filterPool[cmd].values());
906917
return sortStringsByStringEquality(pool, argument);
907918
}
908919

@@ -918,7 +929,7 @@ template <typename Element> class STFLEngine
918929
{
919930
last = args[args.size() - 1];
920931
}
921-
QStringList pool(filterCSPool[cmd].toList());
932+
QStringList pool(filterCSPool[cmd].values());
922933
QStringList list = sortStringsByStringEquality(pool, last);
923934
for (QString &item : list)
924935
{
@@ -1022,7 +1033,7 @@ template <typename Element> class STFLEngine
10221033
void addQueryToStore(QString query)
10231034
{
10241035
QStringList storedCmds = getStoredCmds();
1025-
QStringList cmds = query.split("#", QString::SkipEmptyParts);
1036+
QStringList cmds = query.split("#", Qt::SkipEmptyParts);
10261037
cmds.removeDuplicates();
10271038
for (QString cmd : cmds)
10281039
{
@@ -1082,12 +1093,12 @@ template <typename Element> class STFLEngine
10821093
{
10831094
QMap<int, QStringList> weightedStrings;
10841095
auto compareWithWords =
1085-
compareWith.split(" ", QString::SkipEmptyParts);
1096+
compareWith.split(" ", Qt::SkipEmptyParts);
10861097
for (const QString &str : strings)
10871098
{
10881099
int strEqu = 0xFFFFFF; // infinity...
10891100
for (auto word :
1090-
str.split(" ", QString::SkipEmptyParts))
1101+
str.split(" ", Qt::SkipEmptyParts))
10911102
{
10921103
auto wordA = word.leftJustified(15, ' ');
10931104
for (const auto &word2 : compareWithWords)

0 commit comments

Comments
 (0)