LeechCraft 0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
LC::Util::ViewSelectionTracker Class Reference

Tracks the row selection of a QAbstractItemView and reports it from a clean stack. More...

#include "viewselectiontracker.h"

Inheritance diagram for LC::Util::ViewSelectionTracker:
Collaboration diagram for LC::Util::ViewSelectionTracker:

Signals

void gestureStarted ()
 Emitted on a left mouse button press on the view's viewport.
void selectionStartedChanging ()
 Emitted synchronously when a change is detected that selectionChanging() will report.
void selectionChanging ()
 Emitted from a clean stack whenever the selection or the current row changes, or the model is reset.
void selectionSettled (const QModelIndexList &rows, const QModelIndex &current)
 Emitted from a clean stack once the selection has settled.

Public Member Functions

 ViewSelectionTracker (QAbstractItemView &, QObject *=nullptr)
bool eventFilter (QObject *, QEvent *) override
void EndGesture ()
 Ends the current left mouse button gesture, if any.

Detailed Description

Tracks the row selection of a QAbstractItemView and reports it from a clean stack.

Modifying a model in response to a selection change (like removing a news item or an email after it's been read and deselected) is unsafe inside the selection model's signals: those are also emitted from within the model's own structural changes, where Qt forbids further modification. Besides, the selection model updates the current index and the selection in separate steps, so a synchronous observer also sees intermediate states. Hence changes are coalesced and reported via selectionChanging() from a clean stack, before the next repaint.

Moreover, removing rows while the left mouse button is held shifts the rows under the press position the view's drag selection is anchored to, so model modifications shall wait for selectionSettled(), which is withheld until the button is released.

Note
The view's model and selection model must be set before constructing this object and never replaced afterwards.

Definition at line 41 of file viewselectiontracker.h.

Constructor & Destructor Documentation

◆ ViewSelectionTracker()

LC::Util::ViewSelectionTracker::ViewSelectionTracker ( QAbstractItemView & view,
QObject * parent = nullptr )
explicit

Definition at line 17 of file viewselectiontracker.cpp.

Member Function Documentation

◆ EndGesture()

void LC::Util::ViewSelectionTracker::EndGesture ( )

Ends the current left mouse button gesture, if any.

A press that turns into a drag never delivers its release to the viewport, so a view with drag enabled shall call this from its QAbstractItemView::startDrag() override, after the base implementation returns (that is, once the drag is over). Otherwise the tracker stays gated until the next click.

Definition at line 64 of file viewselectiontracker.cpp.

Referenced by eventFilter().

Here is the caller graph for this function:

◆ eventFilter()

bool LC::Util::ViewSelectionTracker::eventFilter ( QObject * ,
QEvent * ev )
override

Definition at line 38 of file viewselectiontracker.cpp.

References EndGesture(), and gestureStarted().

Here is the call graph for this function:

◆ gestureStarted

void LC::Util::ViewSelectionTracker::gestureStarted ( )
signal

Emitted on a left mouse button press on the view's viewport.

Referenced by eventFilter().

Here is the caller graph for this function:

◆ selectionChanging

void LC::Util::ViewSelectionTracker::selectionChanging ( )
signal

Emitted from a clean stack whenever the selection or the current row changes, or the model is reset.

Changes within one event loop iteration are coalesced into a single emission before the next repaint. This may be emitted while the left mouse button is held on the viewport, so receivers may update the display, but must not modify the model or the selection.

◆ selectionSettled

void LC::Util::ViewSelectionTracker::selectionSettled ( const QModelIndexList & rows,
const QModelIndex & current )
signal

Emitted from a clean stack once the selection has settled.

This follows selectionChanging(), but nothing is emitted while the left mouse button is held on the viewport. Receivers may modify the model.

Parameters
[out]rowsThe selected rows, as in QItemSelectionModel::selectedRows().
[out]currentThe current index, as in QItemSelectionModel::currentIndex().

◆ selectionStartedChanging

void LC::Util::ViewSelectionTracker::selectionStartedChanging ( )
signal

Emitted synchronously when a change is detected that selectionChanging() will report.

This is emitted from within the selection model's or the model's own signal, so receivers must not modify the model or the selection. This is intended for cancelling pending reactions to the previous selection, like stopping a timer.


The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/leechcraft-doc-0.6.70+git.19214.g121e5318a7-build/leechcraft-0.6.70-19214-g121e5318a7/src/util/gui/viewselectiontracker.h
  • /home/abuild/rpmbuild/BUILD/leechcraft-doc-0.6.70+git.19214.g121e5318a7-build/leechcraft-0.6.70-19214-g121e5318a7/src/util/gui/viewselectiontracker.cpp