basetextdocument.h 4.19 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34
#ifndef BASETEXTDOCUMENT_H
#define BASETEXTDOCUMENT_H

#include "texteditor_global.h"

35
#include "itexteditor.h"
36

con's avatar
con committed
37 38 39 40 41 42 43
QT_BEGIN_NAMESPACE
class QTextCursor;
class QTextDocument;
QT_END_NAMESPACE

namespace TextEditor {

44 45
class BaseTextDocumentPrivate;
class ExtraEncodingSettings;
46
class ITextMarkable;
47
class Indenter;
48
class StorageSettings;
49
class SyntaxHighlighter;
50 51
class TabSettings;
class TypingSettings;
con's avatar
con committed
52

53
class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument
con's avatar
con committed
54 55 56 57 58
{
    Q_OBJECT

public:
    BaseTextDocument();
59
    virtual ~BaseTextDocument();
con's avatar
con committed
60

61
    // ITextEditorDocument
62
    QString plainText() const;
63 64 65
    QString textAt(int pos, int length) const;
    QChar characterAt(int pos) const;

Jarek Kobus's avatar
Jarek Kobus committed
66
    void setTypingSettings(const TypingSettings &typingSettings);
67 68
    void setStorageSettings(const StorageSettings &storageSettings);
    void setTabSettings(const TabSettings &tabSettings);
69
    void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
con's avatar
con committed
70

Jarek Kobus's avatar
Jarek Kobus committed
71
    const TypingSettings &typingSettings() const;
72 73
    const StorageSettings &storageSettings() const;
    const TabSettings &tabSettings() const;
74
    const ExtraEncodingSettings &extraEncodingSettings() const;
75

76 77
    void setIndenter(Indenter *indenter);
    Indenter *indenter() const;
78 79
    void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null);
    void autoReindent(const QTextCursor &cursor);
80

81
    ITextMarkable *markableInterface() const;
con's avatar
con committed
82

83
    // IDocument implementation.
84 85 86 87 88 89 90
    bool save(QString *errorString, const QString &fileName, bool autoSave);
    bool setContents(const QByteArray &contents);
    bool shouldAutoSave() const;
    bool isFileReadOnly() const;
    bool isModified() const;
    bool isSaveAsAllowed() const;
    void checkPermissions();
91
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
92
    QString mimeType() const;
con's avatar
con committed
93
    void setMimeType(const QString &mt);
94
    void setFilePath(const QString &newName);
con's avatar
con committed
95

96 97
    QString defaultPath() const;
    QString suggestedFileName() const;
con's avatar
con committed
98

99 100
    void setDefaultPath(const QString &defaultPath);
    void setSuggestedFileName(const QString &suggestedFileName);
con's avatar
con committed
101

102
    virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
103
    virtual bool reload(QString *errorString);
con's avatar
con committed
104

105
    QTextDocument *document() const;
106
    void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
107
    SyntaxHighlighter *syntaxHighlighter() const;
con's avatar
con committed
108

109
    bool reload(QString *errorString, QTextCodec *codec);
110
    void cleanWhitespace(const QTextCursor &cursor);
111

con's avatar
con committed
112
signals:
113
    void mimeTypeChanged();
con's avatar
con committed
114 115

private:
hjk's avatar
hjk committed
116 117
    void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
    void ensureFinalNewLine(QTextCursor &cursor);
118 119

    BaseTextDocumentPrivate *d;
con's avatar
con committed
120 121 122 123
};

} // namespace TextEditor

hjk's avatar
hjk committed
124
#endif // BASETEXTDOCUMENT_H