1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef TEXTEDITORQUICKFIX_H
34 #define TEXTEDITORQUICKFIX_H
36 #include "texteditor_global.h"
37 #include "icompletioncollector.h"
39 #include <QtCore/QSharedPointer>
41 namespace TextEditor {
43 class BaseTextEditorWidget;
46 State of the editor on which the QuickFixFactory and the QuickFixOperation work.
48 This class contains a reference
50 class TEXTEDITOR_EXPORT QuickFixState
53 /// Creates a new state object for the given text editor.
54 QuickFixState(TextEditor::BaseTextEditorWidget *editor);
55 virtual ~QuickFixState();
57 TextEditor::BaseTextEditorWidget *editor() const;
60 TextEditor::BaseTextEditorWidget *_editor;
64 Class to perform a single quick-fix.
66 Quick-fix operations cannot be copied, and must be passed around as explicitly
67 shared pointers ( QuickFixOperation::Ptr ).
69 Subclasses should make sure that they copy parts of, or the whole QuickFixState ,
70 which are needed to perform the quick-fix operation.
72 class TEXTEDITOR_EXPORT QuickFixOperation
74 Q_DISABLE_COPY(QuickFixOperation)
77 typedef QSharedPointer<QuickFixOperation> Ptr;
80 QuickFixOperation(int priority = -1);
81 virtual ~QuickFixOperation();
84 \returns The priority for this quick-fix. See the QuickFixCollector for more
87 virtual int priority() const;
89 /// Sets the priority for this quick-fix operation.
90 void setPriority(int priority);
93 \returns The description for this quick-fix. This description is shown to the
96 virtual QString description() const;
98 /// Sets the description for this quick-fix, which will be shown to the user.
99 void setDescription(const QString &description);
102 Perform this quick-fix's operation.
104 Subclasses should implement this method to do the actual changes.
106 virtual void perform() = 0;
110 QString _description;
114 The QuickFixFactory is responsible for generating QuickFixOperation s which are
115 applicable to the given QuickFixState.
117 A QuickFixFactory should not have any state -- it can be invoked multiple times
118 for different QuickFixState objects to create the matching operations, before any
119 of those operations are applied (or released).
121 This way, a single factory can be used by multiple editors, and a single editor
122 can have multiple QuickFixCollector objects for different parts of the code.
124 class TEXTEDITOR_EXPORT QuickFixFactory: public QObject
129 QuickFixFactory(QObject *parent = 0);
130 virtual ~QuickFixFactory() = 0;
133 \returns A list of operations which can be performed for the given state.
135 virtual QList<QuickFixOperation::Ptr> matchingOperations(QuickFixState *state) = 0;
139 A completion collector which will use the QuickFixFactory classes to generate
140 quickfixes for the given editor.
142 All QuickFixFactory instances returned by #quickFixFactories are queried for
143 possible quick-fix operations. The operations(s) with the highest priority are
144 stored, and can be queried by calling #quickFixes .
146 class TEXTEDITOR_EXPORT QuickFixCollector: public TextEditor::IQuickFixCollector
152 virtual ~QuickFixCollector();
154 QList<TextEditor::QuickFixOperation::Ptr> quickFixes() const
155 { return m_quickFixes; }
157 virtual TextEditor::ITextEditor *editor() const;
158 virtual int startPosition() const;
159 virtual bool triggersCompletion(TextEditor::ITextEditor *editor);
160 virtual int startCompletion(TextEditor::ITextEditor *editor);
161 virtual void completions(QList<TextEditor::CompletionItem> *completions);
163 virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const
164 { return policy == TextEditor::QuickFixCompletion; }
166 /// See IQuickFixCollector::fix
167 virtual void fix(const TextEditor::CompletionItem &item);
169 /// See ICompletionCollector::cleanup .
170 virtual void cleanup();
172 /// Called from #startCompletion to create a QuickFixState .
173 virtual TextEditor::QuickFixState *initializeCompletion(BaseTextEditorWidget *editable) = 0;
175 virtual QList<QuickFixFactory *> quickFixFactories() const = 0;
178 TextEditor::ITextEditor *m_editor;
179 QList<QuickFixOperation::Ptr> m_quickFixes;
182 } // namespace TextEditor
184 #endif // TEXTEDITORQUICKFIX_H