Content is user-generated and unverified.

Claude Code Task List - Add QUBSHighlighter to QCodeEditor

Target: add a UBS-specific syntax highlighter to the existing VS 2015 QCodeEditor project and wire it into the example MainWindow.

Paths

  • QT_ROOT = C:\Qt\Qt5.14.2\5.14.2\msvc2017
  • QT_BIN = %QT_ROOT%\bin
  • SRC_ROOT = C:\Win32CodeProjects\CppUbs3win32\QCodeEditor
  • PROJ_DIR = %SRC_ROOT%\vs2015\QCodeEditor

Step 1 - Place source files (Claude Code writes these from Appendix A, B, C)

  • %SRC_ROOT%\include\QUBSHighlighter (no extension, forwarding header)
  • %SRC_ROOT%\include\internal\QUBSHighlighter.hpp
  • %SRC_ROOT%\src\internal\QUBSHighlighter.cpp

Step 2 - Pre-generate moc output for the new header

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.cpp

Step 3 - Edit QCodeEditor.vcxproj

Add three entries.

3a - Source compile entry

Inside the <ItemGroup> that contains the other src\internal*.cpp entries, add:

xml
<ClCompile Include="..\..\src\internal\QUBSHighlighter.cpp" />

3b - Generated moc compile entry

Inside the same <ItemGroup>, next to the other moc_*.cpp entries, add:

xml
<ClCompile Include="GeneratedFiles\moc_QUBSHighlighter.cpp" />

3c - CustomBuild entry for moc

Inside the <ItemGroup> that contains the other CustomBuild entries (the moc pattern block), add:

xml
<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>

Step 4 - Wire into example MainWindow

Edit %SRC_ROOT%\example\src\MainWindow.cpp.

4a - Add include near the top with the other highlighter includes

cpp
#include <QUBSHighlighter>

4b - Add "UBS" to the highlighter combo list

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:

cpp
ui->highlighterCombo->addItem("UBS");

(Use the actual combo pointer name from the existing code.)

4c - Dispatch on "UBS" selection

In the slot that responds to highlighter combo changes (look for where new QPythonHighlighter(...) is constructed), add a matching branch:

cpp
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.

4d - Optional: add a UBS entry to the Code sample combo

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.

Step 5 - Regenerate moc for MainWindow (it changed)

%MOC% %INC_ARGS% -I..\..\example\include ..\..\example\include\MainWindow.hpp -o GeneratedFiles\moc_MainWindow.cpp

Step 6 - Rebuild

cd %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

Step 7 - Verify

  • Launch %PROJ_DIR%\Release\QCodeEditor.exe
  • Highlighter combo contains "UBS"
  • Selecting UBS and pasting UBS script shows keywords (class, function, inherit, assert, end, if, while, for) coloured as Keyword, built-ins (print, assert, wgui, msoffice, ai) coloured as BuiltIn, strings/numbers/comments highlighted correctly

Appendix A - include\QUBSHighlighter (forwarding header, no extension)

cpp
#pragma once

#include <internal/QUBSHighlighter.hpp>

Appendix B - include\internal\QUBSHighlighter.hpp

cpp
#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;
};

Appendix C - src\internal\QUBSHighlighter.cpp

See the separately-generated QUBSHighlighter.cpp file. Keyword list sourced from:

  • script.cpp Script::Script() bindNative() calls (control flow, block ops, end/inherit/data/args/this)
  • script.cpp Script::Script() bindBindable() calls (print, assert, exists, remove, after, addon, dialogs, whttp*, json*, csv*, ascii*, ai, msoffice)
  • UBS_GUI_Architecture.docx (wgui, wguievents, wevents, guicla, guipropcla)

Troubleshooting

  • LNK2019 on QUBSHighlighter::staticMetaObject: moc_QUBSHighlighter.cpp not compiled - confirm Step 3b
  • Highlighter selected but nothing highlights: SyntaxStyle must define "Keyword", "BuiltIn", "Number", "String", "Comment", "Function" format names - the default style already has these
  • moc parse error on QUBSHighlighter.hpp: confirm the file is the internal header (has Q_OBJECT), not the forwarding header
Content is user-generated and unverified.
    QUBSHighlighter Integration Guide for QCodeEditor | Claude