OSDN Git Service

Merge branch 'origin/2.0' (early part)
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmljseditor / qmljscodecompletion.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef QMLJSCODECOMPLETION_H
31 #define QMLJSCODECOMPLETION_H
32
33 #include <qmljs/qmljsdocument.h>
34 #include <texteditor/icompletioncollector.h>
35 #include <QtCore/QDateTime>
36 #include <QtCore/QPointer>
37
38 namespace TextEditor {
39 class ITextEditable;
40 }
41
42 namespace QmlJS {
43     class ModelManagerInterface;
44
45     namespace Interpreter {
46         class Value;
47     }
48 }
49
50 namespace QmlJSEditor {
51
52 namespace Internal {
53
54 class FunctionArgumentWidget;
55
56 class CodeCompletion: public TextEditor::ICompletionCollector
57 {
58     Q_OBJECT
59
60 public:
61     CodeCompletion(QmlJS::ModelManagerInterface *modelManager, QObject *parent = 0);
62     virtual ~CodeCompletion();
63
64     virtual TextEditor::ITextEditable *editor() const;
65     virtual int startPosition() const;
66     virtual bool shouldRestartCompletion();
67     virtual bool supportsEditor(TextEditor::ITextEditable *editor);
68     virtual bool triggersCompletion(TextEditor::ITextEditable *editor);
69     virtual int startCompletion(TextEditor::ITextEditable *editor);
70     virtual void completions(QList<TextEditor::CompletionItem> *completions);
71     virtual void complete(const TextEditor::CompletionItem &item);
72     virtual bool partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems);
73     virtual QList<TextEditor::CompletionItem> getCompletions();
74
75     virtual void cleanup();
76
77 private:
78     void updateSnippets();
79
80     bool maybeTriggersCompletion(TextEditor::ITextEditable *editor);
81     bool isDelimiter(QChar ch) const;
82
83     void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
84                         const QIcon &icon, int relevance);
85     void addCompletions(const QStringList &newCompletions,
86                         const QIcon &icon, int relevance);
87     void addCompletionsPropertyLhs(
88             const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
89             const QIcon &icon, int relevance);
90
91     QmlJS::ModelManagerInterface *m_modelManager;
92     TextEditor::ITextEditable *m_editor;
93     int m_startPosition;
94     QList<TextEditor::CompletionItem> m_completions;
95
96     QList<TextEditor::CompletionItem> m_snippets;
97     QDateTime m_snippetFileLastModified;
98     QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
99     bool m_restartCompletion;
100 };
101
102
103 } // end of namespace Internal
104 } // end of namespace QmlJSEditor
105
106 #endif // QMLJSCODECOMPLETION_H