OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmljseditor / qmljssemantichighlighter.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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
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 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef SEMANTICHIGHLIGHTER_H
35 #define SEMANTICHIGHLIGHTER_H
36
37 #include "qmljseditor.h"
38
39 #include <QtCore/QWaitCondition>
40 #include <QtCore/QModelIndex>
41 #include <QtCore/QMutex>
42 #include <QtCore/QThread>
43
44 namespace QmlJSEditor {
45 namespace Internal {
46
47 struct SemanticHighlighterSource
48 {
49     QmlJS::Snapshot snapshot;
50     QString fileName;
51     QString code;
52     int line;
53     int column;
54     int revision;
55     bool force;
56
57     SemanticHighlighterSource()
58         : line(0), column(0), revision(0), force(false)
59     { }
60
61     SemanticHighlighterSource(const QmlJS::Snapshot &snapshot,
62            const QString &fileName,
63            const QString &code,
64            int line, int column,
65            int revision)
66         : snapshot(snapshot), fileName(fileName),
67           code(code), line(line), column(column),
68           revision(revision), force(false)
69     { }
70
71     void clear()
72     {
73         snapshot = QmlJS::Snapshot();
74         fileName.clear();
75         code.clear();
76         line = 0;
77         column = 0;
78         revision = 0;
79         force = false;
80     }
81 };
82
83 class SemanticHighlighter: public QThread
84 {
85     Q_OBJECT
86
87 public:
88     SemanticHighlighter(QObject *parent = 0);
89     virtual ~SemanticHighlighter();
90
91     void abort();
92     void rehighlight(const SemanticHighlighterSource &source);
93     void setModelManager(QmlJS::ModelManagerInterface *modelManager);
94
95 Q_SIGNALS:
96     void changed(const QmlJSEditor::SemanticInfo &semanticInfo);
97
98 protected:
99     virtual void run();
100
101 private:
102     bool isOutdated();
103     SemanticInfo semanticInfo(const SemanticHighlighterSource &source);
104
105 private:
106     QMutex m_mutex;
107     QWaitCondition m_condition;
108     bool m_done;
109     SemanticHighlighterSource m_source;
110     SemanticInfo m_lastSemanticInfo;
111     QmlJS::ModelManagerInterface *m_modelManager;
112 };
113
114 } // namespace Internal
115 } // namespace QmlJSEditor
116
117 #endif // SEMANTICHIGHLIGHTER_H