1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include "dynamicrule.h"
38 #include "highlightdefinition.h"
40 using namespace TextEditor;
41 using namespace Internal;
43 Context::Context() : m_fallthrough(false), m_dynamic(false)
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)
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()));
58 const Context &Context::operator=(Context copy)
67 void Context::swap(Context &context)
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);
82 void Context::configureId(const int unique)
83 { m_id.append(QString::number(unique)); }
85 const QString &Context::id() const
88 void Context::setName(const QString &name)
94 const QString &Context::name() const
97 void Context::setLineBeginContext(const QString &context)
98 { m_lineBeginContext = context; }
100 const QString &Context::lineBeginContext() const
101 { return m_lineBeginContext; }
103 void Context::setLineEndContext(const QString &context)
104 { m_lineEndContext = context; }
106 const QString &Context::lineEndContext() const
107 { return m_lineEndContext; }
109 void Context::setFallthroughContext(const QString &context)
110 { m_fallthroughContext = context; }
112 const QString &Context::fallthroughContext() const
113 { return m_fallthroughContext; }
115 void Context::setItemData(const QString &itemData)
116 { m_itemData = itemData; }
118 const QString &Context::itemData() const
119 { return m_itemData; }
121 void Context::setFallthrough(const QString &fallthrough)
122 { m_fallthrough = toBool(fallthrough); }
124 bool Context::isFallthrough() const
125 { return m_fallthrough; }
127 void Context::setDynamic(const QString &dynamic)
128 { m_dynamic = toBool(dynamic); }
130 bool Context::isDynamic() const
131 { return m_dynamic; }
133 void Context::updateDynamicRules(const QStringList &captures) const
135 TextEditor::Internal::updateDynamicRules(m_rules, captures);
138 void Context::addRule(const QSharedPointer<Rule> &rule)
139 { m_rules.append(rule); }
141 void Context::addRule(const QSharedPointer<Rule> &rule, int index)
142 { m_rules.insert(index, rule); }
144 const QList<QSharedPointer<Rule> > & Context::rules() const
147 void Context::addIncludeRulesInstruction(const IncludeRulesInstruction &instruction)
148 { m_instructions.append(instruction); }
150 const QList<IncludeRulesInstruction> &Context::includeRulesInstructions() const
151 { return m_instructions; }
153 void Context::clearIncludeRulesInstructions()
154 { m_instructions.clear(); }
156 void Context::setDefinition(const QSharedPointer<HighlightDefinition> &definition)
157 { m_definition = definition; }
159 const QSharedPointer<HighlightDefinition> &Context::definition() const
160 { return m_definition; }