OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / generichighlighter / context.cpp
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 #include "context.h"
35 #include "rule.h"
36 #include "reuse.h"
37 #include "dynamicrule.h"
38 #include "highlightdefinition.h"
39
40 using namespace TextEditor;
41 using namespace Internal;
42
43 Context::Context() : m_fallthrough(false), m_dynamic(false)
44 {}
45
46 Context::Context(const Context &context) :
47     m_id(context.m_id), m_name(context.m_name), m_lineBeginContext(context.m_lineBeginContext),
48     m_lineEndContext(context.m_lineEndContext), m_fallthroughContext(context.m_fallthroughContext),
49     m_itemData(context.m_itemData), m_fallthrough(context.m_fallthrough),
50     m_dynamic(context.m_dynamic), m_instructions(context.m_instructions),
51     m_definition(context.m_definition)
52 {
53     // Rules need to be deeply copied because of dynamic contexts.
54     foreach (const QSharedPointer<Rule> &rule, context.m_rules)
55         m_rules.append(QSharedPointer<Rule>(rule->clone()));
56 }
57
58 const Context &Context::operator=(Context copy)
59 {
60     swap(copy);
61     return *this;
62 }
63
64 Context::~Context()
65 {}
66
67 void Context::swap(Context &context)
68 {
69     qSwap(m_id, context.m_id);
70     qSwap(m_name, context.m_name);
71     qSwap(m_lineBeginContext, context.m_lineBeginContext);
72     qSwap(m_lineEndContext, context.m_lineEndContext);
73     qSwap(m_fallthroughContext, context.m_fallthroughContext);
74     qSwap(m_itemData, context.m_itemData);
75     qSwap(m_fallthrough, context.m_fallthrough);
76     qSwap(m_dynamic, context.m_dynamic);
77     qSwap(m_rules, context.m_rules);
78     qSwap(m_instructions, context.m_instructions);
79     qSwap(m_definition, context.m_definition);
80 }
81
82 void Context::configureId(const int unique)
83 { m_id.append(QString::number(unique)); }
84
85 const QString &Context::id() const
86 { return m_id; }
87
88 void Context::setName(const QString &name)
89 {
90     m_name = name;
91     m_id = name;
92 }
93
94 const QString &Context::name() const
95 { return m_name; }
96
97 void Context::setLineBeginContext(const QString &context)
98 { m_lineBeginContext = context; }
99
100 const QString &Context::lineBeginContext() const
101 { return m_lineBeginContext; }
102
103 void Context::setLineEndContext(const QString &context)
104 { m_lineEndContext = context; }
105
106 const QString &Context::lineEndContext() const
107 { return m_lineEndContext; }
108
109 void Context::setFallthroughContext(const QString &context)
110 { m_fallthroughContext = context; }
111
112 const QString &Context::fallthroughContext() const
113 { return m_fallthroughContext; }
114
115 void Context::setItemData(const QString &itemData)
116 { m_itemData = itemData; }
117
118 const QString &Context::itemData() const
119 { return m_itemData; }
120
121 void Context::setFallthrough(const QString &fallthrough)
122 { m_fallthrough = toBool(fallthrough); }
123
124 bool Context::isFallthrough() const
125 { return m_fallthrough; }
126
127 void Context::setDynamic(const QString &dynamic)
128 { m_dynamic = toBool(dynamic); }
129
130 bool Context::isDynamic() const
131 { return m_dynamic; }
132
133 void Context::updateDynamicRules(const QStringList &captures) const
134 {
135     TextEditor::Internal::updateDynamicRules(m_rules, captures);
136 }
137
138 void Context::addRule(const QSharedPointer<Rule> &rule)
139 { m_rules.append(rule); }
140
141 void Context::addRule(const QSharedPointer<Rule> &rule, int index)
142 { m_rules.insert(index, rule); }
143
144 const QList<QSharedPointer<Rule> > & Context::rules() const
145 { return m_rules; }
146
147 void Context::addIncludeRulesInstruction(const IncludeRulesInstruction &instruction)
148 { m_instructions.append(instruction); }
149
150 const QList<IncludeRulesInstruction> &Context::includeRulesInstructions() const
151 { return m_instructions; }
152
153 void Context::clearIncludeRulesInstructions()
154 { m_instructions.clear(); }
155
156 void Context::setDefinition(const QSharedPointer<HighlightDefinition> &definition)
157 { m_definition = definition; }
158
159 const QSharedPointer<HighlightDefinition> &Context::definition() const
160 { return m_definition; }