aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmldom/qqmldomindentinglinewriter_p.h
blob: 63ec3fc4321c8a55890f15426926b41dd77d7ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQMLDOMINDENTIGLINEWRITER_P
#define QQMLDOMINDENTIGLINEWRITER_P

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qqmldom_global.h"
#include "qqmldomcodeformatter_p.h"
#include "qqmldomlinewriter_p.h"

#include <QtQml/private/qqmljssourcelocation_p.h>
#include <QtCore/QAtomicInt>
#include <functional>

QT_BEGIN_NAMESPACE
namespace QQmlJS {
namespace Dom {

QMLDOM_EXPORT class IndentingLineWriter : public LineWriter
{
    Q_GADGET
public:
    IndentingLineWriter(const SinkF &innerSink, const QString &fileName,
                        const LineWriterOptions &options = LineWriterOptions(),
                        const FormatTextStatus &initialStatus = FormatTextStatus::initialStatus(),
                        int lineNr = 0, int columnNr = 0, int utf16Offset = 0,
                        QString currentLine = QString())
        : LineWriter(innerSink, fileName, options, lineNr, columnNr, utf16Offset, currentLine),
          m_preCachedStatus(initialStatus)
    {
    }
    void reindentAndSplit(const QString &eol, bool eof = false) override;
    FormatPartialStatus &fStatus();

    void lineChanged() override { m_fStatusValid = false; }
    void willCommit() override;
    bool reindent() const { return m_reindent; }
    void setReindent(bool v) { m_reindent = v; }

private:
    Q_DISABLE_COPY_MOVE(IndentingLineWriter)
protected:
    FormatTextStatus m_preCachedStatus;
    bool m_fStatusValid = false;
    FormatPartialStatus m_fStatus;
};

} // namespace Dom
} // namespace QQmlJS
QT_END_NAMESPACE
#endif