basetextdocument.h 3.97 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 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
class ITextMarkable;
Jarek Kobus's avatar
Jarek Kobus committed
45
class TypingSettings;
46 47
class StorageSettings;
class TabSettings;
48
class ExtraEncodingSettings;
49
class SyntaxHighlighter;
50
class BaseTextDocumentPrivate;
con's avatar
con committed
51

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

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

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

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

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

75
    ITextMarkable *markableInterface() const;
con's avatar
con committed
76

77
    // IDocument implementation.
78 79 80 81 82 83 84
    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();
85
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
86
    QString mimeType() const;
con's avatar
con committed
87
    void setMimeType(const QString &mt);
88
    void setFilePath(const QString &newName);
con's avatar
con committed
89

90 91
    QString defaultPath() const;
    QString suggestedFileName() const;
con's avatar
con committed
92

93 94
    void setDefaultPath(const QString &defaultPath);
    void setSuggestedFileName(const QString &suggestedFileName);
con's avatar
con committed
95

96
    virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
97
    virtual bool reload(QString *errorString);
con's avatar
con committed
98

99
    QTextDocument *document() const;
100
    void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
101
    SyntaxHighlighter *syntaxHighlighter() const;
con's avatar
con committed
102

103
    bool reload(QString *errorString, QTextCodec *codec);
104
    void cleanWhitespace(const QTextCursor &cursor);
105

con's avatar
con committed
106
signals:
107
    void mimeTypeChanged();
con's avatar
con committed
108 109

private:
hjk's avatar
hjk committed
110 111
    void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
    void ensureFinalNewLine(QTextCursor &cursor);
112 113

    BaseTextDocumentPrivate *d;
con's avatar
con committed
114 115 116 117
};

} // namespace TextEditor

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