letsfindaway / OpenBoard

I'm using this fork to contribute features and fixes to the upstream project. In order to create good pull requests, I'm rebasing my feature branches, squashing and reordering commits, etc. If you fork this repository be aware that my development branches may rewrite history without prior notice.
http://openboard.ch/
GNU General Public License v3.0
9 stars 0 forks source link

[Architecture] Harmonize Board and Document thumbnails #190

Open letsfindaway opened 4 days ago

letsfindaway commented 4 days ago

Currently Board mode thumbnails and Document mode thumbnails are separate classes and even separate class hierarchies:

Board thumbnails

classDiagram
    QGraphicsPixmapItem <|-- UBThumbnailPixmapItem
    UBThumbnailPixmapItem <|-- UBDraggableThumbnailItem
    UBDraggableThumbnailItem <|-- UBDraggableLivePixmapItem

Document thumbnails

classDiagram
    QGraphicsPixmapItem <|-- UBThumbnailPixmap
    UBThumbnail <|-- UBThumbnailPixmap
    UBThumbnailPixmap <|-- UBSceneThumbnailPixmap
    UBSceneThumbnailPixmap <|-- UBSceneThumbnailNavigPixmap

But in the end I feel these classes have much in common and we should try to harmonize the class hierarchy as much as possible. If we could even manage to use the same objects for both, then this would further increase loading of a document and reduce memory usage, as we only have to create one kind of thumbnail items.

So the goal of this refactoring is not only to have common code for both kinds of thumbnails, but common instances, even if they have different properties in document mode and board mode. This also avoids that we have to take care about updating both kinds of thumbnails when pages are modified, added or deleted.

letsfindaway commented 3 days ago

Features of the derived classes

What features are added by which derived class? Here a short overview:

UBThumbnailPixmapItem

UBDraggableThumbnailItem

UBDraggableLivePixmapItem

UBThumbnail

UBThumbnailPixmap

Puh, mainly gluing the parent classes together

UBSceneThumbnailPixmap

Very similar to UBThumbnailPixmapItem

UBSceneThumbnailNavigPixmap

Very similar to UBDraggableThumbnailItem

letsfindaway commented 2 days ago

As I said, the aim is to have a common instance of the thumbnail for Document and Board mode. However an item can only be part of one scene. To achieve this we have two choices:

I find the second approach very appealing. The differences can be implemented by switching a class implementing the behavior of the thumbnails. The thumbnails delegate these functions to that class. For resizing the views we use the transformation from scene to view and do no longer scale the individual thumbnails. This does not work because we also have the page number below the pixmap, which must not be scaled. But that also does not seem to be a performance bottleneck as there are already holdoff timers avoiding too frequent rescaling.

We would have one such thumbnails scene for each document which we quickly want to switch to. If we have one document open in Board mode and are then searching around in Document mode, then the thumbnails of the Board mode document will still be there, so that we can quickly switch back. We can also think about keeping this scene for all previously opened documents, so that switching between favorites is very fast. Currently this takes some time for very large documents like the IPCC report, because the thumbnails have to be recreated. We should however include the thumbnails in our considerations about caching!

We would finally need

classDiagram
  direction LR
  class UBThumbnailDecorator
  <<Abstract>> UBThumbnailDecorator
  QGraphicsScene <|-- UBThumbnailScene
  UBThumbnailScene <-- UBDocumentThumbnails
  UBDocumentProxy <-- UBDocumentThumbnails
  UBItemGridLayout <-- UBThumbnailScene
  UBPageThumbnailItem "*" <-- UBDocumentThumbnails
  UBThumbnailScene <-- UBPageThumbnailItem
  QGraphicsItemGroup <|-- UBPageThumbnailItem
  QGraphicsPixmapItem <-- QGraphicsItemGroup
  QGraphicsTextItem <-- QGraphicsItemGroup
  UBThumbnailDecorator <-- UBThumbnailScene
  UBThumbnailDecorator <|-- UBDocumentThumbnailDecorator
  UBThumbnailDecorator <|-- UBBoardThumbnailDecorator

Mermaid class diagrams are not very intuitive, but let me explain it a little bit more.: