1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLPREVIEWFILEENGINE_H
5#define QQMLPREVIEWFILEENGINE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmlpreviewfileloader.h"
19
20#include <private/qabstractfileengine_p.h>
21#include <private/qfsfileengine_p.h>
22#include <QtCore/qbuffer.h>
23
24QT_BEGIN_NAMESPACE
25
26class QQmlPreviewFileEngine : public QAbstractFileEngine
27{
28public:
29 QQmlPreviewFileEngine(const QString &file, const QString &absolute,
30 QQmlPreviewFileLoader *loader);
31
32 void setFileName(const QString &file) override;
33
34 bool open(QIODevice::OpenMode flags, std::optional<QFile::Permissions> permissions) override;
35 bool close() override;
36 qint64 size() const override;
37 qint64 pos() const override;
38 bool seek(qint64) override;
39 qint64 read(char *data, qint64 maxlen) override;
40
41 FileFlags fileFlags(FileFlags type) const override;
42 QString fileName(QAbstractFileEngine::FileName file) const override;
43 uint ownerId(FileOwner) const override;
44
45 Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override;
46 Iterator *endEntryList() override;
47
48 // Forwarding to fallback if exists
49 bool flush() override;
50 bool syncToDisk() override;
51 bool isSequential() const override;
52 bool remove() override;
53 bool copy(const QString &newName) override;
54 bool rename(const QString &newName) override;
55 bool renameOverwrite(const QString &newName) override;
56 bool link(const QString &newName) override;
57 bool mkdir(const QString &dirName, bool createParentDirectories,
58 std::optional<QFile::Permissions> permissions = std::nullopt) const override;
59 bool rmdir(const QString &dirName, bool recurseParentDirectories) const override;
60 bool setSize(qint64 size) override;
61 bool caseSensitive() const override;
62 bool isRelativePath() const override;
63 QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override;
64 bool setPermissions(uint perms) override;
65 QByteArray id() const override;
66 QString owner(FileOwner) const override;
67 QDateTime fileTime(FileTime time) const override;
68 int handle() const override;
69 qint64 readLine(char *data, qint64 maxlen) override;
70 qint64 write(const char *data, qint64 len) override;
71 bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) override;
72 bool supportsExtension(Extension extension) const override;
73
74private:
75 void load() const;
76
77 QString m_name;
78 QString m_absolute;
79 QPointer<QQmlPreviewFileLoader> m_loader;
80
81 mutable QBuffer m_contents;
82 mutable QStringList m_entries;
83 mutable QScopedPointer<QAbstractFileEngine> m_fallback;
84 mutable QQmlPreviewFileLoader::Result m_result = QQmlPreviewFileLoader::Unknown;
85};
86
87class QQmlPreviewFileEngineHandler : public QAbstractFileEngineHandler
88{
89public:
90 QQmlPreviewFileEngineHandler(QQmlPreviewFileLoader *loader);
91 QAbstractFileEngine *create(const QString &fileName) const override;
92
93private:
94 QPointer<QQmlPreviewFileLoader> m_loader;
95};
96
97
98
99QT_END_NAMESPACE
100
101#endif // QQMLPREVIEWFILEENGINE_H
102

source code of qtdeclarative/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.h