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 (const QString &w : std::as_const(t&: warnings))
42 qWarning() << w;
43 }
44 if (shouldRemoveTempFile)
45 tempFile.remove();
46 }
47
48 Status write(const QString &targetFile, function_ref<bool(QTextStream &)> write, int nBk = 2);
49
50 bool shouldRemoveTempFile = false;
51 bool silentWarnings = false;
52 Status status = Status::SkippedDueToFailure;
53 QString targetFile;
54 QFile tempFile;
55 QStringList newBkFiles;
56 QStringList warnings;
57
58private:
59 Q_DISABLE_COPY_MOVE(FileWriter)
60};
61
62} // namespace Dom
63} // namespace QQmlJS
64QT_END_NAMESPACE
65#endif
66

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

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