aboutsummaryrefslogtreecommitdiff
path: root/documentoutlinemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'documentoutlinemodel.cpp')
-rw-r--r--documentoutlinemodel.cpp47
1 files changed, 37 insertions, 10 deletions
diff --git a/documentoutlinemodel.cpp b/documentoutlinemodel.cpp
index a47dafa..47ff3b5 100644
--- a/documentoutlinemodel.cpp
+++ b/documentoutlinemodel.cpp
@@ -39,15 +39,7 @@ void DocumentOutlineModel::appendH1(const QString &title)
void DocumentOutlineModel::appendH2(const QString &title)
{
- if(root.children.size() == 0) {
- root.children.append(Node {
- &root,
- "<missing layer>",
- 1, 0,
- QList<Node> { },
- });
- }
- auto & parent = root.children.last();
+ auto & parent = ensureLevel1();
parent.children.append(Node {
&parent,
title,
@@ -58,7 +50,13 @@ void DocumentOutlineModel::appendH2(const QString &title)
void DocumentOutlineModel::appendH3(const QString &title)
{
-
+ auto & parent = ensureLevel2();
+ parent.children.append(Node {
+ &parent,
+ title,
+ 3, parent.children.size() - 1,
+ QList<Node> { },
+ });
}
void DocumentOutlineModel::endBuild()
@@ -151,3 +149,32 @@ QVariant DocumentOutlineModel::data(const QModelIndex &index, int role) const
return item->title;
}
+
+DocumentOutlineModel::Node & DocumentOutlineModel::ensureLevel1()
+{
+ if(root.children.size() == 0) {
+ root.children.append(Node {
+ &root,
+ "<missing layer>",
+ 1, 0,
+ QList<Node> { },
+ });
+ }
+ return root.children.last();
+}
+
+DocumentOutlineModel::Node & DocumentOutlineModel::ensureLevel2()
+{
+ auto & parent = ensureLevel1();
+
+ if(parent.children.size() == 0) {
+ root.children.append(Node {
+ &parent,
+ "<missing layer>",
+ 2, 0,
+ QList<Node> { },
+ });
+ }
+
+ return parent.children.last();
+}