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

Qt6 & Qt5 version #100

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Qt6 & Qt5 version #100

wants to merge 23 commits into from

Conversation

RaymiiOrg
Copy link

@RaymiiOrg RaymiiOrg commented Jul 18, 2023

This build incorporates fixes from MenloSystems ( @olafmandel ) and compiles under Qt5.15 and Qt6.5 (without warnings). A GitHub Actions file is included to build under Qt5 an Qt6.

I havent ran the tests yet but that could be incorporated into the GitHub actions runner. The project seems dead so i'm unsure of that is worth the effort.

olafmandel and others added 23 commits October 27, 2020 16:56
Qt 5.15 deprecated the operator<(QVariant, QVariant). Do get rid of the
warning and to prepare for the eventual removal of the operator,
implement our own needs in a lessThan() function.

The function is based on the description of
QSortFilterProxyModel::lessThan().

Fixes oKcerG#77
The PatternSyntax enum had to be removed as QRegularExpression only
supports Perl-compatible regular expressions.

As QVariant's comparison operators were removed, a simplified
comparison is now done as a starting point, but should probably
be extended to support more types.

Fixes oKcerG#84
Fixes oKcerG#86
cmake: fix c++17 build requirement for msvc
I was getting the following error:

/usr/bin/ld: isle/3rdparty/SortFilterProxyModel/CMakeFiles/SortFilterProxyModel.dir/SortFilterProxyModel_autogen/mocs_compilation.cpp.o: relocation R_X86_64_PC32 against symbol `__asan_option_detect_stack_use_after_return' can not be used when making a shared object; recompile with -fPIC

And:

/home/mitch/dev/bgv/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.cpp:1: error: In included file: "You must build your code with position independent code if Qt was configured with -reduce-relocations. "         "Compile your code with -fPIC (and not with -fPIE)."

Initially I fixed this with:

    set(CMAKE_POSITION_INDEPENDENT_CODE ON)

but was told the proper solution is to add the missing
target_link_libraries.
In Qt5, QVariant has attempted to convert differing types in order
to evaluate equality. This has been useful when integrating with
QML, so restore that behavior.
The method `QVariant::Type QVariant::type() const` has been deprecated
since Qt 6.0. The recommended replacement is `typeId()` or `metaType()`,
but these are not available under Qt5. So choose to use `userType()`
instead, which is available under both and should cover the use cases as
well.
Comment on lines +7 to +61
int compareVariants(const QVariant &lhs, const QVariant &rhs)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // qt 5
// Do the QString check first because otherwise the canConvert<int> check will get hit for strings.
if (static_cast<QMetaType::Type>(lhs.type()) == QMetaType::QString && static_cast<QMetaType::Type>(rhs.type()) == QMetaType::QString) {
const auto lhsValue = lhs.toString();
const auto rhsValue = rhs.toString();
if (lhsValue == rhsValue)
return 0;
return lhsValue.compare(rhsValue, Qt::CaseInsensitive);
} else if (static_cast<QMetaType::Type>(lhs.type()) == QMetaType::Bool && static_cast<QMetaType::Type>(rhs.type()) == QMetaType::Bool) {
const auto lhsValue = lhs.toBool();
const auto rhsValue = rhs.toBool();
if (lhsValue == rhsValue)
return 0;
// false < true.
return !lhsValue ? -1 : 1;
} else if (static_cast<QMetaType::Type>(lhs.type()) == QMetaType::QDate && static_cast<QMetaType::Type>(rhs.type()) == QMetaType::QDate) {
const auto lhsValue = lhs.toDate();
const auto rhsValue = rhs.toDate();
if (lhsValue == rhsValue)
return 0;
return lhsValue < rhsValue ? -1 : 1;
} else if (static_cast<QMetaType::Type>(lhs.type()) == QMetaType::QDateTime && static_cast<QMetaType::Type>(rhs.type()) == QMetaType::QDateTime) {
const auto lhsValue = lhs.toDateTime();
const auto rhsValue = rhs.toDateTime();
if (lhsValue == rhsValue)
return 0;
return lhsValue < rhsValue ? -1 : 1;
} else if (static_cast<QMetaType::Type>(lhs.type()) == QMetaType::QStringList && static_cast<QMetaType::Type>(rhs.type()) == QMetaType::QStringList) {
const auto lhsValue = lhs.toStringList();
const auto rhsValue = rhs.toStringList();
if (lhsValue == rhsValue)
return 0;
return lhsValue < rhsValue ? -1 : 1;
} else if (lhs.canConvert<int>() && rhs.canConvert<int>()) {
const auto lhsValue = lhs.toInt();
const auto rhsValue = rhs.toInt();
if (lhsValue == rhsValue)
return 0;
return lhsValue < rhsValue ? -1 : 1;
} else if (lhs.canConvert<qreal>() && rhs.canConvert<qreal>()) {
const auto lhsValue = lhs.toReal();
const auto rhsValue = rhs.toReal();
if (qFuzzyCompare(lhsValue, rhsValue))
return 0;
return lhsValue < rhsValue ? -1 : 1;
}

qWarning() << "Don't know how to compare" << lhs << "against" << rhs << "- returning 0";
return 0;
#else
return QPartialOrdering::Less == QVariant::compare(lhs, rhs);
#endif
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code as is written is quite hard to read for no real reason. it should need at least

const auto lhsType = static_cast<QMetaType::Type>(lhs.type());
const auto rhsType = static_cast<QMetaType::Type>(rhs.type());
const bool sameType = (lhsType == rhsType);

at the beginning of the function, which would greatly simplify the if statements

@srijanc
Copy link

srijanc commented Oct 4, 2023

@RaymiiOrg I have been using these changes for an ongoing project that I am working on. I came across a well known warning QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object which occurs if the RegExpFilter property pattern contains a special character which has a meaning within a regular expression, in my case ( or ) or [ or ] . The warning is thrown in multiple times and then it stops and the list model fails to produce correct result

  • Here is a sample code of my RegExpFilter:
                RegExpFilter {
                    roleName: "firstName"
                    pattern: "Aaron Stevens - 123132542 ("
                    caseSensitivity: Qt.CaseInsensitive
                }

May I know if I am missing something in my implementation or do I need to filter my text from these special characters?
Just to confirm, no such warnings were observed when using the released version of SortFilterProxyModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants