| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
1 |
/* |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
2 |
MIT License |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
3 |
|
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
4 |
Copyright (c) 2026 Poul Sander |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
5 |
|
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
6 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
7 |
of this software and associated documentation files (the "Software"), to deal |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
8 |
in the Software without restriction, including without limitation the rights |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
9 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
10 |
copies of the Software, and to permit persons to whom the Software is |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
11 |
furnished to do so, subject to the following conditions: |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
12 |
|
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
13 |
The above copyright notice and this permission notice shall be included in all |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
14 |
copies or substantial portions of the Software. |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
15 |
|
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
16 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
17 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
18 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
19 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
20 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
21 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
22 |
SOFTWARE. |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
23 |
|
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
24 |
*/ |
| 14cf904f |
Poul Sander |
2026-06-22 18:18 |
25 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
26 |
#pragma once |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
27 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
28 |
#include <QAbstractListModel> |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
29 |
#include <QString> |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
30 |
#include <QStringList> |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
31 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
32 |
// Lightweight ajax-style completion model that exposes the immediate |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
33 |
// subdirectories of whatever parent directory the user is typing into the |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
34 |
// path field. Refreshed on each text change via setPrefix(); we only re-scan |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
35 |
// when the parent directory actually changes, so per-keystroke cost is just |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
36 |
// the QCompleter filter pass over an already-loaded list. |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
37 |
// |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
38 |
// Directory enumeration mirrors FsDirModel::listSubdirs (std::filesystem with |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
39 |
// QFile::decodeName), so non-ASCII names that round-trip through the locale |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
40 |
// are listed correctly. |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
41 |
class PathCompleterModel : public QAbstractListModel |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
42 |
{ |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
43 |
Q_OBJECT |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
44 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
45 |
public: |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
46 |
explicit PathCompleterModel(QObject *parent = nullptr); |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
47 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
48 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
49 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
50 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
51 |
public slots: |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
52 |
// Update entries based on the current text in the path field. |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
53 |
void setPrefix(const QString &text); |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
54 |
|
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
55 |
private: |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
56 |
QStringList m_entries; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
57 |
QString m_currentParent; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
58 |
bool m_hasParent = false; |
| fd7f51cd |
Poul Sander |
2026-05-22 15:30 |
59 |
}; |
|
|
1970-01-01 00:00 |
60 |
|