Target: add a UBS-specific syntax highlighter to the existing VS 2015 QCodeEditor project and wire it into the example MainWindow.
From PROJ_DIR:
set MOC="%QT_BIN%\moc.exe"
set INC_ARGS=-I"..\..\include" -I"..\..\include\internal" -I"%QT_ROOT%\include" -I"%QT_ROOT%\include\QtCore" -I"%QT_ROOT%\include\QtGui" -I"%QT_ROOT%\include\QtWidgets"
%MOC% %INC_ARGS% ..\..\include\internal\QUBSHighlighter.hpp -o GeneratedFiles\moc_QUBSHighlighter.cppAdd three entries.
Inside the <ItemGroup> that contains the other src\internal*.cpp entries, add:
<ClCompile Include="..\..\src\internal\QUBSHighlighter.cpp" />Inside the same <ItemGroup>, next to the other moc_*.cpp entries, add:
<ClCompile Include="GeneratedFiles\moc_QUBSHighlighter.cpp" />Inside the <ItemGroup> that contains the other CustomBuild entries (the moc pattern block), add:
<CustomBuild Include="..\..\include\internal\QUBSHighlighter.hpp">
<FileType>Document</FileType>
<Command>"$(QtDir)\bin\moc.exe" -I"$(ProjectDir)..\..\include" -I"$(ProjectDir)..\..\include\internal" -I"$(QtDir)\include" -I"$(QtDir)\include\QtCore" -I"$(QtDir)\include\QtGui" -I"$(QtDir)\include\QtWidgets" "%(FullPath)" -o "$(ProjectDir)GeneratedFiles\moc_%(Filename).cpp"</Command>
<Outputs>$(ProjectDir)GeneratedFiles\moc_%(Filename).cpp;%(Outputs)</Outputs>
<Message>moc %(Filename).hpp</Message>
</CustomBuild>Edit %SRC_ROOT%\example\src\MainWindow.cpp.
#include <QUBSHighlighter>Find the function that populates the Highlighter QComboBox (likely named createHighlighters(), setupHighlighters() or similar - search for addItem calls with "Python" / "C++" / "XML"). Add alongside existing entries:
ui->highlighterCombo->addItem("UBS");(Use the actual combo pointer name from the existing code.)
In the slot that responds to highlighter combo changes (look for where new QPythonHighlighter(...) is constructed), add a matching branch:
else if (text == "UBS")
{
m_highlighter = new QUBSHighlighter(m_codeEditor->document());
}Match the surrounding pattern - the existing code already handles ownership/replacement of m_highlighter.
If MainWindow.cpp has a function loading sample code per language (look for :/code_samples/python.py or similar resource paths), add a UBS sample entry. A simple sample can be:
! UBS sample
defcolor = "brown";
assert(defcolor $= "brown");
dad = class
this.eyes;
eyes = defcolor;
end;If adding this requires resource changes, skip - the highlighter works against any text.
%MOC% %INC_ARGS% -I..\..\example\include ..\..\example\include\MainWindow.hpp -o GeneratedFiles\moc_MainWindow.cppcd %PROJ_DIR%
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
msbuild QCodeEditor.vcxproj /p:Configuration=Release /p:Platform=Win32#pragma once
#include <internal/QUBSHighlighter.hpp>#pragma once
// QCodeEditor
#include <QStyleSyntaxHighlighter>
#include <QHighlightRule>
// Qt
#include <QVector>
#include <QRegularExpression>
class QSyntaxStyle;
/**
* @brief UBS (Universal Binding Service) syntax highlighter.
* Keywords and built-ins mirror the bindings registered in
* Script::Script() in script.cpp.
*/
class QUBSHighlighter : public QStyleSyntaxHighlighter
{
Q_OBJECT
public:
explicit QUBSHighlighter(QTextDocument* document=nullptr);
protected:
void highlightBlock(const QString& text) override;
private:
QVector<QHighlightRule> m_highlightRules;
QRegularExpression m_commentStartPattern;
QRegularExpression m_commentEndPattern;
};See the separately-generated QUBSHighlighter.cpp file. Keyword list sourced from: