Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make CVV module work with Qt6 #3285

Merged
merged 6 commits into from
Nov 16, 2022
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
16 changes: 10 additions & 6 deletions modules/cvv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion modules/cvv/src/qtutil/matchview/matchscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SingleColorKeyPen::SingleColorKeyPen(std::vector<cv::KeyPoint>, QWidget *parent)
auto layout = util::make_unique<QVBoxLayout>();
auto button = util::make_unique<QPushButton>("Color Dialog");

layout->setMargin(0);
layout->setContentsMargins(QMargins());

connect(colordia_, SIGNAL(currentColorChanged(const QColor &)), this,
SLOT(updateColor(const QColor &)));
Expand Down
2 changes: 1 addition & 1 deletion modules/cvv/src/qtutil/matchview/singlecolormatchpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SingleColorMatchPen::SingleColorMatchPen(std::vector<cv::DMatch>, QWidget *paren
connect(button.get(), SIGNAL(clicked(bool)), this,
SLOT(colorButtonClicked()));

layout->setMargin(0);
layout->setContentsMargins(QMargins());
layout->addWidget(button.release());

setLayout(layout.release());
Expand Down
6 changes: 6 additions & 0 deletions modules/cvv/src/qtutil/matchview/zoomableproxyobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 8 additions & 2 deletions modules/cvv/src/qtutil/zoomableimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ZoomableImage::ZoomableImage(const cv::Mat &mat, QWidget *parent)
view_->setFocusPolicy(Qt::NoFocus);
auto layout = util::make_unique<QHBoxLayout>();
layout->addWidget(view.release());
layout->setMargin(0);
layout->setContentsMargins(QMargins());
setLayout(layout.release());
setMat(mat_);
// rightklick
Expand Down Expand Up @@ -398,7 +398,13 @@ QPointF ZoomableImage::mapImagePointToParent(QPointF point) const

void ZoomableImage::mouseMoveEvent(QMouseEvent * event)
{
QPointF imgPos=view_->mapToScene(view_->mapFromGlobal(event->globalPos()));
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
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())
Expand Down
2 changes: 1 addition & 1 deletion modules/cvv/src/qtutil/zoomableimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class ZoomableImage : public QWidget
*/
QPixmap visibleImage() const
{
return QPixmap::grabWidget(view_->viewport());
return view_->viewport()->grab();
}

/**
Expand Down
53 changes: 32 additions & 21 deletions modules/cvv/src/stfl/stfl_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
bebuch marked this conversation as resolved.
Show resolved Hide resolved
}
#endif


namespace cvv
{
namespace stfl
Expand Down Expand Up @@ -162,7 +173,7 @@ template <typename Element> class STFLEngine
}
QList<Element> elemList;
QStringList cmdStrings =
query.split("#", QString::SkipEmptyParts);
query.split("#", Qt::SkipEmptyParts);
elemList = executeFilters(elements, cmdStrings);
elemList = executeSortCmds(elemList, cmdStrings);
auto groups = executeGroupCmds(elemList, cmdStrings);
Expand Down Expand Up @@ -549,7 +560,7 @@ template <typename Element> class STFLEngine
{
using namespace std::placeholders;
QStringList arr =
cmdString.split(" ", QString::SkipEmptyParts);
cmdString.split(" ", Qt::SkipEmptyParts);
QString cmd;
if (arr.empty())
{
Expand All @@ -570,7 +581,7 @@ template <typename Element> 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("\\,", ","); });
Expand Down Expand Up @@ -609,7 +620,7 @@ template <typename Element> class STFLEngine
for (QString cmdString : cmdStrings)
{
QStringList arr =
cmdString.split(" ", QString::SkipEmptyParts);
cmdString.split(" ", Qt::SkipEmptyParts);
if (arr.size() < 2)
{
continue;
Expand All @@ -619,7 +630,7 @@ template <typename Element> class STFLEngine
{
arr.removeFirst();
}
arr = arr.join(" ").split(",", QString::SkipEmptyParts);
arr = arr.join(" ").split(",", Qt::SkipEmptyParts);
for (QString cmdPart : arr)
{
cmdPart = cmdPart.trimmed();
Expand Down Expand Up @@ -647,15 +658,15 @@ template <typename Element> 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); });
}
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); });
Expand All @@ -675,7 +686,7 @@ template <typename Element> class STFLEngine
for (QString cmdString : cmdStrings)
{
QStringList arr =
cmdString.split(" ", QString::SkipEmptyParts);
cmdString.split(" ", Qt::SkipEmptyParts);
if (arr.size() < 2)
{
continue;
Expand All @@ -689,7 +700,7 @@ template <typename Element> class STFLEngine
{
arr.removeFirst();
}
arr = arr.join("").split(",", QString::SkipEmptyParts);
arr = arr.join("").split(",", Qt::SkipEmptyParts);
for (QString cmdPart : arr)
{
QStringList cmdPartList = cmdPart.split(" ");
Expand Down Expand Up @@ -720,7 +731,7 @@ template <typename Element> class STFLEngine
for (auto it = groups.begin(); it != groups.end(); ++it)
{
ElementGroup<Element> elementGroup(
it->first.split("\\|", QString::SkipEmptyParts),
it->first.split("\\|", Qt::SkipEmptyParts),
it->second);
groupList.push_back(elementGroup);
}
Expand All @@ -733,7 +744,7 @@ template <typename Element> class STFLEngine
for (QString cmdString : cmdStrings)
{
QStringList arr =
cmdString.split(" ", QString::SkipEmptyParts);
cmdString.split(" ", Qt::SkipEmptyParts);
if (arr.isEmpty())
{
continue;
Expand All @@ -743,7 +754,7 @@ template <typename Element> class STFLEngine
{
continue;
}
arr = arr.join("").split(",", QString::SkipEmptyParts);
arr = arr.join("").split(",", Qt::SkipEmptyParts);
additionalCommandFuncs[cmd](arr, groups);
}
}
Expand All @@ -762,11 +773,11 @@ template <typename Element> class STFLEngine
if (cmd == "group" || cmd == "sort")
{
int frontCut =
std::min(1 + (hasByString ? 1 : 0), tokens.size());
tokens = cmdQuery.split(" ", QString::SkipEmptyParts)
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(
",", QString::SkipEmptyParts);
",", Qt::SkipEmptyParts);
args.removeDuplicates();
for (auto &arg : args)
{
Expand Down Expand Up @@ -806,7 +817,7 @@ template <typename Element> class STFLEngine
else
{
QStringList args = rejoined.split(
",", QString::SkipEmptyParts);
",", Qt::SkipEmptyParts);
if (isFilterCmd(cmd))
{
suggs = getSuggestionsForFilterCSCmd(cmd, args);
Expand Down Expand Up @@ -902,7 +913,7 @@ template <typename Element> class STFLEngine
QStringList getSuggestionsForFilterCmd(const QString &cmd,
const QString &argument)
{
QStringList pool(filterPool[cmd].toList());
QStringList pool(filterPool[cmd].values());
return sortStringsByStringEquality(pool, argument);
}

Expand All @@ -918,7 +929,7 @@ template <typename Element> 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)
{
Expand Down Expand Up @@ -1022,7 +1033,7 @@ template <typename Element> 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)
{
Expand Down Expand Up @@ -1082,12 +1093,12 @@ template <typename Element> class STFLEngine
{
QMap<int, QStringList> 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)
Expand Down