]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/TocModel.h
Simplify TocModel by using UserRole data.
[lyx.git] / src / frontends / qt4 / TocModel.h
1 // -*- C++ -*-
2 /**
3  * \file TocModel.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef TOCMODEL_H
13 #define TOCMODEL_H
14
15 #include "qt_helpers.h"
16
17 #include <QList>
18 #include <QStandardItemModel>
19 #include <QStringList>
20
21 namespace lyx {
22
23 class Buffer;
24 class BufferView;
25 class DocIterator;
26 class Toc;
27 class TocItem;
28
29 namespace frontend {
30
31 class TocModel : public QStandardItemModel
32 {
33 public:
34         ///
35         TocModel(Toc const & toc);
36         ///
37         void clear();
38         ///
39         TocItem const & tocItem(QModelIndex const & index) const;
40         ///
41         QModelIndex modelIndex(DocIterator const & dit) const;
42         ///
43         int modelDepth() const;
44
45 private:
46         ///
47         void populate(size_t & index, QModelIndex const & parent);
48         ///
49         QList<QModelIndex> toc_indexes_;
50         ///
51         Toc const & toc_;
52         ///
53         int maxdepth_;
54         int mindepth_;
55 };
56
57
58 class TocModels: public QObject
59 {
60         Q_OBJECT
61 public:
62         ///
63         TocModels(): bv_(0) {}
64         ///
65         ~TocModels() { clear(); }
66         ///
67         void reset(BufferView const * bv);
68         ///
69         int depth(int type);
70         ///
71         QStandardItemModel * model(int type);
72         ///
73         QModelIndex currentIndex(int type) const;
74         ///
75         void goTo(int type, QModelIndex const & index) const;
76         ///
77         void init(Buffer const & buffer);
78         /// Test if outlining operation is possible
79         bool canOutline(int type) const;
80         /// Return the list of types available
81         QStringList const & typeNames() const { return type_names_; }
82         ///
83         void updateBackend() const;
84         ///
85         int decodeType(QString const & str) const;
86
87 Q_SIGNALS:
88         /// Signal that the internal toc_models_ has been reset.
89         void modelReset();
90
91 private:
92         ///
93         void clear();
94         ///
95         BufferView const * bv_;
96         ///
97         QList<TocModel *> models_;
98         ///
99         QStringList types_;
100         ///
101         QStringList type_names_;
102 };
103
104 } // namespace frontend
105 } // namespace lyx
106
107 #endif // TOCMODEL_H