Permalink
Browse files

Reworked ExpressionHighlighter to use the token sequence for

highlighting
  • Loading branch information...
aelliott committed Feb 17, 2012
1 parent b447b7a commit 81b9b64a7c1d5b9787483f99c5530a3268769cec
Showing with 120 additions and 212 deletions.
  1. +6 −3 blockhighlighter.cpp
  2. +1 −1 blockhighlighter.hpp
  3. +15 −4 expressionedit.cpp
  4. +3 −0 expressionedit.hpp
  5. +88 −192 expressionhighlighter.cpp
  6. +4 −11 expressionhighlighter.hpp
  7. +1 −1 mainwindow.cpp
  8. +2 −0 testblockwidget.cpp
View
@@ -30,7 +30,7 @@
BlockHighlighter::BlockHighlighter(RegexFactory *factory, QTextEdit *parent)
: QSyntaxHighlighter(parent)
, _factory(factory)
- , _expression(QString())
+ , _pattern("")
{
}
@@ -57,7 +57,10 @@ BlockHighlighter::~BlockHighlighter()
*/
void BlockHighlighter::highlightBlock(const QString &text)
{
- RegexBase *rx = _factory->regexpEngine(_expression);
+ if(_pattern.isEmpty())
+ return;
+
+ RegexBase *rx = _factory->regexpEngine(_pattern);
// If it's invalid we have nothing to do
if(!rx->isValid())
@@ -98,6 +101,6 @@ void BlockHighlighter::highlightBlock(const QString &text)
*/
void BlockHighlighter::updateExpression(QString exp)
{
- _expression = exp;
+ _pattern = exp;
rehighlight();
}
View
@@ -47,7 +47,7 @@ public slots:
private:
RegexFactory *_factory;
- QString _expression;
+ QString _pattern;
};
#endif // BLOCKHIGHLIGHTER_HPP
View
@@ -23,6 +23,7 @@
ExpressionEdit::ExpressionEdit(QWidget *parent)
: QTextEdit(parent)
+ , _factory(0)
{
QSettings settings;
_highlighting = settings.value("Editor/Highlighting", true).toBool();
@@ -31,12 +32,12 @@ ExpressionEdit::ExpressionEdit(QWidget *parent)
connect(this, SIGNAL(textChanged()), this, SLOT(recalculateHeight()));
if(_highlighting)
- _highlighter = new ExpressionHighlighter(this);
+ _highlighter = new ExpressionHighlighter(_factory, this);
}
ExpressionEdit::~ExpressionEdit()
{
- if(_highlighting)
+ if(_highlighter != 0)
delete _highlighter;
}
@@ -76,6 +77,15 @@ void ExpressionEdit::keyReleaseEvent(QKeyEvent *e)
}
}
+void ExpressionEdit::setRegexFactory(RegexFactory *factory)
+{
+ _factory = factory;
+ if(_highlighter != 0)
+ delete _highlighter;
+
+ _highlighter = new ExpressionHighlighter(_factory, this);
+}
+
void ExpressionEdit::rehash()
{
QSettings settings;
@@ -85,12 +95,13 @@ void ExpressionEdit::rehash()
if(previous && !_highlighting)
{
// Stop highlighting
- delete _highlighter;
+ if(_highlighter != 0)
+ delete _highlighter;
}
else if(!previous && _highlighting)
{
// Start highlighting
- _highlighter = new ExpressionHighlighter(this);
+ _highlighter = new ExpressionHighlighter(_factory, this);
}
}
View
@@ -39,12 +39,15 @@ class ExpressionEdit : public QTextEdit
void keyPressEvent(QKeyEvent *e);
void keyReleaseEvent(QKeyEvent *e);
+ void setRegexFactory(RegexFactory *factory);
+
public slots:
void rehash();
void recalculateHeight();
private:
bool _highlighting;
+ RegexFactory *_factory;
ExpressionHighlighter *_highlighter;
};
Oops, something went wrong.

0 comments on commit 81b9b64

Please sign in to comment.