ManuscriptTree.h header

#include <ew/core/document/ManuscriptTree.h>

Namespace ew::core::document

ManuscriptOrder class

class ew::core::document::ManuscriptOrder

Every parent's ordered children, indexed once for a walk that asks about many parents.

orderedChildDocumentIds answers for ONE parent by scanning the whole project, which is right for a single question and quadratic for a tree: the document tree model asks it per node while populating, and so do the manuscript export's recursion, the corkboard and the scene analysis. n nodes times an O(n) scan took 20.6 seconds to walk a 4,000-document manuscript (P-01's sibling defect, P-02).

Building this is one pass and one sort per sibling group; each answer is then a lookup.

Sibling order is still defined in exactly one place, and that place is the precedes comparator both this and orderedChildDocumentIds call – NOT one function implemented on top of the other. That was the first shape, and it made a single-parent question 2.4x slower by indexing and sorting every sibling group in the manuscript to answer about one. The shared comparator is what keeps the model and the reorder commands from drifting apart, which is the property the free function exists to guarantee.

A SNAPSHOT, not a view. It reads the project once; a document added, removed, re-parented or re-sorted afterwards is not reflected. Build one per operation (a rebuild, an export, a count) and let it go.

Members

ew::core::document::ManuscriptOrder::ManuscriptOrder(const ew::core::project::Project &project)

Indexes project's documents by parent, each sibling group in manuscript-tree order.

const std::vector< ew::core::foundation::ContentId > & ew::core::document::ManuscriptOrder::children(ew::core::foundation::ContentId parentId) const

The ids of the documents whose parent is parentId (top-level documents if it is null), in manuscript-tree order. An unknown parent – including a leaf – yields an empty list.

Functions

ew::core::foundation::ContentId ew::core::document::corkboardContainer(const ew::core::project::Project &project, ew::core::foundation::ContentId selected)

The container whose children a corkboard should show for the current selection: the selected document if it has children, otherwise the selected document's parent (so a leaf shows its siblings). A null selection – or a leaf with no parent – yields a null id, meaning the top level.

int ew::core::document::descendantDocumentCount(const ew::core::project::Project &project, ew::core::foundation::ContentId rootId)

How many documents sit under rootId, at any depth.

The manuscript walk starts at the top level and descends, so a document whose parent no longer exists is never reached. Deleting a container therefore drops its whole subtree out of the manuscript tree and out of every export while the documents still sit on disk – which is worth telling the user before they agree to it, and worth telling an MCP caller afterwards (F-0077).

Bounded by the document count, so a parent cycle in a hand-edited project cannot spin it.

int ew::core::document::dropInsertionIndex(const ew::core::project::Project &project, ew::core::foundation::ContentId documentId, ew::core::foundation::ContentId newParentId, int row)

The insertion index to pass to MoveDocumentCommand for a drag that drops documentId under newParentId at visual position row (or -1 to append). When the document stays under the same parent it is removed from the list before reinsertion, so a drop below its current position is shifted up by one; cross-parent drops are used as given.

ew::core::foundation::ContentId ew::core::document::findChildDocumentByTitle(const ew::core::project::Project &project, ew::core::foundation::ContentId parentId, const QString &title)

The id of the child document of parentId (top-level if it is null) whose title is exactly title, or a null id if none matches. Used to find-or-create well-known documents such as the daily-notes folder and a given day's note.

std::vector< ew::core::foundation::ContentId > ew::core::document::orderedChildDocumentIds(const ew::core::project::Project &project, ew::core::foundation::ContentId parentId)

The ids of the documents whose parent is parentId (top-level documents if it is null), in manuscript-tree order: ascending sort index, then title, then id.

Sibling order is defined once, in the precedes comparator this and ManuscriptOrder both use, so a manuscript reads the same everywhere – through whichever of the two a caller reaches for. The commands that reorder documents call this one.

Scans the whole project, which is the right cost for ONE question. Asking about many parents – a tree walk, an export, a subtree count – wants ManuscriptOrder, which the document tree model, the export recursion, the corkboard and the scene analysis all hold.