QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
storemodel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_STOREMODEL_H_
9#define SRC_STOREMODEL_H_
10
11#include <QFileInfo>
12#include <QSortFilterProxyModel>
13#include <optional>
14
15class Pass;
16class QFileSystemModel;
17
32 enum class ItemKind {
34 Directory,
35 File
36 };
37
39 QString path;
40};
41
42class QDataStream;
43
50auto operator<<(QDataStream &out, const StoreDragItem &info) -> QDataStream &;
51
62auto operator>>(QDataStream &in, StoreDragItem &info) -> QDataStream &;
63
65// The one MIME type the store tree drags: a serialised StoreDragItem (see the
66// struct's documentation). Hidden from Doxygen, which reads the
67// constructor-style initialiser as a function taking a string literal.
68inline constexpr QLatin1StringView
69 kStoreDragMimeType("application/vnd.qtpass.store-item");
71
84class StoreModel : public QSortFilterProxyModel {
85 Q_OBJECT
86
87private:
92 QFileSystemModel *fs;
97 QString store;
102 Pass *m_pass{nullptr};
103
110 static auto parseDropData(const QMimeData *data)
111 -> std::optional<StoreDragItem>;
112
126 auto executeDropAction(const StoreDragItem &info, Qt::DropAction action,
127 const QModelIndex &parent) -> bool;
136 auto performDrop(const QString &cleanedSrc, const QString &cleanedDest,
137 Qt::DropAction action, bool force) -> bool;
138
139public:
143 StoreModel();
144
149 void setPass(Pass *pass);
150
157 [[nodiscard]] auto filterAcceptsRow(int source_row,
158 const QModelIndex &source_parent) const
159 -> bool override;
160
166 [[nodiscard]] auto showThis(const QModelIndex &index) const -> bool;
167
173 void setModelAndStore(QFileSystemModel *sourceModel,
174 const QString &passStore);
175
186 auto rootIndexFor(const QString &path) -> QModelIndex;
187
193 void setStore(const QString &passStore);
194
201 [[nodiscard]] auto data(const QModelIndex &index, int role) const
202 -> QVariant override;
203
210 [[nodiscard]] auto lessThan(const QModelIndex &source_left,
211 const QModelIndex &source_right) const
212 -> bool override;
213
218 [[nodiscard]] auto getStore() const -> QString { return store; }
219
220 // QAbstractItemModel interface
221public:
226 [[nodiscard]] auto supportedDropActions() const -> Qt::DropActions override;
227
232 [[nodiscard]] auto supportedDragActions() const -> Qt::DropActions override;
233
239 [[nodiscard]] auto flags(const QModelIndex &index) const
240 -> Qt::ItemFlags override;
241
246 [[nodiscard]] auto mimeTypes() const -> QStringList override;
247
253 [[nodiscard]] auto mimeData(const QModelIndexList &indexes) const
254 -> QMimeData * override;
255
265 auto canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
266 int column, const QModelIndex &parent) const
267 -> bool override;
268
278 auto dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
279 int column, const QModelIndex &parent) -> bool override;
280};
281
282#endif // SRC_STOREMODEL_H_
Abstract base class for password store operations.
Definition pass.h:75
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.
Definition storemodel.h:218
auto data(const QModelIndex &index, int role) const -> QVariant override
Get display data for index.
StoreModel()
Construct a StoreModel.
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.
Pass * m_pass
Backend that performs drag-and-drop Move/Copy; not owned, null until setPass(), in which case drops a...
Definition storemodel.h:102
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.
Definition storemodel.h:97
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 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.
QFileSystemModel * fs
The wrapped file system model, set by setModelAndStore(); null until then, which makes showThis() hid...
Definition storemodel.h:92
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.
Definition storemodel.h:28
QString path
Definition storemodel.h:39
ItemKind
Type of the dragged item.
Definition storemodel.h:32
ItemKind kind
Definition storemodel.h:38