ProjectTemplate.h header
#include <ew/app/ProjectTemplate.h>
Namespace ew::app
ProjectTemplate struct
struct ew::app::ProjectTemplate
The manifest of a project template – a reusable starter project (a genre skeleton such as a novel, a TTRPG campaign, or a screenplay) that a writer can create new projects from or author and share. Stored as a "template.json" file in the template's folder.
Members
QString ew::app::templates::ProjectTemplate::name
The template's display name.
QString ew::app::templates::ProjectTemplate::description
A short description of what the template sets up.
QString ew::app::templates::ProjectTemplate::author
Who authored the template (optional).
QString ew::app::templates::ProjectTemplate::version
The template's version, e.g. "1.0" – so a shared template can be revised and its consumers can tell which revision they have.
QString ew::app::templates::ProjectTemplate::category
The genre/category this template belongs to (e.g. "Novel", "Campaign", "Screenplay"), for grouping in a chooser. Optional.
TemplateEntry struct
struct ew::app::TemplateEntry
A template discovered on disk: its manifest and the absolute path of its folder.
Members
ProjectTemplate ew::app::templates::TemplateEntry::manifest
The template's parsed manifest.
QString ew::app::templates::TemplateEntry::directory
The absolute path of the template's folder.
Functions
bool ew::app::templates::instantiateTemplate(const QString &templateDir, const QString &targetDir)
Instantiates the template folder templateDir into a new project at targetDir by copying the template's files (recursively), excluding the "template.json" manifest so the instance is an ordinary project rather than another template. targetDir is created if needed. Returns true on success; false if the template folder does not exist, the target could not be created, or a file could not be copied.
This copies over a non-empty target rather than refusing it. A file the template also has is REPLACED; a file the target has that the template does not is LEFT IN PLACE. So instantiating into a folder that already holds a project yields a mixture of the two, not the template — a caller that needs the template alone must clear the folder first. (The overwrite is deliberate: re-saving a project as an existing template updates it in place.) A failure part-way through also leaves the files copied so far, since there is no rollback.
std::vector< TemplateEntry > ew::app::templates::listProjectTemplates(const QString &templatesDir)
Lists the project templates under templatesDir: every immediate subfolder that contains a readable "template.json", sorted by template name (then folder name). Returns an empty list when the directory does not exist or holds no templates.
ProjectTemplate ew::app::templates::templateManifestFromJson(const QByteArray &json)
Parses a "template.json" manifest from json. Missing fields become empty strings; malformed JSON yields a default-constructed template.
QByteArray ew::app::templates::templateManifestToJson(const ProjectTemplate &tmpl)
Serialises tmpl to the JSON bytes of a "template.json" manifest.