8#ifndef SRC_STOREMODEL_H_
9#define SRC_STOREMODEL_H_
12#include <QRegularExpression>
13#include <QSortFilterProxyModel>
17class QFileSystemModel;
69inline constexpr QLatin1StringView
70 kStoreDragMimeType(
"application/vnd.qtpass.store-item");
112 -> std::optional<StoreDragItem>;
128 const QModelIndex &parent) -> bool;
137 auto performDrop(
const QString &cleanedSrc,
const QString &cleanedDest,
138 Qt::DropAction action,
bool force) -> bool;
145 [[nodiscard]]
auto isLinkInStore(
const QModelIndex &proxyIndex)
const -> bool;
155 [[nodiscard]]
auto pathOf(
const QModelIndex &sourceIndex)
const -> QString;
166 [[nodiscard]]
auto showsFolder(
const QModelIndex &index,
const QString &path,
167 bool inside,
bool outside)
const -> bool;
188 const QModelIndex &source_parent)
const
196 [[nodiscard]]
auto showThis(
const QModelIndex &index)
const -> bool;
207 hasChildren(
const QModelIndex &parent = QModelIndex()) const ->
bool override;
215 [[nodiscard]] auto
canFetchMore(const QModelIndex &parent) const
221 void fetchMore(const QModelIndex &parent) override;
229 const QString &passStore);
255 [[nodiscard]] static auto
wordsFilter(const QString &query)
256 -> QRegularExpression;
263 void setStore(const QString &passStore);
271 [[nodiscard]] auto
data(const QModelIndex &index,
int role) const
272 -> QVariant override;
280 [[nodiscard]] auto
lessThan(const QModelIndex &source_left,
281 const QModelIndex &source_right) const
309 [[nodiscard]] auto
flags(const QModelIndex &index) const
310 -> Qt::ItemFlags override;
316 [[nodiscard]] auto
mimeTypes() const -> QStringList override;
323 [[nodiscard]] auto
mimeData(const QModelIndexList &indexes) const
324 -> QMimeData * override;
336 int column, const QModelIndex &parent) const
349 int column, const QModelIndex &parent) ->
bool override;
Abstract base class for password store operations.
auto filterAcceptsRow(int source_row, const QModelIndex &source_parent) const -> bool override
Filter whether a row should be displayed.
auto getStore() const -> QString
Get the password store root path.
auto data(const QModelIndex &index, int role) const -> QVariant override
Get display data for index.
StoreModel()
Construct a StoreModel.
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 matc...
static auto parseDropData(const QMimeData *data) -> std::optional< StoreDragItem >
Decode the drag payload from data.
auto showThis(const QModelIndex &index) const -> bool
Check if a specific index should be shown.
auto mimeTypes() const -> QStringList override
Get supported MIME types for drag/drop.
static auto wordsFilter(const QString &query) -> QRegularExpression
The tree filter for what is typed in the search box.
auto pathOf(const QModelIndex &sourceIndex) const -> QString
The path of a file system model index, as the node keeps it.
Pass * m_pass
Backend that performs drag-and-drop Move/Copy; not owned, null until setPass(), in which case drops a...
void setModelAndStore(QFileSystemModel *sourceModel, const QString &passStore)
Initialize model with source model and store path.
auto dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -> bool override
Handle dropped MIME data.
void setStore(const QString &passStore)
Update the store path used for filtering without changing the source model.
auto mimeData(const QModelIndexList &indexes) const -> QMimeData *override
Create MIME data from indexes.
auto executeDropAction(const StoreDragItem &info, Qt::DropAction action, const QModelIndex &parent) -> bool
Resolve a validated drop into a Move or Copy.
void setPass(Pass *pass)
Inject the Pass backend for drag-and-drop Move/Copy operations.
auto rootIndexFor(const QString &path) -> QModelIndex
Set the source filesystem root and map it to a proxy index.
QString store
Store root used to make paths relative for filtering and for the drop boundary check.
auto supportedDragActions() const -> Qt::DropActions override
Get supported drag actions.
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...
void fetchMore(const QModelIndex &parent) override
Fetch more rows, except under a link inside the store.
auto isLinkInStore(const QModelIndex &proxyIndex) const -> bool
Whether a proxy index is a link (or junction) inside the store, the store root excluded.
auto flags(const QModelIndex &index) const -> Qt::ItemFlags override
Get item flags for index.
auto performDrop(const QString &cleanedSrc, const QString &cleanedDest, Qt::DropAction action, bool force) -> bool
Perform the actual Move/Copy for a validated drop.
auto canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const -> bool override
Check if drop is possible.
auto lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const -> bool override
Compare two indices for sorting.
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 po...
QFileSystemModel * fs
The wrapped file system model, set by setModelAndStore(); null until then, which makes showThis() hid...
auto supportedDropActions() const -> Qt::DropActions override
Get supported drop actions.
auto operator>>(QDataStream &in, StoreDragItem &item) -> QDataStream &
Deserialize a StoreDragItem from the QtPass MIME type.
auto operator<<(QDataStream &out, const StoreDragItem &item) -> QDataStream &
Serialize a StoreDragItem for the QtPass MIME type.
What a drag from the store tree carries: the kind of the dragged item and its path.
ItemKind
Type of the dragged item.