From d9e105e6e0accf5def8681334341069117cab213 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Sat, 6 Jun 2020 22:23:20 +0200 Subject: Navigation via outline is now possible. Sexy! --- documentoutlinemodel.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'documentoutlinemodel.cpp') diff --git a/documentoutlinemodel.cpp b/documentoutlinemodel.cpp index 47ff3b5..5978f33 100644 --- a/documentoutlinemodel.cpp +++ b/documentoutlinemodel.cpp @@ -21,39 +21,39 @@ void DocumentOutlineModel::beginBuild() beginResetModel(); root = Node { nullptr, - "", + "", "", 0, 0, QList { }, }; } -void DocumentOutlineModel::appendH1(const QString &title) +void DocumentOutlineModel::appendH1(const QString &title, QString const & anchor) { root.children.append(Node { &root, - title, + title, anchor, 1, 0, QList { }, }); } -void DocumentOutlineModel::appendH2(const QString &title) +void DocumentOutlineModel::appendH2(const QString &title, QString const & anchor) { auto & parent = ensureLevel1(); parent.children.append(Node { &parent, - title, + title, anchor, 2, parent.children.size() - 1, QList { }, }); } -void DocumentOutlineModel::appendH3(const QString &title) +void DocumentOutlineModel::appendH3(const QString &title, QString const & anchor) { auto & parent = ensureLevel2(); parent.children.append(Node { &parent, - title, + title, anchor, 3, parent.children.size() - 1, QList { }, }); @@ -79,6 +79,26 @@ void DocumentOutlineModel::endBuild() endResetModel(); } +QString DocumentOutlineModel::getTitle(const QModelIndex &index) const +{ + if(not index.isValid()) + return ""; + + Node const *childItem = static_cast(index.internalPointer()); + + return childItem->title; +} + +QString DocumentOutlineModel::getAnchor(const QModelIndex &index) const +{ + if(not index.isValid()) + return ""; + + Node const *childItem = static_cast(index.internalPointer()); + + return childItem->anchor; +} + QModelIndex DocumentOutlineModel::index(int row, int column, const QModelIndex &parent) const { if (not hasIndex(row, column, parent)) @@ -155,7 +175,7 @@ DocumentOutlineModel::Node & DocumentOutlineModel::ensureLevel1() if(root.children.size() == 0) { root.children.append(Node { &root, - "", + "", "", 1, 0, QList { }, }); @@ -170,7 +190,7 @@ DocumentOutlineModel::Node & DocumentOutlineModel::ensureLevel2() if(parent.children.size() == 0) { root.children.append(Node { &parent, - "", + "", "", 2, 0, QList { }, }); -- cgit v1.2.3