cppeditor.h 5.9 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
#ifndef CPPEDITOR_H
#define CPPEDITOR_H

33
#include "cppeditordocument.h"
34

35
#include "cppfunctiondecldeflink.h"
36

con's avatar
con committed
37
#include <texteditor/basetexteditor.h>
38
#include <texteditor/semantichighlighter.h>
39
#include <texteditor/texteditorconstants.h>
40

41
#include <utils/qtcoverride.h>
42
#include <utils/uncommentselection.h>
con's avatar
con committed
43

44
#include <QScopedPointer>
con's avatar
con committed
45

46
namespace CPlusPlus { class Symbol; }
47
namespace CppTools { class SemanticInfo; }
con's avatar
con committed
48 49 50 51

namespace CppEditor {
namespace Internal {

52
class CppEditorOutline;
53 54
class CppEditorWidget;
class CppEditorWidgetPrivate;
55
class FollowSymbolUnderCursor;
Roberto Raggi's avatar
Roberto Raggi committed
56

57
class CPPEditor : public TextEditor::BaseTextEditor
con's avatar
con committed
58 59
{
    Q_OBJECT
60

con's avatar
con committed
61
public:
62
    CPPEditor(CppEditorWidget *);
con's avatar
con committed
63

64
    Core::IEditor *duplicate() QTC_OVERRIDE;
con's avatar
con committed
65

66 67 68
    bool open(QString *errorString,
              const QString &fileName,
              const QString &realFileName) QTC_OVERRIDE;
69

70
    TextEditor::CompletionAssistProvider *completionAssistProvider() QTC_OVERRIDE;
con's avatar
con committed
71 72
};

73
class CppEditorWidget : public TextEditor::BaseTextEditorWidget
con's avatar
con committed
74 75 76 77
{
    Q_OBJECT

public:
78 79
    static Link linkToSymbol(CPlusPlus::Symbol *symbol);
    static QString identifierUnderCursor(QTextCursor *macroCursor);
con's avatar
con committed
80

81
public:
82 83 84
    CppEditorWidget(QWidget *parent = 0);
    CppEditorWidget(CppEditorWidget *other);
    ~CppEditorWidget();
85 86

    CPPEditorDocument *cppEditorDocument() const;
87
    CppEditorOutline *outline() const;
88

89
    CppTools::SemanticInfo semanticInfo() const;
90

91 92 93
    QSharedPointer<FunctionDeclDefLink> declDefLink() const;
    void applyDeclDefLinkChanges(bool jumpToMatch);

94 95 96 97
    TextEditor::IAssistInterface *createAssistInterface(
            TextEditor::AssistKind kind,
            TextEditor::AssistReason reason) const QTC_OVERRIDE;

98 99
    FollowSymbolUnderCursor *followSymbolUnderCursorDelegate(); // exposed for tests

Erik Verbruggen's avatar
Erik Verbruggen committed
100
public slots:
101 102 103 104
    void paste() QTC_OVERRIDE;
    void cut() QTC_OVERRIDE;
    void selectAll() QTC_OVERRIDE;

105
    void switchDeclarationDefinition(bool inNextSplit);
106
    void showPreProcessorWidget();
Nikolai Kosjar's avatar
Nikolai Kosjar committed
107 108 109 110 111

    void findUsages();
    void renameSymbolUnderCursor();
    void renameUsages(const QString &replacement = QString());

112
    void semanticRehighlight(bool force = false);
Eike Ziller's avatar
Eike Ziller committed
113
    void highlighterStarted(QFuture<TextEditor::HighlightingResult> *highlighter,
Nikolai Kosjar's avatar
Nikolai Kosjar committed
114
                            unsigned revision);
con's avatar
con committed
115 116

protected:
117 118 119
    bool event(QEvent *e) QTC_OVERRIDE;
    void contextMenuEvent(QContextMenuEvent *) QTC_OVERRIDE;
    void keyPressEvent(QKeyEvent *e) QTC_OVERRIDE;
120

121 122 123 124 125
    void applyFontSettings() QTC_OVERRIDE;
    TextEditor::BaseTextEditor *createEditor() QTC_OVERRIDE;

    bool openLink(const Link &link, bool inNextSplit) QTC_OVERRIDE
    { return openCppEditorAt(link, inNextSplit); }
con's avatar
con committed
126

Nikolai Kosjar's avatar
Nikolai Kosjar committed
127 128 129
    Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
                    bool inNextSplit = false) QTC_OVERRIDE;

Erik Verbruggen's avatar
Erik Verbruggen committed
130
protected slots:
131
    void slotCodeStyleSettingsChanged(const QVariant &) QTC_OVERRIDE;
132

Erik Verbruggen's avatar
Erik Verbruggen committed
133
private slots:
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
134 135
    void updateUses();
    void updateUsesNow();
136 137 138
    void updateFunctionDeclDefLink();
    void updateFunctionDeclDefLinkNow();
    void onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink> link);
139
    void onFilePathChanged();
140
    void onDocumentUpdated();
141
    void onContentsChanged(int position, int charsRemoved, int charsAdded);
142
    void updatePreprocessorButtonTooltip();
con's avatar
con committed
143

144
    void updateSemanticInfo(const CppTools::SemanticInfo &semanticInfo);
145 146
    void highlightSymbolUsages(int from, int to);
    void finishHighlightSymbolUsages();
Roberto Raggi's avatar
Roberto Raggi committed
147

148
    void markSymbolsNow();
149
    void performQuickFix(int index);
150
    void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker);
Nikolai Kosjar's avatar
Nikolai Kosjar committed
151
    void abortDeclDefLink();
152

153 154 155
    void onLocalRenamingFinished();
    void onLocalRenamingProcessKeyPressNormally(QKeyEvent *e);

con's avatar
con committed
156
private:
Nikolai Kosjar's avatar
Nikolai Kosjar committed
157 158
    static bool openCppEditorAt(const Link &, bool inNextSplit = false);

159
    CppEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
160
    void ctor();
161

Nikolai Kosjar's avatar
Nikolai Kosjar committed
162 163
    void createToolBar(CPPEditor *editable);

164 165 166
    unsigned editorRevision() const;
    bool isOutdated() const;

Nikolai Kosjar's avatar
Nikolai Kosjar committed
167 168 169
    const CPlusPlus::Macro *findCanonicalMacro(const QTextCursor &cursor,
                                               CPlusPlus::Document::Ptr doc) const;

170 171
    QTextCharFormat textCharFormat(TextEditor::TextStyle category);

172
    void markSymbols(const QTextCursor &tc, const CppTools::SemanticInfo &info);
con's avatar
con committed
173

174 175
    QList<QTextEdit::ExtraSelection> createSelectionsFromUses(
            const QList<TextEditor::HighlightingResult> &uses);
176

177
private:
178
    QScopedPointer<CppEditorWidgetPrivate> d;
con's avatar
con committed
179 180 181 182 183 184
};

} // namespace Internal
} // namespace CppEditor

#endif // CPPEDITOR_H