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

QSortFilterProxyModel for filtering and displaying password store. More...

#include <storemodel.h>

Inheritance diagram for StoreModel:
Collaboration diagram for StoreModel:

Public Member Functions

 StoreModel ()
 Construct a StoreModel.
void setPass (Pass *pass)
 Inject the Pass backend for drag-and-drop Move/Copy operations.
auto filterAcceptsRow (int source_row, const QModelIndex &source_parent) const -> bool override
 Filter whether a row should be displayed.
auto showThis (const QModelIndex &index) const -> bool
 Check if a specific index should be shown.
auto hasChildren (const QModelIndex &parent=QModelIndex()) const -> bool override
 No children for a link inside the store: it is listed by name but never entered, so the view shows no expand arrow.
auto canFetchMore (const QModelIndex &parent) const -> bool override
 Nothing to fetch under a link inside the store, so the file system model never lists what the link points to.
void fetchMore (const QModelIndex &parent) override
 Fetch more rows, except under a link inside the store.
void setModelAndStore (QFileSystemModel *sourceModel, const QString &passStore)
 Initialize model with source model and store path.
auto rootIndexFor (const QString &path) -> QModelIndex
 Set the source filesystem root and map it to a proxy index.
void setStore (const QString &passStore)
 Update the store path used for filtering without changing the source model.
auto data (const QModelIndex &index, int role) const -> QVariant override
 Get display data for index.
auto lessThan (const QModelIndex &source_left, const QModelIndex &source_right) const -> bool override
 Compare two indices for sorting.
auto getStore () const -> QString
 Get the password store root path.
auto supportedDropActions () const -> Qt::DropActions override
 Get supported drop actions.
auto supportedDragActions () const -> Qt::DropActions override
 Get supported drag actions.
auto flags (const QModelIndex &index) const -> Qt::ItemFlags override
 Get item flags for index.
auto mimeTypes () const -> QStringList override
 Get supported MIME types for drag/drop.
auto mimeData (const QModelIndexList &indexes) const -> QMimeData *override
 Create MIME data from indexes.
auto canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const -> bool override
 Check if drop is possible.
auto dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -> bool override
 Handle dropped MIME data.

Static Public Member Functions

static auto wordsFilter (const QString &query) -> QRegularExpression
 The tree filter for what is typed in the search box.

Private Member Functions

auto executeDropAction (const StoreDragItem &info, Qt::DropAction action, const QModelIndex &parent) -> bool
 Resolve a validated drop into a Move or Copy.
auto performDrop (const QString &cleanedSrc, const QString &cleanedDest, Qt::DropAction action, bool force) -> bool
 Perform the actual Move/Copy for a validated drop.
auto isLinkInStore (const QModelIndex &proxyIndex) const -> bool
 Whether a proxy index is a link (or junction) inside the store, the store root excluded.
auto pathOf (const QModelIndex &sourceIndex) const -> QString
 The path of a file system model index, as the node keeps it.
auto showsFolder (const QModelIndex &index, const QString &path, bool inside, bool outside) const -> bool
 showThis() for a folder with rows: shown when any of them is, or, in a search, when its own name matches.

Static Private Member Functions

static auto parseDropData (const QMimeData *data) -> std::optional< StoreDragItem >
 Decode the drag payload from data.

Private Attributes

QFileSystemModel * fs
 The wrapped file system model, set by setModelAndStore(); null until then, which makes showThis() hide everything.
QString store
 Store root used to make paths relative for filtering and for the drop boundary check.
Pass * m_pass {nullptr}
 Backend that performs drag-and-drop Move/Copy; not owned, null until setPass(), in which case drops are refused.

Detailed Description

QSortFilterProxyModel for filtering and displaying password store.

StoreModel wraps QFileSystemModel to provide password store-specific filtering and display functionality. It handles:

  • Hiding the .git directory from display
  • Removing .gpg extension from file names
  • Supporting drag and drop operations
  • Custom sorting (directories before files)

Definition at line 85 of file storemodel.h.

Constructor & Destructor Documentation

◆ StoreModel()

StoreModel::StoreModel ( )

Construct a StoreModel.

Definition at line 46 of file storemodel.cpp.

Member Function Documentation

◆ canDropMimeData()

auto StoreModel::canDropMimeData ( const QMimeData * data,
Qt::DropAction action,
int row,
int column,
const QModelIndex & parent ) const -> bool
override

Check if drop is possible.

Parameters
dataMIME data to drop.
actionDrop action.
rowTarget row.
columnTarget column.
parentTarget parent index.
Returns
true if drop is possible.

Definition at line 265 of file storemodel.cpp.

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

◆ canFetchMore()

auto StoreModel::canFetchMore ( const QModelIndex & parent) const -> bool
nodiscardoverride

Nothing to fetch under a link inside the store, so the file system model never lists what the link points to.

Parameters
parentProxy index.
Returns
false for a link inside the store, otherwise as the base class.

Definition at line 159 of file storemodel.cpp.

Here is the call graph for this function:

◆ data()

auto StoreModel::data ( const QModelIndex & index,
int role ) const -> QVariant
nodiscardoverride

Get display data for index.

Parameters
indexModel index.
roleData role (e.g., Qt::DisplayRole).
Returns
Display data for the role.

Definition at line 195 of file storemodel.cpp.

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

◆ dropMimeData()

auto StoreModel::dropMimeData ( const QMimeData * data,
Qt::DropAction action,
int row,
int column,
const QModelIndex & parent ) -> bool
override

Handle dropped MIME data.

Parameters
dataMIME data to drop.
actionDrop action.
rowTarget row.
columnTarget column.
parentTarget parent index.
Returns
true if drop was handled.

Definition at line 301 of file storemodel.cpp.

Here is the call graph for this function:

◆ executeDropAction()

auto StoreModel::executeDropAction ( const StoreDragItem & info,
Qt::DropAction action,
const QModelIndex & parent ) -> bool
private

Resolve a validated drop into a Move or Copy.

Both endpoints must resolve inside the store after symlink resolution (the payload could be crafted). A directory is dropped into the target folder; a file onto a folder goes into it, a file onto a file asks the user before overwriting.

Parameters
infoThe decoded drag payload.
actionQt::MoveAction or Qt::CopyAction.
parentProxy index of the drop target.
Returns
true once the operation has been dispatched to the backend; false for an escaping path, an unknown kind or a bad target.

Definition at line 342 of file storemodel.cpp.

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

◆ fetchMore()

void StoreModel::fetchMore ( const QModelIndex & parent)
override

Fetch more rows, except under a link inside the store.

Parameters
parentProxy index.

Definition at line 163 of file storemodel.cpp.

Here is the call graph for this function:

◆ filterAcceptsRow()

auto StoreModel::filterAcceptsRow ( int source_row,
const QModelIndex & source_parent ) const -> bool
nodiscardoverride

Filter whether a row should be displayed.

Parameters
source_rowRow index in source model.
source_parentParent index in source model.
Returns
true if row should be displayed.

Definition at line 50 of file storemodel.cpp.

Here is the call graph for this function:

◆ flags()

auto StoreModel::flags ( const QModelIndex & index) const -> Qt::ItemFlags
nodiscardoverride

Get item flags for index.

Parameters
indexModel index.
Returns
Item flags.

Definition at line 223 of file storemodel.cpp.

◆ getStore()

auto StoreModel::getStore ( ) const -> QString
inlinenodiscard

Get the password store root path.

Returns
Store path.

Definition at line 288 of file storemodel.h.

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

◆ hasChildren()

auto StoreModel::hasChildren ( const QModelIndex & parent = QModelIndex()) const -> bool
nodiscardoverride

No children for a link inside the store: it is listed by name but never entered, so the view shows no expand arrow.

Parameters
parentProxy index.
Returns
false for a link inside the store, otherwise as the base class.

Definition at line 155 of file storemodel.cpp.

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

◆ isLinkInStore()

auto StoreModel::isLinkInStore ( const QModelIndex & proxyIndex) const -> bool
nodiscardprivate

Whether a proxy index is a link (or junction) inside the store, the store root excluded.

Parameters
proxyIndexIndex in this model.
Returns
true for a link inside the store.

Definition at line 132 of file storemodel.cpp.

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

◆ lessThan()

auto StoreModel::lessThan ( const QModelIndex & source_left,
const QModelIndex & source_right ) const -> bool
nodiscardoverride

Compare two indices for sorting.

Parameters
source_leftLeft index to compare.
source_rightRight index to compare.
Returns
true if left < right.

Definition at line 416 of file storemodel.cpp.

◆ mimeData()

auto StoreModel::mimeData ( const QModelIndexList & indexes) const -> QMimeData *
nodiscardoverride

Create MIME data from indexes.

Parameters
indexesList of selected indexes.
Returns
MIME data object.

Definition at line 238 of file storemodel.cpp.

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

◆ mimeTypes()

auto StoreModel::mimeTypes ( ) const -> QStringList
nodiscardoverride

Get supported MIME types for drag/drop.

Returns
List of MIME type strings.

Definition at line 232 of file storemodel.cpp.

◆ parseDropData()

auto StoreModel::parseDropData ( const QMimeData * data) -> std::optional< StoreDragItem >
staticprivate

Decode the drag payload from data.

Parameters
dataMIME data of the drop; may be null.
Returns
The payload, or nothing when data is null, carries no payload of ours, or the payload does not deserialise cleanly.

Definition at line 324 of file storemodel.cpp.

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

◆ pathOf()

auto StoreModel::pathOf ( const QModelIndex & sourceIndex) const -> QString
nodiscardprivate

The path of a file system model index, as the node keeps it.

Not QFileSystemModel::filePath(): that rebuilds the path through parent(), which looks each folder up among all its siblings, and on Windows it gives a resolved link's target instead of the link.

Parameters
sourceIndexIndex in the file system model; fs must be set.
Returns
The absolute path.

Definition at line 147 of file storemodel.cpp.

Here is the caller graph for this function:

◆ performDrop()

auto StoreModel::performDrop ( const QString & cleanedSrc,
const QString & cleanedDest,
Qt::DropAction action,
bool force ) -> bool
private

Perform the actual Move/Copy for a validated drop.

Parameters
cleanedSrcCanonical source path (inside the store).
cleanedDestCanonical destination path (inside the store).
actionQt::MoveAction or Qt::CopyAction.
forceOverwrite an existing destination.
Returns
true once the operation has been dispatched.

Definition at line 393 of file storemodel.cpp.

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

◆ rootIndexFor()

auto StoreModel::rootIndexFor ( const QString & path) -> QModelIndex

Set the source filesystem root and map it to a proxy index.

Wraps the recurring mapFromSource(fs->setRootPath(path)) dance used to point the tree view at a directory, so callers don't reach through to the wrapped QFileSystemModel.

Parameters
pathDirectory to make the source root.
Returns
Proxy index for path, or an invalid index if no source model is set.

Definition at line 176 of file storemodel.cpp.

Here is the caller graph for this function:

◆ setModelAndStore()

void StoreModel::setModelAndStore ( QFileSystemModel * sourceModel,
const QString & passStore )

Initialize model with source model and store path.

Parameters
sourceModelFilesystem model to wrap.
passStoreRoot path of password store.

Definition at line 169 of file storemodel.cpp.

Here is the caller graph for this function:

◆ setPass()

void StoreModel::setPass ( Pass * pass)

Inject the Pass backend for drag-and-drop Move/Copy operations.

Parameters
passPass backend instance; must outlive this StoreModel.

Definition at line 48 of file storemodel.cpp.

Here is the caller graph for this function:

◆ setStore()

void StoreModel::setStore ( const QString & passStore)

Update the store path used for filtering without changing the source model.

Parameters
passStoreNew root path of password store.

Definition at line 183 of file storemodel.cpp.

◆ showsFolder()

auto StoreModel::showsFolder ( const QModelIndex & index,
const QString & path,
bool inside,
bool outside ) const -> bool
nodiscardprivate

showThis() for a folder with rows: shown when any of them is, or, in a search, when its own name matches.

Parameters
indexThe folder's index in the source model.
pathIts path relative to the store.
insideWhether it lies inside the store, below its root.
outsideWhether it lies outside the store.
Returns
Whether the folder is shown.

Definition at line 95 of file storemodel.cpp.

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

◆ showThis()

auto StoreModel::showThis ( const QModelIndex & index) const -> bool
nodiscard

Check if a specific index should be shown.

Parameters
indexModel index to check.
Returns
true if index should be visible.

Definition at line 57 of file storemodel.cpp.

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

◆ supportedDragActions()

auto StoreModel::supportedDragActions ( ) const -> Qt::DropActions
nodiscardoverride

Get supported drag actions.

Returns
Supported Qt::DropActions.

Definition at line 219 of file storemodel.cpp.

◆ supportedDropActions()

auto StoreModel::supportedDropActions ( ) const -> Qt::DropActions
nodiscardoverride

Get supported drop actions.

Returns
Supported Qt::DropActions.

Definition at line 215 of file storemodel.cpp.

◆ wordsFilter()

auto StoreModel::wordsFilter ( const QString & query) -> QRegularExpression
staticnodiscard

The tree filter for what is typed in the search box.

The words, split at spaces, are matched literally and in order, with anything in between: "work vpn" finds work/acme/vpn. Each word is taken at its first place after the one before, which is where an in-order match can always continue, and the pattern is anchored with atomic groups, so a path is searched once: a greedy .* join backtracked through every repeat of a word in a long path.

Parameters
queryThe search box text, with slashes as separators.
Returns
A case-insensitive pattern; empty for no words.

Definition at line 115 of file storemodel.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ fs

QFileSystemModel* StoreModel::fs
private

The wrapped file system model, set by setModelAndStore(); null until then, which makes showThis() hide everything.

Definition at line 93 of file storemodel.h.

◆ m_pass

Pass* StoreModel::m_pass {nullptr}
private

Backend that performs drag-and-drop Move/Copy; not owned, null until setPass(), in which case drops are refused.

Definition at line 103 of file storemodel.h.

◆ store

QString StoreModel::store
private

Store root used to make paths relative for filtering and for the drop boundary check.

Definition at line 98 of file storemodel.h.


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