QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCArchiveModel.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <QtCore/QAbstractListModel>
6#include <QtCore/QString>
7#include <QtCore/QUrl>
8#include <QtQml/QQmlEngine>
9
27class QGCArchiveModel : public QAbstractListModel
28{
29 Q_OBJECT
30 QML_ELEMENT
31
33 Q_PROPERTY(QString archivePath READ archivePath WRITE setArchivePath NOTIFY archivePathChanged)
34
35
37 Q_PROPERTY(QUrl archiveUrl READ archiveUrl WRITE setArchiveUrl NOTIFY archivePathChanged)
38
39
40 Q_PROPERTY(int count READ count NOTIFY countChanged)
41
42
43 Q_PROPERTY(int fileCount READ fileCount NOTIFY fileCountChanged)
44
45
46 Q_PROPERTY(int directoryCount READ directoryCount NOTIFY directoryCountChanged)
47
48
49 Q_PROPERTY(qint64 totalSize READ totalSize NOTIFY totalSizeChanged)
50
51
52 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
53
54
55 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
56
57
58 Q_PROPERTY(FilterMode filterMode READ filterMode WRITE setFilterMode NOTIFY filterModeChanged)
59
60public:
62 enum Role {
63 NameRole = Qt::UserRole + 1,
64 SizeRole,
65 ModifiedRole,
66 IsDirectoryRole,
67 PermissionsRole,
68 FileNameRole,
69 DirectoryRole,
70 FormattedSizeRole,
71 };
72 Q_ENUM(Role)
73
74
75 enum FilterMode {
76 AllEntries,
77 FilesOnly,
78 DirectoriesOnly
79 };
80 Q_ENUM(FilterMode)
81
82 explicit QGCArchiveModel(QObject *parent = nullptr);
83 ~QGCArchiveModel() override;
84
85 // Property accessors
86 QString archivePath() const { return _archivePath; }
87 void setArchivePath(const QString &path);
88
89 QUrl archiveUrl() const { return QUrl::fromLocalFile(_archivePath); }
90 void setArchiveUrl(const QUrl &url);
91
92 int count() const { return static_cast<int>(_filteredEntries.size()); }
93 int fileCount() const { return _fileCount; }
94 int directoryCount() const { return _directoryCount; }
95 qint64 totalSize() const { return _totalSize; }
96 bool loading() const { return _loading; }
97 QString errorString() const { return _errorString; }
98
99 FilterMode filterMode() const { return _filterMode; }
100 void setFilterMode(FilterMode mode);
101
102 // QAbstractListModel interface
103 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
104 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
105 QHash<int, QByteArray> roleNames() const override;
106
108 Q_INVOKABLE void refresh();
109
111 Q_INVOKABLE void clear();
112
114 Q_INVOKABLE QVariantMap get(int index) const;
115
117 Q_INVOKABLE bool contains(const QString &fileName) const;
118
120 Q_INVOKABLE static QString formatSize(qint64 bytes);
121
122signals:
131
133 void loadingComplete(bool success);
134
135private:
136 void _loadArchive();
137 void _applyFilter();
138 void _setLoading(bool loading);
139 void _setErrorString(const QString &error);
140
141 QString _archivePath;
142 QList<QGCCompression::ArchiveEntry> _allEntries;
143 QList<QGCCompression::ArchiveEntry> _filteredEntries;
144 int _fileCount = 0;
145 int _directoryCount = 0;
146 qint64 _totalSize = 0;
147 bool _loading = false;
148 QString _errorString;
149 FilterMode _filterMode = AllEntries;
150};
Shared type definitions for compression/archive operations.
Error error
void filterModeChanged()
void directoryCountChanged()
void archivePathChanged()
void totalSizeChanged()
void errorStringChanged()
void loadingChanged()
void loadingComplete(bool success)
Emitted when archive loading completes (success or failure)
void fileCountChanged()