![]() |
LeechCraft 0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
|
Tracks the row selection of a QAbstractItemView and reports it from a clean stack. More...
#include "viewselectiontracker.h"
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 ¤t) |
| 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. | |
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.
Definition at line 41 of file viewselectiontracker.h.
|
explicit |
Definition at line 17 of file viewselectiontracker.cpp.
| 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().
|
override |
Definition at line 38 of file viewselectiontracker.cpp.
References EndGesture(), and gestureStarted().
|
signal |
Emitted on a left mouse button press on the view's viewport.
Referenced by eventFilter().
|
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.
|
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.
| [out] | rows | The selected rows, as in QItemSelectionModel::selectedRows(). |
| [out] | current | The current index, as in QItemSelectionModel::currentIndex(). |
|
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.