QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
DeselectableTreeView Class Reference

A QTreeView that clears its selection, and emits emptyClicked(), when the user clicks empty space or an already-selected item. More...

#include <deselectabletreeview.h>

Inheritance diagram for DeselectableTreeView:
Collaboration diagram for DeselectableTreeView:

Signals

void emptyClicked ()
 Emitted after deselect() has cleared the selection because of a single click on empty space or on a selected row; MainWindow clears the password panel in response.

Public Member Functions

 DeselectableTreeView (QWidget *parent)
 Construct the view and arm the single-shot deselect timer.
 ~DeselectableTreeView () override=default
 Default destructor.

Private Member Functions

void mousePressEvent (QMouseEvent *event) override
 Remember whether the pressed row was already selected and cancel any pending deselect from the previous click.
void mouseReleaseEvent (QMouseEvent *event) override
 Let QTreeView handle the release at once, then, if the press was on a selected row and the release is over empty space or a still selected row, start deselectTimer.
void deselect ()
 Timer slot: clear the selection and current index and emit emptyClicked(), unless a double-click happened in the meantime.
void mouseDoubleClickEvent (QMouseEvent *event) override
 Cancel the pending deselect so the double-click opens the entry instead of clearing the selection.

Private Attributes

bool doubleClickHappened = false
 Set by mouseDoubleClickEvent() so a deselect() that fires after a double-click's first release does nothing.
bool clickSelected = false
 Whether the row under the last press was already selected; read and reset by the matching release.
QTimer deselectTimer
 Single-shot timer, started by a qualifying release for one double-click interval; its timeout runs deselect().

Detailed Description

A QTreeView that clears its selection, and emits emptyClicked(), when the user clicks empty space or an already-selected item.

The press records whether the row under the pointer was selected, the release handles selection immediately and arms a single-shot timer for the platform's double-click interval, and only when no double-click arrives in that time does deselect() clear the selection. Opening an entry by double-click therefore always wins over deselecting it.

Definition at line 29 of file deselectabletreeview.h.

Constructor & Destructor Documentation

◆ DeselectableTreeView()

DeselectableTreeView::DeselectableTreeView ( QWidget * parent)
inlineexplicit

Construct the view and arm the single-shot deselect timer.

Parameters
parentParent widget forwarded to QTreeView.

Definition at line 37 of file deselectabletreeview.h.

Here is the call graph for this function:

Member Function Documentation

◆ deselect()

void DeselectableTreeView::deselect ( )
inlineprivate

Timer slot: clear the selection and current index and emit emptyClicked(), unless a double-click happened in the meantime.

Definition at line 119 of file deselectabletreeview.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emptyClicked

void DeselectableTreeView::emptyClicked ( )
signal

Emitted after deselect() has cleared the selection because of a single click on empty space or on a selected row; MainWindow clears the password panel in response.

Here is the caller graph for this function:

◆ mouseDoubleClickEvent()

void DeselectableTreeView::mouseDoubleClickEvent ( QMouseEvent * event)
inlineoverrideprivate

Cancel the pending deselect so the double-click opens the entry instead of clearing the selection.

Parameters
eventThe double-click; forwarded to QTreeView.

Definition at line 133 of file deselectabletreeview.h.

◆ mousePressEvent()

void DeselectableTreeView::mousePressEvent ( QMouseEvent * event)
inlineoverrideprivate

Remember whether the pressed row was already selected and cancel any pending deselect from the previous click.

Parameters
eventThe mouse press; forwarded to QTreeView.

Definition at line 77 of file deselectabletreeview.h.

◆ mouseReleaseEvent()

void DeselectableTreeView::mouseReleaseEvent ( QMouseEvent * event)
inlineoverrideprivate

Let QTreeView handle the release at once, then, if the press was on a selected row and the release is over empty space or a still selected row, start deselectTimer.

Parameters
eventThe mouse release; forwarded to QTreeView first.

Definition at line 92 of file deselectabletreeview.h.

Member Data Documentation

◆ clickSelected

bool DeselectableTreeView::clickSelected = false
private

Whether the row under the last press was already selected; read and reset by the matching release.

Definition at line 65 of file deselectabletreeview.h.

◆ deselectTimer

QTimer DeselectableTreeView::deselectTimer
private

Single-shot timer, started by a qualifying release for one double-click interval; its timeout runs deselect().

Definition at line 70 of file deselectabletreeview.h.

◆ doubleClickHappened

bool DeselectableTreeView::doubleClickHappened = false
private

Set by mouseDoubleClickEvent() so a deselect() that fires after a double-click's first release does nothing.

Definition at line 60 of file deselectabletreeview.h.


The documentation for this class was generated from the following file: