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 <QtQmlIntegration/QtQmlIntegration>
9
29class QGCArchiveModel : public QAbstractListModel
30{
31 Q_OBJECT
32 QML_ELEMENT
33
35 Q_PROPERTY(QString archivePath READ archivePath WRITE setArchivePath NOTIFY archivePathChanged)
36
37
39 Q_PROPERTY(QUrl archiveUrl READ archiveUrl WRITE setArchiveUrl NOTIFY archivePathChanged)
40
41
42 Q_PROPERTY(int count READ count NOTIFY countChanged)
43
44
45 Q_PROPERTY(int fileCount READ fileCount NOTIFY fileCountChanged)
46
47
48 Q_PROPERTY(int directoryCount READ directoryCount NOTIFY directoryCountChanged)
49
50
51 Q_PROPERTY(qint64 totalSize READ totalSize NOTIFY totalSizeChanged)
52
53
54 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
55
56
57 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
58
59
61
62public:
74 Q_ENUM(Role)
75
76
82 Q_ENUM(FilterMode)
83
84 explicit QGCArchiveModel(QObject *parent = nullptr);
85 ~QGCArchiveModel() override;
86
87 // Property accessors
88 QString archivePath() const { return _archivePath; }
89 void setArchivePath(const QString &path);
90
91 QUrl archiveUrl() const { return QUrl::fromLocalFile(_archivePath); }
92 void setArchiveUrl(const QUrl &url);
93
94 int count() const { return static_cast<int>(_filteredEntries.size()); }
95 int fileCount() const { return _fileCount; }
96 int directoryCount() const { return _directoryCount; }
97 qint64 totalSize() const { return _totalSize; }
98 bool loading() const { return _loading; }
99 QString errorString() const { return _errorString; }
100
101 FilterMode filterMode() const { return _filterMode; }
102 void setFilterMode(FilterMode mode);
103
104 // QAbstractListModel interface
105 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
106 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
107 QHash<int, QByteArray> roleNames() const override;
108
110 Q_INVOKABLE void refresh();
111
113 Q_INVOKABLE void clear();
114
116 Q_INVOKABLE QVariantMap get(int index) const;
117
119 Q_INVOKABLE bool contains(const QString &fileName) const;
120
122 Q_INVOKABLE static QString formatSize(qint64 bytes);
123
124signals:
133
135 void loadingComplete(bool success);
136
137private:
138 void _loadArchive();
139 void _applyFilter();
140 void _setLoading(bool loading);
141 void _setErrorString(const QString &error);
142
143 QString _archivePath;
144 QList<QGCCompression::ArchiveEntry> _allEntries;
145 QList<QGCCompression::ArchiveEntry> _filteredEntries;
146 int _fileCount = 0;
147 int _directoryCount = 0;
148 qint64 _totalSize = 0;
149 bool _loading = false;
150 QString _errorString;
151 FilterMode _filterMode = AllEntries;
152};
Shared type definitions for compression/archive operations.
Error error
List model for archive contents, suitable for QML ListView binding.
QHash< int, QByteArray > roleNames() const override
int directoryCount() const
static Q_INVOKABLE QString formatSize(qint64 bytes)
Format bytes as human-readable string (e.g., "1.5 MB")
Q_INVOKABLE QVariantMap get(int index) const
Get entry at index (for C++ usage)
void filterModeChanged()
void directoryCountChanged()
qint64 totalSize() const
void archivePathChanged()
void setArchiveUrl(const QUrl &url)
void setArchivePath(const QString &path)
bool loading() const
void setFilterMode(FilterMode mode)
QUrl archiveUrl() const
void totalSizeChanged()
int rowCount(const QModelIndex &parent=QModelIndex()) const override
~QGCArchiveModel() override
Role
Path to the archive file to display (QString)
@ FileNameRole
Just the filename without path (QString)
@ ModifiedRole
Last modified date (QDateTime)
@ IsDirectoryRole
Whether entry is a directory (bool)
@ PermissionsRole
Unix permissions (quint32)
@ FormattedSizeRole
Human-readable size string (QString)
@ DirectoryRole
Parent directory path (QString)
@ SizeRole
Uncompressed size in bytes (qint64)
@ NameRole
Entry name/path (QString)
int fileCount() const
QString errorString() const
void errorStringChanged()
Q_INVOKABLE bool contains(const QString &fileName) const
Check if a file exists in the archive.
void loadingChanged()
FilterMode filterMode() const
void loadingComplete(bool success)
Emitted when archive loading completes (success or failure)
QString archivePath() const
Q_INVOKABLE void clear()
Clear the model and reset all properties.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void fileCountChanged()
int count() const
Q_INVOKABLE void refresh()
Reload archive contents (useful after external changes)
FilterMode
Filter modes for showing subsets of entries.
@ FilesOnly
Show only files (no directories)
@ DirectoriesOnly
Show only directories.
@ AllEntries
Show all files and directories.