Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
file_menu_proxy.h
1#pragma once
2
3#include <QFileInfo>
4#include <QFileSystemModel>
5#include <QSortFilterProxyModel>
6
7class FileTypeProxyModel : public QSortFilterProxyModel
8{
9public:
10 using QSortFilterProxyModel::QSortFilterProxyModel;
11
12 QVariant data(const QModelIndex& index, int role) const override
13 {
14 if (role == Qt::DisplayRole && index.column() == 2) // Type column
15 {
16 auto* fsModel = qobject_cast<QFileSystemModel*>(sourceModel());
17 QModelIndex sourceIndex = mapToSource(index);
18
19 QFileInfo info = fsModel->fileInfo(sourceIndex);
20
21 if (info.isDir())
22 return "dir";
23
24 const QString ext = info.suffix().toLower();
25 return ext;
26 }
27
28 return QSortFilterProxyModel::data(index, role);
29 }
30
31 bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override
32 {
33 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
34 if (!index.isValid())
35 return false;
36
37 auto* fsModel = qobject_cast<QFileSystemModel*>(sourceModel());
38 if (!fsModel)
39 return true;
40
41 QFileInfo info = fsModel->fileInfo(index);
42
43 // Always keep directories visible so the user can navigate
44 if (info.isDir())
45 return true;
46
47#ifdef DEV_BUILD
48 return true;
49#else
50 return mAllowedExtensions.contains(info.suffix().toLower());
51#endif
52 }
53
54private:
55 QSet<QString> mAllowedExtensions = {
56 "h",
57 "hh",
58 "c",
59 "cpp",
60 "txt",
61 "py",
62 "cc",
63 "dzn",
64 "kd"};
65};
Definition file_menu_proxy.h:8