| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
1 |
#pragma once |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
2 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
3 |
#include <QAbstractListModel> |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
4 |
#include <QString> |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
5 |
#include <QStringList> |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
6 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
7 |
// Lightweight ajax-style completion model that exposes the immediate |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
8 |
// subdirectories of whatever parent directory the user is typing into the |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
9 |
// path field. Refreshed on each text change via setPrefix(); we only re-scan |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
10 |
// when the parent directory actually changes, so per-keystroke cost is just |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
11 |
// the QCompleter filter pass over an already-loaded list. |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
12 |
// |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
13 |
// Directory enumeration mirrors FsDirModel::listSubdirs (std::filesystem with |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
14 |
// QFile::decodeName), so non-ASCII names that round-trip through the locale |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
15 |
// are listed correctly. |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
16 |
class PathCompleterModel : public QAbstractListModel |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
17 |
{ |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
18 |
Q_OBJECT |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
19 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
20 |
public: |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
21 |
explicit PathCompleterModel(QObject *parent = nullptr); |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
22 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
23 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
24 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
25 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
26 |
public slots: |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
27 |
// Update entries based on the current text in the path field. |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
28 |
void setPrefix(const QString &text); |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
29 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
30 |
private: |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
31 |
QStringList m_entries; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
32 |
QString m_currentParent; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
33 |
bool m_hasParent = false; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
34 |
}; |
|
|
1970-01-01 00:00 |
35 |
|