aboutsummaryrefslogtreecommitdiff
path: root/documentoutlinemodel.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-06 22:23:20 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-06 22:23:20 +0200
commitd9e105e6e0accf5def8681334341069117cab213 (patch)
tree68764c76f67326aaa3f731ce70726e821c00e11a /documentoutlinemodel.cpp
parent87d787bc2c50eb00c6b86957efaa71e07f9acc07 (diff)
downloadkristall-d9e105e6e0accf5def8681334341069117cab213.tar.gz
Navigation via outline is now possible. Sexy!
Diffstat (limited to 'documentoutlinemodel.cpp')
-rw-r--r--documentoutlinemodel.cpp38
1 files changed, 29 insertions, 9 deletions
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,
- "<ROOT>",
+ "<ROOT>", "",
0, 0,
QList<Node> { },
};
}
-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<Node> { },
});
}
-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<Node> { },
});
}
-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<Node> { },
});
@@ -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<Node const *>(index.internalPointer());
+
+ return childItem->title;
+}
+
+QString DocumentOutlineModel::getAnchor(const QModelIndex &index) const
+{
+ if(not index.isValid())
+ return "";
+
+ Node const *childItem = static_cast<Node const *>(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,
- "<missing layer>",
+ "<missing layer>", "",
1, 0,
QList<Node> { },
});
@@ -170,7 +190,7 @@ DocumentOutlineModel::Node & DocumentOutlineModel::ensureLevel2()
if(parent.children.size() == 0) {
root.children.append(Node {
&parent,
- "<missing layer>",
+ "<missing layer>", "",
2, 0,
QList<Node> { },
});