QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
storetree.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_STORETREE_H_
9#define SRC_STORETREE_H_
10
11#include "storemodel.h"
12#include <QFileInfo>
13#include <QFileSystemModel>
14#include <QModelIndex>
15#include <QObject>
16#include <QString>
17
18class Pass;
19class QTreeView;
20
33class StoreTree : public QObject {
34 Q_OBJECT
35
36public:
44 explicit StoreTree(QTreeView *view, QObject *parent = nullptr);
45
51 void setStore(const QString &path);
52
57 void setPass(Pass *pass);
58
64 void setFilter(const QRegularExpression &pattern);
65
74 [[nodiscard]] auto dirFor(const QModelIndex &index, bool forPass) const
75 -> QString;
76
82 [[nodiscard]] auto currentDir(bool forPass) const -> QString;
83
92 [[nodiscard]] auto fileFor(const QModelIndex &index, bool forPass) const
93 -> QString;
94
100 [[nodiscard]] auto currentFile(bool forPass) const -> QString;
101
107 [[nodiscard]] auto fileInfo(const QModelIndex &index) const -> QFileInfo;
108
115 [[nodiscard]] auto indexFor(const QString &path) const -> QModelIndex;
116
121 [[nodiscard]] auto rootIndex() -> QModelIndex;
122
127 [[nodiscard]] auto currentIndex() const -> QModelIndex;
128
130 [[nodiscard]] auto store() const -> QString { return m_store; }
132 [[nodiscard]] auto proxy() -> StoreModel & { return m_proxy; }
134 [[nodiscard]] auto fileSystem() -> QFileSystemModel & { return m_fs; }
136 [[nodiscard]] auto view() const -> QTreeView * { return m_view; }
137
138private:
140 QTreeView *m_view;
145 QFileSystemModel m_fs;
152 QString m_store;
153};
154
155#endif // SRC_STORETREE_H_
Abstract base class for password store operations.
Definition pass.h:75
QSortFilterProxyModel for filtering and displaying password store.
Definition storemodel.h:84
QString m_store
Absolute store directory last passed to setStore().
Definition storetree.h:152
auto dirFor(const QModelIndex &index, bool forPass) const -> QString
The folder an index stands for.
Definition storetree.cpp:55
auto fileInfo(const QModelIndex &index) const -> QFileInfo
File system information for a view index.
Definition storetree.cpp:92
auto rootIndex() -> QModelIndex
The proxy's root index for the current store.
auto currentIndex() const -> QModelIndex
The view's current index.
auto currentFile(bool forPass) const -> QString
fileFor() applied to the view's current index.
Definition storetree.cpp:88
QTreeView * m_view
The tree view this object drives; owned by the main window.
Definition storetree.h:140
auto fileFor(const QModelIndex &index, bool forPass) const -> QString
The entry an index stands for.
Definition storetree.cpp:75
auto store() const -> QString
Definition storetree.h:130
void setFilter(const QRegularExpression &pattern)
Filter the visible entries.
Definition storetree.cpp:49
StoreTree(QTreeView *view, QObject *parent=nullptr)
Attach the proxy model to the view and set its look: hidden header, indentation, scroll bars,...
Definition storetree.cpp:14
auto view() const -> QTreeView *
Definition storetree.h:136
QFileSystemModel m_fs
Source model over the store directory, filtered to *.gpg; re-rooted by setStore().
Definition storetree.h:145
void setStore(const QString &path)
Point everything at path: file system root, proxy store and view root index. Also drops a search filt...
Definition storetree.cpp:26
StoreModel m_proxy
Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop.
Definition storetree.h:150
auto fileSystem() -> QFileSystemModel &
Definition storetree.h:134
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.
Definition storetree.cpp:96
auto proxy() -> StoreModel &
Definition storetree.h:132
void setPass(Pass *pass)
Hand the proxy the backend it drops onto.
Definition storetree.cpp:47
auto currentDir(bool forPass) const -> QString
dirFor() applied to the view's current index.
Definition storetree.cpp:71
StoreModel, the filtering/sorting proxy over the store's QFileSystemModel, and StoreDragItem,...