Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
InjaBridge Class Reference

Adapter for converting Qt JSON types to Inja template engine format. More...

#include <injabridge.h>

Collaboration diagram for InjaBridge:

Static Public Member Functions

static nlohmann::json toInjaJson (const QJsonValue &value)
 Converts a QJsonValue, value, to nlohmann::json.
static nlohmann::json toInjaJson (const QJsonObject &obj)
 Converts a QJsonObject, obj, to nlohmann::json.
static nlohmann::json toInjaJson (const QJsonArray &array)
 Converts a QJsonArray, array, to nlohmann::json.
static QString render (const QString &templateStr, const QJsonObject &data)
 Renders a template string, templateStr, with provided data.
static QString renderFile (const QString &templatePath, const QJsonObject &data)
 Renders a template file with provided data.

Detailed Description

Adapter for converting Qt JSON types to Inja template engine format.

InjaBridge provides static methods to convert between Qt's native JSON types (QJsonObject, QJsonArray, QJsonValue) and nlohmann::json, which is the data format expected by the Inja template engine.

This adapter allows QDoc to maintain its Qt-native API while leveraging Inja for template-based documentation generation. All JSON data in QDoc's intermediate representation (IR) uses Qt types, and InjaBridge handles the conversion when rendering templates.

Note
All numbers in QJsonValue are stored as doubles. When converted to nlohmann::json, integers are rendered with decimal points (e.g., 30 becomes "30.0" in template output). This is expected behavior.
Inja and nlohmann::json may report template or data errors. QDoc is built with exceptions disabled ({-fno-exceptions}), so such errors are treated as fatal and will terminate the process. This is consistent with Qt's no-exception policy for command-line tools.
See also
QJsonObject, QJsonArray, QJsonValue

Definition at line 16 of file injabridge.h.

Member Function Documentation

◆ render()

QString InjaBridge::render ( const QString & templateStr,
const QJsonObject & data )
static

Renders a template string, templateStr, with provided data.

Uses Inja to render the template with the given JSON data. The data is automatically converted from QJsonObject to nlohmann::json.

The Inja template string, templateStr, supports Jinja2 syntax. data is the JSON data to use for rendering.

Returns the rendered template as a QString.

Definition at line 109 of file injabridge.cpp.

◆ renderFile()

QString InjaBridge::renderFile ( const QString & templatePath,
const QJsonObject & data )
static

Renders a template file with provided data.

Loads and renders a template from the filesystem, using templatePath which holds the absolute path to the template file. The file should use Inja/Jinja2 syntax. data is the JSON data to use for rendering.

Returns the rendered template as a QString.

Definition at line 129 of file injabridge.cpp.

◆ toInjaJson() [1/3]

nlohmann::json InjaBridge::toInjaJson ( const QJsonArray & array)
static

Converts a QJsonArray, array, to nlohmann::json.

Recursively converts all elements in the array, preserving order. Mixed-type arrays are supported.

Returns the equivalent nlohmann::json array.

Definition at line 88 of file injabridge.cpp.

◆ toInjaJson() [2/3]

nlohmann::json InjaBridge::toInjaJson ( const QJsonObject & obj)
static

Converts a QJsonObject, obj, to nlohmann::json.

Recursively converts all values in the object, preserving the key-value structure. Nested objects and arrays are handled correctly.

Returns the equivalent nlohmann::json object.

Definition at line 70 of file injabridge.cpp.

◆ toInjaJson() [3/3]

nlohmann::json InjaBridge::toInjaJson ( const QJsonValue & value)
static

Converts a QJsonValue, value, to nlohmann::json.

Handles all QJsonValue types: Null, Bool, Double, String, Array, Object, and Undefined. Undefined values are treated as null.

Returns the equivalent nlohmann::json representation.

Definition at line 41 of file injabridge.cpp.


The documentation for this class was generated from the following files: