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

The password store as shown in the tree: the QFileSystemModel, the StoreModel proxy on top of it and the QTreeView they drive, with the path questions the main window keeps asking. More...

#include <storetree.h>

Inheritance diagram for StoreTree:
Collaboration diagram for StoreTree:

Signals

void directoryLoaded (const QString &path)
 The file system model the view shows finished listing a folder; also once for the store root after reload() swapped models.
void currentEntryLost (const QString &path)
 After a reload() the current entry or folder could not be shown again: it was removed or renamed, or its folder was not listed yet. Nothing is current then, so currentDir() gives the store root, and a menu opened on that entry must not act on the root instead. One that still exists is made current again if it shows once the listings still under way at the swap are in.

Public Member Functions

 StoreTree (QTreeView *view, QObject *parent=nullptr)
 Attach the proxy model to the view and set its look: hidden header, indentation, scroll bars, context-menu policy. Column hiding and sorting need a source model and happen in setStore().
void setStore (const QString &path)
 Point everything at path: file system root, proxy store and view root index. Also drops a search filter.
void reload ()
 List the store again in a fresh file system model and swap it in once the store root and every folder listed before (expanded or not, so a search still sees inside it) are listed again, keeping the expanded folders, the current entry and the scroll position. Runs by itself a moment after a listed folder changed.
void setPass (Pass *pass)
 Hand the proxy the backend it drops onto.
void setFilter (const QRegularExpression &pattern)
 Filter the visible entries.
auto dirFor (const QModelIndex &index, bool forPass) const -> QString
 The folder an index stands for.
auto currentDir (bool forPass) const -> QString
 dirFor() applied to the view's current index.
auto fileFor (const QModelIndex &index, bool forPass) const -> QString
 The entry an index stands for.
auto currentFile (bool forPass) const -> QString
 fileFor() applied to the view's current index.
auto fileInfo (const QModelIndex &index) const -> QFileInfo
 File system information for a view index.
auto indexFor (const QString &path) const -> QModelIndex
 The view index for an absolute path, or invalid when the file system model does not (yet) know it.
auto rootIndex () -> QModelIndex
 The proxy's root index for the current store.
auto currentIndex () const -> QModelIndex
 The view's current index.
auto store () const -> QString
auto proxy () -> StoreModel &
auto fileSystem () -> QFileSystemModel &
auto view () const -> QTreeView *

Private Member Functions

auto makeModel () -> std::unique_ptr< QFileSystemModel >
 A file system model as the tree uses it: *.gpg only, and not watching (see the class description).
void setUpColumns ()
 Hide the size, type and date columns and sort by name, once a source model is attached.
void watchDir (const QString &dir)
 Watch dir from now on, as the shown model has listed it.
void swapInFresh ()
 Swap in the model reload() built, restoring the view.
auto expandedDirs () const -> QStringList
 The watched folders the view shows expanded, for swapInFresh().
void unwatchGoneDirs ()
 Stop watching the folders that no longer exist.
void shownListed (const QString &path)
 The shown model listed path: watch it, list it in a model being built too, and filter again once the listings a swap did not wait for are done.
void restoreCurrent ()
 Make the entry a swap could not show current again, once it shows. The wait ends when the listings the swap did not wait for are in, or when another entry is made current, even one deselected since.

Private Attributes

QTreeView * m_view
 The tree view this object drives; owned by the main window.
std::unique_ptr< QFileSystemModel > m_fs
 Source model over the store directory, filtered to *.gpg; replaced by setStore() and reload().
std::unique_ptr< QFileSystemModel > m_retired
 The model reload() replaced, kept until the next one: a caller still holding it reads stale rows instead of freed memory.
std::unique_ptr< QFileSystemModel > m_fresh
 The model reload() is building, until it is swapped in.
QSet< QString > m_freshPending
 Folders m_fresh still has to list before the swap.
QSet< QString > m_stillListing
 Folders still being listed when m_fresh was swapped in.
QString m_restoreCurrent
 The current entry a swap could not show yet.
bool m_reloadAgain = false
 A reload() came while m_fresh was built: run one after it.
QTimer m_freshDeadline
 Ends the wait for m_fresh: it is swapped in as it is.
QFileSystemWatcher m_watcher
 The folders the shown model has listed; reload() lists all of them again.
QTimer m_reloadTimer
 Waits for the watched folders to be quiet, then reload().
StoreModel m_proxy
 Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop.
QString m_store
 Absolute store directory last passed to setStore().

Friends

class tst_storetree
class tst_mainwindow

Detailed Description

The password store as shown in the tree: the QFileSystemModel, the StoreModel proxy on top of it and the QTreeView they drive, with the path questions the main window keeps asking.

Owns the two models. setStore() is the one place that re-roots the file system model, the proxy and the view together (this sequence used to be spelled out five times); dirFor()/fileFor() are the two path mappings that were duplicated across MainWindow and Util.

The file system model does not watch the store itself: when files in a folder it lists change, Qt finds each changed row by a linear search, so a pulled commit that rewrote N entries of one folder froze the window for on the order of N² comparisons (half a minute for 20000). StoreTree watches the folders the model has listed instead and, once they have been quiet for a moment, builds a fresh model (reload()), which costs time linear in what it lists.

Definition at line 46 of file storetree.h.

Constructor & Destructor Documentation

◆ StoreTree()

StoreTree::StoreTree ( QTreeView * view,
QObject * parent = nullptr )
explicit

Attach the proxy model to the view and set its look: hidden header, indentation, scroll bars, context-menu policy. Column hiding and sorting need a source model and happen in setStore().

Parameters
viewThe tree view to drive.
parentOwner.

Definition at line 16 of file storetree.cpp.

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

Member Function Documentation

◆ currentDir()

auto StoreTree::currentDir ( bool forPass) const -> QString
nodiscard

dirFor() applied to the view's current index.

Parameters
forPassAs in dirFor().
Returns
Folder path.

Definition at line 313 of file storetree.cpp.

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

◆ currentEntryLost

void StoreTree::currentEntryLost ( const QString & path)
signal

After a reload() the current entry or folder could not be shown again: it was removed or renamed, or its folder was not listed yet. Nothing is current then, so currentDir() gives the store root, and a menu opened on that entry must not act on the root instead. One that still exists is made current again if it shows once the listings still under way at the swap are in.

Parameters
pathAbsolute path the current entry had.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentFile()

auto StoreTree::currentFile ( bool forPass) const -> QString
nodiscard

fileFor() applied to the view's current index.

Parameters
forPassAs in fileFor().
Returns
Entry name or path.

Definition at line 331 of file storetree.cpp.

Here is the call graph for this function:

◆ currentIndex()

auto StoreTree::currentIndex ( ) const -> QModelIndex
nodiscard

The view's current index.

Returns
Proxy index, possibly invalid.

Definition at line 348 of file storetree.cpp.

◆ directoryLoaded

void StoreTree::directoryLoaded ( const QString & path)
signal

The file system model the view shows finished listing a folder; also once for the store root after reload() swapped models.

Parameters
pathAbsolute folder path.
Here is the caller graph for this function:

◆ dirFor()

auto StoreTree::dirFor ( const QModelIndex & index,
bool forPass ) const -> QString
nodiscard

The folder an index stands for.

Parameters
indexView index; a file maps to its folder, an invalid index to the store root.
forPasstrue for a store-relative path ("" for the root), false for an absolute one.
Returns
Folder path ending in the native separator (see forPass).

Definition at line 297 of file storetree.cpp.

Here is the caller graph for this function:

◆ expandedDirs()

auto StoreTree::expandedDirs ( ) const -> QStringList
nodiscardprivate

The watched folders the view shows expanded, for swapInFresh().

Returns
Their absolute paths, parents before their children.

Definition at line 169 of file storetree.cpp.

Here is the caller graph for this function:

◆ fileFor()

auto StoreTree::fileFor ( const QModelIndex & index,
bool forPass ) const -> QString
nodiscard

The entry an index stands for.

Parameters
indexView index; folders and invalid indexes yield an empty string.
forPasstrue for the pass name (store-relative, no .gpg), false for the absolute .gpg path.
Returns
Entry name or path, empty when index is not a file.

Definition at line 317 of file storetree.cpp.

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

◆ fileInfo()

auto StoreTree::fileInfo ( const QModelIndex & index) const -> QFileInfo
nodiscard

File system information for a view index.

Parameters
indexView index.
Returns
QFileInfo of the underlying path.

Definition at line 335 of file storetree.cpp.

Here is the caller graph for this function:

◆ fileSystem()

auto StoreTree::fileSystem ( ) -> QFileSystemModel &
inlinenodiscard
Returns
The file system model under the proxy; reload() replaces it.

Definition at line 156 of file storetree.h.

Here is the caller graph for this function:

◆ indexFor()

auto StoreTree::indexFor ( const QString & path) const -> QModelIndex
nodiscard

The view index for an absolute path, or invalid when the file system model does not (yet) know it.

Parameters
pathAbsolute path inside the store.
Returns
Proxy index.

Definition at line 339 of file storetree.cpp.

Here is the caller graph for this function:

◆ makeModel()

auto StoreTree::makeModel ( ) -> std::unique_ptr< QFileSystemModel >
private

A file system model as the tree uses it: *.gpg only, and not watching (see the class description).

Returns
The new model, not rooted yet.

Definition at line 51 of file storetree.cpp.

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

◆ proxy()

auto StoreTree::proxy ( ) -> StoreModel &
inlinenodiscard
Returns
The proxy the view shows.

Definition at line 154 of file storetree.h.

Here is the caller graph for this function:

◆ reload()

void StoreTree::reload ( )

List the store again in a fresh file system model and swap it in once the store root and every folder listed before (expanded or not, so a search still sees inside it) are listed again, keeping the expanded folders, the current entry and the scroll position. Runs by itself a moment after a listed folder changed.

Definition at line 138 of file storetree.cpp.

Here is the call graph for this function:

◆ restoreCurrent()

void StoreTree::restoreCurrent ( )
private

Make the entry a swap could not show current again, once it shows. The wait ends when the listings the swap did not wait for are in, or when another entry is made current, even one deselected since.

Definition at line 119 of file storetree.cpp.

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

◆ rootIndex()

auto StoreTree::rootIndex ( ) -> QModelIndex
nodiscard

The proxy's root index for the current store.

Returns
Proxy index of the store root.

Definition at line 344 of file storetree.cpp.

Here is the caller graph for this function:

◆ setFilter()

void StoreTree::setFilter ( const QRegularExpression & pattern)

Filter the visible entries.

Parameters
patternRegular expression matched against entry names; an invalid or empty one shows everything.

Definition at line 290 of file storetree.cpp.

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

◆ setPass()

void StoreTree::setPass ( Pass * pass)

Hand the proxy the backend it drops onto.

Parameters
passActive backend (not owned).

Definition at line 288 of file storetree.cpp.

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

◆ setStore()

void StoreTree::setStore ( const QString & path)

Point everything at path: file system root, proxy store and view root index. Also drops a search filter.

Parameters
pathPassword store directory.

Definition at line 256 of file storetree.cpp.

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

◆ setUpColumns()

void StoreTree::setUpColumns ( )
private

Hide the size, type and date columns and sort by name, once a source model is attached.

Definition at line 72 of file storetree.cpp.

Here is the caller graph for this function:

◆ shownListed()

void StoreTree::shownListed ( const QString & path)
private

The shown model listed path: watch it, list it in a model being built too, and filter again once the listings a swap did not wait for are done.

Parameters
pathAbsolute folder path.

Definition at line 90 of file storetree.cpp.

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

◆ store()

auto StoreTree::store ( ) const -> QString
inlinenodiscard
Returns
The store directory set with setStore().

Definition at line 152 of file storetree.h.

◆ swapInFresh()

void StoreTree::swapInFresh ( )
private

Swap in the model reload() built, restoring the view.

Definition at line 198 of file storetree.cpp.

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

◆ unwatchGoneDirs()

void StoreTree::unwatchGoneDirs ( )
private

Stop watching the folders that no longer exist.

Definition at line 185 of file storetree.cpp.

Here is the caller graph for this function:

◆ view()

auto StoreTree::view ( ) const -> QTreeView *
inlinenodiscard
Returns
The tree view.

Definition at line 158 of file storetree.h.

Here is the caller graph for this function:

◆ watchDir()

void StoreTree::watchDir ( const QString & dir)
private

Watch dir from now on, as the shown model has listed it.

Parameters
dirAbsolute folder path.

Definition at line 83 of file storetree.cpp.

Here is the caller graph for this function:

◆ tst_mainwindow

friend class tst_mainwindow
friend

Definition at line 180 of file storetree.h.

◆ tst_storetree

friend class tst_storetree
friend

Definition at line 179 of file storetree.h.

Member Data Documentation

◆ m_fresh

std::unique_ptr<QFileSystemModel> StoreTree::m_fresh
private

The model reload() is building, until it is swapped in.

Definition at line 239 of file storetree.h.

◆ m_freshDeadline

QTimer StoreTree::m_freshDeadline
private

Ends the wait for m_fresh: it is swapped in as it is.

Definition at line 249 of file storetree.h.

◆ m_freshPending

QSet<QString> StoreTree::m_freshPending
private

Folders m_fresh still has to list before the swap.

Definition at line 241 of file storetree.h.

◆ m_fs

std::unique_ptr<QFileSystemModel> StoreTree::m_fs
private

Source model over the store directory, filtered to *.gpg; replaced by setStore() and reload().

Definition at line 232 of file storetree.h.

◆ m_proxy

StoreModel StoreTree::m_proxy
private

Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop.

Definition at line 261 of file storetree.h.

◆ m_reloadAgain

bool StoreTree::m_reloadAgain = false
private

A reload() came while m_fresh was built: run one after it.

Definition at line 247 of file storetree.h.

◆ m_reloadTimer

QTimer StoreTree::m_reloadTimer
private

Waits for the watched folders to be quiet, then reload().

Definition at line 256 of file storetree.h.

◆ m_restoreCurrent

QString StoreTree::m_restoreCurrent
private

The current entry a swap could not show yet.

Definition at line 245 of file storetree.h.

◆ m_retired

std::unique_ptr<QFileSystemModel> StoreTree::m_retired
private

The model reload() replaced, kept until the next one: a caller still holding it reads stale rows instead of freed memory.

Definition at line 237 of file storetree.h.

◆ m_stillListing

QSet<QString> StoreTree::m_stillListing
private

Folders still being listed when m_fresh was swapped in.

Definition at line 243 of file storetree.h.

◆ m_store

QString StoreTree::m_store
private

Absolute store directory last passed to setStore().

Definition at line 263 of file storetree.h.

◆ m_view

QTreeView* StoreTree::m_view
private

The tree view this object drives; owned by the main window.

Definition at line 227 of file storetree.h.

◆ m_watcher

QFileSystemWatcher StoreTree::m_watcher
private

The folders the shown model has listed; reload() lists all of them again.

Definition at line 254 of file storetree.h.


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