OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / quickfix.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef TEXTEDITORQUICKFIX_H
34 #define TEXTEDITORQUICKFIX_H
35
36 #include "texteditor_global.h"
37 #include "icompletioncollector.h"
38
39 #include <QtCore/QSharedPointer>
40
41 namespace TextEditor {
42
43 class BaseTextEditorWidget;
44
45 /*!
46     State of the editor on which the QuickFixFactory and the QuickFixOperation work.
47
48     This class contains a reference
49  */
50 class TEXTEDITOR_EXPORT QuickFixState
51 {
52 public:
53     /// Creates a new state object for the given text editor.
54     QuickFixState(TextEditor::BaseTextEditorWidget *editor);
55     virtual ~QuickFixState();
56
57     TextEditor::BaseTextEditorWidget *editor() const;
58
59 private:
60     TextEditor::BaseTextEditorWidget *_editor;
61 };
62
63 /*!
64     Class to perform a single quick-fix.
65
66     Quick-fix operations cannot be copied, and must be passed around as explicitly
67     shared pointers ( QuickFixOperation::Ptr ).
68
69     Subclasses should make sure that they copy parts of, or the whole QuickFixState ,
70     which are needed to perform the quick-fix operation.
71  */
72 class TEXTEDITOR_EXPORT QuickFixOperation
73 {
74     Q_DISABLE_COPY(QuickFixOperation)
75
76 public:
77     typedef QSharedPointer<QuickFixOperation> Ptr;
78
79 public:
80     QuickFixOperation(int priority = -1);
81     virtual ~QuickFixOperation();
82
83     /*!
84         \returns The priority for this quick-fix. See the QuickFixCollector for more
85                  information.
86      */
87     virtual int priority() const;
88
89     /// Sets the priority for this quick-fix operation.
90     void setPriority(int priority);
91
92     /*!
93         \returns The description for this quick-fix. This description is shown to the
94                  user.
95      */
96     virtual QString description() const;
97
98     /// Sets the description for this quick-fix, which will be shown to the user.
99     void setDescription(const QString &description);
100
101     /*!
102         Perform this quick-fix's operation.
103
104         Subclasses should implement this method to do the actual changes.
105      */
106     virtual void perform() = 0;
107
108 private:
109     int _priority;
110     QString _description;
111 };
112
113 /*!
114     The QuickFixFactory is responsible for generating QuickFixOperation s which are
115     applicable to the given QuickFixState.
116
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).
120
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.
123  */
124 class TEXTEDITOR_EXPORT QuickFixFactory: public QObject
125 {
126     Q_OBJECT
127
128 public:
129     QuickFixFactory(QObject *parent = 0);
130     virtual ~QuickFixFactory() = 0;
131
132     /*!
133         \returns A list of operations which can be performed for the given state.
134      */
135     virtual QList<QuickFixOperation::Ptr> matchingOperations(QuickFixState *state) = 0;
136 };
137
138 /*!
139     A completion collector which will use the QuickFixFactory classes to generate
140     quickfixes for the given editor.
141
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 .
145  */
146 class TEXTEDITOR_EXPORT QuickFixCollector: public TextEditor::IQuickFixCollector
147 {
148     Q_OBJECT
149
150 public:
151     QuickFixCollector();
152     virtual ~QuickFixCollector();
153
154     QList<TextEditor::QuickFixOperation::Ptr> quickFixes() const
155     { return m_quickFixes; }
156
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);
162
163     virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const
164     { return policy == TextEditor::QuickFixCompletion; }
165
166     /// See IQuickFixCollector::fix
167     virtual void fix(const TextEditor::CompletionItem &item);
168
169     /// See ICompletionCollector::cleanup .
170     virtual void cleanup();
171
172     /// Called from #startCompletion to create a QuickFixState .
173     virtual TextEditor::QuickFixState *initializeCompletion(BaseTextEditorWidget *editable) = 0;
174
175     virtual QList<QuickFixFactory *> quickFixFactories() const = 0;
176
177 private:
178     TextEditor::ITextEditor *m_editor;
179     QList<QuickFixOperation::Ptr> m_quickFixes;
180 };
181
182 } // namespace TextEditor
183
184 #endif // TEXTEDITORQUICKFIX_H