diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-06 23:14:21 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-06 23:14:21 +0200 |
| commit | 3aed883402dc8da829fc304434c5efd0570cbb97 (patch) | |
| tree | 48c46ab087a950d80f78819ceb609e93d246b040 /src/documentoutlinemodel.hpp | |
| parent | 44e85dce678e7e36f436a6d0a25c212c9a2d3657 (diff) | |
| download | kristall-3aed883402dc8da829fc304434c5efd0570cbb97.tar.gz | |
Moves source code into subdirectory.
Diffstat (limited to 'src/documentoutlinemodel.hpp')
| -rw-r--r-- | src/documentoutlinemodel.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/documentoutlinemodel.hpp b/src/documentoutlinemodel.hpp new file mode 100644 index 0000000..0476892 --- /dev/null +++ b/src/documentoutlinemodel.hpp @@ -0,0 +1,57 @@ +#ifndef DOCUMENTOUTLINEMODEL_HPP +#define DOCUMENTOUTLINEMODEL_HPP + +#include <QAbstractItemModel> +#include <QList> + +class DocumentOutlineModel : + public QAbstractItemModel +{ + Q_OBJECT +public: + DocumentOutlineModel(); + + void clear(); + + void beginBuild(); + + void appendH1(QString const & title, QString const & anchor); + + void appendH2(QString const & title, QString const & anchor); + + void appendH3(QString const & title, QString const & anchor); + + void endBuild(); + + QString getTitle(QModelIndex const & index) const; + QString getAnchor(QModelIndex const & index) const; + +public: + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + + QModelIndex parent(const QModelIndex &child) const override; + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + +private: + struct Node + { + Node * parent; + QString title; + QString anchor; + int depth = 0; + int index = 0; + QList<Node> children; + }; + + Node root; + + Node & ensureLevel1(); + Node & ensureLevel2(); +}; + +#endif // DOCUMENTOUTLINEMODEL_HPP |
