Conversation
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.
Qvariant less than
Fix clazy warnings
Expression role caching
| 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 | ||
| } |
There was a problem hiding this comment.
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
|
@RaymiiOrg I have been using these changes for an ongoing project that I am working on. I came across a well known warning
May I know if I am missing something in my implementation or do I need to filter my text from these special characters? |
|
Great Effort! I really need this! |
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.