Skip to content

dirmodel: Replace QFileSystemModel with QAbstractItemModel and fix warnings#70

Merged
sjg20 merged 18 commits intomasterfrom
devb
Mar 8, 2026
Merged

dirmodel: Replace QFileSystemModel with QAbstractItemModel and fix warnings#70
sjg20 merged 18 commits intomasterfrom
devb

Conversation

@sjg20
Copy link
Copy Markdown
Owner

@sjg20 sjg20 commented Mar 8, 2026

Summary

  • Replace QFileSystemModel with QAbstractItemModel using synchronous QDir scanning via a DirNode tree structure, fixing subdirectory loading issues
  • Add Dirview tests with two separate repositories and file expansion tests
  • Clean up the build: remove debug mode, fix the clean target to remove paperman-server and root .o files
  • Fix all compiler warnings exposed by -O2: uninitialised variables, longjmp clobber, null-pointer dereference, unused parameters
  • Show filenames in permission/group error messages for easier debugging
  • Fix infinite recursion in SaneFixedSpinBox and QDouble100SpinBox selectAll()

Test plan

  • All 70 tests pass across 6 suites (utils, ops, dirmodel, dirview, searchserver, ocrsearch)
  • Zero compiler warnings with -O2 -Wall -Wextra
  • make clean removes paperman-server and root .o files
  • Each commit is bisect-safe (tests pass at every commit)

🤖 Generated with Claude Code

sjg20 added 18 commits March 8, 2026 16:24
The error messages from utilSetDirGroup() and utilSetGroup() do not
include the filename, making it hard to diagnose failures. Add the
filename to all four messages.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
The debug flag causes paperman to build with -g instead of -O2, which
hides warnings that only appear with optimisation enabled, such as
-Wmaybe-uninitialized and -Wclobbered. Remove it so that both paperman
and paperman-server build with the same flags.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
The selectAll() override calls itself instead of the parent
QSpinBox::selectAll(), causing infinite recursion.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
The selectAll() override calls itself instead of the parent
QSpinBox::selectAll(), causing infinite recursion.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Comparing 'this' to NULL is meaningless in well-defined C++ and
produces a -Wnonnull-compare warning.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
The poppler-qt5 headers use the deprecated QLinkedList, producing
warnings that cannot be fixed in project code. Wrap the include with
pragma to suppress -Wdeprecated-declarations.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Mark variables that cross setjmp() as volatile to fix -Wclobbered
warnings. Check the return value of fread() and handle failure instead
of ignoring it.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Mark the dest parameter as volatile since it crosses a setjmp()
boundary.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Initialise variables that the compiler cannot prove are always set
before use: len, dest, ch and a2 in add_preview(), rle_encode() and
Fax3Encode2DRow() respectively.

Drop the bogus assert(this || ptr) which compares this to NULL; just
assert(ptr) instead.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
The list parameter is only used inside #ifndef QT_NO_DEBUG, so it is
unused in release builds. Add Q_UNUSED() to suppress the warning.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Initialise qgb to nullptr since the default case in the switch does
not set it.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Initialise ok to false in both saveImage() overloads since the PNM
branch does not set it.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
After the while(ci) loop, ci is always null, so the comparison
if(ci == item(0)) can only be true if item(0) is also null, making
the ci-> calls inside undefined behaviour. Fix by re-fetching item(0)
and null-checking it.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
The qmake-generated Makefile only removes object files on 'clean',
leaving the binary behind. Add it to the GNUmakefile clean target.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Add a new TestDirview suite that tests Dirview with a Dirmodel and
Dirproxy, using two independent repositories with different directory
structures. The tests verify context selection, menu getters, directory
expansion with visual-rect visibility checks, and the clicked signal.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Add files alongside the directory structures to make the tests more
realistic. This exposes a bug where subdirectory expansion does not work
because QFileSystemModel with an empty root path cannot load directory
contents below the first level. The subdirectory expansion check is
marked as XFAIL until the fix is in place.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
QFileSystemModel with an empty root path cannot load directory
contents below the first level. This means that expanding
subdirectories in the dir tree shows nothing. The async loading
model is fundamentally incompatible with Dirmodel's virtual-root
architecture.

Replace the QFileSystemModel inheritance with QAbstractItemModel
and synchronous QDir scanning. Introduce a DirNode tree structure
that manages the directory hierarchy directly:

- Add DirNode struct with lazy population via populateNode()
- Scan directories synchronously with QDir on first access
- Re-scan on miss in findPath() to handle external changes
- Remove waitForLoaded(), createRootIndex(), itemRootIndex()
- Remove Diritem's QFileSystemModel dependency (_model, _root)
- Add Dirmodel::FilePathRole/FileNameRole enum (same values as
  QFileSystemModel for compatibility)
- Add rmdir(), fileName() methods previously inherited
- Update all external references in desktopwidget and dirview

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
@sjg20 sjg20 merged commit cb4324e into master Mar 8, 2026
2 checks passed
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.

1 participant