1 | // Copyright (C) 2022 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 QQMLDOMINDENTIGLINEWRITER_P |
5 | #define QQMLDOMINDENTIGLINEWRITER_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 "qqmldomcodeformatter_p.h" |
20 | #include "qqmldomlinewriter_p.h" |
21 | |
22 | #include <QtQml/private/qqmljssourcelocation_p.h> |
23 | #include <QtCore/QAtomicInt> |
24 | #include <functional> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | namespace QQmlJS { |
28 | namespace Dom { |
29 | |
30 | QMLDOM_EXPORT class IndentingLineWriter : public LineWriter |
31 | { |
32 | Q_GADGET |
33 | public: |
34 | IndentingLineWriter(SinkF innerSink, QString fileName, |
35 | const LineWriterOptions &options = LineWriterOptions(), |
36 | const FormatTextStatus &initialStatus = FormatTextStatus::initialStatus(), |
37 | int lineNr = 0, int columnNr = 0, int utf16Offset = 0, |
38 | QString currentLine = QString()) |
39 | : LineWriter(innerSink, fileName, options, lineNr, columnNr, utf16Offset, currentLine), |
40 | m_preCachedStatus(initialStatus) |
41 | { |
42 | } |
43 | void reindentAndSplit(QString eol, bool eof = false) override; |
44 | FormatPartialStatus &fStatus(); |
45 | |
46 | void lineChanged() override { m_fStatusValid = false; } |
47 | void willCommit() override; |
48 | bool reindent() const { return m_reindent; } |
49 | void setReindent(bool v) { m_reindent = v; } |
50 | |
51 | private: |
52 | Q_DISABLE_COPY_MOVE(IndentingLineWriter) |
53 | protected: |
54 | FormatTextStatus m_preCachedStatus; |
55 | bool m_fStatusValid = false; |
56 | FormatPartialStatus m_fStatus; |
57 | }; |
58 | |
59 | } // namespace Dom |
60 | } // namespace QQmlJS |
61 | QT_END_NAMESPACE |
62 | #endif |
63 | |