Commit 823064d9 authored by Leandro Melo's avatar Leandro Melo
Browse files

Generic highlighter: Changed interface of the definition and adaptated relevant code.

parent 7ba6ad38
......@@ -49,7 +49,7 @@ HighlightDefinition::~HighlightDefinition()
{}
template <class Element, class Container>
const QSharedPointer<Element> &HighlightDefinition::
QSharedPointer<Element> HighlightDefinition::
GenericHelper::create(const QString &name, Container &container)
{
if (name.isEmpty())
......@@ -58,12 +58,11 @@ GenericHelper::create(const QString &name, Container &container)
if (container.contains(name))
throw HighlighterException();
container.insert(name, QSharedPointer<Element>(new Element));
return *container.constFind(name);
return container.insert(name, QSharedPointer<Element>(new Element)).value();
}
template <class Element, class Container>
const QSharedPointer<Element> &HighlightDefinition::
QSharedPointer<Element> HighlightDefinition::
GenericHelper::find(const QString &name, const Container &container) const
{
typename Container::const_iterator it = container.find(name);
......@@ -73,34 +72,35 @@ GenericHelper::find(const QString &name, const Container &container) const
return it.value();
}
const QSharedPointer<KeywordList> &HighlightDefinition::createKeywordList(const QString &list)
QSharedPointer<KeywordList> HighlightDefinition::createKeywordList(const QString &list)
{ return m_helper.create<KeywordList>(list, m_lists); }
const QSharedPointer<KeywordList> &HighlightDefinition::keywordList(const QString &list)
QSharedPointer<KeywordList> HighlightDefinition::keywordList(const QString &list)
{ return m_helper.find<KeywordList>(list, m_lists); }
const QSharedPointer<Context> &HighlightDefinition::createContext(const QString &context,
bool initial)
QSharedPointer<Context> HighlightDefinition::createContext(const QString &context, bool initial)
{
if (initial)
m_initialContext = context;
return m_helper.create<Context>(context, m_contexts);
QSharedPointer<Context> newContext = m_helper.create<Context>(context, m_contexts);
newContext->setName(context);
return newContext;
}
const QSharedPointer<Context> &HighlightDefinition::initialContext() const
QSharedPointer<Context> HighlightDefinition::initialContext() const
{ return m_helper.find<Context>(m_initialContext, m_contexts); }
const QSharedPointer<Context> &HighlightDefinition::context(const QString &context) const
QSharedPointer<Context> HighlightDefinition::context(const QString &context) const
{ return m_helper.find<Context>(context, m_contexts); }
const QHash<QString, QSharedPointer<Context> > &HighlightDefinition::contexts() const
{ return m_contexts; }
const QSharedPointer<ItemData> &HighlightDefinition::createItemData(const QString &itemData)
QSharedPointer<ItemData> HighlightDefinition::createItemData(const QString &itemData)
{ return m_helper.create<ItemData>(itemData, m_itemsData); }
const QSharedPointer<ItemData> &HighlightDefinition::itemData(const QString &itemData) const
QSharedPointer<ItemData> HighlightDefinition::itemData(const QString &itemData) const
{ return m_helper.find<ItemData>(itemData, m_itemsData); }
void HighlightDefinition::setSingleLineComment(const QString &start)
......
......@@ -47,16 +47,16 @@ public:
HighlightDefinition();
~HighlightDefinition();
const QSharedPointer<KeywordList> &createKeywordList(const QString &list);
const QSharedPointer<KeywordList> &keywordList(const QString &list);
QSharedPointer<KeywordList> createKeywordList(const QString &list);
QSharedPointer<KeywordList> keywordList(const QString &list);
const QSharedPointer<Context> &createContext(const QString &context, bool initial);
const QSharedPointer<Context> &initialContext() const;
const QSharedPointer<Context> &context(const QString &context) const;
QSharedPointer<Context> createContext(const QString &context, bool initial);
QSharedPointer<Context> initialContext() const;
QSharedPointer<Context> context(const QString &context) const;
const QHash<QString, QSharedPointer<Context> > &contexts() const;
const QSharedPointer<ItemData> &createItemData(const QString &itemData);
const QSharedPointer<ItemData> &itemData(const QString &itemData) const;
QSharedPointer<ItemData> createItemData(const QString &itemData);
QSharedPointer<ItemData> itemData(const QString &itemData) const;
void setKeywordsSensitive(const QString &sensitivity);
Qt::CaseSensitivity keywordsSensitive() const;
......@@ -86,10 +86,10 @@ private:
struct GenericHelper
{
template <class Element, class Container>
const QSharedPointer<Element> &create(const QString &name, Container &container);
QSharedPointer<Element> create(const QString &name, Container &container);
template <class Element, class Container>
const QSharedPointer<Element> &find(const QString &name, const Container &container) const;
QSharedPointer<Element> find(const QString &name, const Container &container) const;
};
GenericHelper m_helper;
......
......@@ -224,7 +224,6 @@ void HighlightDefinitionHandler::contextElementStarted(const QXmlAttributes &att
{
m_currentContext = m_definition->createContext(atts.value(kName), m_initialContext);
m_currentContext->setDefinition(m_definition);
m_currentContext->setName(atts.value(kName));
m_currentContext->setItemData(atts.value(kAttribute));
m_currentContext->setDynamic(atts.value(kDynamic));
m_currentContext->setFallthrough(atts.value(kFallthrough));
......
......@@ -37,6 +37,7 @@
#include "highlighter.h"
#include "highlighterexception.h"
#include "manager.h"
#include "context.h"
#include "normalindenter.h"
#include "fontsettings.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment