TextEditor: Clean up/streamline SyntaxHighlighter setup

No need for the third construction way if that's not
really used by the factories anyway.

Change-Id: Id3b34da5b0320babae9bef96a79bbaa52e0db06d
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-08-27 13:38:02 +02:00
parent 2a5c602341
commit 251a1d2588
17 changed files with 58 additions and 131 deletions

View File

@@ -44,8 +44,7 @@
#include <texteditor/texteditorconstants.h>
namespace PythonEditor {
using namespace PythonEditor::Internal;
namespace Internal {
/**
* @class PyEditor::Highlighter
@@ -65,20 +64,7 @@ using namespace PythonEditor::Internal;
* @endcode
*/
PythonHighlighter::PythonHighlighter(QTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent)
{
init();
}
/// New instance created when opening any document in editor
PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent)
{
init();
}
void PythonHighlighter::init()
PythonHighlighter::PythonHighlighter()
{
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
@@ -98,11 +84,6 @@ void PythonHighlighter::init()
setTextFormatCategories(categories);
}
/// Instance destroyed when one of documents closed from editor
PythonHighlighter::~PythonHighlighter()
{
}
/**
* @brief Highlighter::highlightBlock highlights single line of Python code
* @param text is single line without EOLN symbol. Access to all block data
@@ -123,11 +104,9 @@ void PythonHighlighter::highlightBlock(const QString &text)
/**
* @return True if this keyword is acceptable at start of import line
*/
static inline
bool isImportKeyword(const QString &keyword)
static bool isImportKeyword(const QString &keyword)
{
return (keyword == QLatin1String("import")
|| keyword == QLatin1String("from"));
return keyword == QLatin1String("import") || keyword == QLatin1String("from");
}
/**
@@ -175,4 +154,5 @@ void PythonHighlighter::highlightImport(Scanner &scanner)
}
}
} // namespace Internal
} // namespace PythonEditor

View File

@@ -33,26 +33,24 @@
#include <texteditor/syntaxhighlighter.h>
namespace PythonEditor {
namespace Internal {
namespace Internal { class Scanner; }
class Scanner;
class PythonHighlighter : public TextEditor::SyntaxHighlighter
{
Q_OBJECT
public:
explicit PythonHighlighter(QTextDocument *parent = 0);
explicit PythonHighlighter(TextEditor::BaseTextDocument *parent);
virtual ~PythonHighlighter();
PythonHighlighter();
protected:
virtual void highlightBlock(const QString &text);
void highlightBlock(const QString &text);
private:
int highlightLine(const QString &text, int initialState);
void highlightImport(Internal::Scanner &scanner);
void init();
};
} // namespace Internal
} // namespace PythonEditor
#endif // PYTHONHIGHLIGHTER_H