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

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