DocumentVariantOps.h header

#include <ew/app/DocumentVariantOps.h>

Namespace ew::app

VariantState struct

struct ew::app::VariantState

The three pieces of a document's variant state that change together when the writer creates or switches drafts: the parked alternate variants, the name of the active draft, and the live body. A caller applies these to a document as one undoable step (SetDocumentVariantsCommand).

Members

std::vector<ew::core::document::DocumentVariant> ew::app::document::VariantState::variants

The parked alternate drafts (every variant except the active one).

QString ew::app::document::VariantState::activeName

The name of the active draft (whose content is the body).

QString ew::app::document::VariantState::body

The live body content.

ew::core::document::BodyFormat ew::app::document::VariantState::format =

What kind of text body is – the format of whichever draft is now live.

Functions

VariantState ew::app::document::addVariant(const std::vector< ew::core::document::DocumentVariant > &variants, const QString &activeName, const QString &body, ew::core::document::BodyFormat format, const QString &newName, const QString &fallbackName)

Computes the state after creating a new variant newName from the current draft: the current draft (activeName, or fallbackName when empty) is parked and newName becomes the active draft, seeded with a copy of the current body so the writer can then diverge it. The body is unchanged (the copy stays live); only the active name and the parked list change. Both copies are the same text, so both carry format.

VariantState ew::app::document::switchVariant(const std::vector< ew::core::document::DocumentVariant > &variants, const QString &activeName, const QString &body, ew::core::document::BodyFormat format, int targetIndex, const QString &fallbackName)

Computes the state after switching the active draft to parked variant targetIndex: the current live draft (activeName, body, format) is parked into that slot and the target variant becomes live, so no draft is lost. activeName falls back to fallbackName when empty (the current draft had no name yet). Returns the state unchanged if targetIndex is out of range.

format travels with the body in BOTH directions, because a parked draft can be a different kind of text from the one replacing it: the Markdown migration converts a variant only when it can do so losslessly, so a draft that used colour or a font is still legacy HTML while the main body is Markdown. Swapping bodies without their tags made the document claim one format and hold the other, and every export then shipped raw HTML as visible text (F-0071).