1// Copyright (C) 2021 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 QQMLDOMFILEWRITER_P
5#define QQMLDOMFILEWRITER_P
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 "qqmldom_global.h"
19#include "qqmldomfunctionref_p.h"
20
21#include <QtCore/QDebug>
22#include <QtCore/QFile>
23#include <QtCore/QStringList>
24#include <QtCore/QCoreApplication>
25
26QT_BEGIN_NAMESPACE
27namespace QQmlJS {
28namespace Dom {
29
30class QMLDOM_EXPORT FileWriter
31{
32 Q_GADGET
33 Q_DECLARE_TR_FUNCTIONS(FileWriter)
34public:
35 enum class Status { ShouldWrite, DidWrite, SkippedEqual, SkippedDueToFailure };
36
37 FileWriter() = default;
38
39 ~FileWriter()
40 {
41 if (!silentWarnings) {
42 for (const QString &w : std::as_const(t&: warnings))
43 qWarning(msg: "%ls", qUtf16Printable(w));
44 }
45 if (shouldRemoveTempFile)
46 tempFile.remove();
47 }
48
49 Status write(const QString &targetFile, function_ref<bool(QTextStream &)> write, int nBk = 2);
50
51 bool shouldRemoveTempFile = false;
52 bool silentWarnings = false;
53 Status status = Status::SkippedDueToFailure;
54 QString targetFile;
55 QFile tempFile;
56 QStringList newBkFiles;
57 QStringList warnings;
58
59private:
60 Q_DISABLE_COPY_MOVE(FileWriter)
61};
62
63} // namespace Dom
64} // namespace QQmlJS
65QT_END_NAMESPACE
66#endif
67

source code of qtdeclarative/src/qmldom/qqmldomfilewriter_p.h