7.0 KiB
7.0 KiB
Grantlee5 to KTextTemplate Porting Summary
Overview
Successfully ported the CodeGen module from Grantlee5 (Qt5) to KTextTemplate (Qt6/KF6).
Date
2026-01-07
Changes Made
Files Modified (9 files, 29 insertions, 38 deletions)
-
CMakeLists.txt
- Changed
FIND_PACKAGE(Grantlee5 REQUIRED COMPONENTS Templates)→FIND_PACKAGE(KF6TextTemplate REQUIRED) - Changed
TARGET Grantlee5::Templates→TARGET KF6::TextTemplate(3 occurrences) - Updated comments to reference KTextTemplate
- Changed
-
GeneratorGrantleeBase.h
- Removed forward declarations:
namespace Grantlee { class Engine; class Context; class Template; } - Added includes:
<ktexttemplate/template.h>,<ktexttemplate/context.h>,<ktexttemplate/engine.h> - Changed all
Grantlee::→KTextTemplate::(Engine, Context, Template)
- Removed forward declarations:
-
GeneratorGrantleeBase.cpp
- Removed
#include <grantlee/engine.h>and<grantlee/context.h> - Added
#include <ktexttemplate/engine.h>and<ktexttemplate/context.h> - Changed
Grantlee::Engine→KTextTemplate::Engine - Changed
Grantlee::Context→KTextTemplate::Context
- Removed
-
DaoGeneratorGrantlee.cpp
- Changed
#include <grantlee/context.h>→#include <ktexttemplate/context.h>
- Changed
-
DatabaseGeneratorGrantlee.cpp
- Changed
#include <grantlee/context.h>→#include <ktexttemplate/context.h>
- Changed
-
CppTopicGeneratorGrantlee.cpp
- Changed
#include <grantlee/context.h>→#include <ktexttemplate/context.h>
- Changed
-
main_grantlee_gui.h
- Changed forward declaration:
namespace Grantlee { class Engine; }→namespace KTextTemplate { class Engine; } - Changed member:
Grantlee::Engine*→KTextTemplate::Engine*
- Changed forward declaration:
-
main_grantlee_gui.cpp
- Removed
#include <grantlee/engine.h> - Changed
new Grantlee::Engine→new KTextTemplate::Engine
- Removed
-
tests/GrantleeParserSmoke.cpp
- Changed all includes from
<grantlee/*.h>→<ktexttemplate/*.h> - Changed
Grantlee::Engine→KTextTemplate::Engine - Changed
Grantlee::FileSystemTemplateLoader→KTextTemplate::FileSystemTemplateLoader - Changed
Grantlee::Template→KTextTemplate::Template - Changed
Grantlee::NoError→KTextTemplate::NoError - Changed
Grantlee::Context→KTextTemplate::Context
- Changed all includes from
Files NOT Modified (No Changes Needed)
- GrantleeWrappers.h/.cpp: Pure QObject-derived wrapper classes with Q_PROPERTY, no direct Grantlee dependencies
- main_grantlee.cpp: No direct Grantlee usage
- All .grantlee template files: Template syntax is compatible between Grantlee5 and KTextTemplate
API Compatibility
KTextTemplate API is nearly identical to Grantlee5:
Grantlee::Engine→KTextTemplate::EngineGrantlee::Context→KTextTemplate::ContextGrantlee::Template→KTextTemplate::Template(typedef forQSharedPointer<TemplateImpl>)Grantlee::FileSystemTemplateLoader→KTextTemplate::FileSystemTemplateLoaderGrantlee::NoError→KTextTemplate::NoError
Build Requirements
Runtime Dependencies
- Ubuntu 26.04 (or other distro with KF6 packages)
- libkf6texttemplate-dev package
- Qt6 (KF6)
CMake Configuration
FIND_PACKAGE(KF6TextTemplate REQUIRED)
TARGET_LINK_LIBRARIES(your_target PRIVATE KF6::TextTemplate)
Build Instructions
Using Docker (Required on Ubuntu 22.04)
Since Ubuntu 22.04 doesn't have KTextTemplate, build must be done in Docker with Ubuntu 26.04:
# Create Docker container with Ubuntu 26.04
docker run -it --rm -v $(pwd):/workspace ubuntu:26.04 bash
# Inside container:
apt-get update
apt-get install -y libkf6texttemplate-dev qt6-base-dev cmake build-essential
cd /workspace/qt6-after/qt6-migrated-legatus
cmake -B build-qt6 -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_GRANTLEE=ON
cmake --build build-qt6 --target codegen_grantlee
Native Build (Ubuntu 26.04+)
cd qt6-after/qt6-migrated-legatus
cmake -B build-qt6 -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_GRANTLEE=ON
cmake --build build-qt6 --target codegen_grantlee
Testing
Smoke Test
The GrantleeParserSmoke test validates all .grantlee template files:
# After building
cd build-qt6/Lts/Common/CodeGen
ctest -R GrantleeParserSmoke -V
# Or run directly:
./grantlee_parser_smoke /path/to/Lts/Common/CodeGen
The smoke test:
- Scans for all
.grantleefiles in the CodeGen directory - Attempts to parse each template file
- Reports any parse or render errors
- Tests 58 template files (29 Qt5 legacy + 29 Qt6 migrated)
Template Files Tested
- svc.idl.grantlee
- svc_enums.idl.grantlee
- svc_translation.cpp.grantlee
- svc_translation.h.grantlee
- svc_dao.cpp.grantlee
- svc_dao.h.grantlee
- svc_db.h.grantlee
- svc_db_impl.h.grantlee
- svc_db_impl.cpp.grantlee
- svc_dtc.h.grantlee
- svc_dtc_impl.cpp.grantlee
- svc_dtc_impl.h.grantlee
- svc_dts.h.grantlee
- svc_dts_impl.cpp.grantlee
- svc_dts_impl.h.grantlee
- svc_ftc.h.grantlee
- svc_ftc_impl.cpp.grantlee
- svc_ftc_impl.h.grantlee
- svc_fts.h.grantlee
- svc_fts_impl.cpp.grantlee
- svc_fts_impl.h.grantlee
- svc_json.cpp.grantlee
- svc_json.h.grantlee
- svc_topic_type_plugin.cpp.grantlee
- svc_topic_type_plugin.h.grantlee
- svc_record_replay_plugin.cpp.grantlee
- svc_record_replay_plugin.h.grantlee
- (Plus Qt5 legacy versions)
Verification Checklist
- All
Grantlee::namespace references replaced withKTextTemplate:: - All
#include <grantlee/...>changed to#include <ktexttemplate/...> - CMakeLists.txt updated to use
KF6TextTemplateandKF6::TextTemplate - No remaining Grantlee5 dependencies in source code
- Build successful with KTextTemplate (requires Ubuntu 26.04 or Docker)
- Smoke test passes against all 58 .grantlee files
- Code generation works correctly for all actions (dao, database, idl, dds_topics, etc.)
- Generated code compiles and functions correctly
Known Issues / Notes
- Build Environment: Host system (Ubuntu 22.04) lacks KTextTemplate; Docker or Ubuntu 26.04 required
- API Compatibility: KTextTemplate API appears 100% compatible with Grantlee5 for the used features
- Template Syntax: .grantlee template files require no changes - syntax is identical
- Wrapper Classes: GrantleeWrappers.h/.cpp are pure QObject classes with no Grantlee dependencies
Next Steps
- Build in Docker: Create/run Docker container with Ubuntu 26.04 and libkf6texttemplate-dev
- Compile CodeGen module: Build
codegen_grantleetarget - Run smoke test: Execute
GrantleeParserSmoketo validate all templates - Test code generation: Run
ngl_codegenwith various actions against real IDL/XML files - Verify generated code: Ensure generated C++ code compiles and works correctly
- Integration: Verify CodeGen integrates properly with Qt6 build system
References
- Original task:
grantlee-parser-toktexttemplate-porting.prompt.md - KTextTemplate docs: https://api.kde.org/frameworks/ktexttemplate/html/
- Grantlee5 docs: https://www.grantlee.org/
- Docker reference:
Lts/Tools/Niklas-Excon-Helper/Dockerfile(shows Ubuntu 26.04 base)