Skip to content

COMP/PERF: Qt deprecation fixes and range-loop detach prevention - #1382

Merged
jamesobutler merged 4 commits into
commontk:masterfrom
BRAINSia:clazy-fixes-part1
Mar 29, 2026
Merged

COMP/PERF: Qt deprecation fixes and range-loop detach prevention#1382
jamesobutler merged 4 commits into
commontk:masterfrom
BRAINSia:clazy-fixes-part1

Conversation

@hjmjohnson

Copy link
Copy Markdown
Contributor

Summary

  • COMP: Replace deprecated QAbstractItemModel::invalidateFilter() with beginFilterChange()/endFilterChange() (Qt 6.0+)
  • COMP: Replace deprecated QImage::mirrored() with flipped() (Qt 6.0+)
  • COMP: Replace deprecated Q_ENUMS with Q_ENUM (deprecated since Qt 5.5)
  • PERF: Prevent implicit container detach in range-for loops using std::as_const() (clazy range-loop-detach)

These are the first four commits from #1372 extracted for focused review.

Test plan

  • All 4 commits build cleanly (verified individually via per-commit build check)
  • Qt5 and Qt6 test suites pass with no new failures
  • No new compiler warnings introduced

🤖 Generated with Claude Code

@hjmjohnson

Copy link
Copy Markdown
Contributor Author

@jamesobutler making smaller PRs to make these easier to review. These are all part of the same effort in #1372

Comment thread Libs/DICOM/Core/ctkDICOMFilterProxyModel.cpp Outdated

@jamesobutler jamesobutler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

COMP: Replace deprecated QImage::mirrored() with flipped()

Qt 6.9 deprecated QImage::mirrored() in favor of flipped(Qt::Orientations).
Use #if QT_VERSION guards to select the appropriate API while maintaining
Qt5 compatibility.

^Not sure if you care to change the logic, or just make a note in the commit message, but mirrored() was marked deprecated in Qt 6.9, but then changed in Qt 6.10 to indicate that it was now scheduled for deprecation starting with Qt 6.13, thereby un-deprecating it for a bit. See qt/qtbase@0aa07ce

Comment thread Libs/CommandLineModules/Core/ctkCmdLineModuleFrontend.h Outdated
hjmjohnson and others added 4 commits March 28, 2026 21:02
…dFilterChange

Qt 6.10 deprecated QSortFilterProxyModel::invalidateFilter() in favor of
the beginFilterChange()/endFilterChange() pair. Use #if QT_VERSION guards
to select the appropriate API while maintaining Qt5 and Qt6 <6.10 compat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lity

QImage::flipped(Qt::Orientations) was introduced in Qt 6.9. While
QImage::mirrored() was briefly annotated as deprecated in Qt 6.9 and then
un-deprecated in Qt 6.10 (scheduled for removal from Qt 6.13), the newer
flipped() API is clearer in intent and is the recommended replacement going
forward. Use #if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0) guards to select
the appropriate API while maintaining Qt5 compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
•	Requires explicit declaration of the enum in Q_ENUMS(...).
•	Does not support compile-time introspection via QMetaEnum::fromType<T>().
•	Print conversions via qDebug() or QVariant conversions not automatically supported.

•	Replace all Q_ENUMS(...) with Q_ENUM(...) in your QObject classes.
•	Make sure the enum is declared immediately before the Q_ENUM macro.
•	After migration, there is seamless integration into Qt’s meta-object system, better introspection, and compatibility with modern Qt5 (5.5+) and Qt6.
Use std::as_const() or const local variables to ensure range-for loops
call the const begin()/end() overloads, avoiding unnecessary COW detach
on implicitly shared Qt containers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hjmjohnson

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review @jamesobutler! Addressed all three points:

  1. beginFilterChange() guard — Fixed to use >= Qt 6.9 (commit 9cbf246a). You're right that beginFilterChange() was introduced in 6.9; I've updated all four filter setters so beginFilterChange() is called for Qt 6.9+ while endFilterChange() remains guarded at Qt 6.10+. For Qt 6.9, the sequence is beginFilterChange() → update field → invalidateFilter().

  2. QImage::mirrored() commit message — Updated (commit aba272b4) to clarify that flipped() was introduced in Qt 6.9 while mirrored() was briefly deprecated, then un-deprecated in Qt 6.10 (scheduled for removal from Qt 6.13). The guards remain at >= 6.9 since flipped() is the recommended forward-going API.

  3. Q_ENUM(ParamterValueRole) typo — Fixed in commit e2361bc8. The misplaced/typo'd Q_ENUM before the enum declaration was removed; the correct Q_ENUM(ParameterValueRole) after the enum closing brace remains.

Force-pushed to clazy-fixes-part1.

@hjmjohnson
hjmjohnson requested a review from jamesobutler March 29, 2026 02:18
@jamesobutler
jamesobutler merged commit 819105c into commontk:master Mar 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants