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.
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.

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.

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 84 of file storemodel.h.

Constructor & Destructor Documentation

◆ StoreModel()

StoreModel::StoreModel ( )

Construct a StoreModel.

Definition at line 45 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 178 of file storemodel.cpp.

Here is the call graph for this function:
Here is the caller 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 111 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 214 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 255 of file storemodel.cpp.

Here is the call graph for this function:
Here is the caller 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 49 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 136 of file storemodel.cpp.

◆ getStore()

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

Get the password store root path.

Returns
Store path.

Definition at line 218 of file storemodel.h.

◆ 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 318 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 151 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 145 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 237 of file storemodel.cpp.

Here is the call graph for this function:
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 304 of file storemodel.cpp.

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 92 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 85 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 47 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 99 of file storemodel.cpp.

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 56 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 132 of file storemodel.cpp.

◆ supportedDropActions()

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

Get supported drop actions.

Returns
Supported Qt::DropActions.

Definition at line 128 of file storemodel.cpp.

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 92 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 102 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 97 of file storemodel.h.


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