idocument.h 4.08 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
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
** 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
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

26 27
#ifndef IDOCUMENT_H
#define IDOCUMENT_H
con's avatar
con committed
28 29

#include "core_global.h"
30

31
#include <QObject>
con's avatar
con committed
32

33
namespace Utils { class FileName; }
con's avatar
con committed
34

35 36
namespace Core {
class Id;
37
class InfoBar;
con's avatar
con committed
38

Orgad Shaneh's avatar
Orgad Shaneh committed
39 40 41 42
namespace Internal {
class IDocumentPrivate;
}

43
class CORE_EXPORT IDocument : public QObject
con's avatar
con committed
44 45 46 47
{
    Q_OBJECT

public:
48 49 50 51 52 53
    enum class OpenResult {
        Success,
        ReadError,
        CannotHandle
    };

54 55
    // This enum must match the indexes of the reloadBehavior widget
    // in generalsettings.ui
56 57
    enum ReloadSetting {
        AlwaysAsk = 0,
58
        ReloadUnmodified = 1,
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        IgnoreAll = 2
    };

    enum ChangeTrigger {
        TriggerInternal,
        TriggerExternal
    };

    enum ChangeType {
        TypeContents,
        TypePermissions,
        TypeRemoved
    };

    enum ReloadBehavior {
        BehaviorAsk,
        BehaviorSilent
    };

    enum ReloadFlag {
        FlagReload,
        FlagIgnore
81
    };
con's avatar
con committed
82

83
    IDocument(QObject *parent = 0);
84
    ~IDocument() override;
con's avatar
con committed
85

Orgad Shaneh's avatar
Orgad Shaneh committed
86 87
    void setId(Id id);
    Id id() const;
88

89
    // required to be re-implemented for documents of IEditors
90
    virtual OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName);
91

Orgad Shaneh's avatar
Orgad Shaneh committed
92
    virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false);
93 94

    virtual QByteArray contents() const;
95 96
    virtual bool setContents(const QByteArray &contents);

97
    const Utils::FileName &filePath() const;
98
    virtual void setFilePath(const Utils::FileName &filePath);
99
    QString displayName() const;
100 101 102
    void setPreferredDisplayName(const QString &name);
    QString plainDisplayName() const;
    void setUniqueDisplayName(const QString &name);
103

104
    virtual bool isFileReadOnly() const;
105 106
    bool isTemporary() const;
    void setTemporary(bool temporary);
con's avatar
con committed
107

108 109
    virtual QString fallbackSaveAsPath() const;
    virtual QString fallbackSaveAsFileName() const;
hjk's avatar
hjk committed
110

Orgad Shaneh's avatar
Orgad Shaneh committed
111
    QString mimeType() const;
hjk's avatar
hjk committed
112
    void setMimeType(const QString &mimeType);
con's avatar
con committed
113

114
    virtual bool shouldAutoSave() const;
Orgad Shaneh's avatar
Orgad Shaneh committed
115 116
    virtual bool isModified() const;
    virtual bool isSaveAsAllowed() const;
con's avatar
con committed
117

118
    virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
Orgad Shaneh's avatar
Orgad Shaneh committed
119
    virtual bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
con's avatar
con committed
120

121
    virtual void checkPermissions();
122

123
    bool autoSave(QString *errorString, const QString &filePath);
124 125 126
    void setRestoredFrom(const QString &name);
    void removeAutoSaveFile();

Orgad Shaneh's avatar
Orgad Shaneh committed
127 128
    bool hasWriteWarning() const;
    void setWriteWarning(bool has);
129 130 131

    InfoBar *infoBar();

con's avatar
con committed
132
signals:
133
    // For meta data changes: file name, modified state, ...
con's avatar
con committed
134
    void changed();
135 136 137 138

    // For changes in the contents of the document
    void contentsChanged();

hjk's avatar
hjk committed
139
    void mimeTypeChanged();
140 141

    void aboutToReload();
142 143
    void reloadFinished(bool success);

144
    void filePathChanged(const Utils::FileName &oldName, const Utils::FileName &newName);
145 146

private:
Orgad Shaneh's avatar
Orgad Shaneh committed
147
    Internal::IDocumentPrivate *d;
con's avatar
con committed
148 149
};

hjk's avatar
hjk committed
150
} // namespace Core
con's avatar
con committed
151

152
#endif // IDOCUMENT_H